CAD修改图块插入点到中点
js中实现代码说明: //返回控件的数据库对象var databae = mxOcx.GetDatabase();
//返回数据库中的块表对象
var blkTab = databae.GetBlockTable();
//创建一个遍历块表中所有记录的遍历器
var mBlockTableiter = blkTab.NewIterator();
//移动当前遍历器位置
for (; !mBlockTableiter.Done(); mBlockTableiter.Step())
{
//返回遍历器当前位置的记录
var blkRec = mBlockTableiter.GetRecord();
//创建一个遍历块表中所有记录的遍历器
var mBlockTableReciter = blkRec.NewIterator();
var mMaxPt = mxOcx.NewPoint();
var mMinPt = mxOcx.NewPoint();
var mMaxPtTemp = mxOcx.NewPoint();
var mMinPtTemp =mxOcx.NewPoint();
//移动当前遍历器位置
for (; !mBlockTableReciter.Done(); mBlockTableReciter.Step(true, false))
{
//与用户交互在图面上选择一个实体
var ent = mBlockTableReciter.GetEntity();
//返回实体的最小矩形框外包
ent.GetBoundingBox(mMinPtTemp, mMaxPtTemp);
if ((mMinPtTemp == null) || (mMaxPtTemp == null))
break;
mMaxPt.x = Math.max(mMaxPt.x, mMaxPtTemp.x);
mMaxPt.y = Math.max(mMaxPt.y, mMaxPtTemp.y);
mMinPt.x = Math.min(mMinPt.x, mMinPtTemp.x);
mMinPt.y = Math.min(mMinPt.y, mMinPtTemp.y);
}
if ((mMinPtTemp == null) || (mMaxPtTemp == null))
continue;
var mNewBasePt = mxOcx.NewPoint();
mNewBasePt.x = mMinPt.x + (mMaxPt.x - mMinPt.x) / 2;
mNewBasePt.y = mMinPt.y + (mMaxPt.y - mMinPt.y) / 2;
//块表记录的插入原点属性
blkRec.Origin = mNewBasePt;
//重新生成图,重新生成所有显示数据
mxOcx.Regen();
}
}
页:
[1]