Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Placing an angular dimension. Dose Dimension.FirstArrowheadPostion not exist?

1 REPLY 1
SOLVED
Reply
Message 1 of 2
davidt162003
189 Views, 1 Reply

Placing an angular dimension. Dose Dimension.FirstArrowheadPostion not exist?

davidt162003
Advocate
Advocate

I wanted to write a function which would move the position (Move the quadrant) of an angular dimension to the smallest possible angle and slightly offset from the bisector of the arc produced. this is the code i was going to use 

 Friend Function AngularDimensionFromCenterLines(CenterLine1 As Centerline, CenterLine2 As Centerline, Optional Postion As Point2d = Nothing) As GeneralDimension
     Try
         Dim Line1GI = CenterLine1.Parent.CreateGeometryIntent(CenterLine1)
         Dim Line2GI = CenterLine2.Parent.CreateGeometryIntent(CenterLine2)
         Dim GenDims = CenterLine1.Parent.DrawingDimensions.GeneralDimensions
         Dim AngleDimension As AngularGeneralDimension = GenDims.AddAngular(Postion, Line1GI, Line2GI)
         If Postion Is Nothing Then
             Dim LineIntersection As Point2d
             If CenterLine1.GeometryType = CurveTypeEnum.kLineCurve And CenterLine2.GeometryType = CurveTypeEnum.kLineCurve Then
                 Dim Line1 As Line = CenterLine1.Geometry
                 Dim Line2 As Line = CenterLine2.Geometry
                 LineIntersection = Line1.IntersectWithCurve(Line2)
             End If
             Dim _App = CenterLine1.Application
             FindAnglePlacementPostion(LineIntersection, AngleDimension.FirstArrowheadPostion, AngleDimension.SecondArrowheadPosition, _App)
         End If
     Catch ex As Exception
         Return Nothing
     End Try
 End Function
 Friend Function FindAnglePlacementPostion(CenterPoint As Point2d, Point1 As Point2d, Point2 As Point2d, _App As Inventor.Application) As Point2d
     Dim AngleValue As Double = Math.Atan2(Point1.Y + Point2.Y, Point1.X + Point2.X) 'assume point1 is start point
     Dim StartPoint As Point2d
     Dim EndPoint As Point2d
     If Math.Atan2(Point2.Y + Point1.Y, Point2.X + Point1.X) < AngleValue Then 'If using point2 as the start point produces a smaller angle
         AngleValue = Math.Atan2(Point2.Y + Point1.Y, Point2.X + Point1.X)
         'StartPoint = Point2
         'EndPoint = Point1
     Else
         'StartPoint = Point1
         'EndPoint = Point2
     End If
     Dim ArcRadius = CenterPoint.DistanceTo(StartPoint)
     Dim ArcMidX = ArcRadius * Math.Cos(AngleValue)
     Dim ArcMidY = ArcRadius * Math.Sin(AngleValue)
     Dim ArcMidPoint = GetiPoint2D(ArcMidX, ArcMidY, _App)
     Return ExtendedLineEndPoint(CenterPoint, ArcMidPoint, 2, _App)
 End Function

I'm fairly confident that the geometry of it would work out but as the title suggests i their dose'nt seem to be a property on the general dimension class ↓ which represent the position of the first arrowhead. 

https://help.autodesk.com/view/INVNTOR/2022/ENU/?guid=GeneralDimension

I'm looking specifically for the angular general dimension, the reason I think their would be is because their is a similar property for then second arrowhead. 

https://help.autodesk.com/view/INVNTOR/2022/ENU/?guid=AngularGeneralDimension_SecondArrowheadPositio...

 

Im not entirely confident id be able to pick the correct start/end point on the centre lines so i was just wondering if anyone knew any other method either in the inventor API and geometrically. 

 

 

 

HII
0 Likes

Placing an angular dimension. Dose Dimension.FirstArrowheadPostion not exist?

