在cad使用过程中,用户可以绘制自定义实体。点击此处下载演示实例

调用DrawCustomEntity函数,绘制一个自定义实体对象。

下面代码绘制一个自定义实体,C#代码实现如下:

private void DrawMlineCommand()
{
MxDrawUiPrPoint getPt = new MxDrawUiPrPoint();
getPt.message = "点取第一点";
if (getPt.go() != MCAD_McUiPrStatus.mcOk)
{
return;
} var frstPt = getPt.value();
if (frstPt == null)
{
return;
} MxDrawUiPrPoint getSecondPt = new MxDrawUiPrPoint(); getSecondPt.message = "点取第二点";
getSecondPt.basePoint = frstPt; getSecondPt.setUseBasePt(false); MxDrawCustomEntity spDrawData = getSecondPt.InitUserDraw("DrawCustEntity");
spDrawData.SetDouble("Width", 30); spDrawData.SetPoint("Point1", frstPt); Int32 lCount = 1;
spDrawData.SetLong("Count", 1); while (true)
{
if (getSecondPt.go() != MCAD_McUiPrStatus.mcOk)
break; var secondPt = getSecondPt.value();
if (secondPt == null)
break; lCount++; String sPointName = "Point" + lCount.ToString(); spDrawData.SetPoint(sPointName, secondPt);
spDrawData.SetLong("Count", lCount);
}
if (lCount > 1)
axMxDrawX1.DrawEntity(spDrawData);
}

需要响应DMxDrawXEvents::CustomEntity_Explode事件。

下面例子,得到自实体的数据,C#代码实现如下:

private void axMxDrawX1_CustomEntity_Explode(object sender, AxMxDrawXLib._DMxDrawXEvents_CustomEntity_ExplodeEvent e)
{
MxDrawCustomEntity pCustomEntity = (MxDrawCustomEntity)e.pCustomEntity;
var sGuid = pCustomEntity.Guid; MxDrawWorldDraw pWorldDraw = (MxDrawWorldDraw)e.pDraw; if (sGuid == "DrawCustEntity")
{
MyDrawMline(pWorldDraw, pCustomEntity, null);
e.pRet = 1;
}
} private void MyDrawMline(MxDrawWorldDraw pWorldDraw, MxDrawCustomEntity pCustomEntity, MxDrawPoint curPt)
{
// 取自定义实体的端点数目,属性。
if (!pCustomEntity.IsHave("Count"))
return;
long lCount = pCustomEntity.GetLong("Count");
MxDrawPolyline tmpPl = new MxDrawPolyline();
for (long i = 0; i < lCount; i++)
{
String sName;
sName = "Point" + (i + 1).ToString();
if (!pCustomEntity.IsHave(sName))
break; // 取自定义实体的端点坐标。
MxDrawPoint pt = pCustomEntity.GetPoint(sName); // 把端点坐标,传给pl线,用于生成双线。
tmpPl.AddVertexAt(pt);
}
if (curPt != null)
tmpPl.AddVertexAt(curPt); if (tmpPl.NumVerts < 2)
{
// 端点数少于2就,不构成直线,就不需要显示。
return;
}
// 求pl线,开始点的导数.
MxDrawVector3d vecFx;
if (!tmpPl.GetFirstDeriv(tmpPl.GetStartParam(), out vecFx))
return;
if (vecFx.IsZeroLength())
return;
// 把向量旋转90度.
vecFx.RotateByXyPlan(3.14159265 / 2.0);
vecFx.Normalize();
// 得到双线的宽度属性。
double dWidth = pCustomEntity.GetDouble("Width");
vecFx.Mult(dWidth);
MxDrawPoint startPt = tmpPl.GetStartPoint(); // 向pl线,两个方向偏移,
MxDrawPoint offsetPt1 = new MxDrawPoint();
offsetPt1.x = startPt.x;
offsetPt1.y = startPt.y;
offsetPt1.Add(vecFx);
MxDrawPoint offsetPt2 = new MxDrawPoint();
offsetPt2.x = startPt.x;
offsetPt2.y = startPt.y;
offsetPt2.Sum(vecFx);
MxDrawText text = new MxDrawText();
text.TextString = "Test";
text.Height = 100;
text.Position = startPt;
text.AlignmentPoint = startPt;
MxDrawPoint pt1, pt2;
text.GetBoundingBox(out pt1, out pt2);
MxDrawPoint pt3 = new MxDrawPoint();
pt3.x = pt1.x;
pt3.y = pt2.y;
MxDrawPoint pt4 = new MxDrawPoint();
pt4.x = pt2.x;
pt4.y = pt1.y;
MxDrawPoints pts = new MxDrawPoints();
pts.Add(pt1.x, pt1.y, 0);
pts.Add(pt3.x, pt3.y, 0);
pts.Add(pt2.x, pt2.y, 0);
pts.Add(pt4.x, pt4.y, 0); Int32 lDraworder = pWorldDraw.Draworder;
pWorldDraw.Draworder = lDraworder + 1;
pWorldDraw.DrawWipeout(pts);
pWorldDraw.Draworder = lDraworder + 2;
pWorldDraw.DrawEntity((MxDrawEntity)text);
pWorldDraw.Draworder = lDraworder;
// pWorldDraw->
{
MxDrawResbuf newobj;
if (tmpPl.OffsetCurves(dWidth, offsetPt1, out newobj))
{
for (Int32 j = 0; j < newobj.Count; j++)
{
MxDrawEntity tmpObj = (MxDrawEntity)newobj.AtObject(j);
if (tmpObj == null)
continue; pWorldDraw.DrawEntity(tmpObj);
}
newobj.RemoveAll();
}
}
{
MxDrawResbuf newobj;
if (tmpPl.OffsetCurves(dWidth, offsetPt2, out newobj))
{
for (Int32 j = 0; j < newobj.Count; j++)
{
MxDrawEntity tmpObj = (MxDrawEntity)newobj.AtObject(j);
if (tmpObj == null)
continue; pWorldDraw.DrawEntity(tmpObj);
}
// 这不使用newobj,需要显示调用RemoveAll函数清楚内存。
// 不然这个可能就会程序退出时才释放,这时它会去释放控件对象指针,有可能会出错。
newobj.RemoveAll();
}
}
}

