03-01-2016 02:34 PM
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?
03-01-2016 02:36 PM
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.
03-01-2016 03:10 PM
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
Unofficial Forum Rules and Guidelines
Get going with G! - LabVIEW Wiki.
17 Part Blog on Automotive CAN bus. - Hooovahh - LabVIEW Overlord
04-04-2019 12:24 PM - edited 04-04-2019 12:29 PM
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.
04-04-2019 01:29 PM
Ryan,
try this:
04-04-2019 01:43 PM
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.
04-04-2019 02:17 PM
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.
04-04-2019 02:35 PM
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.
04-04-2019 02:43 PM
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.
04-04-2019 02:50 PM
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.