From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

VI Scripting - Bug with "UI.PlaceObjectOnCursor > mergeVI" method

I'm trying to set up a Quick Drop plugin that places a pre-populated free label onto my cursor (for LV bookmarks). The best 😅 way I've figured out how to do this is to create a more or less empty middleware VI into which I can place a text object using VI Scripting, modify the text of that object, then place the contents of that VI onto my cursor - yes, I know this is nuts.

 

The issue I'm having is that the VI Scripting Method "UI.PlaceObjectOnCursor" doesn't appear to work when the "mergeVI" (i.e., place the VI's contents instead of the VI icon) is set to TRUE. Setting this to FALSE just puts the VI icon onto my cursor, which isn't what I want.

 

AFAIK, This appears to be a known bug, as discussed here: https://forums.ni.com/t5/LabVIEW/Bug-With-Merge-VI-Place-Object-On-Cursor/td-p/3179489?profile.langu... 

 

Has there been any progress towards fixing this bug? It still appears to be an issue in LV2019, and this post is from 2015 and refers to an even older post from 2011! 😖

 

FWIW I have figured out a workable solution using the "UI.PlacePaletteObjOnCursor" method, then putting my middleware VI into "user.lib" so it shows up in my User Libraries palette, then editing the palette set to configure the VI to "Place VI Contents". For obvious reasons, this is a much more cumbersome solution; especially considering this plugin is something I want other members of my team to be able to use!

 

Does anybody know if:

a) There's an easier way to deliberately create a "Merge VI"

-or, more preferably-

2) There's a better way to put a preformatted free label on the cursor so it can be dropped on the Block Diagram

 

Any help / direction is much appreciated!

 

As a final FYI - I'm not permitted to share code directly on the forums. I realize this is unhelpful for all parties involved. 😞

0 Kudos
Message 1 of 8
(1,208 Views)

Just to get a complete picture, what kind of preformatting are you trying to do to the label?

Redhawk
Test Engineer at Moog Inc.

Saying "Thanks that fixed it" or "Thanks that answers my question" and not giving a Kudo or Marked Solution, is like telling your waiter they did a great job and not leaving a tip. Please, tip your waiters.

0 Kudos
Message 2 of 8
(1,195 Views)

Nothing special - just adding some text: a bookmark (selected from a list), user initials, and a timestamp

e.g.: #TODO JR - 2021/08/24

 

That part seems to be working just fine!

 

The idea is I can just chuck this bookmark on my BD and add more text as needed. The tool is intended to give our group a predefined set of bookmarks with initials and dates to facilitate things like code reviews.

 

For history: I had an initial version of my QD plugin that also colored the text objects so it was easier to tell users apart, but that one didn't place the object on the cursor - colors are broken now, but that's a separate issue and not a big one. The problem we had with the initial version was that it would try to place the bookmark somewhere near the mouse cursor by getting its relative position on the Block Diagram, but that turned out to be unreliable (especially with multi-monitor setups because of how LV handles coordinates) and bookmarks often ended up in strange places on diagrams and had to be chased down.

 

0 Kudos
Message 3 of 8
(1,193 Views)

What I think would be much easier would be to place a blank free label on your cursor, then as soon as it's placed auto-populate it with the formatted info. It's easy enough once you're able to get the placed label's reference.

Redhawk
Test Engineer at Moog Inc.

Saying "Thanks that fixed it" or "Thanks that answers my question" and not giving a Kudo or Marked Solution, is like telling your waiter they did a great job and not leaving a tip. Please, tip your waiters.

0 Kudos
Message 4 of 8
(1,179 Views)

I had tried something like that using "UI.PlaceObjectOnCursor" with "Free Label" as the style input. It works insofar as getting the empty label onto my cursor, but I couldn't then figure out how to then get a reference to that object (either before or after placement, but I assume after since it doesn't exist yet otherwise - correct me if I'm wrong on that...).

 

I considered using "Traverse for GObjects.vi", but I'm not sure how I'd avoid getting refs to every free label on a given BD that way.

 

If you have any advice on how to get a ref for the label object that was just placed, I could easily go from there!

 

[Edit: Typo]

 

[Edit again: Idea! I suppose I could to a Traverse for all text objects before creating the label, and then again after dropping it onto the BD, then get the difference between the refnum arrays to find the new (remaining) refnum. Let me know if this is crazy]

0 Kudos
Message 5 of 8
(1,173 Views)

@JRiggles wrote:

Idea! I suppose I could to a Traverse for all text objects before creating the label, and then again after dropping it onto the BD, then get the difference between the refnum arrays to find the new (remaining) refnum. Let me know if this is crazy]


That's 99% what I did to make sure it could be done before responding. Only difference is instead of using Traverse to get all text objects, I just obtain references to all text decorations before and after. Here's the VI, it maybe could use some cleanup. It's bound to CTRL+8 right now and the "formatted" text is just a hardcoded "1234". But place it in your plugins folder and it'll work.

 

Edit: Did some more testing... What I provided doesn't work on a BD that doesn't have any decorations on it yet, so if you're gonna use that as a starting point you'll need to do a little more modifying to handle that edge case.

Redhawk
Test Engineer at Moog Inc.

Saying "Thanks that fixed it" or "Thanks that answers my question" and not giving a Kudo or Marked Solution, is like telling your waiter they did a great job and not leaving a tip. Please, tip your waiters.

0 Kudos
Message 6 of 8
(1,168 Views)

I guess it works if the diff is always "1".  There are corner cases lurking to thwart this method, but it should work well.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 7 of 8
(1,167 Views)

Thanks FFR - looks like you and I are on a similar track. I've gotten something mostly working using Traverse, with a slight peculiarity wherein the 1st bookmark object is added and formatted just fine, but subsequent label objects come in empty until the plugin is used again! It's almost as if it doesn't realize it needs to update the object until its run again, because then the empty label gets formatted as expected and another empty label is placed on the cursor. Very strange!

 

[EDIT: I was able to fix the problem! I was getting the array of "before" refs via Traverse, concatenating (via "Build Array") with the array of "after" refs from a 2nd Traverse, removing duplicates (leaving only 1 ref), and extracting that remaining reference. For whatever reason, swapping the inputs of the "build array" function so the new refs came before the old refs fixed the issue (I'm not 100% sure why, seeing as how "Remove Duplicates" should have handled this already, but I can't probe the arrays to find out...so I'll take what I can get). Now I can create bookmarks to my heart's content, even on an empty Block Diagram!]

 

[EDIT Again: I'm realizing this is because "Remove Duplicates from 1D Array.vim" doesn't work like I think it does! Any unique names are still left in the array, so concatenating [a,b,c] with [a,b,c,d] gets me with [a,a,b,b,c,c,d], and Remove Duplicates still returns [a,b,c,d]!! Can you tell this isn't the first time this has tripped me up? Figuring out a way to actually remove duplicates (leaving me with just [d], as an example) is the way to go. Alternatively, I can ditch removing duplicates altogether and hope that my newest text object ref is always at the top of the list, which is essentially what's happening already.]

 

[EDIT Again, again: Final one for the day, I promise! I've realized that what I'm essentially doing is just looking at the 0th index of the text objet refnum array provided by my 2nd Traverse call, and that happens to be the newest (most recently placed?) text object...which means I don't even really need the 1st call to Traverse since I don't care about those refnums anyway. This may not be the most robust solution, but it's what's happening currently!]

0 Kudos
Message 8 of 8
(1,158 Views)