C#代码实现如下:

private void axMxDrawX1_DynWorldDraw(object sender, AxMxDrawXLib._DMxDrawXEvents_DynWorldDrawEvent e)
{
MxDrawCustomEntity pCustomEntity = (MxDrawCustomEntity)e.pData;
String sGuid = pCustomEntity.Guid;
e.pRet = 0; MxDrawWorldDraw pWorldDraw = (MxDrawWorldDraw)e.pWorldDraw;
MxDrawPoint curPt = new MxDrawPoint();
curPt.x = e.dX;
curPt.y = e.dY; if (sGuid == "DrawCustEntity")
{
MyDrawMline(pWorldDraw, pCustomEntity, curPt);
}
}

需要响应_DMxDrawXEvents::CustomEntity_getGripPoints事件,C#代码实现如下:

private void axMxDrawX1_CustomEntity_getGripPoints(object sender, AxMxDrawXLib._DMxDrawXEvents_CustomEntity_getGripPointsEvent e)
{
MxDrawCustomEntity pCustomEntity = (MxDrawCustomEntity)e.pCustomEntity;
var sGuid = pCustomEntity.Guid;
e.pOk = 0;
if (sGuid == "DrawCustEntity")
{
if (!pCustomEntity.IsHave("Count"))
return; long lCount = pCustomEntity.GetLong("Count"); MxDrawResbuf ret = (MxDrawResbuf)axMxDrawX1.NewResbuf(); for (long i = 0; i < lCount; i++)
{
String sName;
sName = "Point" + (i + 1).ToString();
if (!pCustomEntity.IsHave(sName))
break; // 取自定义实体的端点坐标。
MxDrawPoint pt = pCustomEntity.GetPoint(sName); ret.AddPoint(pt);
}
e.pOk = 1;
axMxDrawX1.SetEventRetEx(ret);
} }

需要响应CustomEntity_moveGripPointsAt事件。

下面例子,夹点移动后,修改自定义实体的属性,C#代码实现如下:

private void axMxDrawX1_CustomEntity_moveGripPointsAt(object sender, AxMxDrawXLib._DMxDrawXEvents_CustomEntity_moveGripPointsAtEvent e)
{
e.pRet = 1;
MxDrawCustomEntity pCustomEntity = (MxDrawCustomEntity)e.pCustomEntity;
var sGuid = pCustomEntity.Guid; if (sGuid == "DrawCustEntity")
{
if (!pCustomEntity.IsHave("Count"))
return; long lCount = pCustomEntity.GetLong("Count"); for (long i = 0; i < lCount; i++)
{
String sName;
sName = "Point" + (i + 1).ToString();
if (!pCustomEntity.IsHave(sName))
break; // 取自定义实体的端点坐标。
MxDrawPoint pt = pCustomEntity.GetPoint(sName); if (i == e.lGridIndex)
{
pt.x = pt.x + e.dOffsetX;
pt.y = pt.y + e.dOffsetY; pCustomEntity.SetPoint(sName, pt);
}
}
}
}

