10-05-2022
07:09 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
10-05-2022
07:09 AM
You can extend your code like this
Some variables have been renamed for better readability.
Sub main()
Dim templateFile = "" ' "Template.idw"
Dim oAsmDoc As AssemblyDocument = ThisDoc.Document
'Main assembly drawing
CreteAssemblyDrawing(oAsmDoc, templateFile)
'Drawings for sub-assemblies
For Each doc As Document In oAsmDoc.AllReferencedDocuments
If doc.DocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then Continue For
CreteAssemblyDrawing(doc, templateFile)
Next
End Sub
Private Sub CreteAssemblyDrawing(oAsmDoc As _Document, templateFile As String)
'Create and activate new drawing
Dim oDrawingDoc As DrawingDocument = ThisApplication.Documents.Add(
DocumentTypeEnum.kDrawingDocumentObject,
templateFile,
True
)
oDrawingDoc.Activate()
'Create sheets
Dim numberOfSheets = 2
For sheetNumber As Integer = 1 To numberOfSheets
If oDrawingDoc.Sheets.Count < sheetNumber Then
Dim size As DrawingSheetSizeEnum = DrawingSheetSizeEnum.kA4DrawingSheetSize
Dim orientation = PageOrientationTypeEnum.kPortraitPageOrientation
Dim oSheet = oDrawingDoc.Sheets.Add(size, orientation)
'TODO: Add title block, border etc.
End If
Next
'Get first sheet
Dim firstSheet As Sheet = oDrawingDoc.Sheets.Item(1)
CreateFirstSheet(firstSheet, oAsmDoc)
'Get second sheet
Dim secondSheet As Sheet = oDrawingDoc.Sheets.Item(2)
CreateSecondSheet(secondSheet, oAsmDoc)
'And so on...
End Sub
Private Sub CreateFirstSheet(oSheet As Sheet, oAsmDoc As _Document)
'Implement you own layout for first sheet
'Create isometric view
Dim isoViewPosition As Point2d = ThisApplication.TransientGeometry.CreatePoint2d(oSheet.Width / 1.25,
oSheet.Height / 3)
Dim isoView = oSheet.DrawingViews.AddBaseView(
oAsmDoc,
isoViewPosition,
1 / 30,
ViewOrientationTypeEnum.kIsoTopRightViewOrientation,
DrawingViewStyleEnum.kShadedDrawingViewStyle
)
'Create frontView
Dim frontViewPosition As Point2d = ThisApplication.TransientGeometry.CreatePoint2d(oSheet.Width / 4,
oSheet.Height / 1.25)
Dim frontView = oSheet.DrawingViews.AddBaseView(
oAsmDoc,
frontViewPosition,
1 / 20,
ViewOrientationTypeEnum.kFrontViewOrientation,
DrawingViewStyleEnum.kHiddenLineRemovedDrawingViewStyle
)
'NOT USED
'Dim V3Point2D As Point2d = ThisApplication.TransientGeometry.CreatePoint2d(frontView.Center.X - 10, frontView.Center.Y)
'Get top view initial position
'Dim topViewPosition As Point2d = ThisApplication.TransientGeometry.CreatePoint2d(frontView.Center.X, frontView.Center.Y + 10)
Dim topViewPosition As Point2d = frontView.Center.Copy()
topViewPosition.Y += 10
'Create top (projected) view
Dim topView As DrawingView = oSheet.DrawingViews.AddProjectedView(
frontView,
topViewPosition,
DrawingViewStyleEnum.kFromBaseDrawingViewStyle
)
'Move top view to final position
Dim oSep As Double = 1 'NOT DECLARED
topViewPosition.Y = frontView.Center.Y - frontView.Height / 2 - oSep - topView.Height / 2
topView.Position = topViewPosition
End Sub
Private Sub CreateSecondSheet(oSheet As Sheet, oAsmDoc As _Document)
'TODO: Implement you own layout for second sheet
'I reuse the same code for first sheet
CreateFirstSheet(oSheet, oAsmDoc)
End Sub