Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.
JelteDeJong
in reply to: ssiem12

I changed the code a bit and you should not get the exception any more. About the styles; the code uses your default drawing template I guess you use another template. In the code a line (6) where you can set the full file name of the template that you want to use.

Sub Main()
    Dim doc As AssemblyDocument = ThisDoc.Document
    Dim def As AssemblyComponentDefinition = doc.ComponentDefinition

    ' Change this if you dont want to use the default template
    Dim templateFileName As String = ""

    Dim dDoc As DrawingDocument = ThisApplication.Documents.Add(DocumentTypeEnum.kDrawingDocumentObject, templateFileName)
    Dim sheet As Sheet = dDoc.ActiveSheet

    FillSheet(sheet, doc)

    For Each refDoc As Document In doc.AllReferencedDocuments
        Dim newSHeet = dDoc.Sheets.Add()
        FillSheet(newSHeet, refDoc)
    Next
End Sub

Private Sub FillSheet(sheet As Sheet, doc As Document)
    sheet.Name = doc.DisplayName
    Dim sheetW4 = sheet.Width / 4
    Dim sheetH4 = sheet.Height / 4

    Try
        Dim position As Point2d = ThisApplication.TransientGeometry.CreatePoint2d(sheetW4, sheetH4)
        Dim baseView As DrawingView = sheet.DrawingViews.AddBaseView(doc, position, 1, ViewOrientationTypeEnum.kFrontViewOrientation, DrawingViewStyleEnum.kHiddenLineDrawingViewStyle)
        Dim scale = CalculateScale(baseView)
        baseView.Scale = scale

        position = ThisApplication.TransientGeometry.CreatePoint2d(sheetW4 * 3, sheetH4)
        Dim view = sheet.DrawingViews.AddProjectedView(baseView, position, DrawingViewStyleEnum.kFromBaseDrawingViewStyle, scale)
        scale = Math.Min(scale, CalculateScale(view))

        position = ThisApplication.TransientGeometry.CreatePoint2d(sheetW4, sheetH4 * 3)
        view = sheet.DrawingViews.AddProjectedView(baseView, position, DrawingViewStyleEnum.kFromBaseDrawingViewStyle, scale)
        scale = Math.Min(scale, CalculateScale(view))

        position = ThisApplication.TransientGeometry.CreatePoint2d(sheetW4 * 3, sheetH4 * 3)
        view = sheet.DrawingViews.AddProjectedView(baseView, position, DrawingViewStyleEnum.kFromBaseDrawingViewStyle, scale)
        scale = Math.Min(scale, CalculateScale(view))

        baseView.Scale = scale
        view.Scale = scale
    Catch ex As Exception
        MsgBox("Something went wrong while creating sheet for model: " & doc.DisplayName)
        Return
    End Try
End Sub

Private Function CalculateScale(view As DrawingView) As Double
    Dim scaleX = view.Parent.Width / view.Width / 2
    Dim scaleY = view.Parent.Height / view.Height / 2
    Return Math.Min(scaleX, scaleY)
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.

EESignature


Blog: hjalte.nl - github.com