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

Set UCS to ECS

12 REPLIES 12
Reply
Message 1 of 13
Anonymous
1271 Views, 12 Replies

Set UCS to ECS

In the midst of a command, I prompt the user to select an entity. I want to set the UCS to the ECS of that object. I'm trying a basic example with the entity being a line (not horizontal obviously), but the Ecs property is always the identity matrix, and thus it doesn't change UCS from WCS.

Transaction tr = db.TransactionManager.StartTransaction();
Entity ent = (Entity)tr.GetObject((ObjectId)id, OpenMode.ForRead);
ed.CurrentUserCoordinateSystem = ent.Ecs;

It should be just that simple (I think). I posted a similar issue dealing with DBText before, but never got a solution. Any ideas?
12 REPLIES 12
Message 2 of 13
Anonymous
in reply to: Anonymous

{quote}

In the midst of a command.....

{quote}

Command: 'UCS
** That command may not be invoked transparently **

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD
Supporting AutoCAD 2000 through 2011

http://www.acadxtabs.com

Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");
Message 3 of 13
Anonymous
in reply to: Anonymous

Sorry Tony, I'm not sure what you're getting at... Perhaps I was unclear. I have a command method. In that method, I want to (programmatically) set the coordinate system to the entity coordinate system of a user selected entity. I'm not calling the UCS command.

The issue I'm running into is that the Ecs property of Entity always seems to be the identity matrix.
Message 4 of 13
Anonymous
in reply to: Anonymous

What I'm getting at is that you can't change the current UCS
while a command is running, regardless of how you do it.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD
Supporting AutoCAD 2000 through 2011

http://www.acadxtabs.com

Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");

wrote in message news:6363281@discussion.autodesk.com...
Sorry Tony, I'm not sure what you're getting at... Perhaps I was unclear. I
have a command method. In that method, I want to (programmatically) set the
coordinate system to the entity coordinate system of a user selected entity.
I'm not calling the UCS command.

The issue I'm running into is that the Ecs property of Entity always seems to be
the identity matrix.
Message 5 of 13
Anonymous
in reply to: Anonymous

That isn't the issue I'm trying to figure out - I am able to change the current UCS without a problem. Forget the reason I'm trying to use Ecs... The problem I have is that Entity.Ecs is always the identity matrix. If I draw a line from 10,10,0 to 50,50,0 it's Ecs property should NOT be (1,0,0,0), (0,1,0,0), (0,0,1,0), (0,0,0,1) - But it is.

This simple function will reproduce the problem I seem to be having:

public static void EcsTest()
{
Point3d start = new Point3d(10, 10, 0);
Point3d end = new Point3d(50, 50, 0);
Line line = new Line(start, end);
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Transaction tr = db.TransactionManager.StartTransaction();
BlockTableRecord mdlSpace = (BlockTableRecord)tr.GetObject(
SymbolUtilityServices.GetBlockModelSpaceId(db),
OpenMode.ForWrite);
mdlSpace.AppendEntity(line);
tr.AddNewlyCreatedDBObject(line, true);
tr.Commit();
doc.Editor.WriteMessage("\nECS: " + line.Ecs);
}

The output I get by running this function is
ECS: ((1,0,0,0),(0,1,0,0),(0,0,1,0),(0,0,0,1)) Edited by: fyathyrio8 on Mar 30, 2010 8:29 PM
Message 6 of 13
Anonymous
in reply to: Anonymous

