- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Automatic multi sheet drawing for assambly and all subassambly
Hi,
I need ilogic code for creation multi sheet drawing for assambly an all sub assambly in all levels.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Please don't confuse this forum with the free coding factory.
Please describe, what do you want to do, what do you try (ideally problematic piece of code) and specify your question. Then members of this forum can help you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Sorry,
I use thise code for automatic drawing sheet bay sheet and only open assambly:
Sub main 'Dim oAsmDoc As Document = ThisDoc.Document Dim oAsmDoc As _Document = ThisApplication.ActiveDocument templateFile = "Template.idw" Dim oDrawingDoc As DrawingDocument = ThisApplication.Documents.Add(DocumentTypeEnum.kDrawingDocumentObject,templateFile,True) oDrawingDoc.Activate() Dim oSheet As Sheet = oDrawingDoc.Sheets.Item(1) Dim oPoint1 As Point2d = ThisApplication.TransientGeometry.CreatePoint2d(oSheet.Width/4, oSheet.Height/1.25) Dim oPoint2 As Point2d = ThisApplication.TransientGeometry.CreatePoint2d(oSheet.Width/1.25, oSheet.Height/3) Dim oView As DrawingView oView = oSheet.DrawingViews.AddBaseView(oAsmDoc, oPoint2, 1/30, ViewOrientationTypeEnum.kIsoTopRightViewOrientation,DrawingViewStyleEnum.kShadedDrawingViewStyle ) 'oView.RotateByAngle((PI / 180), True) oView = oSheet.DrawingViews.AddBaseView(oAsmDoc, oPoint1, 1 / 20, ViewOrientationTypeEnum.kFrontViewOrientation, DrawingViewStyleEnum.kHiddenLineRemovedDrawingViewStyle, ) Dim V2Point2D As Point2d = ThisApplication.TransientGeometry.CreatePoint2d(oView.Center.X, oView.Center.Y + 10) Dim V3Point2D As Point2d = ThisApplication.TransientGeometry.CreatePoint2d(oView.Center.X - 10, oView.Center.Y) Dim oView2 As DrawingView = oSheet.DrawingViews.AddProjectedView(oView, V2Point2D, DrawingViewStyleEnum.kFromBaseDrawingViewStyle) oView2.Position = ThisApplication.TransientGeometry.CreatePoint2d(oView.Center.X, oView.Center.Y - oView.Height / 2 - oSep - oView2.Height / 2) End Sub
, and i lyke to modif for multi sheet drawing and all subassambly with part number.
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
tahks.
"its works", only is created 2 sheets only with same assambly and each subassambly in iwd separate.
I need 1 .iwd with multi sheets for each subassambly whith part number in all levels of BOM. If assambly no have part number, ignore...
Merci.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
OK,
Create new drawing once in Main() method. You have method for creation sheet layout "CreateFirstSheet()" which accepts sheet and assembly document as arguments.
Now you can create new sheet within "For Each doc As Document In oAsmDoc.AllReferencedDocuments" loop and create layout using "CreateFirstSheet(newSheet, doc)" instead of "CreteAssemblyDrawing(doc, templateFile)"