Code to get iProperty of deep part

Code to get iProperty of deep part

peter.ensing
Enthusiast Enthusiast
599 Views
5 Replies
Message 1 of 6

Code to get iProperty of deep part

peter.ensing
Enthusiast
Enthusiast

Hello all!

 

I'm updating some code I wrote to a better one, but this update need some info of a part in a sub assembly.

Google "Inventor vba get iproperties" and there is enough code that debugs an iproperty of all parts.

The thing I need is just for 1 part... this should be easy to do but I just cant figure it out... 

This is what I want to get done:

Pick a sub assembly from the main assembly.

inside this sub assembly there is a part.

this part has a fullfilename or partnumber

msgbox fullfilename (without the need of opening and closing the part to string the data)

 

Sub test()

Dim oDoc As AssemblyDocument
Set oDoc = ThisApplication.ActiveDocument

' Prompt user to pick an occurrence
Dim oOcc As ComponentOccurrence
Set oOcc = ThisApplication.CommandManager.Pick(kAssemblyOccurrenceFilter, "Select bolted connection")

Dim oSub As ComponentOccurrence
Set oSub = oOcc.SubOccurrences.Item(1)

oDoc.SelectSet.Select oSub

 

Dim opDoc As PartDocument
Set opDoc = oSub.something

MsgBox opDoc.FullFileName

 

End Sub

 

 

The selection is still a componentoccurrence and if I'm correct the document propertyset is needed... so is there a way to assign the occurrence as a partdocument or is it not the right way to do? 

 

Kind regards,

 

Peter

0 Likes
Accepted solutions (2)
600 Views
5 Replies
Replies (5)
Message 2 of 6

k14348
Advocate
Advocate

Hi,

    You should use kleafoccurrence instead of assembly occurrence. Hope your issue solved.

 

-Karth

Message 3 of 6

tobias_wiesendanger
Advocate
Advocate
Accepted solution

Yeah. As far as I can tell from your description you should be able to solve this easy when you change to leaf filter.

 

Try something like this:

 

Sub test()

Dim oDoc As AssemblyDocument
Set oDoc = ThisApplication.ActiveDocument

' Prompt user to pick an occurrence
Dim oOcc As ComponentOccurrence
Set oOcc = ThisApplication.CommandManager.Pick(kAssemblyLeafOccurrenceFilter, "Select bolted connection")

MsgBox (oOcc.Definition.Document.PropertySets.Item("Inventor Document Summary Information").Item("Category").Value)

End Sub
Message 4 of 6

k14348
Advocate
Advocate
Accepted solution

Option Explicit

Sub test()

Dim oDoc As AssemblyDocument
Set oDoc = ThisApplication.ActiveDocument

Dim oCommandMgr As CommandManager
Set oCommandMgr = ThisApplication.CommandManager

Dim oAsmDef As AssemblyComponentDefinition
Set oAsmDef = oDoc.ComponentDefinition

Dim oOcc As ComponentOccurrence
Set oOcc = oCommandMgr.Pick(kAssemblyLeafOccurrenceFilter, "Pick occurrence")

Dim strFileName As String
strFileName = oOcc.ReferencedDocumentDescriptor.FullDocumentName

Dim oPartDoc As PartDocument
Set oPartDoc = oOcc.Definition.Document

Dim oProp As Property
Set oProp = oPartDoc.PropertySets.Item("Design Tracking Properties").Item("Part Number")

MsgBox (strFileName & "--" & oProp.Value)
End Sub

Message 5 of 6

peter.ensing
Enthusiast
Enthusiast

Thanks for the fast replies!
I'm not at my work pc now so I cant test the codes, but reading the codes the leaf function is what I want to avoid.
My source code is fixed and the user always picks the assembly to adjust things, the code only needs to read the filename of the first part inside the picked assembly and put that filename in the form. The formt adjusts all items inside the assembly. 
The code I gave is just a testing code I was using to see if it would get the right value in the msgbox so it can be coded inside my source code.

Hope you guys can help me figuring out how to code this bit!

0 Likes
Message 6 of 6

peter.ensing
Enthusiast
Enthusiast

So I should have tested it first... it works like a charm! Thanks guys!

0 Likes