hexagon logo

Command language - Access part mass dynamically

Hi,
I am just beginning with cmd language coding and have a newbie question.
 
I am using the function builder to test my code.
 
Let's say I have a part called VB in my model.
  1. If I go to the function builder, I can type "Model_1.VB.mass" and I will get the mass as output value.
  2. My problem is when I try to dynamically access this value. I type: eval(DB_CHILDREN(DB_DEFAULT(SYSTEM_DEFAULTS,"MODEL") ,"Part")[10]//".mass")
The result is the string I entered in bullet point 1- (see attached screenshots below).
Basically I want Adams to understand this as code and not as a string.
What am I doing wrong?
 
Thanks,
Chris
 
cmd
  • Hi Chris,
     
    Here, you are basically concatenating two strings together using "//" to come up with a new string. However, if you need to access the mass of a part, you would first need to make sure that you are returning an object and then add the .mass at the end of it. returning an object from a string can be done using the STOO() function. Therefore, the code below will work as you need:
     
    STOO(DB_CHILDREN(DB_DEFAULT(SYSTEM_DEFAULTS,"MODEL") ,"Part")[10]).mass
     
    The function builder does have an evaluate function that wraps around the code to evaluate so just putting the above code in your Function Builder and hitting the evaluate button would return the mass value of the 10th part in your model. However, if you need to use this in a script, you would need to manually wrap an eval() function around it as seen below. Please note the parentheses used:
     
    (eval(STOO(DB_CHILDREN(DB_DEFAULT(SYSTEM_DEFAULTS,"MODEL") ,"Part")[10]).mass))
     
    Hope this helps.
     
    Thank you,
    Maziar Rostamian
    MSC Software
  • This definitely helps.
    I understood the problem I had with the string and now I understand how to solve my problem.
    Thanks a lot @Maziar Rostamian​ .