Edit dimension of a part within an assembly with API

Edit dimension of a part within an assembly with API

fpusch
Explorer Explorer
743 Views
8 Replies
Message 1 of 9

Edit dimension of a part within an assembly with API

fpusch
Explorer
Explorer

Hello,

I built an assembly with self made parts in it in Inventor. Now I want to create a code with API in the assembly which changes the dimensions of the parts depending on the input of the API interface. How do I write a Code for that? I only know how to use API in parts.

Thank you!

0 Likes
744 Views
8 Replies
Replies (8)
Message 2 of 9

JelteDeJong
Mentor
Mentor

I'm missing a lot of details needed to help you. But in general, it works like this. You loop over all referenced documents by the assembly. Find the part you need. Use the part API on the part document. that would look something like this.

Dim doc As DrawingDocument = ThisApplication.ActiveDocument

For Each refDoc As Document In doc.AllReferencedDocuments
    ' find the document we need
    If (refDoc.DocumentType <> DocumentTypeEnum.kPartDocumentObject) Then Continue For
    If (refDoc.FullFileName.Contains("") = False) Then Continue For

    ' If the code came here the refDoc is the document we need
    Dim partDoc As PartDocument = refDoc

    ' use the partDoc with the api that you already know

Next

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

Message 3 of 9

robertast
Collaborator
Collaborator

@fpusch  Can you post the file and tell more exactly what you want to get? If you only manage parts depending on the size of the product, then this can be done easier and without API

0 Likes
Message 4 of 9

fpusch
Explorer
Explorer

@robertrast I have to create a computer mouse for a class and the user should be able to use the interface which you can create with the API user forms.

 

So I'm doing a list with some names as an example:

- assembly-name: computer mouse

- name of a part which needs to have changeable dimensions: mouse body

- parameter which needs to be changed within "mouse body": P:01

- name of an input box from the userform for P:01: hand width

 

And I have to do this with a few parameters in a few parts in the same assembly

0 Likes
Message 5 of 9

fpusch
Explorer
Explorer
@JelteDeJong first of all: thank you. Further below in this question I made a reply in which you can see a bit more details about what i need to do.
I have a few questions to your code: the API editor doesnt let me use a few things in the way you postedd it. For example it doesnt let me put the "For" at the end of the lines which begin with "If".
What are things I need to change put my assembly, part or variable names in?
Thank You!
0 Likes
Message 6 of 9

robertast
Collaborator
Collaborator

@fpusch 

Here is one way to solve your problem

Message 7 of 9

robertast
Collaborator
Collaborator

This is the second time when no API is required at all, and management is done from another part file that is not involved in the assembly.

Message 8 of 9

fpusch
Explorer
Explorer

@robertastThank you for your input, unfortunately I need to solve the problem with the VBA / API editor

0 Likes
Message 9 of 9

robertast
Collaborator
Collaborator

It's all just just using video_A  non-iLogic but VBA. Also assign parameters

0 Likes