Getting component from simulation node property

hello guys
just a quick question about how to hopefully clean up my code I can get the component selected in a simulation node property like these
by using the following code

part1Property = comp.getProperty("Program::Part")
part1 = part1Property.Value

I was just wondering if there was a better way to grab the component without having to use two variables one to grab the component property. and one to grab the value of the component property.

which is the component I want. I tried couple things but this is the only way i got it to work so far.

it’s ok because it’s working but I was just wondering if there was a more elgant way to achieve this


Component property is global in component, so the name of property acts like a getter in returning the value of the property. And a node can always be used to refer back to its component.

For component properties that are tabbed, you need to get the property as object unless someone unlocked some secret code. You can also chain things, but that gets messy and I don’t remember if there is a limit to how far you can go with an inline call.


Oh man zesty!! this is great great stuff!!! you answered my question and then some!

thank you so much the examples, they made this very clear! I was actually also trying to get a component from a list node but was failing I knew I had to use and index but I did not know I had to use the name of the listnode as the property as you did in the example “comp.ListNode[x]”

I really appreciate you took the time to go through all the examples with print statements to make it clear what you were getting out of each line of code., I know for you this must be very basic stuff but really helped me alot thank you.

just one thing I wanted to ask that has me scratching my head. its this line

tuck_tuck = getMyPropValue

I understand that this line is assigning the function get myPropValue into the variable tuck_tuck
however I dont understand what is the point to assign it to a varible when you could simply just call the function. Sorry if this is a dumb quetion like I said I’m very new to python.

pedestal = getMyPropValue("Group::Node").Component

should return the same as

pesedtal = tuck_tuck("Group::Node").Component

or am i missing something.

after doing some testing with the code you sent I also noticed that the following lines returned the same value

robot = comp.Node.Component
print robot.Name

robot = comp.Node
print robot.Name

I was wondering if there was actually a difference bewteen using the component or not because i got the same value on the print statement

once again thank you so much you helped alot and sorry for all the nitpicky questions I just want to get a really clear understanding of python.

we have big plans with Visual Components

You are on the right track by asking questions.

In Python API reference, vcComponent inherits vcNode. A component is also a node, i.e. the root node of component, which is why “comp.Node.Name” and “Node.Component.Name” would return same result in this example.

The “comp.Node.Component” in my example was just to highlight what is happening there and how it is good to be aware of recursion and recursive loops, especially with nodes in simulation and robot statements.

About the function example, you are correct, and I would suggest you stick to calling the functions directly unless there is some design decision in which you want to use that approach. Assigning the function to variable just demonstrates the function is a first-class citizen. I have seen it done maybe a few times with lambda functions and with event handlers. As for tuck tuck, I misspelled tuk tuk. For some reason, I was thinking of white sandy beaches, a cold beer and a tasty curry at the time.

1 Like

omg I cannot express how much I love this answer hahaha :rofl: Tuk Tuk.
Thanks for taking the time to make things clearer for me I really really appreciate it as I am trying to build a strong understanding of the basics to have a good foundation to build on.

1 Like