Creating Drawing Views via the Inventor API

By Xiaodong Liang

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 =  _        &#1
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

Comments

8 responses to “Creating Drawing Views via the Inventor API”

  1. cmines Avatar
    cmines

    How can I set a different parts list style for a second sheet?

  2. Xiaodong Liang Avatar
    Xiaodong Liang

    Hi,cmines. Have your tried with PartsList.Style? e.g.
    Dim odoc As DrawingDocument
    Dim oPL As PartsList
    oPL.Style = odoc.StylesManager.PartsListStyles(3)
    -Xiaodong

  3. Is there a way (using API) to update the drawing if I modify the Part? Something equivalent to DrawingView.Update because I can’t find DrawingView.Update.

  4. Xiaodong Liang Avatar
    Xiaodong Liang

    DrawingView has a hidden method _Update.Or you could consider to use Sheet.Update

  5. I don’t see a method to copy a parts list style from another file. Is this possible?

  6. Why am i getting a compile error syntax error after a simple copy past of this macro?

  7. Hi Bob,
    What kind of error you got? I guess you forgot to initialize _InvApplication. this sample is based on a standalone EXE. it assumes you have got _InvApplication, e.g.
    _InvApplication= System.Runtime.InteropServices.Marshal.GetActiveObject(“Inventor.Application”)
    will get the the application of active Inventor process.

  8. Why am i getting template error by simply copy and paste of this code???

Leave a Reply to Xiaodong LiangCancel reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading