Message 1 of 6
Drawing creation for each Part
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi All,
I want to create two views for each part in this code but i dont know how to use document as a component occurences
Sub main Dim modelReference As Document = ThisApplication.ActiveDocument CreateSheet() ShowPanelParts(modelReference) End Sub Sub CreateSheet ' Set the path to the template file Dim templatePath As String = "C:\_VaultPro\Templates\MKT DESIGN TEMPLATE.dwg" Dim oDoc As DrawingDocument = ThisApplication.Documents.Add(DocumentTypeEnum.kDrawingDocumentObject, templatePath) Dim oSheet As Sheet = oDoc.Sheets(1) ' Display message MessageBox.Show("Drawing created successfully from the template!") End Sub Sub ShowPanelParts(modelReference As Document) ' Check if the document is an assembly If modelReference.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then ' Get the assembly document Dim oAsmDoc As AssemblyDocument = modelReference ' Create a collection to store unique part names (without "LEFT" or "RIGHT") Dim uniqueParts As New Collection() ' Loop through all the components in the assembly For Each oComp As ComponentOccurrence In oAsmDoc.ComponentDefinition.Occurrences ' Skip suppressed parts If oComp.Suppressed = False Then ' Check if the component name contains "PANEL" (case-sensitive, all uppercase) If InStr(oComp.Name, "PANEL") > 0 Then ' Remove "LEFT" and "RIGHT" from the name to treat them as one part Dim partName As String = oComp.Name.ToUpper() ' Remove "LEFT" or "RIGHT" from the name partName = Replace(partName, " LEFT", "") partName = Replace(partName, " RIGHT", "") ' Check if the part name already exists in the unique parts collection Dim isDuplicate As Boolean = False For Each uniquePart As String In uniqueParts If uniquePart = partName Then isDuplicate = True Exit For End If Next ' If it's not a duplicate, add it to the collection and show the message If Not isDuplicate Then uniqueParts.Add(partName) ' CreateViews(oComp) MessageBox.Show("Found part: " & oComp.Name) CreateViews(oComp) End If End If End If Next Else MessageBox.Show("The active document is not an assembly.") End If End Sub '*** Define Scale Sub CreateViews(oComp As ComponentOccurrence) ' Scale for the views Dim scale As Double = 1 / 3 ' Get Active Drawing Sheet Dim oDoc As DrawingDocument = ThisApplication.ActiveDocument Dim oSheet As Sheet = oDoc.ActiveSheet DeleteAllViews(oSheet) ' Define View Locations Dim sheetCenterVertical As Double = (oSheet.Height / 2) Dim isoViewHorizontal As Double = (oSheet.Width * 0.25) Dim frontViewHorizontal As Double = (oSheet.Width * 0.75) ' Create Points for View Locations Dim oIsoViewPoint As Point2d = ThisApplication.TransientGeometry.CreatePoint2d(isoViewHorizontal, sheetCenterVertical) Dim oFrontViewPoint As Point2d = ThisApplication.TransientGeometry.CreatePoint2d(frontViewHorizontal, sheetCenterVertical) ' Define View Orientation Dim isoViewOrientation As ViewOrientationTypeEnum = kIsoTopRightViewOrientation Dim frontViewOrientation As ViewOrientationTypeEnum = kFrontViewOrientation ' Define View Style Dim isoViewStyle As DrawingViewStyleEnum = kShadedDrawingViewStyle Dim frontViewStyle As DrawingViewStyleEnum = kHiddenLineRemovedDrawingViewStyle ' Create the Views for the specific panel part Dim oIsoView As DrawingView = oSheet.DrawingViews.AddBaseView(oComp, oIsoViewPoint, scale, isoViewOrientation, isoViewStyle) oIsoView.Name = oComp.Name & " ISOMETRIC VIEW" Dim oFrontView As DrawingView = oSheet.DrawingViews.AddBaseView(oComp, oFrontViewPoint, scale, frontViewOrientation, frontViewStyle) oFrontView.Name = oComp.Name & " FRONT VIEW" End Sub '*** Function To Delete All Views Sub DeleteAllViews(oSheet As Sheet) Dim oView As DrawingView For Each oView In oSheet.DrawingViews oView.Delete() Next End Sub
Can any one help please