I wanted to write a function which would move the position (Move the quadrant) of an angular dimension to the smallest possible angle and slightly offset from the bisector of the arc produced. this is the code i was going to use 

 Friend Function AngularDimensionFromCenterLines(CenterLine1 As Centerline, CenterLine2 As Centerline, Optional Postion As Point2d = Nothing) As GeneralDimension
     Try
         Dim Line1GI = CenterLine1.Parent.CreateGeometryIntent(CenterLine1)
         Dim Line2GI = CenterLine2.Parent.CreateGeometryIntent(CenterLine2)
         Dim GenDims = CenterLine1.Parent.DrawingDimensions.GeneralDimensions
         Dim AngleDimension As AngularGeneralDimension = GenDims.AddAngular(Postion, Line1GI, Line2GI)
         If Postion Is Nothing Then
             Dim LineIntersection As Point2d
             If CenterLine1.GeometryType = CurveTypeEnum.kLineCurve And CenterLine2.GeometryType = CurveTypeEnum.kLineCurve Then
                 Dim Line1 As Line = CenterLine1.Geometry
                 Dim Line2 As Line = CenterLine2.Geometry
                 LineIntersection = Line1.IntersectWithCurve(Line2)
             End If
             Dim _App = CenterLine1.Application
             FindAnglePlacementPostion(LineIntersection, AngleDimension.FirstArrowheadPostion, AngleDimension.SecondArrowheadPosition, _App)
         End If
     Catch ex As Exception
         Return Nothing
     End Try
 End Function
 Friend Function FindAnglePlacementPostion(CenterPoint As Point2d, Point1 As Point2d, Point2 As Point2d, _App As Inventor.Application) As Point2d
     Dim AngleValue As Double = Math.Atan2(Point1.Y + Point2.Y, Point1.X + Point2.X) 'assume point1 is start point
     Dim StartPoint As Point2d
     Dim EndPoint As Point2d
     If Math.Atan2(Point2.Y + Point1.Y, Point2.X + Point1.X) < AngleValue Then 'If using point2 as the start point produces a smaller angle
         AngleValue = Math.Atan2(Point2.Y + Point1.Y, Point2.X + Point1.X)
         'StartPoint = Point2
         'EndPoint = Point1
     Else
         'StartPoint = Point1
         'EndPoint = Point2
     End If
     Dim ArcRadius = CenterPoint.DistanceTo(StartPoint)
     Dim ArcMidX = ArcRadius * Math.Cos(AngleValue)
     Dim ArcMidY = ArcRadius * Math.Sin(AngleValue)
     Dim ArcMidPoint = GetiPoint2D(ArcMidX, ArcMidY, _App)
     Return ExtendedLineEndPoint(CenterPoint, ArcMidPoint, 2, _App)
 End Function

I'm fairly confident that the geometry of it would work out but as the title suggests i their dose'nt seem to be a property on the general dimension class ↓ which represent the position of the first arrowhead. 

https://help.autodesk.com/view/INVNTOR/2022/ENU/?guid=GeneralDimension

I'm looking specifically for the angular general dimension, the reason I think their would be is because their is a similar property for then second arrowhead. 

https://help.autodesk.com/view/INVNTOR/2022/ENU/?guid=AngularGeneralDimension_SecondArrowheadPositio...

 

Im not entirely confident id be able to pick the correct start/end point on the centre lines so i was just wondering if anyone knew any other method either in the inventor API and geometrically. 

 

 

 

HII
1 REPLY 1
Message 2 of 2
davidt162003
in reply to: davidt162003

davidt162003
Advocate
Advocate
Accepted solution

Ive finally found my answer but it was way more difficult than expected. 

