Community
Fusion API and Scripts
Got a new add-in to share? Need something specialized to be scripted? Ask questions or share what you’ve discovered with the community.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Add UserParameter.

9 REPLIES 9
Reply
Message 1 of 10
Anonymous
974 Views, 9 Replies

Add UserParameter.

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...

9 REPLIES 9
Message 2 of 10
Anonymous
in reply to: Anonymous

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
in reply to: Anonymous

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
in reply to: KrisKaplan

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?

Message 5 of 10
KrisKaplan
in reply to: Anonymous

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
Message 6 of 10
Anonymous
in reply to: KrisKaplan

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? ))

Message 7 of 10
ekinsb
in reply to: Anonymous

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
Message 8 of 10
Anonymous
in reply to: ekinsb

 

 

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?

Message 9 of 10
ekinsb
in reply to: Anonymous

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
Message 10 of 10
Anonymous
in reply to: ekinsb

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?

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Technology Administrators