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

How to Move Entity?

4 REPLIES 4
Reply
Message 1 of 5
wesbird
1221 Views, 4 Replies

How to Move Entity?

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
Windows 10 64 bit, AutoCAD (ACA, Map) 2023
4 REPLIES 4
Message 2 of 5
wesbird
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
Windows 10 64 bit, AutoCAD (ACA, Map) 2023
Message 3 of 5
Anonymous
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
Message 4 of 5
Anonymous
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
Message 5 of 5
ChrisArps
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

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