03-08-2024 02:55 AM
Let's say I am the class "Human", how can I read the values of my own attributes set by an external code to use them in my own methods?
Just like self in python
Solved! Go to Solution.
03-08-2024 06:04 AM
What should I do if I want to use the value of the "number of fingers" attribute to perform the calculation required for, lets say, the "grab something" method?
03-08-2024 06:13 AM
A class' attributes are accessed with a simple Unbundle by name in its methods.
External VI's need some access method, like get/set methods.
See "Human class" attached
03-08-2024 06:14 AM
So in LabVIEW the class data is private.
To read and write to the class data from outside one will need to create methods/vi's to accces the data.
Within a class method you can use the unbundle/bundle by name to get access to the private data.
In the class method, the class wire acts as cluster for data.
03-08-2024 07:00 AM
So the only way for the method "grab something" to access the attribute "number of fingers" is having the instance of the object "Human" wired as an input?
03-08-2024 07:16 AM
@eloi.sanchez wrote:
So the only way for the method "grab something" to access the attribute "number of fingers" is having the instance of the object "Human" wired as an input?
Maybe?
If Grab is a method of Human, then yes, you need your class wire attached. If Grab is a free VI then it depends. It might need a Hand-reference or just the integer Number of fingers and so on.
What are you trying to achieve?
03-08-2024 07:22 AM
yes, in this Grab example it is a Human method.
I was wondering if there was a way to access a class attribute without having to change the connector panel.
I am redoing someone else's work and am looking for a way to do it in the most elegant and least intrusive way.
03-08-2024 07:26 AM
Are you talking about CLASS attributes of OBJECT attributes?
A CLASS is a definition of the data structures and methods in the IDE. An OBJECT is what you instantiate in code.
Accessing attributes of a CLASS in code is a very different thing to accessing attributes of an OBJECT (of that class) in code.