CAD绘制自定义实体(com接口)的更多相关文章

  1. CAD把自定义实体,变成普通实体(com接口VB语言)

    主要用到函数说明: MxDrawXCustomEvent::MxDrawXCustomEntity::explode 把自定义实体,变成普通实体,详细说明如下: 参数 说明 LONGLONG lEnt ...

  2. CAD实现自定义实体夹点移动(com接口VB语言)

    主要用到函数说明: MxDrawXCustomEvent::MxDrawXCustomEntity::moveGripPointsAt 自定义实体事件,自定义实体夹点被移动,详细说明如下: 参数 说明 ...

  3. CAD得到自定义实体拖放夹点(com接口VB语言)

    主要用到函数说明: MxDrawXCustomEvent::MxDrawXCustomEntity::getGripPoints 自定义实体事件,得到拖放夹点,详细说明如下: 参数 说明 LONGLO ...

  4. 【CAD】自定义实体的步骤(转)

    本文介绍了构造自定义实体的步骤.必须继承的函数和必须注意的事项 1.新建一个从AcDbEntity继承的类,如EntTest,必须添加的头文件: "stdarx.h"," ...

  5. cad.arx 自定义实体之编译第一个项目(甜头)

    本篇不从零开始讲如何制造自定义图元,而是教新手们如何设置了环境之后编译张帆书中的代码. 利用vs2010编译 张帆<AutoCAD ObjectARX(VC)开发基础与实例教程>一书中的自 ...

  6. CAD控件:COM接口实现自定义实体

    1. 实现步骤: 3 1. 实现步骤: 参考例子 :Src\MxDraw5.2\samples\ie\iedemoTest.htm 1) 增加自定义实体对象 调用DrawCustomEntity函数, ...

  7. CAD控件使用教程 自定义实体的实现

    自定义实体的实现 1 .       自定义实体... 3 1.1      说明... 3 1.2      类的类型信息... 3 1.3      worldDraw.. 4 1.4      ...

  8. 梦想CAD控件自定义实体实现

    一.增加自定义实体对象 调用DrawCustomEntity函数,绘制一个自定义实体对象. 下面代码绘制一个自定义实体,C#代码实现如下: private void DrawMlineCommand( ...

  9. CAD由一个自定义实体事件中的id得到自定义实体对象(com接口VB语言)

    由一个自定义实体事件中的id得到自定义实体对象.该函数只能在自定义实体事件中调用. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 2 ...

随机推荐

  1. selenium第三课(selenium八种定位页面元素方法)

    selenium webdriver进行元素定位时,通过seleniumAPI官方介绍,获取页面元素的方式一共有以下八种方式,现按照常用→不常用的顺序分别介绍一下. 官方api地址:https://s ...

  2. ZOJ3659 Conquer a New Region 并查集

    Conquer a New Region Time Limit: 5 Seconds      Memory Limit: 32768 KB The wheel of the history roll ...

  3. linux内核对块设备的使用

    1 partition table 这里的分析以经典的MBR为例. 在MBR里面有partition table,每一项对应一个逻辑的块设备,partion table中的每一项是16个字节. 第一个 ...

  4. 深度理解apache 重写模块rewrite_mod,重写不再犯错

    1.RewriteRule ^(com\/.*)$ index.php?do=$1 问:上面的规则匹配表达式 "^(.*)$" 匹配的内容是什么 答:匹配内容是URI站点目录:/d ...

  5. 脱离开发软件启动Tomcat访问项目

    作为开发人员平时用的最多的就是通过开发软件启动Tomcat服务,从而访问项目.这样便于开发的bug调试 此处讲的是脱离开发软件启动Tomcat访问项目 链接参考: http://jingyan.bai ...

  6. ios28--UIScrollView

    // // ViewController.m // UIScrollVIew #import "ViewController.h" @interface ViewControlle ...

  7. Killer Problem(暴力)

    题意: 给定一个序列,每次询问l到r之间两个数差的绝对值的最小值. 分析: 开始以为是线段树离线处理,实际暴力就好! #include <map> #include <set> ...

  8. 基于ASP.NET MVC的快速开发平台,给你的开发一个加速度!

    基于ASP.NET MVC的快速开发平台,给你的开发一个加速度! bingo炸了 2017/4/6 11:07:21 阅读(37) 评论(0) 现在的人做事情都讲究效率,最好能达到事半功倍那种效果,软 ...

  9. 三种解密 HTTPS 流量的方法介绍

    转载自:https://imququ.com/post/how-to-decrypt-https.html作者: Jerry Qu Web 安全是一项系统工程,任何细微疏忽都可能导致整个安全壁垒土崩瓦 ...

  10. 并不对劲的spoj nsubstr

    题意是求一个字符串每个长度的子串出现次数最多的那个出现了多少次,也就是求每个到根的最长路的right集合最大值 . 先建后缀自动机,然后将每个前缀所在的集合的初值设为1,因为所有前缀的right集合肯 ...