在网页中怎么查找文字?
MxDraw网页开发|黄洪辉|2018-05-04 16:47
-
回答:
实例化一个构造选择集进行过滤,该类封装了选择集及其处理函数。将文字对象当作过滤条件,得到文字对象(此处可以是文字或多行文字)。
12345678// 创建选择集对象
ss = mxOcx.NewSelectionSet();
// 创建一个链表对象
var
spFilte = mxOcx.NewResbuf();
// 把文字,多行文字当着过滤条件
spFilte.AddStringEx(
"TEXT,MTEXT"
,5020);
// 得到图上所有文字,5代码,全图选择
ss.Select2(5,
null
,
null
,
null
,spFilte);
遍历每个文字对象,将文字放到视区中间并绘制一个标记圆。
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364// 遍历每个文字.
var
bFind =
false
;
// 遍历选择集
for
(
var
i = 0; i < ss.Count;i++)
{
// 得到选集中的实体
var
ent = ss.Item(i);
if
(ent ==
null
)
continue
;
if
(ent.ObjectName ==
"McDbText"
) {
// 得到文字内容
var
sTxt = ent.TextString;
if
(sTxt == txt) {
// 把文字放到视区中间.
mxOcx.PutEntityInView(ent.ObjectID, 300);
var
dLen = mxOcx.ViewLongToDocCoord(80);
// 绘制一个标记圆.
mxOcx.DrawVectorCircle(ent.Position.x,
ent.Position.y,
dLen, 65280);
bFind =
true
;
}
}
else
if
(ent.ObjectName ==
"McDbMText"
) {
var
param = mxOcx.NewResbuf();
param.AddObjectId(ent.ObjectID);
// 得到多行文字中的文字本内容
var
ret = mxOcx.CallEx(
"Mx_GetMTextContent"
, param);
if
(ret.AtString(0) ==
"Ok"
) {
if
(ret.AtString(1) == txt) {
// 把文字放到视区.
mxOcx.PutEntityInView(ent.ObjectID, 300);
var
dLen = mxOcx.ViewLongToDocCoord(80);
// 绘制一个标记圆.
mxOcx.DrawVectorCircle(ent.Location.x,
ent.Location.y,
dLen, 65280);
bFind =
true
;
break
;
}
}
}
ent =
null
;
}
if
(!bFind) {
alert(
"没有找到文字对象"
);
}
// 在这里必须显示释放控件的COM对象指针.
ss =
null
;
spFilte =
null
;
CollectGarbage();
}