How to debug this automate drafting rule

How to debug this automate drafting rule

ssiem12
Contributor Contributor
357 Views
2 Replies
Message 1 of 3

How to debug this automate drafting rule

ssiem12
Contributor
Contributor

Hello

I got this rule from a cool guy

 

 

this rule is purpose to generate drawing with file in every class

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

    Dim dDoc As DrawingDocument = ThisApplication.Documents.Add(DocumentTypeEnum.kDrawingDocumentObject)
    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

    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)

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

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

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

    baseView.Scale = scale
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

I've run this rule and there is error on 26row

ssiem12_0-1685335380109.png

Could any guy help me?

 

additionally it generate sheet with size A and i use size A3 usually can i change this setting?

and I will use this like run this rule and generate sheets and copy these sheets then past it on my drawing file that I'm working

but the style is not updated so line color is not fit like below

ssiem12_1-1685335782514.png

above is a drawing made from sheet generated by rule

ssiem12_2-1685335818564.png

above is pasted on my working drawing file

ssiem12_3-1685335842767.png

above is a style I use usually on my working drawing file

 

 

0 Likes
Accepted solutions (1)
358 Views
2 Replies
Replies (2)
Message 2 of 3

JelteDeJong
Mentor
Mentor
Accepted solution

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

0 Likes
Message 3 of 3

ssiem12
Contributor
Contributor

are you god of programming?

0 Likes