@vkpunique a écrit :
what if drawing that i want to jig is not drawn yet. Means user will trigger my custom command enter dimension via editor , program will generate all entity using fix 0,0 base point, and all of entity will by passed to move jig.
can i do this in single transaction or i have to do multiple transactions
Here's an example adding newly created entities to the current space before dragging them with a jig.
[CommandMethod("TEST1")]
public static void Test1()
{
var doc = Application.DocumentManager.MdiActiveDocument;
var db = doc.Database;
var ed = doc.Editor;
var ucs = ed.CurrentUserCoordinateSystem;
// Create some entities
var entities = new List<Entity>();
var circle = new Circle(Point3d.Origin, Vector3d.ZAxis, 10.0);
entities.Add(circle);
var line = new Line(new Point3d(-10.0, -10.0, 0.0), new Point3d(10.0, 10.0, 0.0));
entities.Add(line);
line = new Line(new Point3d(-10.0, 10.0, 0.0), new Point3d(10.0, -10.0, 0.0));
entities.Add(line);
using (var tr = db.TransactionManager.StartTransaction())
{
// Add the entities to the current space
var curSpace = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
foreach (var entity in entities)
{
entity.TransformBy(ucs);
curSpace.AppendEntity(entity);
tr.AddNewlyCreatedDBObject(entity, true);
}
// Drag the entities using a MoveJig instance
var jig = new MoveJig(entities, ucs.CoordinateSystem3d.Origin, "\nSpecify insertion point: ");
var result = ed.Drag(jig);
// Transform the entities if PromptResult.Status is OK
if (result.Status == PromptStatus.OK)
{
entities.ForEach(e => e.TransformBy(jig.Transform));
}
// erase them otherwise
else
{
entities.ForEach(e => e.Erase());
}
tr.Commit();
}
}
Another example which only add the newly created entities if the Jig PromptResult.Status is OK
[CommandMethod("TEST2")]
public static void Test2()
{
var doc = Application.DocumentManager.MdiActiveDocument;
var db = doc.Database;
var ed = doc.Editor;
var ucs = ed.CurrentUserCoordinateSystem;
// Create some entities and add them to a List
var entities = new List<Entity>();
var circle = new Circle(Point3d.Origin, Vector3d.ZAxis, 10.0);
entities.Add(circle);
var line = new Line(new Point3d(-10.0, -10.0, 0.0), new Point3d(10.0, 10.0, 0.0));
entities.Add(line);
line = new Line(new Point3d(-10.0, 10.0, 0.0), new Point3d(10.0, -10.0, 0.0));
entities.Add(line);
entities.ForEach(e => e.TransformBy(ucs));
// Drag the entities using a MoveJig instance
var jig = new MoveJig(entities, ucs.CoordinateSystem3d.Origin, "\nSpecify insertion point: ");
var result = ed.Drag(jig);
// Add the entities to the current space if PromptResult.Status is OK
if (result.Status == PromptStatus.OK)
{
using (var tr = db.TransactionManager.StartTransaction())
{
var curSpace = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
foreach (var entity in entities)
{
curSpace.AppendEntity(entity);
tr.AddNewlyCreatedDBObject(entity, true);
entity.TransformBy(jig.Transform);
}
tr.Commit();
}
}
// dispose them otherwise
else
{
entities.ForEach(e => e.Dispose());
}
}