VBA / API - how to iterate through all Components of .IPN

VBA / API - how to iterate through all Components of .IPN

fullevent
Advisor Advisor
1,631 Views
12 Replies
Message 1 of 13

VBA / API - how to iterate through all Components of .IPN

fullevent
Advisor
Advisor

Hello,

 

I'm trying to find a way to go through all PublicationComponents of an .ipn to find a specific one by name.

 

I have the following information:
FullFileName of the .ipn and the

name of the component (e.g. "00009 - Sechskantschraube:1")

 

What I need is the Rangebox of that Component.

2020-05-29 11_00_45-Microsoft Visual Basic for Applications - Default.ivb [break].png

 

I can access the document via the .Parent property, but unfortunately not in the same way from the document to the component.

2020-05-29 10_54_38-Autodesk Inventor Professional 2018 - [TestIPN.ipn].png

There is no "Publication" propertyThere is no "Publication" property

 

...so how can I find the PublicationComponent in an IPN only by knowing the name?

Is there a way?

 

Best regards


Aleksandar Krstic
Produkt- und Projektmanager

0 Likes
Accepted solutions (1)
1,632 Views
12 Replies
Replies (12)
Message 2 of 13

fullevent
Advisor
Advisor

I have a sample data set, which I can send via pm if desired.

Unfortunately I still haven't found a possible solution.

 

If someone wants to try this and needs the sample data, just let me know.

Would be great to get some support for this issue. Thanks in advance.

 

Best regards,

 


Aleksandar Krstic
Produkt- und Projektmanager

0 Likes
Message 3 of 13

marcin_otręba
Advisor
Advisor

Try this for start:

Dim ipn As PresentationDocument
 ipn = ThisApplication.ActiveDocument
Dim odoc As AssemblyDocument
 odoc = ipn.ReferencedDocuments.Item(1)
Dim occ As ComponentOccurrence
occ = odoc.ComponentDefinition.Occurrences.ItemByName("your name")

 

and for traverse trough all occ:

 

Dim ipn As PresentationDocument
 ipn = ThisApplication.ActiveDocument
Dim odoc As AssemblyDocument
 odoc = ipn.ReferencedDocuments.Item(1)
Dim occ As ComponentOccurrence

For Each occ In odoc.ComponentDefinition.Occurrences
Debug.Print occ.Name
Next

 

Hi, maybe you want to check my apps:


DrawingTools   View&ColoringTools   MRUFolders

0 Likes
Message 4 of 13

fullevent
Advisor
Advisor

Hello @marcin_otręba,

 

first of all thank you for your time.

 

Your code gets me the componentOccurrence of the iam. That's not quite what I'm trying to do.

I am trying to find the PublicationOccurrence of an IPN.

But I can't find a way to go through all PublicationOccurrences of an IPN.

 

I expected to do something along those lines.

Dim occ As PublicationOccurrence

For Each occ In oIPN.PublicationOccurrences 'but it does not exist
Debug.Print occ.Name
Next

 

Maybe you have another idea?

 

2020-06-02 13_44_01-Window.png

 

regards,


Aleksandar Krstic
Produkt- und Projektmanager

0 Likes
Message 5 of 13

marcin_otręba
Advisor
Advisor

Something like this ?

 

Dim ipn As PresentationDocument
ipn = ThisApplication.ActiveDocument
Dim oDoc As PresentationComponent
 oDoc = ipn.ActiveScene.TopSceneComponent
Dim osub As PresentationComponent
For Each osub In oDoc.SubComponents
MessageBox.Show(osub.Name, "Title")
Next

 

Hi, maybe you want to check my apps:


DrawingTools   View&ColoringTools   MRUFolders

Message 6 of 13

fullevent
Advisor
Advisor

This is going in the right direction! Thanks a lot for the help.

 

The reason why I want to find PublicationOccurrence is because I want to check the rangebox.
It seems the PresentationOccurrence has no rangebox or is there a way to get it by the PresentationOccurrence?

 

2020-06-02 14_42_40-Window.png2020-06-02 14_43_12-Window.png


Aleksandar Krstic
Produkt- und Projektmanager

0 Likes
Message 7 of 13

marcin_otręba
Advisor
Advisor

what you want to get from rangebox? position? size?

Hi, maybe you want to check my apps:


DrawingTools   View&ColoringTools   MRUFolders

0 Likes
Message 8 of 13

fullevent
Advisor
Advisor

I need the MaxPoint and the MinPoint.. so i need all 6 values.

 

2020-06-02 17_02_06-Window.png


Aleksandar Krstic
Produkt- und Projektmanager

0 Likes
Message 9 of 13

marcin_otręba
Advisor
Advisor
Accepted solution

Try something like code below only be careful it will not work for subcomponents type assemblies, in tjhhis scenario you must go deeper to subcomponent of that component.

 

 

On Error Resume Next
Dim ipn As PresentationDocument
 ipn = ThisApplication.ActiveDocument
Dim oDoc As PresentationComponent
  oDoc = ipn.ActiveScene.TopSceneComponent
Dim osub As PresentationComponent
For Each osub In oDoc.SubComponents
If osub.SubComponents.Count = 0 Then
Debug.Print osub.Name & " " & osub.SurfaceBodies.Item(1).RangeBox.MaxPoint.X & " " & osub.SurfaceBodies.Item(1).RangeBox.MaxPoint.Y & " " & osub.SurfaceBodies.Item(1).RangeBox.MaxPoint.Z
Else
Dim osub1 As PresentationComponent
For Each osub1 In osub.SubComponents
Debug.Print osub1.Name & " " & osub1.SurfaceBodies.Item(1).RangeBox.MaxPoint.X & " " & osub1.SurfaceBodies.Item(1).RangeBox.MaxPoint.Y & " " & osub1.SurfaceBodies.Item(1).RangeBox.MaxPoint.Z
Next
End If
Next

 

Hi, maybe you want to check my apps:


DrawingTools   View&ColoringTools   MRUFolders

Message 10 of 13

fullevent
Advisor
Advisor

That looks very good. Thank you a lot.

 

..confusing.. I'm getting different values... here for comparison:

Max Points using your Code:

2020-06-02 17_31_34-Window.png

 

MaxPoints of "PublicationOccurrence.Rangebox"

2020-06-02 17_28_00-Window.png2020-06-02 17_28_22-Window.png

 

I'm not sure what the difference is between the two. Right now I don't even know which range box is the right one. I will try to find out tomorrow and get back to you.

Thanks for your support!

 

Best regards,


Aleksandar Krstic
Produkt- und Projektmanager

0 Likes
Message 11 of 13

fullevent
Advisor
Advisor

Hello @marcin_otręba,

 

I was able to test your code and I got exactly the rangebox I was looking for. Thank you!

 

The initial question is not answered, but now I also know that the question would not have led to my goal.

..Sometimes you do not know what you are looking for until you find it.
*deep*😎🤣

 

Have a nice day!


Aleksandar Krstic
Produkt- und Projektmanager

0 Likes
Message 12 of 13

edv
Participant
Participant

Hello @marcin_otręba 

is it possible to make the script work for IV2016?

Because there is no PresentationComponent or ActiveScene

0 Likes
Message 13 of 13

marcin_otręba
Advisor
Advisor

sorry, i do not have 2016.. also i think it is not possible due fact that it was introduced in 2018.

Hi, maybe you want to check my apps:


DrawingTools   View&ColoringTools   MRUFolders