Horizontal and Vertical Dimensions Orientation

Horizontal and Vertical Dimensions Orientation

danijel.radenkovic
Collaborator Collaborator
2,049 Views
6 Replies
Message 1 of 7

Horizontal and Vertical Dimensions Orientation

danijel.radenkovic
Collaborator
Collaborator

Hello,

I am trying to sort my sketch dimensions by using dimension orientation enumerator: (Inventor.DimensionOrientationEnum.kHorizontalDim,Inventor.DimensionOrientationEnum.kVerticalDim)

horizontal_and_vertical_dims.png

 

Parameter value of all horizontal dimensions I would like to increase for some value, and vertical for some other values.

 

I tried something but this code just recognize creation type of the dimensions, not orientation.

 

' Get a reference to the DimensionConstraints collection.
    Dim dimConstraints As Inventor.DimensionConstraints
    Set dimConstraints = Sketch1.DimensionConstraints
    
' Get a reference to the Horizontal DimensionConstraints collection.
    Dim dimHoriz As DimensionConstraint
    For Each dimHoriz In dimConstraints
        If dimHoriz.Type = kTwoPointDistanceDimConstraintObject Then
            dimHoriz.Parameter.Value = dimHoriz.Parameter.Value + 0.1
        End If
    Next

I would appreciate if someone can give me advice.

 

Best regards

Danijel

 

Inventor 2018/Windows 10 x64
If this information was helpful, please consider marking it as an Accepted Solution by using the Accept as Solution. Kudos are also gladly accepted.
0 Likes
Accepted solutions (1)
2,050 Views
6 Replies
Replies (6)
Message 2 of 7

ekinsb
Alumni
Alumni

Your code works ok for two point dimensions but horizontal dimensions can also be created in other ways.  There's the special case of where a two point dimension is aligned but the points are aligned along the Y so the dimension is a horizontal dimension.  There's also an offset type of dimension where a line is selected first and the dimension is perpendicular from that line to a point.  If the line is vertical then it results in a horizontal dimension.  I have some test VBA code below that handles these cases.  Hopefully this helps.

 

Public Sub DimensionTest()
    Dim partDoc As PartDocument
    Set partDoc = ThisApplication.ActiveDocument
    
    Dim sk As sketch
    Set sk = partDoc.ActivatedObject
    
    Dim dimConstraints As DimensionConstraints
    Set dimConstraints = sk.DimensionConstraints
    
    Dim hs As HighlightSet
    Set hs = partDoc.CreateHighlightSet
    Dim i As Integer
    For i = 1 To dimConstraints.Count
        Dim dimConstraint As DimensionConstraint
        Set dimConstraint = dimConstraints.Item(i)
        hs.AddItem dimConstraint
        hs.Clear
           
        If TypeOf dimConstraint Is TwoPointDistanceDimConstraint Then
            Dim dimHoriz As TwoPointDistanceDimConstraint
            Set dimHoriz = dimConstraint
            If dimHoriz.Orientation = kHorizontalDim Then
                dimConstraint.Parameter.value = dimConstraint.Parameter.value + 0.1
            ElseIf dimHoriz.Orientation = kAlignedDim Then
                If WithinTol(dimHoriz.PointOne.Geometry.y, dimHoriz.PointTwo.Geometry.y, 0.000001) Then
                    dimConstraint.Parameter.value = dimConstraint.Parameter.value + 0.1
                End If
            End If
        ElseIf TypeOf dimConstraint Is OffsetDimConstraint Then
            Dim dimOffset As OffsetDimConstraint
            Set dimOffset = dimConstraint
            If WithinTol(dimOffset.Line.StartSketchPoint.Geometry.x, dimOffset.Line.EndSketchPoint.Geometry.x, 0.000001) Then
                dimConstraint.Parameter.value = dimConstraint.Parameter.value + 0.1
            End If
        End If
    Next
End Sub

Private Function WithinTol(Value1 As Double, Value2 As Double, Tolerance As Double)
    If Abs(Value1 - Value2) <= Tolerance Then
        WithinTol = True
    Else
        WithinTol = False
    End If
End Function

Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
Message 3 of 7

danijel.radenkovic
Collaborator
Collaborator

Hello Mr. Ekins,

