AutoCAD Map 3D Developer
Welcome to Autodesk’s AutoCAD Map 3D Developer Forums. Share your knowledge, ask questions, and explore popular AutoCAD Map 3D Developer topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

遍历文本内容

1 REPLY 1
Reply
Message 1 of 2
Anonymous
295 Views, 1 Reply

遍历文本内容

BlockTable  bt=(BlockTable)tr.GetObject(db.BlockTableId,OpenMode.ForRead,false);

BlockTableRecord btr=(BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace]),OpenMode.ForRead,false);

foreach(objectId id in btr)

{

    Entity ent=tr.GetObject(id,OpenMode.ForRead,false) as Entity;

    string se=id.ObjectClass.DxfName;

    if(se.Equals("TEXT"))

    {

       .......

    }

}

现在是先遍历实体,然后再在实体中找出文本。我现在想做的是在遍历实体前就筛选出文本类型,然后遍历文本类型的实体,该怎么做?请给出代码。

 

然后帮我找一个CAD中实现他查找对话框的代码。(就是在CAD中输入Find后出现的对话框),有实现这类功能的代码吗?

 

谢谢!

1 REPLY 1
Message 2 of 2
norman.yuan
in reply to: Anonymous

Well, if you don want to loop through entire ModelSpace for certain type of entities, you can use Editor.SelectAll(SelectionSetFilter filter), something like:

 

var vals = TypedValue[]

{

    new TypedValue((int)DxfCode.Start, "TEXT"),

    new TypedValue((int)DxfCode.LayoutName, "MODEL")

};

 

var res=activeDocument.Editor.SelelctAll(new SelectionSetFilter(vals));

if (res.Status==PromptStatus.OK)

{

    using (var tran=.....)

    {

        foreach (var id in res.Value.GetObjectIds())

        {

            var textEntity=(DbText)tran.GetObject(id, OpenMode.ForRead);

            ......

           //comparing DbText's TextString with the text to be searched for here

        }

        tran.Commit()

    }

}

 

In reality, looping through entire ModelSpace may not be as bad/as slow in comparison to getting a filtered SelectionSet, as one thinks, depending on drawing. And sometimes, the fraction of second difference is ignorable

Norman Yuan

Drive CAD With Code

EESignature

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report