Multiple User Objects
I'm sure there is a simple architecture aspect I'm missing, but I'm struggling to work out how to manage multiple results within an extension.
I have a custom extension that creates a result. It employs User Objects to request data from the extension user. It works well if I add a single example of the result in. However, practically it would be useful to have anywhere between about 3 and 10 instances of the result in the model, and this is where I'm running into a difficulty.
I believe my issue lies with the way I'm using GetUserObjects. If we use this line as an example:
ExtAPI.DataModel.GetUserObjects('FlangeUtil')[1].Properties[8].Value=Tens
I think the issue lies with the [1] referring to a fixed index.
If I could find an ID for each specific instance of the result being added in, that may work, but I'm struggling to find out how to do so.
Is there a way to create/identify and reference each instance of the result as it is added in? Or is there another way to structure multiple user objects to deal with this?
Answers
-
ExtAPI.DataModel.GetUserObjects('FlangeUtil') will return a list of objects that are created per the app scope. You are correct that your [1] index is the issue, but the more fundamental issue is you shouldn't be using this as the index is not a good way to get it.
Every object in the tree has an Obj.ObjectId that is unique for the entire model, not just the extension.
You can track the ACT objects by ExtAPI.DataModel.GetObjectById(ActObj.ObjectId). This returns a single object (or none if no matching object with that ID)You can also use ExtAPI.DataModel.GetObjectsByName to get an object by its current text name. Note this will return a list of objects even if there is only one.
Please note that the ACT Object that is defined in the ACT scripting scope is not the same as the Mechanical object returned from the methods above. The Mechanical object is the mechanical representation of the internal ACT object. The one you want depends on the nature of what you are trying to do. The ACT Object is what will be passed to the ACT callbacks like GetCommands or OnAdd. The Mech object will be returned with the ExtAPI.DataModel.... methods.
1 -
Thank you. I think that helps.
I'd gotten to a similar solution of using the object Id myself in the meantime, so useful to know that you'd recommend a similar approach.
The problem I'm having now is that I can't get ExtAPI.DataModel.GetObjectById(ActObj.ObjectId) to work. I've identified the Object Id in two ways (one through the extension and one through the shell), and they both return the same Id with the same type. However if I then plug that Id into GetObjectById it tells me it doesn't exist. I'll have a bit more of a dig.
Thank you
0 -
I think I've identified the issue with the GetObjectById error. It seems there are two distinct IDs that an object will return, one if you use .Id and one if you use .ObjectId. I'm not sure I understand what the first one is pointing to, but if I use the latter my function now seems to work.
0