Message 1 of 10
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Is there an example of using NamedValues to pass data from a script to another command?
-CQ
Solved! Go to Solution.
Is there an example of using NamedValues to pass data from a script to another command?
Solved! Go to Solution.
Carlo,
The only time I've seen the use of named value pairs shown was in the answer to this forum post. Even that one named value pair was valuable to me. I'm with you -- it would certainly be helpful if someone from the Autodesk team could share other commons pairs, even if only on an unofficial don't-blame-us-if-it-breaks-in-the-next-release basis.
PS
Carlos,
I'm afraid I don't know how you'd get access to the NamedValue pairs in your on command execute handler. I went down that road myself in the past, hoping that they would be exposed as part of the commandEventArgs, but no luck. Hopefully someone more knowledgeable will chime in?
One other thought, in case it helps as a workaround: if AlignComponentsCmd isn't native, and presumably the script/add-in from which you are executing it is also non-native, then you have access to the source code for both? Maybe you could call AlignComponentsCmd's run method as a java/python call directly instead of routing it through the API's execute layer. In that case you could, presumably, pass any arguments you'd like? That's what I ended up doing -- it's messy, because it means I had to drop another developer's add-in code inside my own add-in, but at least that way I could call it programatically, and without their UI layer popping up.
Good luck,
PS
the "executeImmediately" option is all that's currently supported. This was added to be able to add functionality for a few commands in the future but we've not taken advantage of it yet. Even if we choose to in the future I expect it to be very limited to a handful of commands. It's not intended to be a way to fully drive commands via the API. I don't expect that to ever happen.
Thanks for the reply. So is there any way to pass in data to another script or command via the Fusion API?
I guess we need to first define some terms to make sure we're talking about the same thing.
A "command" is what's created and executed when a user clicks a button in the user-interface or you get a specific CommandDefinition and call the execute method. Commands are designed to interact with the user and most of them have a command dialog to gather the required input from the user. They're not designed to be interacted with through the API. There are a few commands that will use the current selections as their initial input so you can take advantage of that by pre-selecting entities and then executing the command. The user still typically has to do some interaction and do the final command execution.
Where it really makes sense it's possible to modify a command so that it can use provided input and either reduce the amount of input needed from the user or skip it all together. This was done in Inventor in a handful of cases. Primarily for commands that required the user to select a file. It was possible to provide the filename so the command would use that instead of prompting the user and then continue in it's normal way. For example, inserting a new part into an assembly when you already knew the name of the file to insert but wanted to take advantage of the rest of the command that allows the user to position the part into the assembly. It's possible that we could do something like this in Fusion too but it would have to be implemented on a command-by-command basis.
I would consider the term "script" as referring to any script or add-in for Fusion written in any of the three languages supported. There are some workarounds for Python, but in general they can only run by the user through the Scripts and Add-ins dialog, or by Fusion when it automatically runs add-ins at start-up. I think we need to provide an API around these to let you essentially do the equivalent of the Scripts and Add-Ins dialog through the API.
If there are two add-ins that know about each other and want to communicate for some reason, there isn't anything in place for that today. However we're working on something that we're adding to support multiple threads that allows a worker thread to fire an event back to the primary thread. This event can include data that the worker wants to send. This same event can potentially be used to fire an event from one add-in to another.
Ok, that does clarify things. So at the moment, there's no way to have two scripts to exchange any data (primitives or otherwise) via the API, correct?
I'm glad to hear there might be a solution in the pipeline. What you described at the end sounds perfect (and really useful!), but I'm curious where it falls on the roadmap? Assuming this coming out in the next couple of months, I have to decide how to move forward. I could either:
(1) scrap my current approach and just write everything in Python (so I pass data like described in the first reply), or
(2) hack my way through this problem by storing my data (just a big JSON really) as an attribute on the root component or something.
Any suggestions or anything else come to mind?
Thank you Brian!
PS Are you going to AU?
Most of the work is done for the event I talked about. Now some testing and writing documentation. Assuming we don't run into any unexpected problems I expect it to be available in January.
Yes, I will be at AU. Let's be sure and connect there.