函数McDbObjectId CreateLine1(McGePoint3d pt1,McGePoint3d pt2)会返回新绘制的对象id。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | // ------------------------------------------------------------------------- // Summary: // 改变实体颜色 // Parameters: // id - 实体的id // color - 实体的新颜色 // Returns: // 成功返回true // ------------------------------------------------------------------------- bool ChangeColor(McDbObjectId id,const McCmColor& color) { // 用智能指针打开对象,写方式打开。智能指针会自动关闭对象. McDbObjectPointer spEnt(id,McDb::kForWrite); if (spEnt.openStatus() != Mcad::eOk) { // 如果对象,在其它地方打开,就会打开的失败. return false ; } // 设置对象颜色 spEnt->setColor(color); return true ; } |
COM接口调用方式,如C#代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | // ------------------------------------------------------------------------- // Summary: // 改变实体颜色 // Parameters: // id - 实体的id. // iR, iG,iB - 实体的颜色 // Returns: // 成功返回true // ------------------------------------------------------------------------- bool ChangeColor(Int64 id,int iR,int iG,int iB) { // 由id得到实体对象. MxDrawEntity ent = (MxDrawEntity)axMxDrawX1.ObjectIdToObject(id); if (ent == null ) return false ; MxDrawMcCmColor color = new MxDrawMcCmColor(); color.SetRGB(iR, iG, iB); // 设置实体颜色。 ent.TrueColor = color; return true ; } |
COM接口调用方式,如js代码:
1 2 3 4 5 6 | // 向当前空间增加直线 newline 是增加的新直线。 var newline = curSpace.AddLine(point1.x,point1.y,point2.x,point2.y); var color = MxDrawXCtrl_Obj.NewComObject( "IMxDrawMcCmColor" ); color.SetRGB(255,77,0); newline.TrueColor = color; |