TheSwamp

Code Red => .NET => Topic started by: franciscocsilva on June 08, 2020, 07:35:36 AM

Title: how select polyline and get current coordinates
Post by: franciscocsilva on June 08, 2020, 07:35:36 AM
hello

who can help me?

I need select a polyline and read startpint ans end point in a current coordinate system.

I have this:

Code: [Select]
Dim id1 As ObjectId = SelectSpecificObjectType(vbLf & "Select polyline: ", GetType(Polyline))

        If id1.IsNull Then
            Return
        End If

Code: [Select]
Private Shared Function SelectSpecificObjectType(ByVal prompt As String, ByVal objectClass As System.Type) As ObjectId
        Dim ed As Editor = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor

        Using tr As Transaction = ed.Document.Database.TransactionManager.StartTransaction()

            While True
                Dim res As PromptEntityResult = ed.GetEntity(prompt)

                If res.Status <> PromptStatus.OK Then


                    Return ObjectId.Null
                End If

                Dim ob As DBObject = tr.GetObject(res.ObjectId, OpenMode.ForRead)

                If objectClass.IsAssignableFrom(ob.[GetType]()) Then
                    Return res.ObjectId
                End If

                ed.WriteMessage(vbLf & "Invalid selection, {0} entity expected", RXClass.GetClass(objectClass).DxfName)
            End While
        End Using

Code: [Select]
Dim lineA As Polyline = CType(acTrans.GetObject(id2, OpenMode.ForRead), Polyline)

 IntersectionPointA = lineIntersectors(AuxMuroA.StartPoint, AuxMuroA.EndPoint, lineA.StartPoint, lineA.EndPoint)

i need a current user coordinates system for lineA.

thank you
Title: Re: how select polyline and get current coordinates
Post by: n.yuan on June 09, 2020, 10:44:17 AM
Entity's coordinates in database are always World. If you need the coordinate in current UCS, simply transform the coordinate point with Editor.CurrentUserSystemCoordinate:, something like:

var ed=Application.DocumentManager.MdiDocument.Editor;
var startPt=LineA.StartPoint.TransformBy(ed.CurrentUserCoorinateSystem);
var endPt=LineA.EndPoint.TransformBy(ed.CurrentUserCoorinateSystem);

Similarly, if you picked point in current UCS that is different from World, before you use the point to do calculation with entity, you would translate the picked point into World coordinate system by transforming it with Editor.CurrentUserCooordinateSystem.Inverse().
Title: Re: how select polyline and get current coordinates
Post by: franciscocsilva on July 20, 2020, 07:19:14 AM
Entity's coordinates in database are always World. If you need the coordinate in current UCS, simply transform the coordinate point with Editor.CurrentUserSystemCoordinate:, something like:

var ed=Application.DocumentManager.MdiDocument.Editor;
var startPt=LineA.StartPoint.TransformBy(ed.CurrentUserCoorinateSystem);
var endPt=LineA.EndPoint.TransformBy(ed.CurrentUserCoorinateSystem);

Similarly, if you picked point in current UCS that is different from World, before you use the point to do calculation with entity, you would translate the picked point into World coordinate system by transforming it with Editor.CurrentUserCooordinateSystem.Inverse().

Thank you very much
Title: Re: how select polyline and get current coordinates
Post by: emrahctrk on October 15, 2020, 08:08:15 AM
do you have C# codes for this solution?
Title: Re: how select polyline and get current coordinates
Post by: Atook on October 15, 2020, 01:12:14 PM
do you have C# codes for this solution?

https://codeconverter.icsharpcode.net/