Problem renaming model parameters

Problem renaming model parameters

brad.bylls
Collaborator Collaborator
695 Views
3 Replies
Message 1 of 4

Problem renaming model parameters

brad.bylls
Collaborator
Collaborator

I am trying to rename and reset values of model parameters.

Everything I find in the forums and help files say this should work, but no luck.

Here is the code I am using:

        product = app.activeProduct
        param = product.rootComponent.modelParameters.itemByName('d1')  << This line seems ok, no error
        param.value = BodyLength  <<  This line throws the error below
        param.name = 'Screw_Length'  << I reversed these two and this one also throws the error
 
Brad Bylls
0 Likes
Accepted solutions (1)
696 Views
3 Replies
Replies (3)
Message 2 of 4

brad.bylls
Collaborator
Collaborator

Looks like the screen shot of the error was removed.

It said:

Attribute Error: 'None Type' object has no attribute 'value'

 

Brad Bylls
0 Likes
Message 3 of 4

KrisKaplan
Autodesk
Autodesk
Accepted solution

Brad,

 

itemByName will return None if there is no item with that name in the collection. It will not raise an exception in this case (because it isn't really an error, the search was successful just with no result found). So you should check the returned parameter is not None to determine if the search found any match.

 

Kris



Kris Kaplan
0 Likes
Message 4 of 4

brad.bylls
Collaborator
Collaborator
Thanks Kris.
I'll try to figure out where in the code it needs to go.
Brad Bylls
0 Likes