• Blog posts


    By Luke Davenport 


    You want to accurately position your Inventor views in 2D sheet space.



    Some simple iLogic code to modify the XY position of your views.



    Inventor users don’t often need to accurately position drawing views in 2D sheet space relative to each other. However there are some scenarios we’ve come across where an Inventor drawing is being exported to (or opened in) AutoCAD, and the drawing view needs to be precisely positioned with respect to some other geometry in the drawing. Simply dragging and dropping the Inventor drawing view until the position looks close enough is not an option. So let’s use some simple iLogic code to set the position.


    Notes: This code only moves the view to the position specified by the user, it doesn’t lock the position of the view. As far as I’m aware locking the view position (and preventing a user from dragging a view around) is not possible in Inventor (if you know how – let me know!). What the code does do is sets the View Justification to be Fixed, which helps a little with keeping drawing views where they are supposed to be. See this great article from Design and Motion for more info on this setting:




    iLogic Code:

    ' This code allows user to accurately set the lower left corner position of drawing view 1 and drawing view 2 on sheet 1

    ' Be careful when copying and pasting – don’t introduce new lines accidentally……


    Dim oView As DrawingView = Nothing

    Dim oBasePosition As Point2d = Nothing

    Dim Title As String = "Cadline iLogic"

    Dim oDrawingViews As DrawingViews = ThisApplication.ActiveDocument.Sheets.Item(1).DrawingViews

    Dim XPos As String

    Dim YPos As String


    ' Loop through first two drawing views in first sheet

    For i = 1 To oDrawingViews.Count


        ' Reset values for X and Y positions

        XPos = "a"

        YPos = "a"


        ' Define drawing view

        oView = oDrawingViews.Item(i)


        ' Get user input for X co-ordinate

        Do While Not IsNumeric(XPos)

            XPos = InputBox("Enter X co-ordinate for View " & i & " (" & oView.Name & ")", Title, "50")

            If XPos = "" Then


            End If



        ' Get user input for Y co-ordinate

        Do While Not IsNumeric(YPos)

            YPos = InputBox("Enter Y co-ordinate for View " & i & " (" & oView.Name & ")", Title, "50")

            If YPos = "" Then


            End If



        ' Correct units

        XPos /= 10

        YPos /= 10


        ' Create a new point to move the baseview to.

        oBasePosition = ThisApplication.TransientGeometry.CreatePoint2d()

        oBasePosition.X = XPos + (oView.Width/2)

        oBasePosition.Y = YPos + (oView.Height/2)


        'Move the baseview to the new position

        oView.Position = oBasePosition


        ' Ensure that the geometry in this view will not move if new geometry is added (and the view size changes as a result)

        ' Note this doesn't prevent a user dragging the view around!

        oView.ViewJustification = ViewJustificationEnum.kFixedViewJustification