知识库 / Delphi开发 / 详情
得到图上所有PL线,然后再PL线打碎,变成直线,和圆弧,得样条线,并离散成点.
得到图上所有PL线,然后再PL线打碎,变成直线,和圆弧,得样条线,并离散成点.
Delphi开发|大少爷|2017-07-27 15:40
回答:
       procedure TForm3.Button1Click(Sender: TObject);
        var ss        : IMxDrawSelectionSet;
        filter        : IMxDrawResbuf;
        ii,jj                    : Integer;
        pEnt,pTmp                  : IMxDrawEntity;
        pPolyline             : IMxDrawPolyline;
        param        : IMxDrawResbuf;
        line         : IMxDrawLine;
        pts,pte,minPt,maxPt,pt      : IMxDrawPoint;
        arc          : IMxDrawArc;
        spl          : IMxDrawSpline;
        points       : IMxDrawPoints;
        dApproxEps   : DOUBLE;
        blkRef       : MxDrawBlockReference;
        begin                // 创建一个选择集对象                ss :=  CoMxDrawSelectionSet.Create();                // 创建一个过滤条件对象                filter := CoMxDrawResbuf.Create();                // 选择图上所有实体                ss.AllSelect(filter);                // 遍历构造后的选择集实体,找到边界线。
                for ii := 0 to ss.Count -1 do
                begin                        // 遍历所有实体
                    pEnt := ss.Item(ii);                    // 对图块的处理.
                    pEnt.QueryInterface(MxDrawBlockReference, blkRef);                    if blkRef <> nil then
                    begin                    // 是个图块文件.
                        param := blkRef.Explode();                        for jj := 0 to param.Count -1 do
                        begin
                                pTmp :=  IMxDrawEntity(param.AtObject(jj) );
                                pTmp.QueryInterface(IMxDrawLine, line);                                if(line <> nil) then
                                begin                                  // 这是图块内的直线。                                  showmessage('Line');
                                end;                                // 处理其它实体,图块里面还可能再嵌套图块,这时需要递归处理.
                                // ...

                                // 删除临时生成的文件.
                                pTmp.Erase();
                        end;

                    end;                    ///
                    pEnt.QueryInterface(IMxDrawSpline, spl);                    if spl <> nil then
                    begin                      // 对象是个样条线。
                      // 得到样条线的外包
                      points := spl.GetBoundingBox2();                      //   dApproxEps样条线的离形精度
                      dApproxEps := 0.01;                      // 根据样条线的大小,动态确定离线精度。
                      if points.Count > 1 then
                      begin                          // 外包的最小点,和最大点
                          minPt := points.Item(0);
                          maxPt := points.Item(1);                          //    dApproxEps取外包最短边长的 1/20
                          if abs(minPt.x - maxPt.x) < abs(minPt.y - maxPt.y)then
                          begin
                            dApproxEps := abs(minPt.x - maxPt.x) / 20;
                          end                          else
                          begin
                            dApproxEps := abs(minPt.y - maxPt.y) / 20;
                          end;                          // 如果为 dApproxEps零,就默认取   0.01
                          if dApproxEps < 0.0000001 then
                               dApproxEps := 0.01;


                      end;                     // showmessage(Format('dApproxEps:%g',[dApproxEps]) );

                     // 离散样条线.
                      points := spl.GetSamplePoints(dApproxEps);                      // 遍历样条线上的所有点,可以把这些点,做为样条线的拟合点,用来重生样条线。
                       for jj := 1 to points.Count -1 do
                       begin
                             pt :=   points.Item(jj);
                             showmessage(Format('X:%g,Y:%g',[pt.x,pt.y]) );

                       end;

                    end;

                    pEnt.QueryInterface(IMxDrawPolyline, pPolyline);                    if pPolyline <> nil then
                    begin                           // 得到一个PL线对象。
                           // 打碎PL线,把PL线变成直线,和圆弧                           param :=    CoMxDrawResbuf.Create();
                           param.AddObjectId(pEnt.ObjectID);                           // 调用打碎函数,打碎实体.
                           param := MxDrawResbuf(MxDrawX1.CallEx('Mx_Explode', param));                           // 遍历打碎后的实体,得到所有曲线。
                           for jj := 1 to param.Count -1 do
                           begin                                //
                                pEnt := IMxDrawEntity(param.AtObject(jj));
                                pEnt.QueryInterface(IMxDrawLine, line);                                if(line <> nil) then
                                begin                                    // 这是PL线里的直线
                                    // 得到直线的,开始点,和结束点,
                                    pts := line.StartPoint;
                                    pte := line.EndPoint;                                      //showmessage('line');
                                    // 调用Delphi的绘制直线函数,绘直线
                                    // ...

                                end;

                                pEnt.QueryInterface(IMxDrawArc, arc);                                 if(arc <> nil) then
                                 begin                                    // 这是PL线里的圆弧
                                    // 得到圆弧中点,半径,开始角,结束角,
                                    // arc.Center;
                                    // arc.StartAngle;
                                    // arc.EndAngle;
                                    // arc.Radius;

                                   //showmessage('arc');

                                    // 调用Delphi的绘圆弧函数,绘直线
                                    // ...

                                end;
                                pEnt.Erase();

                           end;
                    end;
                end;
            end;


相关问题
判断一个点是否在pl线组成的闭合区域内
遍历图中的所有实体,找到块名为A23TIT_KH的图
如何向块中增加一个属性文字 C#代码 ?
如何提示输入一个点坐标?
如何实现自定义实体?
如何设置动态提示?
如何设置光标矩形框大小?
如何设置光标长度?
如何设置对象夹点显示颜色?
如何把DWG文件当着背景导入?
梦想CAD是专业的CAD插件(控件),可轻松在网页、手机及BS/CS程序中浏览编辑DWG文件,不需安装AutoCAD即可运行。经十余年累积已非常稳定可靠,有关键的空间搜索算法,并使用汇编优化,可同时处理50万级实体,有非常高的图形显示和处理效率。
技术服务
TEL:400-888-5703
185-8173-1060
客服I QQ: 3570505660
技术I QQ: 827867134
技术II QQ:6884123
产品购买
TEL:156-8136-8971
QQ:710714273
用户交流
控件QQ交流群1:73281982
控件QQ交流群2:112199959
MxCAD软件群 1:515771658
技术I:QQ
827867134
客服I:QQ
3570505660
销售QQ
710714273
联系电话400-888-5703