Issue
I need to automate the creation of drawing views of parts/assemblies via the Inventor API. How do I do this?
Solution
The following VB.NET code illustrates how to create a drawing document, then add drawing views to the document.
Public Sub CreateViews() ' assume we have had inventor application ' Create a new drawing document via a ' standard drawing template file Dim sTemplateFile As String sTemplateFile = _InvApplication.FileManager. _ GetTemplateFile( _ DocumentTypeEnum.kDrawingDocumentObject) Dim oDrawDoc As DrawingDocument oDrawDoc = _ _InvApplication.Documents.Add( _ DocumentTypeEnum.kDrawingDocumentObject, _ sTemplateFile) ' The drawing is created with a single sheet, ' so we'll add our views to it. Dim oSheet As Sheet = oDrawDoc.Sheets.Item(1) ' Now we define the placement points for ' the two drawing views we shall be adding to the sheet Dim oPlacementPoint1 As Point2d Dim oPlacementPoint2 As Point2d oPlacementPoint1 = _ _InvApplication.TransientGeometry. _ CreatePoint2d(10.0, 10.0) oPlacementPoint2 = _ _InvApplication.TransientGeometry. _ CreatePoint2d(10.0, 30.0) ' Define the view scales that we need. Dim ViewScale1 As Double Dim ViewScale2 As Double ViewScale1 = 1.0 ViewScale2 = 5.0 ' define the view orientation for each view Dim ViewOrientation1 As ViewOrientationTypeEnum = _ 
60; ViewOrientationTypeEnum.kBottomViewOrientation Dim ViewOrientation2 As ViewOrientationTypeEnum = _ ViewOrientationTypeEnum.kRightViewOrientation ' define the view style for each view Dim ViewStyle1 As DrawingViewStyleEnum = _ DrawingViewStyleEnum.kHiddenLineDrawingViewStyle Dim ViewStyle2 As DrawingViewStyleEnum = _ DrawingViewStyleEnum.kShadedDrawingViewStyle ' we assume there is a part called 'Part.ipt' ' in the project workspace, which we want to create views for Dim sPartPath As String = _ _InvApplication.FileLocations.Workspace _ & "Part1.ipt" Dim oPartDoc As PartDocument = _ _InvApplication.Documents.Open(sPartPath, False) ' now create our two views Dim oView As DrawingView oView = oSheet.DrawingViews.AddBaseView( _ oPartDoc, oPlacementPoint1, _ ViewScale1, ViewOrientation1, _ ViewStyle1) oView = oSheet.DrawingViews.AddBaseView( _ oPartDoc, oPlacementPoint2, _ ViewScale2, ViewOrientation2, _ ViewStyle2) Call oPartDoc.Close(True) ' drawing document isn't saved End Sub

Leave a Reply to Xiaodong LiangCancel reply