Also, you can change the UCS in a command as is shown by this (only slightly modified from http://discussion.autodesk.com/forums/thread.jspa?messageID=6357968ϐ)

I would think that the Ecs property of the line in my previous post should match the mat matrix in the below code.

public static void ChangeUcsTest()
{
Point3d pt1 = new Point3d(10, 10, 0);
Point3d pt2 = new Point3d(50, 50, 0);
Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
Vector3d zAxis = ed.CurrentUserCoordinateSystem.CoordinateSystem3d.Zaxis;
Vector3d xAxis = pt1.GetVectorTo(pt2).GetNormal();
Vector3d yAxis = zAxis.CrossProduct(xAxis).GetNormal();
Matrix3d mat = Matrix3d.AlignCoordinateSystem(
Point3d.Origin,
Vector3d.XAxis,
Vector3d.YAxis,
Vector3d.ZAxis,
pt1,
xAxis,
yAxis,
zAxis);
ed.CurrentUserCoordinateSystem = mat;
}
Message 7 of 13
Anonymous
in reply to: Anonymous

The ECS of lines that lie in the WCS XY plane is always the Identity matrix.

The only thing AutoCAD knows about an entity's coordinate system is its
normal, because that's the only thing it stores.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD
Supporting AutoCAD 2000 through 2011

http://www.acadxtabs.com

Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");

wrote in message news:6363868@discussion.autodesk.com...
That isn't the issue I'm trying to figure out - I am able to change the current
UCS without a problem. Forget the reason I'm trying to use Ecs... The problem
I have is that Entity.Ecs is always the identity matrix. If I draw a line from
10,10,0 to 50,50,0 it's Ecs property should NOT be (1,0,0,0), (0,1,0,0),
(0,0,1,0), (0,0,0,1) - But it is.

This simple function will reproduce the problem I seem to be having:

public static void EcsTest()
{
Point3d start = new Point3d(10, 10, 0);
Point3d end = new Point3d(50, 50, 0);
Line line = new Line(start, end);
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Transaction tr = db.TransactionManager.StartTransaction();
BlockTableRecord mdlSpace = (BlockTableRecord)tr.GetObject(
SymbolUtilityServices.GetBlockModelSpaceId(db),
OpenMode.ForWrite);
mdlSpace.AppendEntity(line);
tr.AddNewlyCreatedDBObject(line, true);
tr.Commit();
doc.Editor.WriteMessage("\nECS: " + line.Ecs);
}

The output I get by running this function is
ECS: ((1,0,0,0),(0,1,0,0),(0,0,1,0),(0,0,0,1))

Edited by: fyathyrio8 on Mar 30, 2010 8:29 PM
Message 8 of 13
Anonymous
in reply to: Anonymous

Well, that's unfortunate. Any idea how AutoCAD determines the ECS when you use the UCS command with the E option?
Message 9 of 13
Anonymous
in reply to: Anonymous

It depends both on the object and what part of the
object was picked. For lines, it just sets the origin
to the end nearest the pick point and aligns the X
axis with the line.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD
Supporting AutoCAD 2000 through 2011

http://www.acadxtabs.com

Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");

wrote in message news:6364273@discussion.autodesk.com...
Well, that's unfortunate. Any idea how AutoCAD determines the ECS when you use
the UCS command with the E option?
Message 10 of 13
Anonymous
in reply to: Anonymous

this is a serious problem for me too
how can i do calculations relative to the ECS? ( i mean the one that fyathyrio8 mentioned) it is very easy in LISP with the "trans" function, i can't believe, that it's not possible in .NET

all entities in World's XY plane have normal (0,0,1) and Ecs property (1,0,0,0), (0,1,0,0), (0,0,1,0), (0,0,0,1), so that's not the way to do it
Message 11 of 13
Anonymous
in reply to: Anonymous

You compose a transformation matrix, using whatever
parameters you want (e.g., the rotation set to the angle
of a line in the WCS XY plane; the translation set to the
end of the line that is to be the origin of the destination
coordinate system), and you use the matrix to transform
points, entities, etc, by passing it to their TransformBy()
method.

The problem isn't that there's no way to do what you
need, the problem is that you're not familar with the
tools needed to do the job, namely the geometry library
(from the Autodesk.AutoCAD.Geometry namespace),
which is not available to LISP.

That library allows you to do what you mistakenly
believe can't be done, and many other things that
would need to be done entirely 'by-hand' in LISP.

Try to avoid thinking about Managed ObjectARX
as being the .NET equivalent of LISP, because
that's not what it is.

Managed ObjectARX is much more powerful than
LISP, and along with that power comes additional
complexity and finer granularity, which means that
most things require more code than LISP.

See this sample code:

http://www.caddzone.com/EntityECSExample.cs

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD
Supporting AutoCAD 2000 through 2011

http://www.acadxtabs.com

Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");

wrote in message news:6393021@discussion.autodesk.com...
this is a serious problem for me too
how can i do calculations relative to the ECS? ( i mean the one that fyathyrio8
mentioned) it is very easy in LISP with the "trans" function, i can't believe,
that it's not possible in .NET

all entities in World's XY plane have normal (0,0,1) and Ecs property (1,0,0,0),
(0,1,0,0), (0,0,1,0), (0,0,0,1), so that's not the way to do it
Message 12 of 13
Anonymous
in reply to: Anonymous

i didn't mean, that transforming is not possible at all, i just meant that there must be an easier way (but it seems there isn't)
i used to work in LISP for years, only a month or so in .NET, so the old habits are still strong

anyway, you mentioned a line, which is very easy, but that means, that as simple thing (for LISP) as working in OCS would require me to analyse all possible types of entities and choose a different approach for each type?

can you give me a hint for dimensions? (aligned and rotated) that's what i need right now, others can wait for their time

edit: GetStretchPoints looks like a good way Edited by: matus.brlit@cemos.sk on May 19, 2010 7:58 AM
Message 13 of 13
Anonymous
in reply to: Anonymous

Your only problem is that you've not learned to use
the tools yet.

The code sample I posted is not specific to lines,
it shows how to compose a matrix from existing
geometry.

Exactly how you use the existing geometry is an
implementation detail which I have no clue about.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD
Supporting AutoCAD 2000 through 2011

http://www.acadxtabs.com

Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");

wrote in message news:6393567@discussion.autodesk.com...
i didn't mean, that transforming is not possible at all, i just meant that there
must be an easier way (but it seems there isn't)
i used to work in LISP for years, only a month or so in .NET, so the old habits
are still strong

anyway, you mentioned a line, which is very easy, but that means, that as simple
thing (for LISP) as working in OCS would require me to analyse all possible
types of entities and choose a different approach for each type?

can you give me a hint for dimensions? (aligned and rotated) that's what i need
right now, others can wait for their time

edit: GetStretchPoints looks like a good way

Edited by: matus.brlit@cemos.sk on May 19, 2010 7:58 AM

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