Community
Inventor Forum
Welcome to Autodesk’s Inventor Forums. Share your knowledge, ask questions, and explore popular Inventor topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Repositioning Dimensions

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
jacofiero
2046 Views, 2 Replies

Repositioning Dimensions

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
Next

 

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?

2 REPLIES 2
Message 2 of 3
mrattray
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

Message 3 of 3
jozef.dubaj
in reply to: jacofiero

Hello,

 

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
   Next

   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
   Else
    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
         Else
            dPosition = oDimension.Text.Origin.X
         End If
      Else
         ' Change the position of the dimension.
         Dim oPosition As Point2d
         Set oPosition = oDimension.Text.Origin
         If bHorizontal Then
            oPosition.Y = dPosition
         Else
            oPosition.X = dPosition
         End If
    
         oDimension.Text.Origin = oPosition
      End If
   Next
End Sub

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report