.NET

Reply
Distinguished Contributor
wesbird
Posts: 351
Registered: ‎12-05-2003
Message 1 of 5 (338 Views)

How to Move Entity?

338 Views, 4 Replies
09-29-2005 01:05 PM
Hi,
In VBA, AcadObject.Move is the easist way to move a object. I can not find it in .Net. the similar I found: IAcadEntityDispatchImpl::Move is not wrapped for .Net yet. So if I understand correctly, Entity.TransformBy is the only way to move Entity, is this correct? then how? does anybody have a example. thanks a lot


Wes
Distinguished Contributor
wesbird
Posts: 351
Registered: ‎12-05-2003
Message 2 of 5 (338 Views)

Re: How to Move Entity?

09-29-2005 02:22 PM in reply to: wesbird
I already got a step further:

pt1, pt2 are move from and to point

here is the code:

Vector3d oldX = new Vector3d(1, 0, 0);
Vector3d oldY = new Vector3d(0, 1, 0);
Vector3d oldZ = new Vector3d(0, 0, 1);

Matrix3d m = Matrix3d.AlignCoordinateSystem(pt1, oldX, oldY, oldZ, pt2, oldX, oldY, oldZ);
ent.TransformBy(m);

which stil not working. What's wrong in my code?



Thank you

Wes
*Albert Szilvasy
Message 3 of 5 (338 Views)

Re: How to Move Entity?

09-29-2005 11:05 PM in reply to: wesbird
You can call the COM API from .NET if that's what you are familiar with.
IAcadEnittyDispatchImpl::Move will never be wrapped. It is part of the COM
API implementation and the COM API is callable from .NET already.

albert

wrote in message news:4971251@discussion.autodesk.com...
Hi,
In VBA, AcadObject.Move is the easist way to move a object. I can not find
it in .Net. the similar I found: IAcadEntityDispatchImpl::Move is not
wrapped for .Net yet. So if I understand correctly, Entity.TransformBy is
the only way to move Entity, is this correct? then how? does anybody have a
example. thanks a lot


Wes
*Albert Szilvasy
Message 4 of 5 (338 Views)

Re: How to Move Entity?

09-29-2005 11:09 PM in reply to: wesbird
It is difficult to say. The code that you are showing does what you'd like
it to do but I don't know what else is around this and how you observe the
failure.

albert

wrote in message news:4971352@discussion.autodesk.com...
I already got a step further:

pt1, pt2 are move from and to point

here is the code:

Vector3d oldX = new Vector3d(1, 0, 0);
Vector3d oldY = new Vector3d(0, 1, 0);
Vector3d oldZ = new Vector3d(0, 0, 1);

Matrix3d m = Matrix3d.AlignCoordinateSystem(pt1, oldX, oldY, oldZ, pt2,
oldX, oldY, oldZ);
ent.TransformBy(m);

which stil not working. What's wrong in my code?



Thank you

Wes
Distinguished Contributor
ChrisArps
Posts: 311
Registered: ‎07-29-2004
Message 5 of 5 (338 Views)

Re: How to Move Entity?

09-30-2005 05:56 AM in reply to: wesbird
Here is how to use transform for moving an entity.

_
Public Sub TestMove()
Dim editor As Editor = Application.DocumentManager.MdiActiveDocument.Editor
Dim db As Database = Application.DocumentManager.MdiActiveDocument.Database
Dim trans As Transaction = db.TransactionManager.StartTransaction()

Try
Dim selOpts As New PromptSelectionOptions()
Dim res As PromptSelectionResult

selOpts.SingleOnly = True
selOpts.MessageForAdding = "Select an entity"
res = editor.GetSelection(selOpts)
If res.Status PromptStatus.OK Then Return

Dim id As ObjectId = res.Value.GetObjectIds(0)
Dim mesg As String

Dim ent As Entity = trans.GetObject(id, OpenMode.ForWrite, False)
Dim mat As Matrix3d = ent.Ecs
Dim s As String = mat.ToString()

Dim fromPt As Point3d
Dim toPt As Point3d
Dim ptRes As PromptPointResult

ptRes = editor.GetPoint("Pick a from point")
If ptRes.Status PromptStatus.OK Then Return
fromPt = ptRes.Value

ptRes = editor.GetPoint("Pick a to point")
If ptRes.Status PromptStatus.OK Then Return
toPt = ptRes.Value

Dim moveVec As New Vector3d(toPt.X - fromPt.X, toPt.Y - fromPt.Y, toPt.Z - fromPt.Z)
Dim moveMat As Matrix3d = Matrix3d.Displacement(moveVec)

ent.TransformBy(ent.Ecs.PostMultiplyBy(moveMat))

trans.Commit()
Catch ex As Exception
trans.Abort()
MsgBox(ex.Message)
Finally
trans.Dispose()
End Try

End Sub

Please excuse the bad display of angle brackets, I will figure out how to post html eventually.

Chris Arps Message was edited by: CArps
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.