derived part material

derived part material

Anonymous
Not applicable
1,367 Views
14 Replies
Message 1 of 15

derived part material

Anonymous
Not applicable

is it possible to get the material of the derived part in vba ?

0 Likes
Accepted solutions (1)
1,368 Views
14 Replies
Replies (14)
Message 2 of 15

jdkriek
Advisor
Advisor

I might be missing it, but I looked around the VBA locals and couldn't find material for the Derived part.

 

F8 through this code and look at locals (View > Locals Window)

 

Normally you'd find it under the Definition section...

 

Public Sub FindDer()
    Dim oDoc As PartDocument
    Set oDoc = ThisApplication.ActiveDocument
    Dim oDerPartComp As DerivedPartComponent
    Set oDerPartComp = oDoc.ComponentDefinition.ReferenceComponents.DerivedPartComponents.Item(1)
    MsgBox ("Found " & oDerPartComp.name)
End Sub
Jonathan D. Kriek
MFG Solutions Engineer
KETIV Technologies, Inc.


0 Likes
Message 3 of 15

Anonymous
Not applicable
Accepted solution
Public Sub Derived_Material()
    Dim oPartDoc As PartDocument
    Set oPartDoc = ThisApplication.ActiveDocument
    
    Dim oderivedPart As DerivedPartComponent
    Set oderivedPart = oPartDoc.ComponentDefinition.ReferenceComponents.DerivedPartComponents.Item(1)
    
    Dim oRefPart As PartDocument
    Set oRefPart = oderivedPart.ReferencedDocumentDescriptor.ReferencedDocument
    
    Dim oRefPartDef As PartComponentDefinition
    Set oRefPartDef = oRefPart.ComponentDefinition
            
    Dim oMaterial As Material
    Set oMaterial = oRefPartDef.Material
    
    MsgBox (oMaterial.Name)
End Sub

 

0 Likes
Message 4 of 15

jdkriek
Advisor
Advisor

That's interesting; the locals never show access to the material. I had originally assumed that it was accessed the same way as any other part, but Intellisense never picked it up and locals never dropped down to that scope in the definition. 

Jonathan D. Kriek
MFG Solutions Engineer
KETIV Technologies, Inc.


0 Likes
Message 5 of 15

Anonymous
Not applicable

>>>jd & sassen....

 

thank you guys....

 

works perfectly....

0 Likes
Message 6 of 15

Formsprag
Advocate
Advocate

I see this post was solved in 2013, is it still applicable in 2020? I get an error when I try in to 2020. Any input would be helpful!

 

thanks

0 Likes
Message 7 of 15

Curtis_Waguespack
Consultant
Consultant

Hi @Formsprag 

 

I did a quick test with Inventor 2020.

 

I ran this on a derived part and it showed me the material of the part from which it was derived without issue.

 

Just to confirm, the part referenced in your derived part is a part file rather than an assembly, right?

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

 

EESignature

0 Likes
Message 8 of 15

Formsprag
Advocate
Advocate

Yes it is a part file. 

 

Here's the error I get.....

2020-02-20_16-05-05.jpg

0 Likes
Message 9 of 15

Curtis_Waguespack
Consultant
Consultant

Hi @Formsprag 

 

Ahh, okay the example posted in this thread was authored for VBA, so a bit of reformatting is need to run it in iLogic

 

Firstly, you can do a search for "Set" and just replace it with nothing, and then secondly you can just remove the "Sub..." and "End Sub" lines like this or make the Sub line read "Sub Main"

 

so basically here are two versions that will run via ilogic:

 

