Get point on circle from Selection Filter

Get point on circle from Selection Filter

pball
Mentor Mentor
263 Views
2 Replies
Message 1 of 3

Get point on circle from Selection Filter

pball
Mentor
Mentor

I've had a script for adding leader text to the center of a selected line in drawings for a while. I just fixed a bug where selecting a circle would cause the code to fail. I figured out that the MidPoint of a curve doesn't exist for circles, so if that is nothing, I'm using the CenterPoint instead.

 

Now for my actual question. I would like to have my leader attach to the outside of a selected circle instead of the center point. This is just because I'm curious and think it would look better that way. So if anyone can help out I'd appreciate it.


Example of where I would like to have the leader attached.

pball_0-1734038110811.png

 

    Public Sub InsertLeaderText(sText As String)
        Dim oDrawDoc As DrawingDocument = ThisApplication.ActiveDocument
        Dim oActiveSheet As Sheet = oDrawDoc.ActiveSheet

        Dim oDrawingCurveSegment As DrawingCurveSegment
        oDrawingCurveSegment = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingCurveSegmentFilter, "Select a line")
        If (oDrawingCurveSegment Is Nothing) Then Exit Sub

        Dim oDrawingCurve As DrawingCurve
        oDrawingCurve = oDrawingCurveSegment.Parent

        ' Get the mid point of the selected curve assuming that the selected curve is linear
        Dim oMidPoint As Point2d = oDrawingCurve.MidPoint
'New line to account for circles, set variable to center point
        If (oMidPoint Is Nothing) Then oMidPoint = oDrawingCurve.CenterPoint

        ' Set a reference to the TransientGeometry object.
        Dim oTG As TransientGeometry = ThisApplication.TransientGeometry

        Dim oLeaderPoints As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection

        ' Create a leader point.
        Call oLeaderPoints.Add(oTG.CreatePoint2d(oMidPoint.X + 2, oMidPoint.Y + 2))

        ' Create an intent and add to the leader points collection.
        ' This is the geometry that the leader text will attach to.
        Dim oGeometryIntent As GeometryIntent = oActiveSheet.CreateGeometryIntent(oDrawingCurve, oMidPoint)

        Call oLeaderPoints.Add(oGeometryIntent)

        Dim oLeaderNote As LeaderNote = oActiveSheet.DrawingNotes.LeaderNotes.Add(oLeaderPoints, sText)
    End Sub

I've h

Check out my style edits for the Autodesk forums
pball's Autodesk Forum Style
0 Likes
Accepted solutions (1)
264 Views
2 Replies
Replies (2)
Message 2 of 3

marcin_otręba
Advisor
Advisor
Accepted solution

Hi,

 

use Circle2d:

 

Dim ocircle As Circle2d = oDrawingCurve.Segments(1).Geometry

 

then you can play with it like:

   Dim oGeometryIntent As GeometryIntent = oActiveSheet.CreateGeometryIntent(oDrawingCurve, oTG.CreatePoint2d(oMidPoint.X +ocircle.Radius, oMidPoint.Y ))

marcin_otrba_2-1734080870644.png

 

 or 

   Dim oGeometryIntent As GeometryIntent = oActiveSheet.CreateGeometryIntent(oDrawingCurve, oTG.CreatePoint2d(oMidPoint.X , oMidPoint.Y +ocircle.Radius ))

 

marcin_otrba_1-1734080851830.png

 

or 

 

        Dim oGeometryIntent As GeometryIntent = oActiveSheet.CreateGeometryIntent(oDrawingCurve, oTG.CreatePoint2d(oMidPoint.X + sin(ocircle.Radius), oMidPoint.Y + sin(ocircle.Radius)))

marcin_otrba_0-1734080823575.png

 

Hi, maybe you want to check my apps:


DrawingTools   View&ColoringTools   MRUFolders

0 Likes
Message 3 of 3

pball
Mentor
Mentor

Thanks, that was a bit easier than I thought it might be.

Check out my style edits for the Autodesk forums
pball's Autodesk Forum Style
0 Likes