Inventor General Discussion

Inventor General Discussion

Active Member
Posts: 9
Registered: ‎03-28-2013
Message 1 of 3 (365 Views)
Accepted Solution

Repositioning Dimensions

365 Views, 2 Replies
06-24-2013 01:33 PM

I'm trying to reposition dimensions in a drawing through the API, but I'm not having much luck.  The output of my code seems to indicate the method is working, but after it runs the drawing is unchanged.  Here's the code (in VBA):


Dim oDoc As DrawingDocument
Set oDoc = ThisApplication.ActiveDocument
Dim oSheet As Sheet
Set oSheet = oDoc.Sheets.Item(1)
Dim oLdim As LinearGeneralDimension
Dim oLeaderNote As LeaderNote
Dim oDimLine As LineSegment2d ' Dimension Line
Dim oStartPt As Point2d ' Dimension Line Start Point
Dim oEndPt As Point2d ' Dimension Line End Point
Dim oNewSP(1) As Double
Dim oNewEP(1) As Double


For Each oLeaderNote In oSheet.DrawingNotes
Set oLdim = oLeaderNote.Leader.AllLeafNodes.Item(1).AttachedEntity.Geometry
Set oDimLine = oLdim.DimensionLine
Set oStartPt = oDimLine.StartPoint
Set oEndPt = oDimLine.EndPoint
Debug.Print "Original Start Point (" & oStartPt.X & ", " & oStartPt.Y & ")"
Debug.Print "Original End Point (" & oEndPt.X & ", " & oEndPt.Y & ")"

oNewSP(0) = 1
oNewSP(1) = oStartPt.Y
oNewEP(0) = 1
oNewEP(1) = oEndPt.Y

If oLeaderNote.Text = "220V" Then
oDimLine.PutLineSegmentData oNewSP, oNewEP
Set oStartPt = oDimLine.StartPoint
Set oEndPt = oDimLine.EndPoint
Debug.Print "New Start Point (" & oStartPt.X & ", " & oStartPt.Y & ")"
Debug.Print "New End Point (" & oEndPt.X & ", " & oEndPt.Y & ")"
End If


The output:

Original Start Point (2.99802199356311, 12.0741570755029)
Original End Point (2.99802199356311, 15.8658429244971)
New Start Point (1, 12.0741570755029)
New End Point (1, 15.8658429244971)


Looks like it moved my vertical dimension left, but it doesn't actually do anything.  

What am I doing wrong here?  Is this not a viable method for repositioning a dimension?

*Expert Elite*
Posts: 2,473
Registered: ‎09-13-2011
Message 2 of 3 (359 Views)

Re: Repositioning Dimensions

06-24-2013 01:54 PM in reply to: jacofiero

Questions like this tend to recieve a better response when they're posted to the Inventor Customization forum. That's where all of the developer types hang around. Try asking this question there and linking this post to your new thread (to help future answer seekers).

Mike (not Matt) Rattray

Posts: 41
Registered: ‎11-22-2011
Message 3 of 3 (287 Views)

Re: Repositioning Dimensions

07-01-2013 11:20 PM in reply to: jacofiero



repositioning of dimension is achievable through xxxDimension.Text.Origin transient object. See the example from the Inventor API help:


VBA Sample Code

The first dimension selected defines the origin of the axis. A drawing document must be open and at least two dimensions selected.

Public Sub DimensionAlign()
   Dim oDrawDoc As DrawingDocument
   Set oDrawDoc = ThisApplication.ActiveDocument

   ' Determine if there are any dimensions in the select set.
   Dim oSelectSet As SelectSet
   Set oSelectSet = oDrawDoc.SelectSet
   Dim colDimensions As New Collection
   Dim i As Long
   For i = 1 To oSelectSet.Count
      If Typeof oSelectSet.Item(i) Is DrawingDimension Then
         ' Add any dimensions to the collection. We need to save them
         ' in something besides the selection set because once we start
         ' manipulating them the select set will be cleared.
         colDimensions.Add oSelectSet.Item(i)
      End If

   If colDimensions.Count < 2 Then
      MsgBox "You must select at least 2 dimensions for this operation."
      Exit Sub
   End If

   ' Ask the user if he/she wants vertical or horizontal alignment.
   Dim bHorizontal As Boolean
   If MsgBox("Do you want horizontal alignment? (Selecting ""No"" results in vertical alignment)", vbQuestion + vbYesNo, "Align Dimensions") = vbYes Then
       bHorizontal = True
    bHorizontal = False
   End If

   For i = 1 To colDimensions.Count
      Dim oDimension As DrawingDimension
      Set oDimension = colDimensions.Item(i)

      If i = 1 Then
         ' Get the position of the first dimension text. This is
         ' the position the other dimensions will be aligned to.
         Dim dPosition As Double
         If bHorizontal Then
            dPosition = oDimension.Text.Origin.Y
            dPosition = oDimension.Text.Origin.X
         End If
         ' Change the position of the dimension.
         Dim oPosition As Point2d
         Set oPosition = oDimension.Text.Origin
         If bHorizontal Then
            oPosition.Y = dPosition
            oPosition.X = dPosition
         End If
         oDimension.Text.Origin = oPosition
      End If
End Sub
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.