LabVIEW APIs Discussions

cancel
Showing results for 
Search instead for 
Did you mean: 

Replace Control in a template with selected control

I orignally posted this in the Blog instead of the discussion. Here is my original question, and the first response I got below that...

Hello,

I have a template that takes in a control. I would like to write a scripting program that if I select a control in another VI (not necessarily a type def) I could create a VI from that template with the selected control replacing the input placeholder control. The problem is the replace invoke node allows me to choose a style, path, or palette string. I want this to work even if the selected control is not saved as a type def, and it could be a cluster thus not appearing in the palette. Can I even use replace in this scenario?

  • You are better off posting this in the Scripting community... BUT -  I have done this very thing on scripting code I use to automate code writing for LabVIEW Class Replication, and other scripting tools like auto create of Functional Global Variables. What I did was allow for either built-in LabVIEW Controls to be selected as the data type and then created code to open a new .ctl file and let the developer create the control and then when the developer closes the .ctl file I save to a temporary location thus giving me a path to the control. The code then deletes the temporary control file when done. If it is a tyepdef type of control that is already created by the developer then I just open a File Dialog and ask them to select the control - this also gives a Path. Having a path in both instances allows me to use the same Scripting Code to enact the VI Control replacement.

0 Kudos
Message 1 of 11
(8,731 Views)

https://decibel.ni.com/content/thread/2952?tstart=0

I tried to easily link the Main Scripting Board to the topic in my reply - let me know if that link above does not work.  Its a little difficult to use that discussion topic, but there is a lot of good information in it.

That was my reply above.  Let me know if I was not clear enough.

Ryan Vallieu CLA, CLED
Senior Systems Analyst II
NASA Ames Research Center
0 Kudos
Message 2 of 11
(8,444 Views)

This is a bit overly complicated, but here is some code I posted a while ago which is intended to replace controls using scripting.  While it isn't exactly what you want you might learn something about how scripting and control replacing works.

http://forums.ni.com/t5/LabVIEW/Replace-cluster-bug/m-p/3148093#M906580

0 Kudos
Message 3 of 11
(8,444 Views)

Without the ability to use a control reference I was unsure how to get specifically created custom controls to replace items on a "template" VI.  Property:Style ID from the Control Ref wired to the Replace: Style input?

 

I'm trying that now as I am writing some more scripting tools to replace controls in a VI copied from a template with user selected controls.  Using the Path function gave me the exact control the user desired and set up the way they wanted without it being a typedef.  For instance if I have a Boolean and want to replace with a Double - the user just drops the double on the VI front panel, the code detects the control, replaces the template control, forces an update if needed and saves the new VI, library, Class, etc.

Ryan Vallieu CLA, CLED
Senior Systems Analyst II
NASA Ames Research Center
0 Kudos
Message 4 of 11
(6,968 Views)

Ryan, 

              try this:

 

ryan.png

Sam Taggart
CLA, CPI, CTD, LabVIEW Champion
DQMH Trusted Advisor
Read about my thoughts on Software Development at sasworkshops.com/blog
GCentral
0 Kudos
Message 5 of 11
(6,960 Views)

Sorry I think I misunderstood what you were asking for.  I thought you were having trouble finding the control but rereading, it seems you are having trouble replacing it.

Sam Taggart
CLA, CPI, CTD, LabVIEW Champion
DQMH Trusted Advisor
Read about my thoughts on Software Development at sasworkshops.com/blog
GCentral
0 Kudos
Message 6 of 11
(6,956 Views)

Yes, traverse and finding the control is not an issue.  The replace Scripting function doesn't allow a control reference input. It requires a Path to a call file, Style input or Palette String.  The Path works fine for me.  Just trying the style option to see if it works on ANY control.

Ryan Vallieu CLA, CLED
Senior Systems Analyst II
NASA Ames Research Center
0 Kudos
Message 7 of 11
(6,952 Views)

https://forums.ni.com/t5/LabVIEW/Using-scripting-to-copy-a-cluster-from-one-vi-to-another/td-p/10870...

 

You could try the move method (to a new vi with duplicate true) on the control or create selection, copy and then paste.  That would get it from 1 VI to another.

 

Then you could you could just use the terminal and the wiring methods to rewire.  Seems like a pain.  

 

Let me look.  I might have somethinng already.  I feel like I have done this before.

Sam Taggart
CLA, CPI, CTD, LabVIEW Champion
DQMH Trusted Advisor
Read about my thoughts on Software Development at sasworkshops.com/blog
GCentral
0 Kudos
Message 8 of 11
(6,949 Views)

Sorry.  Just looked through my scripting toolbox and I don't have that.

 

Another thought might be to save the ctl off to a temp file, do the replacement and then delete it.

 

You could also do a VI method called create from datatype, but I that won't preserve the attributes at all.

Sam Taggart
CLA, CPI, CTD, LabVIEW Champion
DQMH Trusted Advisor
Read about my thoughts on Software Development at sasworkshops.com/blog
GCentral
0 Kudos
Message 9 of 11
(6,946 Views)

So we've come full circle to my original solution 😄

 

The saving to a temp file is my current implementation - simple enough actually.  I was just reacting to Hoovahs reply that it seemed overly complicated, but I couldn't find another way to do it more easily.

Ryan Vallieu CLA, CLED
Senior Systems Analyst II
NASA Ames Research Center
0 Kudos
Message 10 of 11
(6,943 Views)