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: 

How to get access on assembly level to part.sheetmetal

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
Damian_Apex
461 Views, 4 Replies

How to get access on assembly level to part.sheetmetal

Hello,

I am looking for code that will run in assembly and it will loop through all parts and for bent plates will read SheetMetal.FlatExtentsLength and SheetMetal.FlatExtentsWidth. 

I have a problem to get from assembly level to Part sheetmetal.

 

Sub main
Dim oAssDoc As AssemblyDocument = ThisDoc.Document
Dim oDoc As Document
Dim BoxLength, BoxWidth As Double	

For Each oDoc In oAssDoc.AllReferencedDocuments
	If oDoc.DocumentType = kPartDocumentObject And oDoc.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then 'sheet metal part'

		Dim dir1 As Double = SheetMetal.FlatExtentsLength 'oDoc.SheetMetal.FlatExtentsLength ?
		Dim dir2 As Double = SheetMetal.FlatExtentsWidth 'oDoc.SheetMetal.FlatExtentsWidth ? 	
		
		Dim lengths As New List(Of Double) From {dir1, dir2}
		lengths.Sort

		BoxWidth = lengths(0)
		BoxLength = lengths(1)
		
		Trace.Write("oDoc: " & oDoc.DisplayName)	
		Trace.Write("BoxWidth: " & BoxWidth)
		Trace.Write("BoxLength: " & BoxLength)
	End If 
Next
End Sub

 

 

4 REPLIES 4
Message 2 of 5
Damian_Apex
in reply to: Damian_Apex

I discovered this line of code, this will do the job ? 

Sub main
Dim oAssDoc As AssemblyDocument = ThisDoc.Document
Dim oDoc As Document
Dim BoxLength, BoxWidth As Double	

For Each oDoc In oAssDoc.AllReferencedDocuments
	If oDoc.DocumentType = kPartDocumentObject And oDoc.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then 'sheet metal part'

                Dim oSMDef As SheetMetalComponentDefinition 
oSMDef = PartDoc.ComponentDefinition
Dim dir1 As Double = oSMDef.FlatPattern.Length
Dim dir2 As Double = oSMDef.FlatPattern.Width 
Dim lengths As New List(Of Double) From {dir1, dir2} lengths.Sort BoxWidth = lengths(0) BoxLength = lengths(1) Trace.Write("oDoc: " & oDoc.DisplayName) Trace.Write("BoxWidth: " & BoxWidth) Trace.Write("BoxLength: " & BoxLength) End If Next End Sub

 

Message 3 of 5
WCrihfield
in reply to: Damian_Apex

I believe that those two iLogic snippets for getting flat pattern size target the 'active' document, which in this case would be the main assembly, and they don't appear to have an option that would allow you to specify a different component name or document name for them to target.  So, the next path to get those numbers is by stepping down through the normal Inventor API objects until we get to them.  They are two of the properties of the actual FlatPattern object, which is under the special SheetMetalComponentDefinition object, and acts like its own special type of ComponentDefinition.

Here is an alternate iLogic rule you can use.  You may, or may not have to convert the units of the resulting values returned, depending on your needs.

 

Sub main
	Dim oAssDoc As AssemblyDocument = ThisDoc.Document
	Dim oDoc As Document
	Dim BoxLength, BoxWidth As Double	

	For Each oDoc In oAssDoc.AllReferencedDocuments
		If oDoc.DocumentType = kPartDocumentObject And oDoc.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then 'sheet metal part'
			Dim oPDoc As PartDocument = oDoc
			Dim oSMDef As SheetMetalComponentDefinition = oPDoc.ComponentDefinition
			Dim oFP As FlatPattern
			If Not oSMDef.HasFlatPattern Then
				Try
					'tries to generate a FlatPattern
					oSMDef.Unfold
				Catch
				End Try
			End If
			If Not oSMDef.HasFlatPattern Then Continue For 'skip to next oDoc
			oFP = oSMDef.FlatPattern
			Dim dir1 As Double = oFP.Length
			Dim dir2 As Double = oFP.Width 	
			
			Dim lengths As New List(Of Double) From {dir1, dir2}
			lengths.Sort

			BoxWidth = lengths(0)
			BoxLength = lengths(1)
			
			Trace.Write("oDoc: " & oDoc.DisplayName)	
			Trace.Write("BoxWidth: " & BoxWidth)
			Trace.Write("BoxLength: " & BoxLength)
		End If 
	Next
End Sub

 

Oops...I didn't see that earlier response when posting this, that contains similar code.  Oh well.  My version contains a few extra checks in there to help avoid potential errors that you might like.

 

If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click (LIKE or KUDOS) 👍.

If you want and have time, I would appreciate your Vote(s) for My IDEAS :light_bulb: or you can Explore My CONTRIBUTIONS

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 4 of 5
WCrihfield
in reply to: Damian_Apex

Actually, now that I'm looking at the code in your second post here, I think I see a problem.

This line:

oSMDef = PartDoc.ComponentDefinition

most likely won't work, because that variable you are using there "PartDoc" has not been created/defined yet.

If might work like this though:

oSMDef = oDoc.ComponentDefinition

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 5 of 5
Damian_Apex
in reply to: Damian_Apex

Thank you for your attention. This is part of bigger code and I am transferring it to sub procedure and rename it.

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

Post to forums  

Autodesk Design & Make Report