This works great but just with the straight lines, but what if I have to dimensioning of arc?

 

dimensioningofarc.png

Thank you so much for help that you provide.

Danijel

 

 

Inventor 2018/Windows 10 x64
If this information was helpful, please consider marking it as an Accepted Solution by using the Accept as Solution. Kudos are also gladly accepted.
0 Likes
Message 4 of 7

ekinsb
Alumni
Alumni

I think it should handle the case you show in the picture because the dimension is really just between two points.  It's just that one of the points happens to be the end of an arc, but that doesn't matter to the program.  It's very possible that there are some cases that the program isn't currently looking for but if they're identified it can probably be modified to account for those.

 

A useful way to look at a sketch is that it's a bunch of points with geometry connected to the points.  To modify a line you're actually changing the position of its endpoints.  The same with an arc.  A lot of the dimensions are controlling the points and the geometry just goes along for the ride.


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
0 Likes
Message 5 of 7

danijel.radenkovic
Collaborator
Collaborator

But I am getting the error message.

error.png

 

Regards

Danijel

 

Inventor 2018/Windows 10 x64
If this information was helpful, please consider marking it as an Accepted Solution by using the Accept as Solution. Kudos are also gladly accepted.
0 Likes
Message 6 of 7

ekinsb
Alumni
Alumni
Accepted solution

When a sketch dimension was dependent on a line, the program was getting the sketch points at the end of the line to determine if the line is vertical or not.  It turns out that when you include a line from the model or another sketch that the sketch line doesn't have start and end sketch points so that part of the code was failing.  I've modified it so it's no longer dependent on sketch points for the line.

 

Public Sub DimensionTest()
    Dim partDoc As PartDocument
    Set partDoc = ThisApplication.ActiveDocument
    
    Dim sk As sketch
    Set sk = partDoc.ActivatedObject
    
    Dim dimConstraints As DimensionConstraints
    Set dimConstraints = sk.DimensionConstraints
    
    Dim hs As HighlightSet
    Set hs = partDoc.CreateHighlightSet
    Dim i As Integer
    For i = 1 To dimConstraints.Count
        Dim dimConstraint As DimensionConstraint
        Set dimConstraint = dimConstraints.Item(i)
        hs.AddItem dimConstraint
        hs.Clear
           
        If TypeOf dimConstraint Is TwoPointDistanceDimConstraint Then
            Dim dimHoriz As TwoPointDistanceDimConstraint
            Set dimHoriz = dimConstraint
            If dimHoriz.Orientation = kHorizontalDim Then
                dimConstraint.Parameter.value = dimConstraint.Parameter.value + 0.1
            ElseIf dimHoriz.Orientation = kAlignedDim Then
                If WithinTol(dimHoriz.PointOne.Geometry.y, dimHoriz.PointTwo.Geometry.y, 0.000001) Then
                    dimConstraint.Parameter.value = dimConstraint.Parameter.value + 0.1
                End If
            End If
        ElseIf TypeOf dimConstraint Is OffsetDimConstraint Then
            Dim dimOffset As OffsetDimConstraint
            Set dimOffset = dimConstraint
            If WithinTol(dimOffset.Line.Geometry.StartPoint.x, dimOffset.Line.Geometry.endPoint.x, 0.000001) Then
                dimConstraint.Parameter.value = dimConstraint.Parameter.value + 0.1
            End If
        End If
    Next
End Sub

Private Function WithinTol(Value1 As Double, Value2 As Double, Tolerance As Double)
    If Abs(Value1 - Value2) <= Tolerance Then
        WithinTol = True
    Else
        WithinTol = False
    End If
End Function

Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
Message 7 of 7

danijel.radenkovic
Collaborator
Collaborator

Hello Mr. Ekins,

This time works great. Smiley Happy

Thank you!


By the way, couple of days I am struggling to find a right answer on the question described in one of my topics.

http://forums.autodesk.com/t5/inventor-customization/move-eop-marker-step-by-step-in-the-modeling-tr...

If you have some advice, please provide.

Thank you so much for all you've done to help me.

Regards

Danijel

Inventor 2018/Windows 10 x64
If this information was helpful, please consider marking it as an Accepted Solution by using the Accept as Solution. Kudos are also gladly accepted.
0 Likes