이번에 하는 프로젝트의 요구 사항중 하나로 Model Space에 있는 Entity(Annotation,Dimension)을 Paper Space로 이동하는 예입니다.
[펌]
[펌]
AutoCAD .NET: Move Entity from Model Space to Paper Space
In this article, let us move an AutoCAD entity from the model space either WCS or UCS to the default paper space using AutoCAD .NET.
We demonstrated moving an AutoCAD entity from the model space either WCS or UCS to a block reference (INSERT) a bit earlier. We also demonstrated moving an AutoCAD entity from the model space either WCS or UCS to a nested block reference (INSERT) last time.
[CommandMethod("MoveFromModelToPaper", CommandFlags.NoPaperSpace)]
public static void MoveFromModelToPaper_Method()
{
Database db = HostApplicationServices.WorkingDatabase;
Editor ed = MgdAcApplication.DocumentManager.MdiActiveDocument.Editor;
try
{
PromptEntityResult prEntRes1 = ed.GetEntity("Select an entity: ");
if (prEntRes1.Status == PromptStatus.OK)
{
using (Transaction tr = db.TransactionManager.StartTransaction())
{
Entity ent = tr.GetObject(prEntRes1.ObjectId, OpenMode.ForWrite) as Entity;
BlockTableRecord space = tr.GetObject(SymbolUtilityServices.GetBlockPaperSpaceId(db), OpenMode.ForWrite) as BlockTableRecord;
Entity clone = ent.Clone() as Entity;
space.AppendEntity(clone);
tr.AddNewlyCreatedDBObject(clone, true);
ent.Erase();
tr.Commit();
}
}
}
catch (System.Exception ex)
{
ed.WriteMessage(ex.ToString());
}
}
If the command is run in the model space of AutoCAD and an entity is picked, the drawing area may look something like the following:
[CommandMethod("MoveFromModelToPaper", CommandFlags.NoPaperSpace)]
public static void MoveFromModelToPaper_Method()
{
Database db = HostApplicationServices.WorkingDatabase;
Editor ed = MgdAcApplication.DocumentManager.MdiActiveDocument.Editor;
try
{
PromptEntityResult prEntRes1 = ed.GetEntity("Select an entity: ");
if (prEntRes1.Status == PromptStatus.OK)
{
using (Transaction tr = db.TransactionManager.StartTransaction())
{
Entity ent = tr.GetObject(prEntRes1.ObjectId, OpenMode.ForWrite) as Entity;
BlockTableRecord space = tr.GetObject(SymbolUtilityServices.GetBlockPaperSpaceId(db), OpenMode.ForWrite) as BlockTableRecord;
Entity clone = ent.Clone() as Entity;
space.AppendEntity(clone);
tr.AddNewlyCreatedDBObject(clone, true);
ent.Erase();
tr.Commit();
}
}
}
catch (System.Exception ex)
{
ed.WriteMessage(ex.ToString());
}
}
If the command is run in the model space of AutoCAD and an entity is picked, the drawing area may look something like the following:
After switching to the default paper space, we will find the entity has been properly moved there.
By the way, the test C# project along with most code of the test command and the transaction starter code were all automatically created by AutoCAD .NET Addin Wizard (AcadNetAddinWizard), more specifically, its AutoCAD .NET Addin project wizard, Local Commands item wizard, and Entity Appender coder.
By the way, the test C# project along with most code of the test command and the transaction starter code were all automatically created by AutoCAD .NET Addin Wizard (AcadNetAddinWizard), more specifically, its AutoCAD .NET Addin project wizard, Local Commands item wizard, and Entity Appender coder.
Very
답글삭제