adding parameters in C++

adding parameters in C++

Anonymous
Not applicable
1,446 Views
7 Replies
Message 1 of 8

adding parameters in C++

Anonymous
Not applicable

Is there an example somewhere for C++ in adding user parameters? I have trouble adding them to the active file. I can read them, count them and so on, but when I make changes or add another one nothing changes in the parameters tab.

 

so the code is something similar to this:
 

Ptr<Product> product2 = app->activeProduct();
if (!product) return false;
Ptr<Design> design2 = product;
if (!design) return false;
Ptr<UserParameters> userParameters = design2->userParameters();
if(!userParameters) return false;

Ptr<ValueInput> valueInput = adsk::core::ValueInput::createByString(fileParam->expression());
userParameters->add(fileParam->name(), valueInput, fileParam->unit(), fileParam->comment());

I can though edit parameters in other files with pretty much the same code. 

0 Likes
Accepted solutions (1)
1,447 Views
7 Replies
Replies (7)
Message 2 of 8

Anonymous
Not applicable

1) some inconsistency in your code

 

code.PNG

 

2) you did not post the code for the object "fileParam" - so I used string objects/literals in my example. If you extract the correct strings from your "fileParam" object, it should work as well.

 

This works:

Ptr<Product> product2 = app->activeProduct();
	if (!product2) return false;
	Ptr<Design> design2 = product2;
	if (!design2) return false;
	Ptr<UserParameters> userParameters = design2->userParameters();
	if (!userParameters) return false;

	Ptr<ValueInput> valueInput = adsk::core::ValueInput::createByString("5 mm");
	isOk = userParameters->add("Test_blabla", valueInput, "mm", "comment_blabla");

parameter.PNG

0 Likes
Message 3 of 8

Anonymous
Not applicable

Still no luck. It doesn't really do anything.
The product2 was a typo since the code was a quick rewrite. I tried your code and added a messagebox to it. 

 

Ptr<Product> product2 = app->activeProduct();
if (!product2) return false;
Ptr<Design> design2 = product2;
 if (!design2) return false;
Ptr<UserParameters> userParameters = design2->userParameters();
if (!userParameters) return false;
                                    
Ptr<ValueInput> valueInput = adsk::core::ValueInput::createByString("5 mm");
Ptr<UserParameter> test = userParameters->add("Test_blabla", valueInput, "mm", "comment_blabla");
if(!test) ui->messageBox("this is not working");

Skärmavbild 2019-02-14 kl. 12.37.03.png 

Skärmavbild 2019-02-14 kl. 12.47.44.png

Could it have something to do with the fact that I have another file opened in silent mode at the same time?

 

0 Likes
Message 4 of 8

Anonymous
Not applicable

@Anonymous wrote:

....

....

Could it have something to do with the fact that I have another file opened in silent mode at the same time?

 


?? -> Opening files on a new thread

0 Likes
Message 5 of 8

Anonymous
Not applicable

Ok, I found the problem. I am executing the command with a button in Add-In menu and it seems to only work when executing it from the CommandExecutedHandler.

 

Anyone have an idea if I can get execute it in the InputChangedHandler?

0 Likes
Message 6 of 8

Anonymous
Not applicable

I had to do this in the same thread and it's unfortunately really slow.

 

I wrote a sharedParameters add-in and would like functionality to import parameters to the current file. Right now it is sending sending/updating the parameters in the other tagged project files.  Then I'll probably also add file exporting possibility(parameterIO) just to have everything in one place.  

0 Likes
Message 7 of 8

BrianEkins
Mentor
Mentor
Accepted solution

Changes to the model should be done in either the executePreview or execute events.  However, anything done in the executePreview will automatically be aborted the next time executePreview is called and if it's a permanent change you're making you'll need to continually keep making the change until the command is finally executed.  If you set the isValidResult property of the CommandEventArgs object passed into the executePreview to True, then execute event will be skipped and you'll keep whatever was created in the last executePreview event.

 

I'm surprised your program is slow.  I wouldn't expect creating parameters to be an expensive operation.  Maybe there's something else in your workflow that's contributing the time?

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
Message 8 of 8

Anonymous
Not applicable

Thanks for the info. Sounds like I should read through the documentation again, I haven't touched fusion360 API in while and my memory isn't the greatest 🙂

The slowness unfortunately comes from accessing/saving files in the cloud. If you have any idea in how to modify/access file parameters faster i'm all ears 🙂

0 Likes