API - Add custom property

API - Add custom property

AnJanson
Advocate Advocate
1,134 Views
6 Replies
Message 1 of 7

API - Add custom property

AnJanson
Advocate
Advocate

Hi, is it possible to add a new custom property to a FactoryInstance with the API?

Accepted solutions (1)
1,135 Views
6 Replies
Replies (6)
Message 2 of 7

olegd.prod
Autodesk
Autodesk
Yes - you'd need to find the PropertyGroup with Name="Custom", add your property to it, and then call UpdateInstances.
This property will show up in the "Custom" section of FDU UI.

https://knowledge.autodesk.com/support/factory-design-utilities/learn-explore/caas/CloudHelp/cloudhe...

HTH

Oleg
0 Likes
Message 3 of 7

AnJanson
Advocate
Advocate

Hi Oleg, 

the Custom-PropertyGroup does not exist, if there is no custom property.

How can I add this group? Is it possible?

If the Custom-PropertyGroup exists but the custom property, I would like to add, does not exists, can I add it? If yes, how?

Regards Andreas 

0 Likes
Message 4 of 7

olegd.prod
Autodesk
Autodesk
Sure, you can do all this through the API - add a group to the list, add a property to the group, etc - you can use the objects in the Autodesk.Factory.PublicAPI.Objects.v2 namespace.
The easiest place to start may be to create some custom properties on an asset instance, and examine the results through the API - that should make it clear what the structure is
HTH

Oleg
0 Likes
Message 5 of 7

AnJanson
Advocate
Advocate

Hi Oleg, 

I have no problems to read or write a custom property that already exists, but I can see no "groups.add" command.

Can you please provide a short example? 

Regards Andreas 

0 Likes
Message 6 of 7

olegd.prod
Autodesk
Autodesk
Accepted solution
Don't try to compile this 🙂

var newGroup = new Autodesk.Factory.PublicAPI.Objects.v2.InstancePropertyGroup();
newGroup.Name = "example";

//add properties to the group
var newProp = new Autodesk.Factory.PublicAPI.Objects.v2.InstanceProperty();
newProp.Name = "foobar";
//assign all the newProp stuff, add it to new group, etc

var instances = API.GetAssetInstances(doc);
var inst = instances[0];
var list = inst.PropertyGroups.ToList();
list.Add (newGroup)
inst.PropertyGroups = list.ToArray();
API.UpdateAssetInstances (layoutDoc, instances);
0 Likes
Message 7 of 7

AnJanson
Advocate
Advocate

Hi Oleg,

that worked. Thank you!

Regards Andreas

0 Likes