使用Teigha.net读取CAD的常用功能模块
teigha中实体旋转
代码:
using (var trans = database.transactionmanager.starttransaction())
{
entity ent = trans.getobject(entityid, openmode.forwrite) asentity;
if (ent != null )
{
extents3d exts = ent.geometricextents;
point3d pocenter = newpoint3d((exts.minpoint.x + exts.maxpoint.x) / 2, (exts.minpoint.y + exts.maxpoint.y) / 2, 0);
matrix3d matr4 = matrix3d.rotation((30 * math.pi / 180),vector3d.zaxis, pocenter);
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();
上一篇: 15个必须知道的chrome开发者技巧
下一篇: Mac Go 环境变量配置