.NET

Reply
*Carlos
Message 1 of 3 (308 Views)

Inserting block with orientation - UCS question

308 Views, 2 Replies
07-28-2005 11:32 AM
Hello,

I used to insert and orient blocks in AutoCAD by changing the UCS and then
using the insert command. How is this done using .NET?

In C#, I use the following method (this isn't all of the code, but you get
the idea) to insert the block:

ObjectId idBTR = doc.Database.Insert("My Block Name",db,true);
BlockReference bref = new BlockReference(location, idBTR);
btr.AppendEntity(bref);

Now I just need to figure out how to get it oriented properly (I've got two
direction vectors that specify its orientation). Is this done by setting a
UCS before calling the Insert method?

Any rough guidelines on how to orient blocks using .NET are greatly
appreciated.

Thanks!

-Carlos
*Jim Awe
Message 2 of 3 (308 Views)

Re: Inserting block with orientation - UCS question

07-30-2005 08:51 PM in reply to: *Carlos
You do it by calling TransformBy() with the appropriate transformation
matrix. Are you trying to just get it oriented correctly in the current
UCS? If so, see the example uses of
Utils.Db.TransformToWcs();

in the sample MgdDbg that was posted here last week. If you orienting to
something else, then you'll have to figure out the relative transformation
between the current UCS and where you want it to go. Look at something like
"ObjTests\ModifyEntTests.cs", function "XformWcsOrigin()" for an example of
aligning two coordinate systems.

Jim Awe
Autodesk, Inc.


"Carlos" wrote in message
news:4914012@discussion.autodesk.com...
Hello,

I used to insert and orient blocks in AutoCAD by changing the UCS and then
using the insert command. How is this done using .NET?

In C#, I use the following method (this isn't all of the code, but you get
the idea) to insert the block:

ObjectId idBTR = doc.Database.Insert("My Block Name",db,true);
BlockReference bref = new BlockReference(location, idBTR);
btr.AppendEntity(bref);

Now I just need to figure out how to get it oriented properly (I've got two
direction vectors that specify its orientation). Is this done by setting a
UCS before calling the Insert method?

Any rough guidelines on how to orient blocks using .NET are greatly
appreciated.

Thanks!

-Carlos
*Carlos
Message 3 of 3 (308 Views)

Re: Inserting block with orientation - UCS question

08-01-2005 05:20 PM in reply to: *Carlos
Thanks so much Jim! I got something that works by looking at your examples.

I realize there's probably a neater way (this is probably more of an
embarrassment than a useful bit of code), but here's what I did (in case
anyone is ever interested in what not to do):

Point3d origin = new Point3d(0, 0, 0);
Matrix3d m = new Matrix3d();
Vector3d oldX = new Vector3d(1, 0, 0);
Vector3d oldY = new Vector3d(0, 1, 0);
Vector3d oldZ = new Vector3d(0, 0, 1);
m.SetToAlignCoordinateSystem(origin, oldX, oldY, oldZ, NewLocation, xVector,
yVector,
xVector.CrossProduct(yVector));
bref.TransformBy(m);

Thanks again!

-Carlos


"Jim Awe" wrote in message
news:4915680@discussion.autodesk.com...
You do it by calling TransformBy() with the appropriate transformation
matrix. Are you trying to just get it oriented correctly in the current
UCS? If so, see the example uses of
Utils.Db.TransformToWcs();

in the sample MgdDbg that was posted here last week. If you orienting to
something else, then you'll have to figure out the relative transformation
between the current UCS and where you want it to go. Look at something like
"ObjTests\ModifyEntTests.cs", function "XformWcsOrigin()" for an example of
aligning two coordinate systems.

Jim Awe
Autodesk, Inc.


"Carlos" wrote in message
news:4914012@discussion.autodesk.com...
Hello,

I used to insert and orient blocks in AutoCAD by changing the UCS and then
using the insert command. How is this done using .NET?

In C#, I use the following method (this isn't all of the code, but you get
the idea) to insert the block:

ObjectId idBTR = doc.Database.Insert("My Block Name",db,true);
BlockReference bref = new BlockReference(location, idBTR);
btr.AppendEntity(bref);

Now I just need to figure out how to get it oriented properly (I've got two
direction vectors that specify its orientation). Is this done by setting a
UCS before calling the Insert method?

Any rough guidelines on how to orient blocks using .NET are greatly
appreciated.

Thanks!

-Carlos
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 or visit the Installation and Licensing Forum to get help installing your software.