TranslateCoordinates to DCS .NET C#\VB

TranslateCoordinates to DCS .NET C#\VB

Anonymous
Not applicable
1,498 Views
2 Replies
Message 1 of 3

TranslateCoordinates to DCS .NET C#\VB

Anonymous
Not applicable

Hello. I wanted to convert the coordinates of 2 points. I used this method once ...

 

Dim point1DCS() As Double = AcadApp.ActiveDocument.Utility.TranslateCoordinates(pt1, AcCoordinateSystem.acWorld, AcCoordinateSystem.acDisplayDCS, False)

 

Anyone know how to get this effect in NET API?

 

0 Likes
Accepted solutions (2)
1,499 Views
2 Replies
Replies (2)
Message 2 of 3

Ed__Jobe
Mentor
Mentor
Accepted solution

You can still use that if you reference the ActiveX api using Autodesk.AutoCAD.Interop

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

Message 3 of 3

_gile
Consultant
Consultant
Accepted solution

Hi,

 

With plain .NET, you can use the following extension methods.

 

Dim point1DCS() As Double = AcadApp.ActiveDocument.Utility.TranslateCoordinates(pt1, AcCoordinateSystem.acWorld, AcCoordinateSystem.acDisplayDCS, False)

would be:

Point3d point1DCS = pt1.TransformBy(ed.WCS2DCS());

 

using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;
using System;

namespace AutoCadUtilsLibrary
{
    public static class Extension
    {
        public static Matrix3d EyeToWorld(this AbstractViewTableRecord view)
        {
            if (view == null)
                throw new ArgumentNullException("view");
            return
                Matrix3d.Rotation(-view.ViewTwist, view.ViewDirection, view.Target) *
                Matrix3d.Displacement(view.Target.GetAsVector()) *
                Matrix3d.PlaneToWorld(view.ViewDirection);
        }

        public static Matrix3d WorldToEye(this AbstractViewTableRecord view)
        {
            if (view == null)
                throw new ArgumentNullException("view");
            return
                Matrix3d.WorldToPlane(view.ViewDirection) *
                Matrix3d.Displacement(view.Target.GetAsVector().Negate()) *
                Matrix3d.Rotation(view.ViewTwist, view.ViewDirection, view.Target);
        }

        public static Matrix3d DCS2WCS(this Editor ed)
        {
            if (ed == null)
                throw new ArgumentNullException("ed");
            using (ViewTableRecord view = ed.GetCurrentView())
            {
                return view.EyeToWorld();
            }
        }
        public static Matrix3d WCS2DCS(this Editor ed)
        {
            if (ed == null)
                throw new ArgumentNullException("ed");
            using (ViewTableRecord view = ed.GetCurrentView())
            {
                return view.WorldToEye();
            }
        }
    }
}

 



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub