www.mxdraw.com
|
把一堆对象,输出到一个新的Database中。 Js调用.
MxDrawDatabase Mx_Wblock(McDbObjectIdArray aryId, McGePoint3d bastPt);
例如: js
function ToDwg() { //实例化一个构造选择集进行过滤,该类封装了选择集及其处理函数。 var ss = mxOcx.NewSelectionSet(); ss.Select2(8, null, null, null, null); var param =mxOcx.NewResbuf(); var aryId = new Array(); for (var i = 0; i < ss.Count; i++) { var ent = ss.Item(i); if (ent != null) { param.AddObjectId(ent.ObjectID); //aryId.Add(ent.ObjectID); aryId[i]=ent.ObjectID; ent.Close(); } } // 计算新的图块的插入基点,把所实体外包的中点做为插入基点。 //返回控件的数据库对象 var curDatabase =mxOcx.GetDatabase(); var dMinX = 0, dMinY = 0, dMaxX = 0, dMaxY = 0; var isFirstEnt = true; for (var l = 0; l < aryId.length; l++) { var pObj = curDatabase.ObjectIdToObject(aryId[l]); if (pObj == null) continue; var pEnt = pObj; if (pEnt == null) continue; var pt1Ob=mxOcx.NewPoint(); var pt2Ob=mxOcx.NewPoint(); pEnt.GetBoundingBox(pt1Ob,pt2Ob); var minPt = pt1Ob; var maxPt = pt2Ob; if (minPt != null && maxPt != null) { if(isFirstEnt) { dMinX = minPt.x; dMinY = minPt.y; dMaxX = maxPt.x; dMaxY = maxPt.y; isFirstEnt = false; } else { if (dMinX > minPt.x) dMinX = minPt.x; if (dMinY > minPt.y) dMinY = minPt.y; if (dMaxX < maxPt.x) dMaxX = maxPt.x; if (dMaxY < maxPt.y) dMaxY = maxPt.y; } } } if(isFirstEnt) { // 没有实体 return; } var pos = mxOcx.NewPoint(); pos.x = dMinX + (dMaxX - dMinX) / 2.0; pos.y = dMinY + (dMaxY - dMinY) / 2.0; param.AddPoint(pos); var newDatabase = mxOcx.CallEx("Mx_Wblock", param); // 保存为dwg文件。 if (newDatabase.SaveAs("D:\wblock.dwg", 1, null)) { alert("Ok"); } else { alert("Failed"); } }