Hello, here I have prepared a code that could help you. Since I do not know where you will take the list, I assumed that one could select the parts directly from the assembly file, through a "Do While" loop.
So in the assembly file, execute this macro.
Sub NewDrawing()
' Set path of drawing template file
Dim templateFile As String
templateFile = "E:\Inventor\Plantillas\RIAL_A4.idw"
'-------------------------------------------------
'''Set collection occurrences
Dim comps As ObjectCollection
Set comps = ThisApplication.TransientObjects.CreateObjectCollection
Dim comp As ComponentOccurrence
Do While True
Set comp = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAssemblyOccurrenceFilter, "Select a component")
If comp Is Nothing Then Exit Do
Call comps.Add(comp)
Loop
'---------------------------------------------
''' Create new drawing from sheetmetal
' Create a new NameValueMap object
Dim oBaseViewOptions As NameValueMap
Set oBaseViewOptions = ThisApplication.TransientObjects.CreateNameValueMap
Call oBaseViewOptions.Add("SheetMetalFoldedModel", False) 'True = folded view _False = flat pattern view
' If there are selected components we can do something
For Each comp In comps
On Error Resume Next
Dim oDoc As Document
Set oDoc = comp.Definition.Document ' Document from occurrence
'Remove extension .ipt
Dim oFilename As String
oFilename = Left(oDoc.FullFileName, (InStrRev(oDoc.FullFileName, ".", -1, vbTextCompare) - 1))
If oDoc.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then
Dim oDef As SheetMetalComponentDefinition
oDef = oDoc.ComponentDefinition
If oDef.HasFlatPattern = True Then
Dim oDrawingDoc As DrawingDocument
Set oDrawingDoc = ThisApplication.Documents.Add(DocumentTypeEnum.kDrawingDocumentObject, templateFile, True)
Call oDrawingDoc.Activate
Dim oSheet As Sheet
Set oSheet = oDrawingDoc.Sheets.Item(1)
Dim oPoint1 As Point2d
Set oPoint1 = ThisApplication.TransientGeometry.CreatePoint2d(5, 5)
Dim oView As DrawingView
Set oView = oSheet.DrawingViews.AddBaseView(oDoc, oPoint1, 1, ViewOrientationTypeEnum.kDefaultViewOrientation, DrawingViewStyleEnum.kHiddenLineDrawingViewStyle, , , oBaseViewOptions)
Call oDoc.ReleaseReference
' Save New Drawing Document
Call oDrawingDoc.SaveAs(oFilename & ".idw", True)
'Call oDrawingDoc.Close
Call FlatPatternDXF(oDoc, oFilename)
Call oDoc.Close(True)
End If
End If
Next
End Sub
Private Sub FlatPatternDXF(oDoc As Document, oFilename As String)
'config
'Change values located here to change output.
Dim sOut As String
sOut = "FLAT PATTERN DXF?AcadVersion=2000" _
+ "&OuterProfileLayer=OUTER_PROF&OuterProfileLayerColor=0;0;0" _
+ "&InteriorProfilesLayer=INNER_PROFS&InteriorProfilesLayerColor=0;0;0" _
+ "&FeatureProfileLayer=FEATURE&FeatureProfileLayerColor=0;0;0" _
+ "&BendUpLayer=BEND_UP&BendUpLayerColor=0;255;0&BendUpLayerLineType=37634" _
+ "&BendDownLayer=BEND_DOWN&BendDownLayerColor=0;255;0&BendDownLayerLineType=37634" _
'/config
'Processing:
Dim oDataIO As DataIO
Set oDataIO = oDoc.ComponentDefinition.DataIO
Dim oDXFfileNAME As String
oDXFfileNAME = oFilename & ".dxf"
Call oDataIO.WriteDataToFile(sOut, oDXFfileNAME)
End Sub
Then you select the parts that you want to create the drawing files, if they are metal sheet and have the "FlatPattern" they will create the drawings of these parts. In the drawing you will create the "FlatPattern" view, then save this file and export a dxf from the source part file. If you want to close this drawing file you could activate the deactivated line (the green code line 'oDrawingDoc.Close)
I have deactivated this line because usually one must customize the drawing a little by adding dimensions notes, etc.
Try to make the code legible, divide it up so that the collection of objects is understood and how to work with them, if you have a list you could touch up the code and add your personalized part.
I hope the content is useful. regards
Please accept as solution and give likes if applicable.
I am attaching my Upwork profile for specific queries.
Sergio Daniel Suarez
Mechanical Designer
| Upwork Profile | LinkedIn