Hello,
This is VBA Code for automatic creation of Drawings in Assembly file. Here i got one small difficulty, while creations of section views
In that attachment code,
' Get the circular edge of the top of the part.
Dim oObjs As ObjectCollection
Set oObjs = oAssemblyDoc.AttributeManager.FindObjects("Name", "Name", "Edge11")
Dim oCircularEdge As Edge
Set oCircularEdge = oObjs.Item(1)
Highlighted line got error in this code.
Pls find the suitable solutions for this
Option Explicit
' This creates a toolbar with buttons for the macros to be demonstrated.
Public Sub CreateDemoToolbar()
Dim oCommandBar As CommandBar
Set oCommandBar = ThisApplication.UserInterfaceManager.CommandBars.Add("Drawing Automation Samples", "")
oCommandBar.Visible = True
' Buttons for drawing view related samples.
Set oMacroDef = ThisApplication.CommandManager.ControlDefinitions.AddMacroControlDefinition("modOverallDimensions.TestOverallDimensions")
Call oCommandBar.Controls.AddMacro(oMacroDef)
Set oMacroDef = ThisApplication.CommandManager.ControlDefinitions.AddMacroControlDefinition("modSamples.MakeDrawing")
Call oCommandBar.Controls.AddMacro(oMacroDef)
End Sub
' Demonstrates the ability to automatically create a drawing. It's hard coded to look for edges
' with specific attributes attached. The supplied model is already set up.
Public Sub MakeDrawing()
' Create a new drawing document using the default template.
Dim oDrawDoc As DrawingDocument
Set oDrawDoc = ThisApplication.Documents.Add(kDrawingDocumentObject, "dwg", True)
Dim oSheet As Sheet
Set oSheet = oDrawDoc.ActiveSheet
' Open the part to be inserted into the drawing.
Dim oAssemblyDoc As AssemblyDocument
Set oAssemblyDoc = ThisApplication.Documents.Open("Assembly.iam", False)
Dim oTG As TransientGeometry
Set oTG = ThisApplication.TransientGeometry
MsgBox "Create base and orthographic views."
' Place the base front view.
Dim oFrontView As DrawingView
Set oFrontView = oSheet.DrawingViews.AddBaseView(oAssemblyDoc, oTG.CreatePoint2d(12, 15), 5, kFrontViewOrientation, kHiddenLineDrawingViewStyle)
' Create the top, right and iso views.
Dim oTopView As DrawingView
Set oTopView = oSheet.DrawingViews.AddProjectedView(oFrontView, oTG.CreatePoint2d(12, 30), kFromBaseDrawingViewStyle)
Dim oIsoView As DrawingView
Set oIsoView = oSheet.DrawingViews.AddProjectedView(oFrontView, oTG.CreatePoint2d(44, 33), kHiddenLineRemovedDrawingViewStyle)
MsgBox "Create section view."
' Create a front section view by defining a section line in the front view.
Dim oSectionSketch As DrawingSketch
Set oSectionSketch = oFrontView.Sketches.Add
oSectionSketch.Edit
' Get the circular edge of the top of the part.
Dim oObjs As ObjectCollection
Set oObjs = oAssemblyDoc.AttributeManager.FindObjects("Name", "Name", "Edge11")
Dim oCircularEdge As Edge
Set oCircularEdge = oObjs.Item(1)
' Get the associated drawingcurve.
Dim oDrawViewCurves As DrawingCurvesEnumerator
Set oDrawViewCurves = oFrontView.DrawingCurves(oCircularEdge)
Dim oCircularCurve As DrawingCurve
Set oCircularCurve = oDrawViewCurves.Item(1)
Dim oCircularEntity As SketchEntity
Set oCircularEntity = oSectionSketch.AddByProjectingEntity(oCircularCurve)
' Draw the section line.
Dim oSectionLine As SketchLine
Set oSectionLine = oSectionSketch.SketchLines.AddByTwoPoints(oTG.CreatePoint2d(0, 0.9), oTG.CreatePoint2d(0, -0.9))
' Create a constraint to the projected circle center point and the line.
Call oSectionSketch.GeometricConstraints.AddCoincident(oSectionLine, oCircularEntity.CenterSketchPoint)
oSectionSketch.ExitEdit
' Create the section view.
Dim oSectionView As SectionDrawingView
Set oSectionView = oSheet.DrawingViews.AddSectionView(oFrontView, oSectionSketch, oTG.CreatePoint2d(24, 10), kHiddenLineRemovedDrawingViewStyle, , False)
MsgBox "Create detail view."
' Create the detail view.
Dim oDetailView As DetailDrawingView
Set oDetailView = oSheet.DrawingViews.AddDetailView(oSectionView, oTG.CreatePoint2d(35, 15), kFromBaseDrawingViewStyle, True, oTG.CreatePoint2d(23, 16), 2, , 5, , "A")
' Get the various edges of the model.
Dim aoEdges(1 To 12) As Edge
Dim i As Integer
For i = 1 To 12
Set oObjs = oAssemblyDoc.AttributeManager.FindObjects("Name", "Name", "Edge" & i)
Set aoEdges(i) = oObjs.Item(1)
Next
' Get the equivalent drawing curves.
Dim aoDrawCurves(1 To 12) As DrawingCurve
For i = 1 To 12
Set oDrawViewCurves = oFrontView.DrawingCurves(aoEdges(i))
Set aoDrawCurves(i) = oDrawViewCurves.Item(1)
Next
MsgBox "Create dimensions to the curves in the view."
' Create some dimensions
Dim oGeneralDims As GeneralDimensions
Set oGeneralDims = oSheet.DrawingDimensions.GeneralDimensions
Dim oDim As GeneralDimension
Set oDim = oGeneralDims.AddLinear(oTG.CreatePoint2d(7, 15), oSheet.CreateGeometryIntent(aoDrawCurves(1)), oSheet.CreateGeometryIntent(aoDrawCurves(3)), kVerticalDimensionType)
Set oDim = oGeneralDims.AddLinear(oTG.CreatePoint2d(12, 9), oSheet.CreateGeometryIntent(aoDrawCurves(2)), oSheet.CreateGeometryIntent(aoDrawCurves(4)), kHorizontalDimensionType)
Set oDim = oGeneralDims.AddRadius(oTG.CreatePoint2d(16, 19), oSheet.CreateGeometryIntent(aoDrawCurves(8)))
Set oDim = oGeneralDims.AddDiameter(oTG.CreatePoint2d(8, 20), oSheet.CreateGeometryIntent(aoDrawCurves(9)), True, False)
MsgBox "Create a text box with a leader."
' Place a text box with a leader.
Dim oObjColl As ObjectCollection
Set oObjColl = ThisApplication.TransientObjects.CreateObjectCollection
Call oObjColl.Add(oTG.CreatePoint2d(16.5, 15))
Dim oEval As Curve2dEvaluator
Set oEval = aoDrawCurves(4).Evaluator2D
Dim adParams(0) As Double
adParams(0) = 0.6
Dim adPoints(1 To 2) As Double
Call oEval.GetPointAtParam(adParams, adPoints)
Call oObjColl.Add(oSheet.CreateGeometryIntent(aoDrawCurves(4), oTG.CreatePoint2d(adPoints(1), adPoints(2))))
Dim oLeaderNote As LeaderNote
Set oLeaderNote = oSheet.DrawingNotes.LeaderNotes.Add(oObjColl, "Text with a leader")
oLeaderNote.DimensionStyle = oLeaderNote.DimensionStyle
End Sub
Thanks,
Karthick