CAD开发者社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

ObjectARX 开发指南

使用 AcGi 的示例

2022-12-31 15:30| 发布者: admin| 查看: 319| 评论: 0|来自: AutoCAD

以下示例说明了如何使用 AcGi。首先,它保存颜色、线型和图层的当前实体属性值。然后,它将子实体特征颜色值更改为蓝色并绘制一条三点折线。接下来,将子实体特征颜色值更改为当前图层颜色,将线型值更改为 xline,然后绘制一条 xline。DASHDOT

示例代码包括两个函数,并且允许您从字符串中获取线型或图层的 ID。getLinetypeFromString()getLayerIdFromString()

注意:实际上,这些函数可能太慢而无法在其中使用,应直接存储和使用对象 ID。worldDraw()

static Acad::ErrorStatus
getLinetypeIdFromString(const TCHAR* str, AcDbObjectId& id);
static Acad::ErrorStatus
getLayerIdFromString(const TCHAR* str, AcDbObjectId& id);
 Adesk::Boolean 
 AsdkTraitsSamp::subWorldDraw(AcGiWorldDraw* pW) 
 { 
 // At this point, the current property traits are 
 // the entity's property traits.  If the current 
 // property traits are changed and you want to 
 // reapply the entity's property traits, this is 
 // the place to save them. 
 // 
 Adesk::UInt16 entity_color 
 = pW->subEntityTraits().color(); 
 AcDbObjectId  entity_linetype 
 = pW->subEntityTraits().lineTypeId(); 
 AcDbObjectId  entity_layer 
 = pW->subEntityTraits().layerId(); 
  
 // Override the current color and make it blue. 
 // 
 pW->subEntityTraits().setColor(kBlue); 
  
 // Draw a blue 3-point polyline. 
 // 
 int num_pts = 3; 
 AcGePoint3d *pVerts = new AcGePoint3d[num_pts]; 
 pVerts[0] = AcGePoint3d(0.0, 0.0, 0); 
 pVerts[1] = AcGePoint3d(1.0, 0.0, 0); 
 pVerts[2] = AcGePoint3d(1.0, 1.0, 0); 
  
 pW->geometry().polyline(num_pts, pVerts); 
  
 // Force the current color to use current layer's color. 
 // 
 pW->subEntityTraits().setColor(kColorByLayer); 
  
 // Force current line type to "DASHDOT".  If 
 // "DASHDOT" is not loaded, the current line 
 // type will still be in effect. 
 // 
 AcDbObjectId dashdotId; 
 if (getLinetypeIdFromString(_T("DASHDOT"), dashdotId) 
 == Acad::eOk) 
 { 
 pW->subEntityTraits().setLineType(dashdotId); 
 } 
  
 // Force current layer to "MY_LAYER".  If 
 // "MY_LAYER" is not loaded, the current layer 
 // will still be in effect. 
 // 
 AcDbObjectId layerId; 
 if (getLayerIdFromString(_T("MY_LAYER"), layerId) 
 == Acad::eOk) 
 { 
 pW->subEntityTraits().setLayer(layerId); 
 } 
  
 // Draw a dashdot'd xline in "MY_LAYER"'s color. 
 // 
 pW->geometry().xline(pVerts[0], pVerts[2]); 
  
 delete [] pVerts; 
  
 return Adesk::kTrue; 
 } 
  
  
 // A useful function that gets the linetype ID from the 
 // linetype's name -- must be in upper case. 
 // 
 static Acad::ErrorStatus 
 getLinetypeIdFromString(const TCHAR* str, AcDbObjectId& id) 
 { 
 Acad::ErrorStatus err; 
  
 // Get the table of currently loaded linetypes. 
 // 
 AcDbLinetypeTable *pLinetypeTable; 
 err = acdbHostApplicationServices()->workingDatabase() 
 ->getSymbolTable(pLinetypeTable, AcDb::kForRead); 
 if (err != Acad::eOk) 
 return err; 
  
 // Get the id of the linetype with the name that 
 // 'str' contains. 
 // 
 err = pLinetypeTable->getAt(str, id, Adesk::kTrue); 
  
 pLinetypeTable->close(); 
  
 return err; 
 } 
  
  
 // A useful function that gets the layer ID from the 
 // layer's name -- must be in upper case. 
 // 
 static Acad::ErrorStatus 
 getLayerIdFromString(const TCHAR* str, AcDbObjectId& id) 
 { 
 Acad::ErrorStatus err; 
  
 // Get the table of currently loaded layers. 
 // 
 AcDbLayerTable *pLayerTable; 
 err = acdbHostApplicationServices()->workingDatabase() 
 ->getSymbolTable(pLayerTable, AcDb::kForRead); 
 if (err != Acad::eOk) 
 return err; 
  
 // Get the ID of the layer with the name that 'str' 
 // contains. 
 // 
 err = pLayerTable->getAt(str, id, Adesk::kTrue); 
  
 pLayerTable->close(); 
  
 return err; 
 } 

路过

雷人

握手

鲜花

鸡蛋

最新评论

QQ|Archiver|CAD开发者社区 ( 苏ICP备2022047690号-1 )

GMT+8, 2024-5-27 11:01

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

返回顶部