.NET

Reply
New Member
Trei
Posts: 1
Registered: ‎05-18-2005
Message 1 of 7 (648 Views)

Cursor Coordinate Problems

648 Views, 6 Replies
05-18-2005 07:37 PM
We are in the process of customizing the DockingPalette C# sample found in C:\ObjectARX 2006\samples\dotNet\DockingPalette.

We are attempting to insert an entity into the database at the X,Y drawing coordinates where the user released the mouse button. We are able to retrieve the X,Y pixel coordinates from System.Windows.Forms.DragEventArgs, but have not found a way to translate those into X, Y coordinates useful for inserting an entity at an accurate spot on the drawing. In addition, we haven't found anyway to retrieve the current X, Y of the mouse position when we receive our drop event.

Can anyone provide any guidance on either:

A) translating System.Windows.Forms.DragEventArgs X,Y coords into World Coordinate or User Coordinate system X,Y values

B) retrieving World Coordinate or User Coordinate system X,Y values for the current mouse position

BTW, we're I'd like to thank whoever got a .NET forum setup. We're looking forward to a better repository of .NET knowledge for the ObjectARX api.
Distinguished Contributor
NathTay
Posts: 1,691
Registered: ‎12-15-2003
Message 2 of 7 (648 Views)

Re: Cursor Coordinate Problems

05-18-2005 08:14 PM in reply to: Trei
The ObjectARX and .NET API's are different. That is the reason we wanted this forum. Unfortunately Autodesk have blurred the line by packaging the .NET API documentation with the ObjectARX SDK and originally telling .NET API users to use the ObjectARX discussion group. Hopefully Autodesk will further help end this confusion by seperating the .NET API documentation and putting out material that explains they are different.

Regards - Nathan
*Murph
Message 3 of 7 (648 Views)

Re: Cursor Coordinate Problems

05-19-2005 05:23 AM in reply to: Trei
If the pros that program all day long have a hard time understanding this,
us amateurs that dabble with it part-time are going nuts. So is that VB,
dotnet, C#, C++ or VS? Waitress, can I get another cup of coffee?

Murph

wrote in message news:4849966@discussion.autodesk.com...
Hopefully Autodesk will further help end this confusion by seperating the
.NET API documentation and putting out material that explains they are
different.

Regards - Nathan
*J. Daniel Smith
Message 4 of 7 (648 Views)

Re: Cursor Coordinate Problems

