Can I do it with the API?

I’m pretty sure I had a similar post already about this topic but it might have got lost when we migrated our blogs from TypePad.

Often you already know how to do something in the User Interface and just want to automate the process, e.g. creating a new boundary patch feature.

The best thing is to create the relevant object in the User Interface, select it, and then inside VBA check ThisApplication.ActiveDocument.SelectSet(1) in the Watches window:

Now you can drill down into the various properties of the object – e.g. in the above case you can check the Definition, its BoundaryPatchLoops, GuideRails, etc

If you select an object in the UI, but the SelectSet does not contain an item, or its type is just Object then it’s not supported via the API

Sometimes an object is supported via the API, but it only provides read access.
If you find the collection that the object is part of, but that collection does not have an Add… function (e.g. PartComponentDefinition.Features.GrillFeatures), then most likely you cannot create that object via the API.

Other times the API might impose restrictions that are not there in the User Interface: e.g. I can select a single open Edge as the BoundaryPatchLoop for a Boundary Patch Feature but the API only allows a closed loop:
(https://help.autodesk.com/view/INVNTOR/2027/ENU/?guid=BoundaryPatchLoops_Add)

… If the entities do not form a closed loop or if their order in the collection does not represent a set of end-to-end connected entities, then the creation of the boundary loop will fail.

So do check the API documentation as well.


Comments

One response to “Can I do it with the API?”

  1. freshad0e76ae7a Avatar
    freshad0e76ae7a

    I like this practical approach to automation because starting with a working UI example makes it much easier to understand what needs to be reproduced in VBA. Using the Watches window to inspect the selected object is a simple but useful debugging technique. It also reminds me of Veck IO, where understanding how individual elements work can make it easier to navigate and experiment.

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading