How to understand the API object model?

How to understand the API object model?

mikhail_tsarev
Enthusiast Enthusiast
1,919 Views
3 Replies
Message 1 of 4

How to understand the API object model?

mikhail_tsarev
Enthusiast
Enthusiast

Hello, everybody.
I am very interested in Inventor customization. But as for a non-programmer it can be very difficult to understand some features. I would really appreciate it if someone could explain the next thing:

 

In API.pdf we can see object model.

 

Безымянный2.PNG

 

The same thing in the API help book:
 Безымянный.png

 

At the top level, we see the application. Next comes the various documents, and then goes specific structure of the document.

For examle

"PartDocument - PartDocumentDefinition - PartFeatures";

"AssemblyDocument - AssemblyDocumentDefinition".

 

However, if we try to use something like this:

 

 

 

Dim partDoc as PartDocument = ThisApplication.ActiveDocument

Dim extrude As ExtrudeFeature = partDoc.PartComponentDefinition.PartFeatures.ExtrudeFeatures.Item(1)

 

 

 

this will not work, because there is no such a thing as "PartDocumentDefinition" or "AssemblyDocumentDefinition" and there is no "PartFeatures" thing too. Instead we should use "partDoc.ComponentDefinition" and "Features" as it is shown in API help examples...

 

 

 

Dim partDoc as PartDocument = ThisApplication.ActiveDocument

   Dim extrude As ExtrudeFeature
   extrude = partDoc.ComponentDefinition.Features.ExtrudeFeatures.Item(1)

 

 

 

First, they provide a theory and then give examples that do not match it. 😞
And it drives me crazy... I don't understand how to use this table then, if we can't believe it.


I couldn't find any explanation in the help for this issue. Perhaps, there is certain "general idea" that makes this transition in syntax understandable. If so, please share it with me. And if this example is just an exception, can you tell if there are other similar exceptions?

 

Accepted solutions (1)
1,920 Views
3 Replies
Replies (3)
Message 2 of 4

JhoelForshav
Mentor
Mentor
Accepted solution

Hi @mikhail_tsarev 

The object model represents the classes, not the references. For example PartDocument.ComponentDefinition is an object of type (class) PartComponentDefinition. The reference to reach it is .ComponentDefinition, this does not mean that the class name is ComponentDefinition. In this case however PartComponentDefinition is derived from the class ComponentDefinition, so you can write for example:

Dim oDef As ComponentDefinition = PartDocument.ComponentDefinition

ComponentDefinition is the base class of both PartComponentDefinition and AssemblyComponentDefinition.

The point though is that there's a difference between the property name containing the object and the object type (class name).

 

What you're looking for is the API reference manual. It will show you how to reference the different objects:

https://help.autodesk.com/view/INVNTOR/2021/ENU/?guid=GUID-C5FA9FB4-A7AD-47B3-9BA9-1EFF8B55388D

ReferenceManual.PNG

Message 3 of 4

Anonymous
Not applicable
Message 4 of 4

mikhail_tsarev
Enthusiast
Enthusiast

Thank you @JhoelForshav !

I'm not sure I fully understood everything you wrote, as I do not have enough theoretical knowledge on object-oriented programming. But now I have a direction to develop and a common understanding of the subject!

You have helped me a lot!

 

@Anonymous Thank you very much! I watched this video with great pleasure! The author explains the material very clearly.
It's a pity that there is no complete tutorial or a book about programming for Inventor .
I took a videocourse on VB.NET from Bob Tabor. It's a very good course, but it covers a bit different parts of the language than the ones used in the Inventor API. Although I have definitely learned something. 

 

P.S. Also, I apologize for mistakes in my messages, English is not my native language.

0 Likes