使用Teigha.net讀取CAD的經常使用功能模塊

Teigha中實體旋轉佈局

代碼:字體

using (var trans = database.TransactionManager.StartTransaction())spa

{3d

Entity ent = trans.GetObject(entityId, OpenMode.ForWrite) asEntity;orm

if (ent != null )文檔

{string

Extents3d exts = ent.GeometricExtents;it

Point3d poCenter = newPoint3d((exts.MinPoint.X + exts.MaxPoint.X) / 2, (exts.MinPoint.Y + exts.MaxPoint.Y) / 2, 0);io

Matrix3d Matr4 = Matrix3d.Rotation((30 * Math.PI / 180),Vector3d.ZAxis, poCenter);form

ent.TransformBy(Matr4);

}

trans.Commit();

}

//以實體的外接矩形的中心點爲圓心旋轉30度。

 

Teigha中跳轉至顯示視圖跳轉到某點,並以此爲圓心顯示內容

代碼:

using (var trans = database.TransactionManager.StartTransaction())

{

Point3d EndPoint=new Point3d(0,0,0);

using (Teigha.GraphicsSystem.View pView = helperDevice.ActiveView)

{

pView.Dolly(EndPoint.X - pView.Position.X, EndPoint.Y - pView.Position.Y, 0);

}

trans.Commit();

}

if (helperDevice != null)

helperDevice.Update();

Invalidate();

 

Teigha 窗體內容的旋轉

代碼:

if (helperDevice != null)

{

using (Teigha.GraphicsSystem.View pView = BaseF.helperDevice.ActiveView)

{

//2爲指定的角度

pView.Roll(2 * Math.PI / 180);

Invalidate();

}

helperDevice.Update();

helperDevice.Invalidate();

}

Invalidate();

 

 

Teigha 直接將塊中內容導入其餘塊中(適用於不一樣dwg文件的導入)

代碼:

Database databa = newDatabase(false, false);

databa.ReadDwgFile(@"C:\Users\admin\Desktop\安裝略圖.dwg", FileOpenMode.OpenForReadAndAllShare, false, "");

using (var trans = database.TransactionManager.StartTransaction())

{

BlockTable block = database.BlockTableId.GetObject(OpenMode.ForWrite) asBlockTable;

using (var tran = databa.TransactionManager.StartTransaction())

{

BlockTable blockold = databa.BlockTableId.GetObject(OpenMode.ForWrite) asBlockTable;

database.Insert("須要導入的塊名稱", databa, false);

database.Insert( "須要導入的塊名稱",從新建立一個新的名字, databa, false);

}

trans.Commit();

}

 

Teigha 獲取文檔中包含的字體樣式(主要用於計算機不包含CAD字體時)

//修改字體後須要刷新內容,最好是來回切換佈局!

代碼:

List<string> StrList = newList<string>();

using (var trans = BaseF.database.TransactionManager.StartTransaction())

{

using (TextStyleTable txtstyles = (TextStyleTable)trans.GetObject(BaseF.database.TextStyleTableId, OpenMode.ForRead))

{

string exCADlow = .eot,.eot,.otf,.fon,.font,.ttf,.ttc,.woff,.woff2,.shx

foreach (ObjectId item in txtstyles)

{

using (TextStyleTableRecord txtse = (TextStyleTableRecord)trans.GetObject(item, OpenMode.ForRead))

{

if (exCADlow.Contains(Path.GetExtension(txtse.FileName).ToLower()) && Path.GetExtension(txtse.FileName).ToLower() != "")

{

StrList.Add(txtse.FileName);

}

 

 

}

}

}

 

Teigha 實現移動視圖的效果

//根據按下和移動時的鼠標座標移動窗體顯示的CAD內容

代碼:

///<summary>

///移動視圖

///</summary>

///<param name="PoMove"></param>

privatevoid Viewer_UDLR(Point PoMove)

{

double dx = -(PoMove.X - MouseDowns.X);

double dy = -(PoMove.Y - MouseDowns.Y);

MouseDowns = PoMove;

using (DBObject pVpObj = Aux.active_viewport_id(database).GetObject(OpenMode.ForWrite))

{

AbstractViewportData pAVD = newAbstractViewportData(pVpObj);

Teigha.GraphicsSystem.View pView = pAVD.GsView;

Vector3d vec = newVector3d(dx, dy, 0.0);

vec = vec.TransformBy((pView.ScreenMatrix * pView.ProjectionMatrix).Inverse());

pView.Dolly(vec);

pAVD.SetView(pView);

pAVD.Dispose();

pVpObj.Dispose();

Invalidate();

}

 

}

 

Teigha 移動實體所在位置

代碼:

///<summary>

///移動實體

///</summary>

///<param name="PoMove"></param>

privatevoid MoverEntity_view(Point PoMove)

{

Point3d Podown1 = toEyeToWorld(MouseDowns.X, MouseDowns.Y);

Point3d Pomove1= toEyeToWorld(PoMove.X, PoMove.Y);

 

double dx = Pomove1.X - Podown1.X;

double dy = Pomove1.Y - Podown1.Y;

MouseDowns = PoMove;

List<ObjectId> Listitem = newList<ObjectId>();

 

using (var trans = database.TransactionManager.StartTransaction())

{

foreach (ObjectId item in SelectID)

{

if (Listitem.FindIndex(s1 => s1 == item) == -1)

{

Listitem.Add(item);

using (Entity Ent = item.GetObject(OpenMode.ForWrite) asEntity)

{

PoDowns = newPoint3d(PoDowns.X + dx, PoDowns.Y + dy,0);

Point3d Pointnew = newPoint3d(dx, dy, 0);

Matrix3d mat = Matrix3d.Displacement(Pointnew.GetAsVector());

Ent.TransformBy(mat);

}

}

}

trans.Commit();

}

Listitem.Clear();

if (helperDevice != null)

helperDevice.Update();

相關文章
相關標籤/搜索