I'm creating  a angular dimension from 2 centrelines one of them being an axis, if you where to use 3 points you could skip some of my code slightly.

 Friend Function AngularDimensionFromCenterLines(CenterLine1 As Centerline, CenterLine2 As Centerline, Optional Postion As Point2d = Nothing) As GeneralDimension
     Dim AngleDimension As AngularGeneralDimension
     Try
         Dim Line1GI = CenterLine1.Parent.CreateGeometryIntent(CenterLine1)
         Dim Line2GI = CenterLine2.Parent.CreateGeometryIntent(CenterLine2)
         Dim GenDims = CenterLine1.Parent.DrawingDimensions.GeneralDimensions

         '  
         If Postion Is Nothing Then
             Postion = GetiPoint2D(0, 0, CenterLine1.Application)
             AngleDimension = GenDims.AddAngular(Postion, Line1GI, Line2GI)
             Dim LineIntersection As Point2d
             If CenterLine1.GeometryType = CurveTypeEnum.kLineCurve And CenterLine2.GeometryType = CurveTypeEnum.kLineCurve Then ''Actually produces a line segment type for some reason so fix ig 
                 Dim Line1 As Line = CenterLine1.Geometry
                 Dim Line2 As Line = CenterLine2.Geometry
                 LineIntersection = Line1.IntersectWithCurve(Line2)
             End If
             If LineIntersection Is Nothing Then
                 LineIntersection = FindProjectedIntersection(CenterLine1.Geometry.startpoint, CenterLine1.Geometry.endpoint,
                                                              CenterLine2.Geometry.startpoint, CenterLine2.Geometry.endpoint,
                                                              CenterLine1.Application)
             End If
             Dim _App = CenterLine1.Application
             Dim CenterLine1AnglePoint As Point2d
             Dim CenterLine2AnglePoint As Point2d
             If LineIntersection.IsEqualTo(CenterLine1.EndPoint) Then
                 CenterLine1AnglePoint = CenterLine1.StartPoint
             Else
                 CenterLine1AnglePoint = CenterLine1.EndPoint
             End If
             Dim StartPointPos = FindAnglePlacementPostion(LineIntersection, CenterLine1AnglePoint, CenterLine2.StartPoint, _App)
             AngleDimension.Text.Origin = StartPointPos
             Dim startPointPosVal = AngleDimension.ModelValue
             Dim EndPointPos = FindAnglePlacementPostion(LineIntersection, CenterLine1AnglePoint, CenterLine2.EndPoint, _App)
             AngleDimension.Text.Origin = EndPointPos
             Dim EndPointPosVal = AngleDimension.ModelValue
             If EndPointPosVal > startPointPosVal Then
                 AngleDimension.Text.Origin = StartPointPos
             Else
                 AngleDimension = EndPointPos
             End If
             Return AngleDimension
         End If
         Return GenDims.AddAngular(Postion, Line1GI, Line2GI)
     Catch ex As Exception
         If AngleDimension IsNot Nothing Then
             Return AngleDimension
             ' AngleDimension.Delete()
         End If
         Return Nothing
     End Try
 End Function

first I create the angular dimension at (0,0)

then if the centrelines intersect I use that as the CenterPoint, otherwise I calculate the projected intersection of the lines. 

Then I use the point of the non axis centre line that is from the intersection.  Then I run this function for either end point of the other line as the closest one may not give me the best angle.

    Friend Function FindAnglePlacementPostion(CenterPoint As Point2d, Point1 As Point2d, Point2 As Point2d, _App As Inventor.Application, Optional Point3 As Point2d = Nothing) As Point2d
#Region "Region: using polar coordinates"
        Dim Point1Shifted = GetiPoint2D(Point1.X - CenterPoint.X, Point1.Y - CenterPoint.Y, _App)
        Dim Point2Shifted = GetiPoint2D(Point2.X - CenterPoint.X, Point2.Y - CenterPoint.Y, _App) 'shift to origin to use polars
        Dim SecondArmPoint As Point2d
        Dim SecondArmTheta As Double
        Dim Point1Theta As Double
        If Point1Shifted.X < 0 And Point1Shifted.Y > 0 Then 'second quadrant
            Point1Theta = Math.Atan(Point1Shifted.Y / Point1Shifted.X) + Math.PI
        ElseIf Point1Shifted.X < 0 And Point1Shifted.Y < 0 Then
            Point1Theta = -(Math.PI - Math.Atan(Point1Shifted.Y / Point1Shifted.X))
        ElseIf Point1Shifted.X > 0 And Point1Shifted.Y > 0 Then
            Point1Theta = Math.Atan(Point1Shifted.Y / Point1Shifted.X)
        Else
            Point1Theta = Math.Atan(Point1Shifted.Y / Point1Shifted.X)
        End If
        Dim Point2Theta = Math.Atan(Point2Shifted.Y / Point2Shifted.X)
#Region "Region Testing against a 3rd point"
        If Point3 IsNot Nothing Then
            Dim Point3Shifted = GetiPoint2D(Point3.X - CenterPoint.X, Point3.Y - CenterPoint.Y, _App)
            Dim Point3Theta = Math.Atan(Point3Shifted.Y / Point3Shifted.X)
            If (Point2Theta - Point1Theta) > (Point3Theta - Point1Theta) Then
                SecondArmPoint = Point3Shifted
                SecondArmTheta = Point3Theta
            Else
                SecondArmPoint = Point2Shifted
                SecondArmTheta = Point2Theta
            End If
        Else
            SecondArmPoint = Point2Shifted
            SecondArmTheta = Point2Theta
        End If
