www.mxdraw.com
内容索引主面
前一个向上下一个
IMxDrawSelectionSet 接口

控件中的选择集构造管理器,用图面上的实体搜索,与用户交互选择等操作

IDL
[ object, uuid(A020BE47-FE0C-4D58-BEAE-85B50F147079), dual, nonextensible, helpstring("IMxDrawSelectionSet interface"), pointer_default(unique) ]
interface IMxDrawSelectionSet : IDispatch;

MxDrawSelectionSet.idl

例如: 比如,找查图面上的文字 C#

private void FindText(string str)
        {
            // 创建选择集对象

            MxDrawSelectionSet ss = new MxDrawSelectionSet();

            // 创建过滤对象.
            MxDrawResbuf spFilte = new MxDrawResbuf();
   
            // 把文字对象,当着过滤条件.
            spFilte.AddStringEx("TEXT,MTEXT", 5020);

            // 得到图上,所有文字对象.
            ss.Select2(MCAD_McSelect.mcSelectionSetAll, null, null, null, spFilte);


            // 遍历每个文字.
            bool bFind = false;
            for (int i = 0; i < ss.Count; i++)
            {
                MxDrawEntity ent = ss.Item(i);
                if (ent == null)
                    continue;
                if (ent.ObjectName == "McDbText")
                {
                    // 是一个文字
                    MxDrawText text = (MxDrawText)ent;
                    string sTxt = text.TextString;

                    if (sTxt == str)
                    {
                        // 找到把文字放到视区中间.
                        axMxDrawX1.PutEntityInView(ent.ObjectID, 300);


                        var dLen = axMxDrawX1.ViewLongToDocCoord(80);

                        // 绘制一个标记圆.
                        axMxDrawX1.DrawVectorCircle(text.Position.x,
                        text.Position.y,
                        dLen, 65280);
                        bFind = true;
                    }
                }
                else if (ent.ObjectName == "McDbMText")
                {
                    // 找到一个多行文字

                    MxDrawResbuf param = new MxDrawResbuf();
                    param.AddObjectId(ent.ObjectID);
                    MxDrawMText mtext = (MxDrawMText)ent;

                    // 得到多行文字中的,文字内容.
                    MxDrawResbuf ret = (MxDrawResbuf)axMxDrawX1.CallEx("Mx_GetMTextContent", param);
                    if (ret.AtString(0) == "Ok")
                    {

                        if (ret.AtString(1) == str)
                        {
                            // 把文字放到视区.
                            axMxDrawX1.PutEntityInView(ent.ObjectID, 300);

                            var dLen = axMxDrawX1.ViewLongToDocCoord(80);

                            // 绘制一个标记圆.
                            axMxDrawX1.DrawVectorCircle(mtext.Location.x,
                                mtext.Location.y,
                                dLen, 65280);
                            bFind = true;

                            break;
                        }
                    }
                }
        

            }
            if (bFind)
                MessageBox.Show("找到文字");
            else
                MessageBox.Show("没有找到文字");
        }

 

例如: C# 扩展数据值过滤选择, 下面,代码得到图上所有直线,并且有扩展数据,扩展数据名为TestApp,Long组码为1071,值为:77678 的直线。

            MxDrawResbuf filter = new MxDrawResbuf();
            filter.AddStringEx("LINE", 5020);
            filter.AddAppName("TestApp");
            filter.AddLongEx(77678, 1071);
            MxDrawSelectionSet ss = new MxDrawSelectionSet();
            ss.AllSelect(filter);

            MessageBox.Show(ss.Count.ToString() );

 

例如: PB 得到图上文字内容

         // 创建构造选择集对象
        oleobject ss
        long ret
        ss =create oleobject
        ss.connecttonewobject("MxDrawX.MxDrawSelectionSet")

        // 选择图上所有实体
        oleobject param
        ss.AllSelect(param)


        // 构造类型转换组件
         oleobject change
        change =create oleobject
        ret = change.connecttonewobject("MxDrawX.MxDrawChange")
        if ret < 0 then
            messagebox("错误","MxDrawChange")
        end if

        oleobject mytext
        oleobject ent   

        // 得到选择集中第0个对象

        if ss.Count > 0 then
            ent = ss.Item(0)
            if(string(ent.ObjectName) = "McDbText") then
                // 如果是一个文字,就把ent变成文字对象.
                mytext = change.ToText(ent)
    
                 // 得到文字字符串
                messagebox("text",string(mytext.TextString))
                destroy mytext      
             end if
            destroy ent
        end if

        destroy ss
        destroy change

 

例如: C# 与用交互,选择图上对象.

    MxDrawSelectionSet ss = new MxDrawSelectionSet();
     ss.Select(MCAD_McSelect.mcSelectionSetUserSelect, null, null);
     for (int i = 0; i < ss.Count; i++)
     {
         MxDrawEntity entity  = ss.Item(i);
         entity.Erase();
     }

例如: C# 与用交互,加逻辑或作为条件过滤,下面选择Layer1或Layer2图层上的实体

       MxDrawSelectionSet ssGet = new MxDrawSelectionSet();
     MxDrawResbuf filter = new MxDrawResbuf();
     filter.AddStringEx("<OR", -4);
     filter.AddStringEx("Layer1", 8);
     filter.AddStringEx("Layer2", 8);
     filter.AddStringEx("OR>", -4);

     MxDrawUtility mxUtility = new MxDrawUtility();
     mxUtility.Prompt("n 选择实体:");
     ssGet.Select(MCAD_McSelect.mcSelectionSetUserSelect,null, null, filter);

     String sTip = "选择了" + ssGet.Count + "个实体";
     MessageBox.Show(sTip);

例如: 得到指定颜色的实体

        MxDrawSelectionSet ss = new MxDrawSelectionSet();
        // 创建过滤对象.
        MxDrawResbuf spFilte = new MxDrawResbuf();
        // 按颜色,62是颜色的dxf组码.1 代表是cad的颜色索引,1表示为红色.
        spFilte.AddLongEx(1, 62);

        // 得到图上,所有文字对象.
        ss.Select2(MCAD_McSelect.mcSelectionSetAll, null, null, null, spFilte);

        MessageBox.Show(ss.Count.ToString());

 

例如:删除图上所有图片 C#

       MxDrawSelectionSet ss = new MxDrawSelectionSet();

     // 创建过滤对象.
     MxDrawResbuf spFilte = new MxDrawResbuf();

     // 把文字对象,当着过滤条件.
     spFilte.AddStringEx("IMAGE", 5020);

     // 得到图上,所有文字对象.
     ss.Select2(MCAD_McSelect.mcSelectionSetAll, null, null, null, spFilte);


     bool bFind = false;
     for (int i = 0; i < ss.Count; i++)
     {
         MxDrawEntity ent = ss.Item(i);
         if (ent == null)
             continue;
         ent.Erase();
     }
Copyright (c) 2010. All rights reserved.
你认为该帮助怎么样? 发送反馈信息!