Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

retrieving material values from individual components at an assembly level

6 REPLIES 6
SOLVED
Reply
Message 1 of 7
vex
Collaborator
366 Views, 6 Replies

retrieving material values from individual components at an assembly level

I'm attempting to create a rule that will automatically udpate a simple hand calculation as the user alters the physical constraints of the model via a form.  This requires access to the material properties of a single component on an assembly level, namely I need to pull the Yield Strength of the material and the Young's Modulus.  I however can not seem to locate the way to do this.  I'm thinking I would need to use a similar function as


[code]ThisDoc.Document.ComponentDefinition.Material.YieldStrength[/code]

 

However, how do I point this function to the component of interest?  For ease and clarity, let's assume the material information I desire is contained in the name of "Pipe:1" on the assembly level, and the assembly is "Tow"

6 REPLIES 6
Message 2 of 7
prakasht66
in reply to: vex

Hi ,

This might be usefull for your case.

 

Public Sub MaterialProperty()
Dim InvDoc As Document
Set InvDoc = ThisApplication.ActiveDocument
If InvDoc.DocumentType = kAssemblyDocumentObject Then
Dim oAssyDoc As AssemblyDocument
Set oAssyDoc = ThisApplication.ActiveDocument
Dim oRefDocs As DocumentsEnumerator
Set oRefDocs = oAssyDoc.AllReferencedDocuments
For tt = 1 To oRefDocs.Count
Dim oDoc As Document
Set oDoc = oRefDocs.Item(tt)
If oDoc.DocumentType = kPartDocumentObject Then
Dim oOccEnum As ComponentOccurrencesEnumerator
Dim oPartCompDef As PartComponentDefinition
Set oOccEnum = oAssyDoc.ComponentDefinition.Occurrences.AllReferencedOccurrences(oDoc)
Dim oOcc As ComponentOccurrence
Set oOcc = oOccEnum.Item(1)
If oOcc.DefinitionDocumentType = kPartDocumentObject Then
Set oPartCompDef = oOcc.Definition
MsgBox "YieldStrength = " & oPartCompDef.Material.YieldStrength, vbInformation, oOcc.Name
End If

End If
Next tt
End If
End Sub

Message 3 of 7
vex
Collaborator
in reply to: prakasht66

That seems pretty close, but I'm having a bit of difficulty following the specific particulars of the code.  Could you explain the operation of it for me?

 

I think it's looking at the entire document and recursively hunting for a part file, and once found displays a message box with the material yield strength assigned to the part file. And then continues on searching the various parts contained within the assembly. Is that correct?

 

If so, I could pull the yield strength value by

 

Dim yieldStrength As Double

yieldStrength = oPartCompDef.Material.YieldStrength

 

And forcing the hunt to a specific part title...

 

I think I'll give it a shot and report back.

 

Thanks for the help!

Message 4 of 7
vex
Collaborator
in reply to: vex

So I was able to decompose your code--though it's not pretty by any stretch of the imagination and appears to be outputting the incorrect value for the yield strength.  I should be getting 34,000 PSI, but the output is 234.421747967724.  Running the original code, outputs that same value instead of the correct 34 ksi.

 

Thoughts on that end?  The code I used was set to find the particular component:

SyntaxEditor Code Snippet

For tt = 1 To ThisApplication.ActiveDocument.AllReferencedDocuments.Count
    If ThisApplication.ActiveDocument.ComponentDefinition.Occurrences.AllReferencedOccurrences(ThisApplication.ActiveDocument.AllReferencedDocuments.Item(tt)).Item(1).Name = "Pipe:1" Then
        MsgBox("YieldStrength = " & ThisApplication.ActiveDocument.ComponentDefinition.Occurrences.AllReferencedOccurrences(ThisApplication.ActiveDocument.AllReferencedDocuments.Item(tt)).Item(1).Definition.Material.YieldStrength, vbInformation, ThisApplication.ActiveDocument.ComponentDefinition.Occurrences.AllReferencedOccurrences(ThisApplication.ActiveDocument.AllReferencedDocuments.Item(tt)).Item(1).Name)
        MsgBox("TT = " & tt,vbInformation, "tt count")
    End If
Next tt
Message 5 of 7
vex
Collaborator
in reply to: vex

Forgot that the output of the [].Material.YieldStrength is in MPa rather tha PSI.  Easy fix.

Message 6 of 7
prakasht66
in reply to: vex

Sorry,actually the code i posted here is for your reference only.However you need to modify this code based on your requirement.

Anyway you got the exact solution now.tats great !

Message 7 of 7
vex
Collaborator
in reply to: prakasht66

Yeah, I got the hang of it after I tried wrapping my head around all the property calls.  I'm now having a different issue with it, which isn't exactly obvious to my eyes.

 

I get the correct value pulled according the message box.  However, when I apply the value to the user paramater to show up in a form, it alters the value to 0.68 psi for some reason... nothing in my code alters it beyond conversion from MPa to PSI (multiplying the call by 147.0377377), and that number is correct (verified via output of a message box).

 

Anything I should be made aware of how Inventor handles the data from this sort of function call and is placed into the user parameter?

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report