Public Sub Main
    Dim oPartDoc As PartDocument
    oPartDoc = ThisApplication.ActiveDocument
    
    Dim oderivedPart As DerivedPartComponent
    oderivedPart = oPartDoc.ComponentDefinition.ReferenceComponents.DerivedPartComponents.Item(1)
    
    Dim oRefPart As PartDocument
    oRefPart = oderivedPart.ReferencedDocumentDescriptor.ReferencedDocument
    
    Dim oRefPartDef As PartComponentDefinition
    oRefPartDef = oRefPart.ComponentDefinition
            
    Dim oMaterial As Material
    oMaterial = oRefPartDef.Material
    
    MsgBox (oMaterial.Name)
End Sub

or 

 

    Dim oPartDoc As PartDocument
    oPartDoc = ThisApplication.ActiveDocument
    
    Dim oderivedPart As DerivedPartComponent
    oderivedPart = oPartDoc.ComponentDefinition.ReferenceComponents.DerivedPartComponents.Item(1)
    
    Dim oRefPart As PartDocument
    oRefPart = oderivedPart.ReferencedDocumentDescriptor.ReferencedDocument
    
    Dim oRefPartDef As PartComponentDefinition
    oRefPartDef = oRefPart.ComponentDefinition
            
    Dim oMaterial As Material
    oMaterial = oRefPartDef.Material
    
    MsgBox (oMaterial.Name)

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

EESignature

Message 10 of 15

Formsprag
Advocate
Advocate

Both ways worked perfectly! Thanks!

 

Could the code be tweaked so it would physically match the material from the parent rather the just display the parent in a message box?  

0 Likes
Message 11 of 15

bradeneuropeArthur
Mentor
Mentor

Hi,

 

You could vote one of my ideas in the idea station:

Derive I-properties!

Regards, 


Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 12 of 15

Curtis_Waguespack
Consultant
Consultant

@Formsprag wrote:

Both ways worked perfectly! Thanks!

 

Could the code be tweaked so it would physically match the material from the parent rather the just display the parent in a message box?  



Hi @Formsprag 

 

I think this should do it.

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

 

Dim oPartDoc As PartDocument
oPartDoc = ThisApplication.ActiveDocument

Dim oderivedPart As DerivedPartComponent
oderivedPart = oPartDoc.ComponentDefinition.ReferenceComponents.DerivedPartComponents.Item(1)

Dim oRefPart As PartDocument
oRefPart = oderivedPart.ReferencedDocumentDescriptor.ReferencedDocument

Dim oRefPartDef As PartComponentDefinition
oRefPartDef = oRefPart.ComponentDefinition
        
Dim oMaterial As Material
oMaterial = oRefPartDef.Material

Dim sMaterial As String
sMaterial = oMaterial.Name

iProperties.Material = sMaterial

EESignature

Message 13 of 15

Formsprag
Advocate
Advocate

That worked perfect! Thanks Curtis

 

Is there anyway to trigger the rule if the part is derived and ignored if not derived?

I tried to simply use the Event Triggers hoping the rule would be ignored if it didn't detect the parent file.

 

Thanks 

0 Likes
Message 14 of 15

Curtis_Waguespack
Consultant
Consultant

Hi @Formsprag 

 

This will catch the error when there is no derived component reference and just exit the rule, so the while it will still be triggered, the rule wont error out.

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

 

Dim oPartDoc As PartDocument
oPartDoc = ThisApplication.ActiveDocument

Dim oderivedPart As DerivedPartComponent
Try
oderivedPart = oPartDoc.ComponentDefinition.ReferenceComponents.DerivedPartComponents.Item(1)
Catch
	Return 'exit rule
End Try

Dim oRefPart As PartDocument
oRefPart = oderivedPart.ReferencedDocumentDescriptor.ReferencedDocument

Dim oRefPartDef As PartComponentDefinition
oRefPartDef = oRefPart.ComponentDefinition
        
Dim oMaterial As Material
oMaterial = oRefPartDef.Material

Dim sMaterial As String
sMaterial = oMaterial.Name

iProperties.Material = sMaterial

EESignature

Message 15 of 15

Formsprag
Advocate
Advocate

Perfect! Thanks for your help....

0 Likes