05-19-2005 06:26 AM in reply to: Trei
I've been calling the .NET APIs "ARX.NET" for lack of an official name. I
think ARX is/was for AutoCAD Runtime eXtension (maybe now it's "just three
letters") which still makes sense for .NET.

The line is somewhat blury because a .NET language like Managed C++ or
C++/CLI can readily use both ARX.NET and ObjectARX. Even VB.NET and C# can
make limited use of ObjectARX through P/Invoke and COM Interop.

Also, just as System.Windows.Forms is built on Win32, ARX.NET is largly
built on ObjectARX. Eventually, this will be just an "implementation
detail" (and there will be new .NET-only functionality), but right now it
can still be helpful to know Win32 and ObjectARX even if you're only using
the .NET APIs.

Dan

wrote in message news:4849966@discussion.autodesk.com...
The ObjectARX and .NET API's are different. That is the reason we wanted
this forum. Unfortunately Autodesk have blurred the line by packaging the
.NET API documentation with the ObjectARX SDK and originally telling .NET
API users to use the ObjectARX discussion group. Hopefully Autodesk will
further help end this confusion by seperating the .NET API documentation and
putting out material that explains they are different.

Regards - Nathan
*Albert Szilvasy
Message 5 of 7 (648 Views)

Re: Cursor Coordinate Problems

05-19-2005 05:25 PM in reply to: Trei
There's no first class .NET API to convert pixel to world coordinates and
back. You will need to P/Invoke 2 C++ APIs to accomplish this. Here's how to
do it:
public class ArxApi
{
[DllImport("acad.exe", CallingConvention = CallingConvention.Cdecl,
EntryPoint="?acedCoordFromPixelToWorld@@YAHHVCPoint@@QAN@Z")]
extern static bool acedCoordFromPixelToWorld(int viewportNumber,
System.Drawing.Point pixel, out Autodesk.AutoCAD.Geometry.Point3d worldPt);

[DllImport("acad.exe", CallingConvention = CallingConvention.Cdecl,
EntryPoint="?acedCoordFromWorldToPixel@@YAHHQBNAAVCPoint@@@Z")]
extern static bool acedCoordFromWorldToPixel(int viewportNumber, ref
Autodesk.AutoCAD.Geometry.Point3d worldPt, out System.Drawing.Point pixel);

[CommandMethod("testpix")]
public void Test()
{
Point3d pt = new Point3d(0,0,0);
System.Drawing.Point pix;
acedCoordFromWorldToPixel(0,ref pt,out pix);
Point3d res;
acedCoordFromPixelToWorld(0,pix,out res);
}
}

To convert between UCS and WCS you can use the transformation matrix
returned by Editor.CurrentUserCoordinateSystem

Albert

wrote in message news:4849962@discussion.autodesk.com...
We are in the process of customizing the DockingPalette C# sample found in
C:\ObjectARX 2006\samples\dotNet\DockingPalette.

We are attempting to insert an entity into the database at the X,Y drawing
coordinates where the user released the mouse button. We are able to
retrieve the X,Y pixel coordinates from System.Windows.Forms.DragEventArgs,
but have not found a way to translate those into X, Y coordinates useful for
inserting an entity at an accurate spot on the drawing. In addition, we
haven't found anyway to retrieve the current X, Y of the mouse position when
we receive our drop event.

Can anyone provide any guidance on either:

A) translating System.Windows.Forms.DragEventArgs X,Y coords into World
Coordinate or User Coordinate system X,Y values

B) retrieving World Coordinate or User Coordinate system X,Y values for the
current mouse position

BTW, we're I'd like to thank whoever got a .NET forum setup. We're looking
forward to a better repository of .NET knowledge for the ObjectARX api.
*Tony Tanzillo
Message 6 of 7 (648 Views)

Re: Cursor Coordinate Problems

05-19-2005 08:05 PM in reply to: Trei
Hi Albert.

Thanks for the great samples.

Can we presume that System.Drawing.Point and CPoint are
call-compatible types?

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006
http://www.acadxtabs.com

"Albert Szilvasy" wrote in message news:4851284@discussion.autodesk.com...
There's no first class .NET API to convert pixel to world coordinates and
back. You will need to P/Invoke 2 C++ APIs to accomplish this. Here's how to
do it:
public class ArxApi
{
[DllImport("acad.exe", CallingConvention = CallingConvention.Cdecl,
EntryPoint="?acedCoordFromPixelToWorld@@YAHHVCPoint@@QAN@Z")]
extern static bool acedCoordFromPixelToWorld(int viewportNumber,
System.Drawing.Point pixel, out Autodesk.AutoCAD.Geometry.Point3d worldPt);

[DllImport("acad.exe", CallingConvention = CallingConvention.Cdecl,
EntryPoint="?acedCoordFromWorldToPixel@@YAHHQBNAAVCPoint@@@Z")]
extern static bool acedCoordFromWorldToPixel(int viewportNumber, ref
Autodesk.AutoCAD.Geometry.Point3d worldPt, out System.Drawing.Point pixel);

[CommandMethod("testpix")]
public void Test()
{
Point3d pt = new Point3d(0,0,0);
System.Drawing.Point pix;
acedCoordFromWorldToPixel(0,ref pt,out pix);
Point3d res;
acedCoordFromPixelToWorld(0,pix,out res);
}
}

To convert between UCS and WCS you can use the transformation matrix
returned by Editor.CurrentUserCoordinateSystem

Albert

