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

Inserting block with orientation - UCS question

2 REPLIES 2
Reply
Message 1 of 3
Anonymous
626 Views, 2 Replies

Inserting block with orientation - UCS question

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
2 REPLIES 2
Message 2 of 3
Anonymous
in reply to: Anonymous

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
Message 3 of 3
Anonymous
in reply to: Anonymous

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

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