LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

VI scripting: Cleaning up code inside structures

Solved!
Go to solution

I want to programmatically run the cleanup method on a subdiagram contained within a structure (a for-loop in this case). When I attempt to do so, as shown below, I get an error saying that LabVIEW cannot locate the cleanup method. Note: TargetVI.vi contains one for-loop.

ForLoop.Diagram.CleanUpForLoop.Diagram.CleanUp

When I attempt to cleanup the entire VI I don't get the error. The two ways I try this are shown below.

VI.BD.CleanUpVI.BD.CleanUpForLoop.Owner.CleanUpForLoop.Owner.CleanUp

Since you can cleanup selected parts of a VI using the cleanup tool in the editor I thought this has to be doable with VI scripting. Any idea what I might be doing wrong?

 

I am using LabVIEW 17.0.1f3 and I am attaching the VIs I used to take the screenshots here (in case anyone wishes to try to recreate this on their machine).

 

Thanks,

Ghassan

Message 1 of 6
(2,461 Views)
Solution
Accepted by topic author Ghassan.A

Some of the other methods for subdiagrams seem to be broken too.

But you can just select the objects in the For Loop, then use cleanup method for the top level diagram.

See attachment.

"If you weren't supposed to push it, it wouldn't be a button."
Message 2 of 6
(2,408 Views)

Hi,

 

it seems like there is no invoke-method for "clean selection". You can try something like:

1. copy the FOR loop into a blank VI

2. clean the block diagram there (which consists only of the loop)

3. copy it back into your target VI

4. connect the tunnels

5. remove the original loop

I tried an approach like that and came out with the attached code. Sorry for the huge mess.. I just don't have any more time right now...

 

PS: Error-wires deserve love, too 😉

ʍolɟɐʇɐp ʞuıɥʇ
Message 3 of 6
(2,385 Views)

If you add elements to the selection list then call the BD.Cleanup method (of the *VI* class), it will clean up the selection instead of the whole diagram.

Message 4 of 6
(2,372 Views)

@Darren wrote:

If you add elements to the selection list then call the BD.Cleanup method (of the *VI* class), it will clean up the selection instead of the whole diagram.


Works fine, I just tried it. But you have to make sure you add all object refs, all wire refs of the loop into the selection list and then add the loop reference last. If you put the loop ref in first the result is anything but "clean".

ʍolɟɐʇɐp ʞuıɥʇ
Message 5 of 6
(2,325 Views)

Thanks for all the replies! 

 

Paul's suggestion is straightforward and definitely works. I didn't know that TopLevelDiagram.CleanUp (or VI.BD.CleanUp) could be limited to the selection only even with VI scripting. This is good to know. Thanks Darren for breaking this down and Crabman for taking the time to suggest the alternative method!

 

    

0 Kudos
Message 6 of 6
(2,305 Views)