wrote in message news:4849962@discussion.autodesk.com...
We are in the process of customizing the DockingPalette C# sample found in
C:\ObjectARX 2006\samples\dotNet\DockingPalette.

We are attempting to insert an entity into the database at the X,Y drawing
coordinates where the user released the mouse button. We are able to
retrieve the X,Y pixel coordinates from System.Windows.Forms.DragEventArgs,
but have not found a way to translate those into X, Y coordinates useful for
inserting an entity at an accurate spot on the drawing. In addition, we
haven't found anyway to retrieve the current X, Y of the mouse position when
we receive our drop event.

Can anyone provide any guidance on either:

A) translating System.Windows.Forms.DragEventArgs X,Y coords into World
Coordinate or User Coordinate system X,Y values

B) retrieving World Coordinate or User Coordinate system X,Y values for the
current mouse position

BTW, we're I'd like to thank whoever got a .NET forum setup. We're looking
forward to a better repository of .NET knowledge for the ObjectARX api.
*Albert Szilvasy
Message 7 of 7 (648 Views)

Re: Cursor Coordinate Problems

05-19-2005 09:15 PM in reply to: Trei
I don't have control over either of these types so I can't say whether this
will be safe assumption forever but they are certainly bit by bit compatible
right now.
Same is true for Point3d and double[3], Point2d and double[2].

Albert

"Tony Tanzillo" wrote in message
news:4851364@discussion.autodesk.com...
Hi Albert.

Thanks for the great samples.

Can we presume that System.Drawing.Point and CPoint are
call-compatible types?

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006
http://www.acadxtabs.com

"Albert Szilvasy" wrote in message
news:4851284@discussion.autodesk.com...
There's no first class .NET API to convert pixel to world coordinates and
back. You will need to P/Invoke 2 C++ APIs to accomplish this. Here's how to
do it:
public class ArxApi
{
[DllImport("acad.exe", CallingConvention = CallingConvention.Cdecl,
EntryPoint="?acedCoordFromPixelToWorld@@YAHHVCPoint@@QAN@Z")]
extern static bool acedCoordFromPixelToWorld(int viewportNumber,
System.Drawing.Point pixel, out Autodesk.AutoCAD.Geometry.Point3d worldPt);

[DllImport("acad.exe", CallingConvention = CallingConvention.Cdecl,
EntryPoint="?acedCoordFromWorldToPixel@@YAHHQBNAAVCPoint@@@Z")]
extern static bool acedCoordFromWorldToPixel(int viewportNumber, ref
Autodesk.AutoCAD.Geometry.Point3d worldPt, out System.Drawing.Point pixel);

[CommandMethod("testpix")]
public void Test()
{
Point3d pt = new Point3d(0,0,0);
System.Drawing.Point pix;
acedCoordFromWorldToPixel(0,ref pt,out pix);
Point3d res;
acedCoordFromPixelToWorld(0,pix,out res);
}
}

To convert between UCS and WCS you can use the transformation matrix
returned by Editor.CurrentUserCoordinateSystem

Albert

wrote in message news:4849962@discussion.autodesk.com...
We are in the process of customizing the DockingPalette C# sample found in
C:\ObjectARX 2006\samples\dotNet\DockingPalette.

We are attempting to insert an entity into the database at the X,Y drawing
coordinates where the user released the mouse button. We are able to
retrieve the X,Y pixel coordinates from System.Windows.Forms.DragEventArgs,
but have not found a way to translate those into X, Y coordinates useful for
inserting an entity at an accurate spot on the drawing. In addition, we
haven't found anyway to retrieve the current X, Y of the mouse position when
we receive our drop event.

Can anyone provide any guidance on either:

A) translating System.Windows.Forms.DragEventArgs X,Y coords into World
Coordinate or User Coordinate system X,Y values

B) retrieving World Coordinate or User Coordinate system X,Y values for the
current mouse position

BTW, we're I'd like to thank whoever got a .NET forum setup. We're looking
forward to a better repository of .NET knowledge for the ObjectARX api.

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community