#End Region
        Dim MidPntTheta = (SecondArmTheta + (Point1Theta - SecondArmTheta) / 2)
        Dim R1 = Math.Sqrt(Point1Shifted.X ^ 2 + Point1Shifted.Y ^ 2)
        Dim R2 = Math.Sqrt(SecondArmPoint.X ^ 2 + SecondArmPoint.Y ^ 2)
        Dim Radius As Double
        If R1 > R2 Then
            Radius = R1
        Else
            Radius = R2
        End If
        Dim MidPnt = GetiPoint2D(Radius * Math.Cos(MidPntTheta), Radius * Math.Sin(MidPntTheta), _App)
        Dim MidPntShifted = GetiPoint2D(MidPnt.X + CenterPoint.X, MidPnt.Y + CenterPoint.Y, _App)
        Return ExtendedLineEndPoint(CenterPoint, MidPntShifted, 2, _App)
#End Region
    End Function

 This uses polar coordinates to find the midpoint chord of the arc produced by the input points, then extends that chord slightly further than the radius. in VB.net the math.Atan didn't function as suspected, it would return -1.57(-90 deg)  rather than the expected  4.71(270 deg), so I  had to include the offset. 

 

With both points returned i move the angle to both in inventor and use whichever produces the smallest angle.

Its not prefect but it works for what I'm doing, hopefully it can help some else as well.

 

Ps. Originally tried using the equation of a circle but when solving would give 2 results and didn't know which one to pick  

HII
0 Likes

Ive finally found my answer but it was way more difficult than expected. 

I'm creating  a angular dimension from 2 centrelines one of them being an axis, if you where to use 3 points you could skip some of my code slightly.

 Friend Function AngularDimensionFromCenterLines(CenterLine1 As Centerline, CenterLine2 As Centerline, Optional Postion As Point2d = Nothing) As GeneralDimension
     Dim AngleDimension As AngularGeneralDimension
     Try
         Dim Line1GI = CenterLine1.Parent.CreateGeometryIntent(CenterLine1)
         Dim Line2GI = CenterLine2.Parent.CreateGeometryIntent(CenterLine2)
         Dim GenDims = CenterLine1.Parent.DrawingDimensions.GeneralDimensions

         '  
         If Postion Is Nothing Then
             Postion = GetiPoint2D(0, 0, CenterLine1.Application)
             AngleDimension = GenDims.AddAngular(Postion, Line1GI, Line2GI)
             Dim LineIntersection As Point2d
             If CenterLine1.GeometryType = CurveTypeEnum.kLineCurve And CenterLine2.GeometryType = CurveTypeEnum.kLineCurve Then ''Actually produces a line segment type for some reason so fix ig 
                 Dim Line1 As Line = CenterLine1.Geometry
                 Dim Line2 As Line = CenterLine2.Geometry
                 LineIntersection = Line1.IntersectWithCurve(Line2)
             End If
             If LineIntersection Is Nothing Then
                 LineIntersection = FindProjectedIntersection(CenterLine1.Geometry.startpoint, CenterLine1.Geometry.endpoint,
                                                              CenterLine2.Geometry.startpoint, CenterLine2.Geometry.endpoint,
                                                              CenterLine1.Application)
             End If
             Dim _App = CenterLine1.Application
             Dim CenterLine1AnglePoint As Point2d
             Dim CenterLine2AnglePoint As Point2d
             If LineIntersection.IsEqualTo(CenterLine1.EndPoint) Then
                 CenterLine1AnglePoint = CenterLine1.StartPoint
             Else
                 CenterLine1AnglePoint = CenterLine1.EndPoint
             End If
             Dim StartPointPos = FindAnglePlacementPostion(LineIntersection, CenterLine1AnglePoint, CenterLine2.StartPoint, _App)
             AngleDimension.Text.Origin = StartPointPos
             Dim startPointPosVal = AngleDimension.ModelValue
             Dim EndPointPos = FindAnglePlacementPostion(LineIntersection, CenterLine1AnglePoint, CenterLine2.EndPoint, _App)
             AngleDimension.Text.Origin = EndPointPos
             Dim EndPointPosVal = AngleDimension.ModelValue
             If EndPointPosVal > startPointPosVal Then
                 AngleDimension.Text.Origin = StartPointPos
             Else
                 AngleDimension = EndPointPos
             End If
             Return AngleDimension
         End If
         Return GenDims.AddAngular(Postion, Line1GI, Line2GI)
     Catch ex As Exception
         If AngleDimension IsNot Nothing Then
             Return AngleDimension
             ' AngleDimension.Delete()
         End If
         Return Nothing
     End Try
 End Function

