Wblock问题
用选择集选择了一些对象,并获得了id集,使用database.wblock(idcollection,basepiont)方法创建一个database,如何让选择对象在新的database里的插入点是坐标原点,假定已经知道了选择对象的范围的minpoint。第二个参数应该就是吧 试过了,改变参数没反应! 我也有个问题,database.wblock 能否将图形添加到已存在的图形中? basepiont 我设置为 new point3d(100,100,0)与设置为db.Ucsorg效果一样。 可以用事件处理吧 写块在 db有对应的事件 能稍微具体点吗?
public static void ExecuteViewSetting()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
PromptSelectionResult prRes = ed.GetSelection();
if (prRes.Status != PromptStatus.OK) return;
ObjectIdCollection objIds = new ObjectIdCollection();
ObjectId[] objIdArray = prRes.Value.GetObjectIds();
double dMinX = 0, dMinY = 0, dMaxX = 0, dMaxY = 0;
/// Copy objectIds to objectIdCollection
foreach (ObjectId id in objIdArray)
{
using (Transaction txn = id.Database.TransactionManager.StartTransaction())
{
Entity acEnt = txn.GetObject(id, OpenMode.ForRead) as Entity;
if (null != acEnt)
{
try
{
if ((dMinX == 0) && (dMinY == 0) && (dMaxX == 0) && (dMaxY == 0))
{
dMinX = acEnt.GeometricExtents.MinPoint.X;
dMinY = acEnt.GeometricExtents.MinPoint.Y;
dMaxX = acEnt.GeometricExtents.MaxPoint.X;
dMaxY = acEnt.GeometricExtents.MaxPoint.Y;
}
else
{
if (dMinX > acEnt.GeometricExtents.MinPoint.X) dMinX = acEnt.GeometricExtents.MinPoint.X;
if (dMinY > acEnt.GeometricExtents.MinPoint.Y) dMinY = acEnt.GeometricExtents.MinPoint.Y;
if (dMaxX < acEnt.GeometricExtents.MaxPoint.X) dMaxX = acEnt.GeometricExtents.MaxPoint.X;
if (dMaxY < acEnt.GeometricExtents.MaxPoint.Y) dMaxY = acEnt.GeometricExtents.MaxPoint.Y;
}
}
catch { }
}
txn.Commit();
}
objIds.Add(id);
}
using (Database acDatabase = new Database(true, false))
{
db.Wblock(acDatabase, objIds, Point3d.Origin, DuplicateRecordCloning.Ignore);
///translate to (0,0,0)
using (Transaction txn = acDatabase.TransactionManager.StartTransaction())
{
Matrix3d mat = Matrix3d.Displacement(new Point3d((dMinX + dMaxX) * 0.5, (dMinY + dMaxY) * 0.5, 0).GetVectorTo(Point3d.Origin));
BlockTable acBlkTbl = (BlockTable)txn.GetObject(acDatabase.BlockTableId, OpenMode.ForRead);
BlockTableRecord acBlkTblRcd = (BlockTableRecord)txn.GetObject(acBlkTbl, OpenMode.ForWrite);
foreach (ObjectId objId in acBlkTblRcd)
{
Entity acEnt = txn.GetObject(objId, OpenMode.ForWrite) as Entity;
if (null != acEnt)
{
acEnt.TransformBy(mat);
}
}
ed.ZoomExtens();
txn.Commit();
}
///up to here
string FileName = "C:\\temp\\wblock.dwg";
acDatabase.SaveAs(FileName, DwgVersion.Current);
}
}
页:
[1]