Add UserParameter.

Add UserParameter.

Anonymous
Not applicable
1,659 Views
9 Replies
Message 1 of 10

Add UserParameter.

Anonymous
Not applicable

Good day.

 

Please, help me, what is incorrect in this code:

 

design = adsk.fusion.Design.cast(app.activeProduct)
design.designType = adsk.fusion.DesignTypes.ParametricDesignType
pathValue = adsk.core.ValueInput.createByString("anyString")              
design.userParameters.add("pathdwg", pathValue, "", "")

I need to save parameters for design (strings and doubles). As I understand UserParameters are made for this.

But this code doesn't work. It rises RuntimeError: 3. 

 

UserParametersError.png

 

I test so many variants that I have no more ideas...

0 Likes
1,660 Views
9 Replies
Replies (9)
Message 2 of 10

Anonymous
Not applicable

Can save double, using this code:

 design.userParameters.add('longitude', adsk.core.ValueInput.createByReal(float(coordt[2])), "", "longitude")

And string only in this way (with '.expression'):

design.userParameters.add('pathFile', adsk.core.ValueInput.createByReal(1), "", "pathFile")
design.userParameters.itemByName('pathFile').expression = pathFile

 

Message 3 of 10

KrisKaplan
Autodesk
Autodesk

The problem would be that the pathValue string value 'anyString' does not evaluate to a number.  As the documentation for the 'value' argument state, if the value is a string, it must be an expression that will evaluate consistent with the specified unit type.  If the units type is set to 'No Units' (an empty string), it must still evaluate to a numeric value.  There is no unit type that will accept an arbitrary string value.  You ca verify the API behavior should be consistent with using the 'Add User Parameter' dialog in the Parameters dialog in the UI (and it will not allow you to create a No Units parameter with an arbitrary string expression).

 

The fact that you are able to set the expression to an arbitrary expression value would be a bug, and I will file one for it.  Setting the expression on a parameter with a string that does not evaluate to a value consistent with the unit type should have failed the same as the add method.

 

It sounds like you are trying to use user parameters for general custom properties or attributes in the document.  Parameters are only meant to be used as values in the parametric design.  The API does not yet have custom attributes, but it is something we definitely plan for a future update.  If you do want to use parameters to hold this sort of data, you could use the comment to hold an arbitrary string value (though as a user, I would not want my parameter namespace used for application specific custom data so I would not recommend it).

 

Kris



Kris Kaplan
Message 4 of 10

Anonymous
Not applicable

Thanks for the detailed answer, Kris.


Am I right that there is no way in the API to add a custom attribute to an object? Can I anyway mark bodies and meshes to differ them in future work?

I can set the name to bodies but the name is able for changing in user interface. And thus the difference may be lost. Is there any other way?

0 Likes
Message 5 of 10

KrisKaplan
Autodesk
Autodesk

That is correct.  We do not yet have the custom attribute APIs completed.  The only property set-able on a body that can contain any data is the name, and there is no way to prevent the name from being changed through the UI browser.

 

Kris



Kris Kaplan
0 Likes
Message 6 of 10

Anonymous
Not applicable

Thank you.

 

Are there any dates, when you are going to implement this option?

And also there is no way to monitor name changing, is there? Any name-changing-event or something like that? ))

0 Likes
Message 7 of 10

ekinsb
Alumni
Alumni

We don't have a date for custom attributes yet.  It is high on our priority list and there are a lot of apps that will require this functionality before they can be written.  Unfortunately there's quite a bit of core work that needs to be done first before the API can expose the functionality.  There also is not any kind of event you can list for to know if the user is changing the name.  I currently don't see any kind of workaround.


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
0 Likes
Message 8 of 10

Anonymous
Not applicable

 

 

Good day. Thanks for the reply, Brian.


I'm sorry  for diverting you. I have another small question, and I don't want to create individual topic for it.
When will be realized the ability to work with textures using the API? To get and save the textures for bodies?

0 Likes
Message 9 of 10

ekinsb
Alumni
Alumni

By "texture" do you mean setting the appearance associated with a body or do you mean applying a decal?  If it's the former, the API supports this now.  You can see this demonstrated in the ApplyAppearanceToSelection sample that's one of the sample scripts available in the "Scripts and Add-Ins" dialog.

 

If you are referring to applying a decal, that is not currently supported and is not scheduled but is something we intend to support at some point in the future.


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
0 Likes
Message 10 of 10

Anonymous
Not applicable

I mean decal - the image (TextureImage) for TriangleMesh object. TriangleMesh has such properties as .textureImage or .textureCoordinates. But calling it rises exception  "RuntimeError: 5:  API Function not yet implemented". So these properties won't be implemented in the next few months? Did I understand you correctly?

0 Likes