.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Cursor Coordinate Problems

6 REPLIES 6
Reply
Message 1 of 7
Trei
2114 Views, 6 Replies

Cursor Coordinate Problems

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.
6 REPLIES 6
Message 2 of 7
NathTay
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
Message 3 of 7
Anonymous
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
Message 4 of 7
Anonymous
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
Message 5 of 7
Anonymous
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.
Message 6 of 7
Anonymous
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.
Message 7 of 7
Anonymous
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.

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

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost