Hi @Anonymous
The m_inventorApp is the Inventor application object. I don't know from where you want to run this sub. But I made an example iLogic code for you. There's a problem in the original code that I fixed. The argument variable in the sub is called "app", but then the sub uses a variable called m_inventorApp. Thats just a misstake i guess... So if you change the name of the argument variable to m_inventorApp and pass the application object to it it works 🙂
I've tested this iLogic rule and it runs without any error. Just remember to rename the ipt you can download from the link to Part1.ipt and place it at the hard coded path. Then run this iLogic rule 🙂
Sub Main
CreateDrawing(ThisApplication)
End Sub
Public Sub CreateDrawing(ByRef m_inventorApp As Inventor.Application)
' Create a new drawing document using the default template.
Dim oDrawDoc As DrawingDocument
oDrawDoc = m_inventorApp.Documents.Add(DocumentTypeEnum.kDrawingDocumentObject, m_inventorApp.FileManager.GetTemplateFile(DocumentTypeEnum.kDrawingDocumentObject))
Dim oSheet As Sheet
oSheet = oDrawDoc.ActiveSheet
' Open the part to be inserted into the drawing.
Dim oPartDoc As PartDocument
oPartDoc = m_inventorApp.Documents.Open("c:\temp\Part1.ipt", False)
Dim oTG As TransientGeometry
oTG = m_inventorApp.TransientGeometry
MsgBox("Create base and orthographic views.")
' Place the base front view.
Dim oFrontView As DrawingView
oFrontView = oSheet.DrawingViews.AddBaseView( _
oPartDoc, _
oTG.CreatePoint2d(15, 12), _
3, _
ViewOrientationTypeEnum.kFrontViewOrientation, _
DrawingViewStyleEnum.kHiddenLineDrawingViewStyle)
' Create the top, right and iso views.
Dim oTopView As DrawingView
oTopView = oSheet.DrawingViews.AddProjectedView( _
oFrontView, _
oTG.CreatePoint2d(15, 30), _
DrawingViewStyleEnum.kFromBaseDrawingViewStyle)
Dim oIsoView As DrawingView
oIsoView = oSheet.DrawingViews.AddProjectedView( _
oFrontView, _
oTG.CreatePoint2d(40, 30), _
DrawingViewStyleEnum.kHiddenLineRemovedDrawingViewStyle)
MsgBox("Create section view.")
' Create a front section view by
' defining a section line in the front view.
Dim oSectionSketch As DrawingSketch
oSectionSketch = oFrontView.Sketches.Add
oSectionSketch.Edit()
' Get the circular edge of the top of the part.
Dim oObjs As ObjectCollection
oObjs = oPartDoc.AttributeManager.FindObjects("Name", "Name", "Edge13")
Dim oCircularEdge As Edge
oCircularEdge = oObjs.Item(1)
' Get the associated drawingcurve.
Dim oDrawViewCurves As DrawingCurvesEnumerator
oDrawViewCurves = oFrontView.DrawingCurves(oCircularEdge)
Dim oCircularCurve As DrawingCurve
oCircularCurve = oDrawViewCurves.Item(1)
Dim oCircularEntity As SketchEntity
oCircularEntity = oSectionSketch.AddByProjectingEntity(oCircularCurve)
' Draw the section line.
Dim oSectionLine As SketchLine
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
oSectionView = oSheet.DrawingViews.AddSectionView( _
oFrontView, _
oSectionSketch, _
oTG.CreatePoint2d(34, 10), _
DrawingViewStyleEnum.kHiddenLineRemovedDrawingViewStyle, _
Nothing, _
False)
MsgBox("Create detail view.")
' Create the detail view.
Dim oDetailView As DetailDrawingView
oDetailView = oSheet.DrawingViews.AddDetailView( _
oSectionView, _
oTG.CreatePoint2d(35, 15), _
DrawingViewStyleEnum.kFromBaseDrawingViewStyle, _
False, _
oTG.CreatePoint2d(21, 16), _
oTG.CreatePoint2d(24, 18), , 10, , "A")
' Get the various edges of the model.
Dim aoEdges(0 To 13) As Edge
Dim i As Integer
For i = 1 To 13
oObjs = oPartDoc.AttributeManager.FindObjects( _
"Name", "Name", "Edge" & i)
aoEdges(i) = oObjs.Item(1)
Next
' Get the equivalent drawing curves.
Dim aoDrawCurves(0 To 13) As DrawingCurve
For i = 1 To 13
oDrawViewCurves = oFrontView.DrawingCurves(aoEdges(i))
aoDrawCurves(i) = oDrawViewCurves.Item(1)
Next
MsgBox("Create dimensions to the curves in the view.")
' Create some dimensions
Dim oGeneralDims As GeneralDimensions
oGeneralDims = oSheet.DrawingDimensions.GeneralDimensions
Dim oDim As GeneralDimension
oDim = oGeneralDims.AddLinear( _
oTG.CreatePoint2d(15.5, 13), _
oSheet.CreateGeometryIntent(aoDrawCurves(1)), _
oSheet.CreateGeometryIntent(aoDrawCurves(3)), _
DimensionTypeEnum.kVerticalDimensionType)
oDim = oGeneralDims.AddLinear( _
oTG.CreatePoint2d(16, 9), _
oSheet.CreateGeometryIntent(aoDrawCurves(2)), _
oSheet.CreateGeometryIntent(aoDrawCurves(4)), _
DimensionTypeEnum.kHorizontalDimensionType)
oDim = oGeneralDims.AddRadius( _
oTG.CreatePoint2d(17, 19), _
oSheet.CreateGeometryIntent(aoDrawCurves(13)))
oDim = oGeneralDims.AddDiameter( _
oTG.CreatePoint2d(8, 20), _
oSheet.CreateGeometryIntent(aoDrawCurves(13)), _
True, False)
MsgBox("Create a text box with a leader.")
' Place a text box with a leader.
Dim oObjColl As ObjectCollection
oObjColl = m_inventorApp.TransientObjects.CreateObjectCollection
Call oObjColl.Add(oTG.CreatePoint2d(17.5, 11))
Dim oEval As Curve2dEvaluator
oEval = aoDrawCurves(4).Evaluator2D
Dim adParams(0) As Double
adParams(0) = 0.6
Dim adPoints(0 To 1) As Double
Call oEval.GetPointAtParam(adParams, adPoints)
Call oObjColl.Add(oTG.CreatePoint2d(adPoints(0), adPoints(1)))
Dim oLeaderNote As LeaderNote
oLeaderNote = oSheet.DrawingNotes.LeaderNotes.Add( _
oObjColl, "Text with a leader")
oLeaderNote.DimensionStyle = oLeaderNote.DimensionStyle
End Sub