06-06-2022 01:55 PM
I want to be able to read every property from every object in a vi and write those properties to a text file. I am really not sure how to go about this as I don't understand how to dynamically access properties from a sub-class. Any ideas/help would be appreciated.
Solved! Go to Solution.
06-07-2022 02:06 AM
There are some generic methods for getting/setting properties, but I don't know their details and I think that their limitations would probably make them impractical for your case.
What you can do is have explicit code to cast references to the correct classes to be able to access the relevant properties. This is a lot of code, but something like the property saver on this page already did most of the heavy lifting for you: http://www.kshif.com/lv/index.html
Note that this hasn't been updated in a long time, so it's possible there's stuff it doesn't cover.
06-07-2022 09:20 AM
You could also look at MGI Save & Restore Settings. It's in the VIPM (VI Package Manager). It only handles some of the larger controls that would generally make the most difference like containers, graphs and table/listbox type controls.
It WILL give you an idea of just how deep the "All Properties of All Objects" rabbit-hole actually goes. LabVIEW is capable of nesting all kinds of controls and YOU will have to descend into every one of them until you hit the bottom level properties. That doesn't even deal with the different pallets. Will you have and Classic, Silver, NXG, Express, etc. controls in use? There are also custom controls to consider.
I would suggest you ask yourself why you need to do this and if simply saving your VIs properly (SVC) is not enough.
06-07-2022 11:17 AM
Let's back up just a bit- do you mean "objects" as in front panel objects, including controls, indicators, plots, etc? Or do you mean LVOOP objects you've written on your own?
If the former, look at the QControls toolkit, which creates LVOOP versions of your standard controls and indicators and adds LVOOP property support, which might help you out. If the latter, then you should just bite the bullet and write your own serializer. Serializing a generic object is a very non-trivial task. MGI's read-write anything might help somewhat, and I think Aristos Queue released a version of a "serialize anything" library a while back.
Also, this sounds like an XY problem. What are you actually trying to do? I seriously doubt you truly need to save EVERY property of EVERY object on a front panel. I can see the need to save and restore LVOOP objects, but that's really a bear of a problem to tackle in a general sense.
06-07-2022 11:18 AM
As the other repliers have mentioned, this is a pretty heavy task.
Can you rewind and tell us why you have decided that this is the way to accomplish "something", and what that "something" is? It seems likely that whatever you want to accomplish might have a better solution than what you're asking how to do here, given its difficulty.
06-07-2022 11:34 AM
I am talking about objects such as controls, decorations, plots, etc.. You're right that I don't need EVERY property. I need to be able to get the properties off a previously made vi so that they can be used to render a similar front panel in a separate software. So no, I do not need every property but I need all that pertain to an objects' visual appearance, position, caption etc.. This needs to be generic as I will be doing this for many different VI's and I will not know exactly what they all contain.
06-07-2022 11:43 AM
Do you care about object data only or data with visual and block diagram properties?
If you only care about the object data (object state), you can use the flatten to xml vi which works nicely.
If you need all the visual properties for front panel and block diagram, well that is a bit more work, you could probably get a job at NI and they might pay you to do that because if you made that, you could do a text diff on your VIs which is only a step or two away from doing a text merge for VIs, which would be welcome by many here.
Throw up a VI example of what you have so far, let's see if we can get NI's attention.
06-07-2022 12:09 PM - edited 06-07-2022 12:15 PM
Unfortunately I do care about visual properties so the flatten to xml doesn't quite meet what I need. I realize it's asking a lot and it's possible no one might have a good answer. Also unfortunately due to my organization I can't show what I've done so far. Basically right now I've focused on controls and I am looping through all controls and taking all the properties I care about and writing those to a file. The problem is a control (for example a scale) might have properties specific to it that I can't access through a generic control property node.
06-07-2022 12:49 PM - edited 06-07-2022 12:56 PM
Take a look at the code in my Property Browser, available here. I have code that retrieves all of the readable properties of Front Panel, Block Diagram, and Project Explorer objects and displays them in a window. At least it gets you part of the way there by helping you get the values.
For me, it needed to be really quick so that the user doesn't see much lag when selecting different objects. I accomplished this by having a VI for each object class in the VI Server (made via scripting) that has a property node with all readable properties. It gets ran dynamically with the object's reference passed to it and the all of the indicators values are read all at once after it executed.
If I were trying to do what you are describing: I would get references to all objects, use the VIs I created and dynamically call and read the values in a loop on those references, and write that data to a file somehow.
Chief LabVIEW Architect, Testeract | Owner, Q Software Innovations, LLC (QSI)
Director, GCentral | Admin, LabVIEW Wiki | Creator, The QControl Toolkit
Certified LabVIEW Architect | LabVIEW Champion | NI Alliance Partner
06-07-2022 01:07 PM - edited 06-07-2022 01:13 PM
@shynds wrote:
... The problem is a control (for example a scale) might have properties specific to it that I can't access through a generic control property node.
THAT is exactly the problem. You will have to start with the ClassName of AllObjs[], then start descending into the containers (possibly with more nested containers) until you get to all properties of all the controls. The properties will be different so that means you will need a case structure full of cases for every control.
What you need is the hierarchy of all the controls>properties in a big table or tree diagram but I don't know if that is available. Maybe try to contact NI support? You might get lucky and they have a developer utility you could use. 🤓
EDIT: That QSI tool looks really useful! May not do everything you need and I would still contact NI to see if there's a master property reference you could access but it looks like a great start. I'm going to check it out myself...