first I create the angular dimension at (0,0)

then if the centrelines intersect I use that as the CenterPoint, otherwise I calculate the projected intersection of the lines. 

Then I use the point of the non axis centre line that is from the intersection.  Then I run this function for either end point of the other line as the closest one may not give me the best angle.

    Friend Function FindAnglePlacementPostion(CenterPoint As Point2d, Point1 As Point2d, Point2 As Point2d, _App As Inventor.Application, Optional Point3 As Point2d = Nothing) As Point2d
#Region "Region: using polar coordinates"
        Dim Point1Shifted = GetiPoint2D(Point1.X - CenterPoint.X, Point1.Y - CenterPoint.Y, _App)
        Dim Point2Shifted = GetiPoint2D(Point2.X - CenterPoint.X, Point2.Y - CenterPoint.Y, _App) 'shift to origin to use polars
        Dim SecondArmPoint As Point2d
        Dim SecondArmTheta As Double
        Dim Point1Theta As Double
        If Point1Shifted.X < 0 And Point1Shifted.Y > 0 Then 'second quadrant
            Point1Theta = Math.Atan(Point1Shifted.Y / Point1Shifted.X) + Math.PI
        ElseIf Point1Shifted.X < 0 And Point1Shifted.Y < 0 Then
            Point1Theta = -(Math.PI - Math.Atan(Point1Shifted.Y / Point1Shifted.X))
        ElseIf Point1Shifted.X > 0 And Point1Shifted.Y > 0 Then
            Point1Theta = Math.Atan(Point1Shifted.Y / Point1Shifted.X)
        Else
            Point1Theta = Math.Atan(Point1Shifted.Y / Point1Shifted.X)
        End If
        Dim Point2Theta = Math.Atan(Point2Shifted.Y / Point2Shifted.X)
#Region "Region Testing against a 3rd point"
        If Point3 IsNot Nothing Then
            Dim Point3Shifted = GetiPoint2D(Point3.X - CenterPoint.X, Point3.Y - CenterPoint.Y, _App)
            Dim Point3Theta = Math.Atan(Point3Shifted.Y / Point3Shifted.X)
            If (Point2Theta - Point1Theta) > (Point3Theta - Point1Theta) Then
                SecondArmPoint = Point3Shifted
                SecondArmTheta = Point3Theta
            Else
                SecondArmPoint = Point2Shifted
                SecondArmTheta = Point2Theta
            End If
        Else
            SecondArmPoint = Point2Shifted
            SecondArmTheta = Point2Theta
        End If
#End Region
        Dim MidPntTheta = (SecondArmTheta + (Point1Theta - SecondArmTheta) / 2)
        Dim R1 = Math.Sqrt(Point1Shifted.X ^ 2 + Point1Shifted.Y ^ 2)
        Dim R2 = Math.Sqrt(SecondArmPoint.X ^ 2 + SecondArmPoint.Y ^ 2)
        Dim Radius As Double
        If R1 > R2 Then
            Radius = R1
        Else
            Radius = R2
        End If
        Dim MidPnt = GetiPoint2D(Radius * Math.Cos(MidPntTheta), Radius * Math.Sin(MidPntTheta), _App)
        Dim MidPntShifted = GetiPoint2D(MidPnt.X + CenterPoint.X, MidPnt.Y + CenterPoint.Y, _App)
        Return ExtendedLineEndPoint(CenterPoint, MidPntShifted, 2, _App)
#End Region
    End Function

 This uses polar coordinates to find the midpoint chord of the arc produced by the input points, then extends that chord slightly further than the radius. in VB.net the math.Atan didn't function as suspected, it would return -1.57(-90 deg)  rather than the expected  4.71(270 deg), so I  had to include the offset. 

 

With both points returned i move the angle to both in inventor and use whichever produces the smallest angle.

Its not prefect but it works for what I'm doing, hopefully it can help some else as well.

 

Ps. Originally tried using the equation of a circle but when solving would give 2 results and didn't know which one to pick  

HII

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

Post to forums  

Autodesk Design & Make Report