- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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 FunctionI've run this rule and there is error on 26row
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
above is a drawing made from sheet generated by rule
above is pasted on my working drawing file
above is a style I use usually on my working drawing file
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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.
Blog: hjalte.nl - github.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report