www.mxdraw.com
|
绘制块引用对象
[id(72), helpstring("method DrawBlockReference")] LONGLONG DrawBlockReference(DOUBLE dPosX, DOUBLE dPosY, BSTR pszBlkName, DOUBLE dScale, DOUBLE dAng);
参数 |
说明 |
DOUBLE dPosX |
插入点的X坐标 |
DOUBLE dPosY |
插入点的Y坐标 |
BSTR pszBlkName |
图块名 |
DOUBLE dScale |
图块缩放比例 |
DOUBLE dAng |
图块的旋转角度 |
返回块引用对象id
例如:VB
Private Sub InsertBlock_Click() '把颜色改回黑白色 MxDrawX1.DrawColor = 0 '创建一个图层,名为"BlockLayer" MxDrawX1.AddLayer "BlockLayer" '设置当前图层为"BlockLayer" MxDrawX1.LayerName = "BlockLayer" ' MxDrawX1.InsertBlock MxDrawX1.GetOcxAppPath + "Blk树.dwg", "TestTree" MxDrawX1.DrawBlockReference 0, 3600, "TestTree", 1, 0 MxDrawX1.ZoomAll MxDrawX1.UpdateDisplay End Sub
例如: 插入图块前修改图块文字,再插入。C#代码
private void InsertBlock() { // 插入块的块名。 String sBlkName = "MyBlkName"; // 把要插入的块文件引入到控件数据库中。 axMxDrawX1.InsertBlock("DwgFile", sBlkName); // 取到控件数据库 MxDrawDatabase database = (MxDrawDatabase)(axMxDrawX1.GetDatabase()); // 得到块表对象 MxDrawBlockTable blkTable = database.GetBlockTable(); // 当前块表中是否已经有名为sBlkName的块表记录 MxDrawBlockTableRecord blkRec = blkTable.GetAt(sBlkName, true); if (blkRec == null) { // 证明InsertBlock函数失败,没有成功把文件插入数据库中。 return; } // // 创建一个用于遍历块表遍历器 MxDrawBlockTableRecordIterator iter = blkRec.NewIterator(); if (iter == null) return; for (; !iter.Done(); iter.Step(true, false)) { // 得到遍历器当前的实体 MxDrawEntity ent = iter.GetEntity(); if (ent == null) continue; if (ent is MxDrawText) { // 当前实体是一个文字 MxDrawText text = (MxDrawText)ent; // 修改文字内容为 "MyContent" text.TextString = "MyContent"; } } // 创建块引用,把图块插入到当前空间,并显示。 axMxDrawX1.DrawBlockReference(0, 0, sBlkName, 1.0, 0.0); }
例如: c#插入图块,把图块左下角设置成插入基点.
axMxDrawX1.InsertBlock("H:\juxing.DXF", "junxing"); MxDrawDatabase database = (MxDrawDatabase)axMxDrawX1.GetDatabase(); MxDrawBlockTable blkTab = database.GetBlockTable(); MxDrawBlockTableRecord rec = blkTab.GetAt("junxing"); if (rec == null) return; MxDrawBlockTableRecordIterator iter = rec.NewIterator(); double dMinX = 0, dMinY = 0; bool isSet = false; for (; !iter.Done(); iter.Step()) { MxDrawEntity ent = iter.GetEntity(); MxDrawPoint pt1, pt2; ent.GetBoundingBox(out pt1,out pt2); if (pt1 == null) continue; if (isSet) { if (dMinX > pt1.x) dMinX = pt1.x; if (dMinY > pt1.y) dMinY = pt1.y; } else { dMinX = pt1.x; dMinY = pt1.y; isSet = true; } } if (isSet) { MxDrawPoint pt = new MxDrawPoint(); pt.x = dMinX; pt.y = dMinY; rec.Origin = pt; } axMxDrawX1.DrawBlockReference(0, 0, "junxing", 1, 0); axMxDrawX1.ZoomAll();
例如: Qt调用.
qlonglong nId = pMxDrawX->DrawBlockReference(pBlock->ptIns[0], pBlock->ptIns[1], pBlock->strBlockTypeName, pBlock->dScale[0], pBlock->dAngle*180.0/osg::PI); IDatabase *database = (IDatabase *)pMxDrawX->querySubObject("GetDatabase()"); IBlockRef * pBlkRef = (IBlockRef * ) database->querySubObject("ObjectIdToObject(qlonglong)",nId); IMxDrawBlockReference * pBlkRef = (IMxDrawBlockReference * ) database->querySubObject("ObjectIdToObject(qlonglong)",nId);