06-27-2024
03:35 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
06-27-2024
03:35 AM
Hi, Maybe this can be a start.
Sub main ' Get the active assembly. '------------------------------------------------------------------------------------- Dim AssyName As String = "Section3_AngleSupports" 'name of the SubAssy Dim TemplateName As String = "white.dwg" 'name of the template Dim Scale As String = "1:1" 'scale '------------------------------------------------------------------------------------- Dim oAsmDoc As AssemblyDocument = ThisApplication.ActiveDocument ' Call the function that does the recursion. TraverseAssembly(oAsmDoc.ComponentDefinition.Occurrences, 1, AssyName, TemplateName, Scale) End Sub Private Sub TraverseAssembly(Occurrences As ComponentOccurrences, Level As Integer, Name As String, TemplateName As String, scale As String) ' Iterate through all of the occurrence in this collection. This ' represents the occurrences at the top level of an assembly. Dim DesignProject = ThisApplication.DesignProjectManager.ActiveDesignProject Dim DrawingTemplate As String = System.IO.Path.Combine(DesignProject.TemplatesPath, TemplateName) Dim oOcc As ComponentOccurrence For Each oOcc In Occurrences ' Check to see if this occurrence represents a subassembly ' and recursively call this function to traverse through it. If oOcc.DefinitionDocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then If oOcc.Name = Name Then Dim AssyDoc As AssemblyDocument = oOcc.Definition.Document Dim oDrawDoc As DrawingDocument = CreateDrawing(DrawingTemplate) CreateViews(oDrawDoc, AssyDoc, scale) End If TraverseAssembly(oOcc.SubOccurrences, Level + 1, Name, TemplateName, scale) End If Next End Sub Private Function CreateDrawing(DrawingDoc As String) As DrawingDocument Dim result As DrawingDocument = Nothing Try Dim oNewDrawDoc As DrawingDocument = Nothing oNewDrawDoc = ThisApplication.Documents.Add(DocumentTypeEnum.kDrawingDocumentObject, DrawingDoc) result = oNewDrawDoc Catch ex As Exception MsgBox(ex.ToString, MsgBoxStyle.Critical, "CreateDrawing") End Try Return result End Function Private Sub CreateViews(ByVal oDrawDoc As DrawingDocument, ByVal oAssyDoc As AssemblyDocument, scale As String) Try 'Set a reference to the active sheet. Dim oSheet As Sheet = oDrawDoc.ActiveSheet ' Create the placement point object. Dim Point1 As Double = ((oSheet.Width) / 2) - 8 Dim Point2 As Double = ((oSheet.Height) / 2) - 6 Dim oPoint As Point2d oPoint = ThisApplication.TransientGeometry.CreatePoint2d(Point1, Point2) 'view 1 FrontView Dim oView As DrawingView = CreateView(oAssyDoc, oSheet, oPoint, True, "Front", ViewOrientationTypeEnum.kFrontViewOrientation) oView.ScaleString = scale oView.ViewStyle = DrawingViewStyleEnum.kShadedDrawingViewStyle CreateProjectedView(oView, oSheet, "Top", oView.Height) CreateProjectedView(oView, oSheet, "Side", , oView.Width) CreateProjectedView(oView, oSheet, "Iso", oView.Height, oView.Width) Catch ex As Exception MsgBox("General error in CreateViews, ex= " & ex.GetBaseException.ToString, MsgBoxStyle.Critical, "Error") End Try End Sub Private Function CreateView(ByVal oAssyDoc As AssemblyDocument, oSheet As Sheet, oInsertionPoint2D As Point2d, Folded As Boolean, ByVal DrawingViewName As String, ByVal ViewOrientation As ViewOrientationTypeEnum) As DrawingView Dim result As DrawingView = Nothing Try ' Create a BaseView. Dim oBaseView As DrawingView oBaseView = oSheet.DrawingViews.AddBaseView(oAssyDoc, oInsertionPoint2D, 1, ViewOrientation, DrawingViewStyleEnum.kShadedDrawingViewStyle) oBaseView.Name = DrawingViewName result = oBaseView Catch ex As Exception MsgBox("General error in CreateView, ex= " & ex.GetBaseException.ToString, MsgBoxStyle.Critical, "Error") End Try Return result End Function Private Function CreateProjectedView(ByVal baseView As DrawingView, sheet As Sheet, DrawingViewName As String, Optional height As Double = 0, Optional width As Double = 0) As DrawingView Dim result As DrawingView = Nothing Try Dim oPositionBaseView As Point2d = baseView.Position Dim xBaseView As Double = oPositionBaseView.X Dim yBaseView As Double = oPositionBaseView.Y Dim oPointBottomView2 As Point2d oPointBottomView2 = ThisApplication.TransientGeometry.CreatePoint2d((xBaseView + width * 3), (yBaseView + height * 1.5)) 'BottomView Dim oProjected As DrawingView oProjected = sheet.DrawingViews.AddProjectedView(baseView, oPointBottomView2, DrawingViewStyleEnum.kShadedDrawingViewStyle) oProjected.Name = DrawingViewName result = oProjected Catch ex As Exception MsgBox("General error in CreateView, ex= " & ex.GetBaseException.ToString, MsgBoxStyle.Critical, "Error") End Try Return result End Function