I just gave you the way you can do it for ipt. You can make a loop that iterates through all components in assembly(iam) and does that routine for each component. You can also make a macro that creates flat patterns for selected components for example, just need to now how you wan't it to work.
Is your plan to use this together with flat pattern dxf export? If it is, you can add that snippet inside the flat pattern export macro. Here is flat pattern creation added to dxf export code. So this will make flat pattern for sheet metal parts that has no flat pattern before creating the view. Is this what you need?
'Create sheet for sheetmetal parts with flatpattern
'Get Inventor and Document
Dim oApp As Inventor.Application
Set oApp = ThisApplication
Dim oDoc As AssemblyDocument
Set oDoc = oApp.ActiveDocument
Dim oDrawing As DrawingDocument
Set oDrawing = oApp.Documents.Add(kDrawingDocumentObject)
'oApp.SilentOperation = True
Dim oDXFSheet As Sheet
Set oDXFSheet = oDrawing.Sheets.Add(DrawingSheetSizeEnum.kA0DrawingSheetSize, PageOrientationTypeEnum.kLandscapePageOrientation, "DXF")
'Set oDXFSheet = oDrawing.ActiveSheet
'DXFSheet.name = "DXF"
Dim oUserProps As PropertySet
Set oUserProps = oDoc.PropertySets.Item("User Defined Properties")
Dim oPoint As Point2d
Dim oTG As TransientGeometry
Set oTG = oApp.TransientGeometry
Set oPoint = oTG.CreatePoint2d(0, 0)
Dim oPartDoc As PartDocument
Dim blnHasFlat As Boolean
Dim oPartProps As PropertySets
Dim dblSheetWidth As Double
Dim dblSheetHeight As Double
Dim oOcc As ComponentOccurrence
Dim oBOMView As BOMView
Set oBOMView = oDoc.ComponentDefinition.BOM.BOMViews.Item("Parts Only")
'Set oBOMView = oDoc.ComponentDefinition.BOM.BOMViews.Item("Structured")
Dim oView As DrawingView
Dim oBOMRow As BOMRow
Dim i As Integer
i = 1
Dim dblViewOffset As Double
dblViewOffset = 5
For Each oBOMRow In oBOMView.BOMRows
'get ipt
If oBOMRow.ComponentDefinitions.Item(1).Type = ObjectTypeEnum.kSheetMetalComponentDefinitionObject Then
Set oPartDoc = oBOMRow.ComponentDefinitions.Item(1).Document
Set oPartProps = oPartDoc.PropertySets 'you can get iproperty values to textboxes also
If oPartDoc.ComponentDefinition.Type = ObjectTypeEnum.kSheetMetalComponentDefinitionObject Then 'if you have controlling custom property that tells if dxf-view should be created put it also to this line with "AND"
If oPartDoc.ComponentDefinition.HasFlatPattern = False Then
'create flat pattern
Dim oSM As SheetMetalComponentDefinition
Set oSM = oPartDoc.ComponentDefinition
Call oSM.Unfold
End If
If oPartDoc.ComponentDefinition.HasFlatPattern = True Then
'create drawing view
Dim oBaseViewOptions As NameValueMap
Set oBaseViewOptions = oApp.TransientObjects.CreateNameValueMap
Call oBaseViewOptions.Add("SheetMetalFoldedModel", False)
Set oView = oDXFSheet.DrawingViews.AddBaseView(oPartDoc, oPoint, 1, ViewOrientationTypeEnum.kDefaultViewOrientation, DrawingViewStyleEnum.kHiddenLineRemovedDrawingViewStyle, , , oBaseViewOptions)
'move view to new position
Dim newPos As Point2d
If i > 1 Then
Set newPos = oTG.CreatePoint2d(oDXFSheet.DrawingViews.Item(i - 1).Position.X + oDXFSheet.DrawingViews.Item(i - 1).Width / 2 + oView.Width / 2 + dblViewOffset, oDXFSheet.DrawingViews.Item(i).Height / 2 + dblViewOffset / 2)
oView.Position = newPos
'dblSheetWidth = dblSheetWidth + oDXFSheet.DrawingViews.Item(i).Width + dblViewOffset
ElseIf i = 1 Then
Set newPos = oTG.CreatePoint2d(oDXFSheet.DrawingViews.Item(i).Width / 2 + dblViewOffset / 2, oDXFSheet.DrawingViews.Item(i).Height / 2 + dblViewOffset / 2)
oView.Position = newPos
End If
'create text boxes for part info
Dim strPartnum As String
Dim strMaterial As String
Dim strItemQTY As String
strPartnum = "Part Number: " & oBOMRow.ItemNumber 'normally balloon value
strMaterial = "Material: " & oPartDoc.ComponentDefinition.Material.name
strItemQTY = "Item Quantity:" & oBOMRow.ItemQuantity & "Pcs"
'Add info to sheet
Dim oText1 As Inventor.GeneralNote
Dim oText2 As Inventor.GeneralNote
Dim oText3 As Inventor.GeneralNote
Dim oTxtPoint1 As Point2d
Dim oTxtPoint2 As Point2d
Dim oTxtPoint3 As Point2d
Dim dblOffset As Double
dblOffset = 1
Set oTxtPoint1 = oTG.CreatePoint2d(oView.Position.X, (oView.Position.Y - oView.Height / 2 - dblOffset))
Set oText1 = oDXFSheet.DrawingNotes.GeneralNotes.AddFitted(oTxtPoint1, strPartnum)
Set oTxtPoint2 = oTG.CreatePoint2d(oTxtPoint1.X, (oTxtPoint1.Y - dblOffset))
Set oText2 = oDXFSheet.DrawingNotes.GeneralNotes.AddFitted(oTxtPoint2, strMaterial)
Set oTxtPoint3 = oTG.CreatePoint2d(oTxtPoint2.X, (oTxtPoint2.Y - dblOffset))
Set oText3 = oDXFSheet.DrawingNotes.GeneralNotes.AddFitted(oTxtPoint3, strItemQTY)
i = i + 1
End If
End If
End If
Next
'save dxf
' Get the DXF translator Add-In.
Dim DXFAddIn As TranslatorAddIn
Set DXFAddIn = ThisApplication.ApplicationAddIns.ItemById("{C24E3AC4-122E-11D5-8E91-0010B541CD80}")
Dim oContext As TranslationContext
Set oContext = ThisApplication.TransientObjects.CreateTranslationContext
oContext.Type = kFileBrowseIOMechanism
' Create a NameValueMap object
Dim oOptions As NameValueMap
Set oOptions = ThisApplication.TransientObjects.CreateNameValueMap
' Create a DataMedium object
Dim oDataMedium As DataMedium
Set oDataMedium = ThisApplication.TransientObjects.CreateDataMedium
' Check whether the translator has 'SaveCopyAs' options
If DXFAddIn.HasSaveCopyAsOptions(oDrawing, oContext, oOptions) Then
Dim strIniFile As String
strIniFile = "C:\DXF_test.ini"
' Create the name-value that specifies the ini file to use.
oOptions.Value("Export_Acad_IniFile") = strIniFile
End If
'Set the destination file name
oDataMedium.filename = "c:\tempdxfout.dxf"
'Publish document.
Call DXFAddIn.SaveCopyAs(oDrawing, oContext, oOptions, oDataMedium)