.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Reply
Message 1 of 6
Anonymous
635 Views, 5 Replies

Move

I am using auto2006 with .net.
Now I want to move entity.
there is a my code. something wrong.
can any body tell me the solution.
many thanks

static public void Move()

{
//Start Transaction-----------------------------------
Database acadDB =HostApplicationServices.WorkingDatabase;
Autodesk.AutoCAD.DatabaseServices.TransactionManager
acadTransmgr= acadDB.TransactionManager;
Transaction acadTrans = acadTransmgr.StartTransaction();
Editor ed = acadApp.DocumentManager.MdiActiveDocument.Editor ;
try
{
//Start Transaction-----------------------------------
PromptSelectionOptions selOpts = new PromptSelectionOptions();
PromptSelectionResult res;

selOpts.MessageForAdding = "Select an entity";
res = ed.GetSelection();

Autodesk.AutoCAD.EditorInput.SelectionSet SS=res.Value;

Point3d fromPt;
Point3d toPt;
PromptPointResult ptRes;
PromptPointResult ptTo;
ptRes = ed.GetPoint("Pick a from point");

fromPt = ptRes.Value;

ptTo = ed.GetPoint("Pick a to point");

toPt = ptTo.Value;
Vector3d moveVec = new Vector3d(toPt.X - fromPt.X, toPt.Y - fromPt.Y, toPt.Z - fromPt.Z);
ObjectId [] idarray = SS.GetObjectIds();
foreach (ObjectId id in idarray)
{

Entity ent = (Entity)acadTrans.GetObject(id, OpenMode.ForWrite, true);
Matrix3d moveMat = Matrix3d.Displacement(moveVec);
ent.TransformBy(ent.Ecs.PostMultiplyBy(moveMat));

}//end foreach


//end Transaction-----------------------------------------
acadTrans.Commit();
}catch(System.Exception ex)
{
ed.WriteMessage(ex.ToString());
acadTrans.Abort();
}
finally
{
acadTrans.Dispose();
}
//end Transaction-------------------------------


}//end move
5 REPLIES 5
Message 2 of 6
Anonymous
in reply to: Anonymous

http://www.autocad.ru/cgi-bin/f1/board.cgi?t=37926PN#20070902171533
Message 3 of 6
Anonymous
in reply to: Anonymous

Thank you Alexender.
Message 4 of 6
Anonymous
in reply to: Anonymous

Alexander it looks like
AcGe.Vector3d vec =resPt2.Value —resPt1.Value;
would give the same value.
Message 5 of 6
Anonymous
in reply to: Anonymous

In any UCS? 🙂 What about this simple test:
[code]
Command: LINE Specify first point: 0,0
Specify next point or [Undo]: 1,1
Specify next point or [Undo]:
Command: (mapcar '- (getpoint) (getpoint)) (1.0 1.0 0.0)
Command: UCS
Current ucs name: *WORLD*
Enter an option [New/Move/orthoGraphic/Prev/Restore/Save/Del/Apply/?/World]
: N
Specify origin of new UCS or [ZAxis/3point/OBject/Face/View/X/Y/Z] <0,0,0>: Z
Specify rotation angle about Z axis <90>: 30
Command: (mapcar '- (getpoint) (getpoint)) (1.36603 0.366025 0.0)
[/code]
Message 6 of 6
Anonymous
in reply to: Anonymous

Sorry, I did a bad test.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Forma Design Contest


Autodesk Design & Make Report