This is not perfect but I guess it's a good start. You will need to change some stuff where I added comments
Sub Main()
Dim doc As AssemblyDocument = ThisDoc.Document
Dim def As AssemblyComponentDefinition = doc.ComponentDefinition
For Each refDoc As Document In doc.AllReferencedDocuments
If (refDoc.DocumentType <> DocumentTypeEnum.kPartDocumentObject) Then Continue For
If (refDoc.SubType <> "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}") Then Continue For
DoStuffToSheetmetalPart(refDoc)
Next
End Sub
Private Sub DoStuffToSheetmetalPart(modelDoc As Document)
' Set your templateFileName
Dim templateFileName = ""
Dim drawingDoc As DrawingDocument = ThisApplication.Documents.Add(DocumentTypeEnum.kDrawingDocumentObject, templateFileName)
Dim sheet As Sheet = drawingDoc.ActiveSheet
Dim view As DrawingView = CreateBaseFlatPatternView(sheet, modelDoc)
AddBendNotes(view)
CreateIsoView(sheet, modelDoc)
Dim name = System.IO.Path.ChangeExtension(modelDoc.FullDocumentName, ".idw")
drawingDoc.SaveAs(name, True)
name = System.IO.Path.ChangeExtension(modelDoc.FullDocumentName, ".pdf")
drawingDoc.SaveAs(name, True)
name = System.IO.Path.ChangeExtension(modelDoc.FullDocumentName, ".dwg")
drawingDoc.SaveAs(name, True)
drawingDoc.Close(True)
End Sub
Private Function GetModelDocument(modelDocName As String)
Dim modelDoc As Document = ThisApplication.Documents.Open(modelDocName)
Dim oSMDef As SheetMetalComponentDefinition = modelDoc.ComponentDefinition
If oSMDef.HasFlatPattern = False Then
oSMDef.Unfold()
oSMDef.FlatPattern.ExitEdit()
End If
Return modelDoc
End Function
Private Sub AddBendNotes(view As DrawingView)
Dim bendCurves = view.DrawingCurves.Cast(Of DrawingCurve).
Where(Function(curve) curve.EdgeType = DrawingEdgeTypeEnum.kBendDownEdge Or
curve.EdgeType = DrawingEdgeTypeEnum.kBendUpEdge).ToList()
Dim layers As LayersEnumerator = view.Parent.Parent.StylesManager.Layers
' change to your own layer
Dim layer As Layer = layers.Item("Hatch (ANSI)")
Dim bendNotes = view.Parent.DrawingNotes.BendNotes
For Each curve As DrawingCurve In bendCurves
Dim note = bendNotes.Add(curve)
note.Layer = layer
For Each segment As DrawingCurveSegment In curve.Segments
segment.Layer = layer
Next
Next
End Sub
Private Function CreateBaseFlatPatternView(sheet As Sheet, modelDoc As Document)
Dim oBaseViewOptions As NameValueMap = ThisApplication.TransientObjects.CreateNameValueMap
oBaseViewOptions.Add("SheetMetalFoldedModel", False)
' Change view position here
Dim position As Point2d = ThisApplication.TransientGeometry.CreatePoint2d(10, 10)
' change scale here
Dim scale As Double = 0.5
Dim view As DrawingView = sheet.DrawingViews.AddBaseView(modelDoc, position,
scale,
ViewOrientationTypeEnum.kFrontViewOrientation,
DrawingViewStyleEnum.kShadedDrawingViewStyle,,,
oBaseViewOptions)
Return view
End Function
Private Function CreateIsoView(sheet As Sheet, modelDoc As Document)
' Change view position here
Dim position As Point2d = ThisApplication.TransientGeometry.CreatePoint2d(20, 20)
' change scale here
Dim scale As Double = 0.5
Dim view As DrawingView = sheet.DrawingViews.AddBaseView(modelDoc, position,
scale,
ViewOrientationTypeEnum.kIsoTopLeftViewOrientation,
DrawingViewStyleEnum.kShadedDrawingViewStyle)
Return view
End Function
Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

Blog: hjalte.nl - github.com