Jump to content

Getting from UID to object reference when owning VI was opened outside project


Recommended Posts

Posted

Perhaps not fully a scription question, but I am not sure where it fits better...(and perhaps easy to answer for anyone with a little bit more scripting experience than me too):

Upgrading to LV2024 from 2022 I noticed that some shortcut menu plugin did not work anymore and the reason is that NI has for some reason redesigned the framework to always nullify any references a plugin might try to hand off to a dynamically called VI...To get around this you will either have to avoid using dynamic VIs (but this will prevent you from making plugins that stay open without blocking access to anything else until you close the plugin window..), or hand off UIDs instead of references. This is where I ran into an issue though; I can pass on UIDs, but to get from UIDs to a reference (event structure ref in this case) within a specific instance of a VI I only found this method:

image.png.5d3ee592b489da64bce15b7bf28bcae8.png

 

I successfully use the scripting function UID to GOBJ Reference.vi (found in the hidden gems palette e.g.) by feeding it the UID to the event structures I found. This also requires a reference to the owning VI though (which the plugin framework also will not allow me to pass without nullifying it), so I pass on the name of the owning VI and use Open VI reference on that to get the right VI instance....For Open VI Reference to get the right VI instance though I use the Project.ActiveProject node, read the app property of that and feed that to the Open VI Reference...and this works. The problem is that if the owning VI was opened outside a project the activeproject node will not provide anything...(I think LabVIEW could have solved this by having a "virtual"/"root" project for such VIs which would allow all code relying on project refs to work even in such VIs...but no). So...How do I get the proper application instance ref to feed into Open VI Reference if the VI does not belong to a project? Or alternatively; is there a way to get from UID to GObj Ref (in this case event structure references) that bypasses this issue?

PS: The 2024 changed shortcut plugin framework seems to work in a slightly mysterious way as the refererences I might create based on UIDs received from it will *also* be nullified when the plugin finishes (not just references handed directly) - so the dynamically called VI that tries to work via the UIDs will have to make sure it creates those references after the plugin has finished with this cleanup... 😮

 

Posted

If ActiveProject doesn't return a valid reference, you can use the "Default Application" property to get a reference to the Main Application Instance, which is the app instance used for VIs open outside of a project.

image.png.7ab4e3f69d7cf6e2fb6a4b714211adb8.png

Posted
4 hours ago, Darren said:

If ActiveProject doesn't return a valid reference, you can use the "Default Application" property to get a reference to the Main Application Instance, which is the app instance used for VIs open outside of a project.

image.png.7ab4e3f69d7cf6e2fb6a4b714211adb8.png

For some reason that does not seem to be the right application reference either...Open VI ref for the owning VI in that context still returns error 1004. 

Posted (edited)

Aren't shortcut menus invoked in the UI thread and maybe will instantiate any menu handling VIs in the LVDialogContext? The same that is used when you place VIs in the Tools menu (or maybe a similar other specific context). Did you try a This App Reference constant?

Edited by Rolf Kalbermatter
Posted
On 1/10/2025 at 10:36 PM, Mads said:

For some reason that does not seem to be the right application reference either...Open VI ref for the owning VI in that context still returns error 1004. 

I was wrong, the reason this did not work was something else...So, I now have it working.👍 Thanks for all the help @Darren and @Rolf Kalbermatter

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.