设为首页收藏本站

中国膜结构网

 找回密码
 立即注册

QQ登录

只需一步,快速开始

膜结构车棚
膜结构车棚膜结构资质国产膜材 膜结构网中国膜结构协会
查看: 137|回复: 0

CAD ObjectARX扩展工具的源码3

[复制链接]
  • TA的每日心情
    开心
    2021-6-22 09:39
  • 签到天数: 1542 天

    [LV.Master]伴坛终老

    发表于 2020-12-29 14:06 | 显示全部楼层 |阅读模式
    1. //得到文本边界
    2. oid CDrawFunction::getTextBoundary(AcDbObjectId objectId,double offset,AcDbObjectId &textBoundaryId)
    3. {
    4. AcDbExtents Ext;
    5. AcDbEntity *pEnt;
    6. acdbOpenObject(pEnt,objectId,AcDb::kForWrite);
    7. if(pEnt->isKindOf(AcDbText::desc()))
    8. {
    9. AcDbText *pText=AcDbText::cast(pEnt);
    10. AcGePoint3d basePoint;
    11. basePoint=pText->position();
    12. double rotateAngle=pText->rotation();
    13. pText->setRotation(0);
    14. pText->getGeomExtents(Ext);
    15. AcGePoint3d minPt,maxPt;
    16. minPt=Ext.minPoint();
    17. maxPt=Ext.maxPoint();
    18. AcGePoint3dArray pointArray;
    19. AcGePoint3d point1,point2,point3,point4;
    20. point1.x=minPt.x-offset;point1.y=minPt.y-offset;point1.z=0;
    21. pointArray.append(point1);
    22. point2.x=maxPt.x+offset;point2.y=minPt.y-offset;point2.z=0;
    23. pointArray.append(point2);
    24. point3.x=maxPt.x+offset;point3.y=maxPt.y+offset;point3.z=0;
    25. pointArray.append(point3);
    26. point4.x=minPt.x-offset;point4.y=maxPt.y+offset;point4.z=0;
    27. pointArray.append(point4);
    28. DrawPolyline(textBoundaryId,pointArray,1,0,TRUE,"0","CONTINUOUS");
    29. AcGeMatrix3d matrix;
    30. AcGeector3d axis;
    31. ident_init(matrix);
    32. axis.set(0,0,1);
    33. matrix=matrix.rotation(rotateAngle,axis,basePoint); //旋转矩阵
    34. AcDbEntity *BounEnt;
    35. acdbOpenObject(BounEnt,textBoundaryId,AcDb::kForWrite);
    36. BounEnt->transformBy(matrix);
    37. BounEnt->close();
    38. pText->setRotation(rotateAngle);
    39. }
    40. else if(pEnt->isKindOf(AcDbMText::desc()))
    41. {
    42. AcDbMText *pMtext=AcDbMText::cast(pEnt);
    43. AcGePoint3d basePoint;
    44. basePoint=pMtext->location();
    45. double rotateAngle=pMtext->rotation();
    46. pMtext->setRotation(0);
    47. AcGePoint3dArray pointArray;
    48. double width=pMtext->actualWidth();
    49. double height=pMtext->actualHeight();
    50. AcGePoint3d point1,point2,point3,point4;
    51. point1.x=basePoint.x-offset;point1.y=basePoint.y+offset;point1.z=0;
    52. pointArray.append(point1);
    53. point2.x=basePoint.x+width+offset;point2.y=basePoint.y+offset;point2.z=0;
    54. pointArray.append(point2);
    55. point3.x=basePoint.x+width+offset;point3.y=basePoint.y-height-offset;point3.z=0;
    56. pointArray.append(point3);
    57. point4.x=basePoint.x-offset;point4.y=basePoint.y-height-offset;point4.z=0;
    58. pointArray.append(point4);
    59. DrawPolyline(textBoundaryId,pointArray,1,0,TRUE,"0","CONTINUOUS");
    60. AcGeMatrix3d matrix;
    61. AcGeector3d axis;
    62. ident_init(matrix);
    63. axis.set(0,0,1);
    64. matrix=matrix.rotation(rotateAngle,axis,basePoint); //旋转矩阵
    65. AcDbEntity *BounEnt;
    66. acdbOpenObject(BounEnt,textBoundaryId,AcDb::kForWrite);
    67. BounEnt->transformBy(matrix);
    68. BounEnt->close();
    69. pMtext->setRotation(rotateAngle);
    70. }
    71. pEnt->close();
    72. return;
    73. }


    74. AcDbObjectId CDrawFunction::createNewLayer(CString LayerName)
    75. {
    76. AcDbLayerTable *LayerTable;
    77. acdbHostApplicationSerices()->workingDatabase()->getSymbolTable(LayerTable,AcDb::kForWrite);
    78. AcDbObjectId LayerId;
    79. if(!LayerTable->has(LayerName))
    80. {
    81. AcDbLayerTableRecord *LayerTableRecord=new AcDbLayerTableRecord;
    82. LayerTableRecord->setName(LayerName);
    83. LayerTable->add(LayerId,LayerTableRecord);
    84. LayerTableRecord->close();
    85. }
    86. else
    87. {
    88. LayerTable->getAt(LayerName,LayerId,FALSE);
    89. }
    90. LayerTable->close();
    91. return LayerId;
    92. }

    93. bool CDrawFunction::insertBlock(AcDbObjectId &newEntId,CString BlockName,double fwj,AcGePoint3d basePoint,double scalex,
    94. CString Text1,CString Text2,CString Text3,
    95. int text1color,int text2color,int text3color,
    96. double text1height,double text2height,double text3height,
    97. double text1scator,double text2scator,double text3scator,
    98. CString littleFont,CString bigFont,CString layerName,double dx,double dy) //每块可有三个属性定义
    99. {
    100. AcDbObjectId blockId;
    101. double x,y;
    102. x=basePoint[X];
    103. y=basePoint[Y];
    104. bool a=AcDbSymbolUtilities::hasBlock(BlockName.GetBuffer(BlockName.GetLength()),acdbHostApplicationSerices()->workingDatabase());
    105. if(!a)return FALSE;
    106. AcDbSymbolUtilities::getBlockId(blockId,BlockName.GetBuffer(BlockName.GetLength()),acdbHostApplicationSerices()->workingDatabase());
    107. AcDbBlockReference *pBlkRef = new AcDbBlockReference;
    108. // pBlkRef->treatAsAcDbBlockRefForExplode();///////////
    109. pBlkRef->setBlockTableRecord(blockId);
    110. pBlkRef->setLayer(layerName);//设置层/////////////////////////////
    111. struct resbuf to, from;
    112. from.restype = RTSHORT;
    113. from.resal.rint = 1; // UCS
    114. to.restype = RTSHORT;
    115. to.resal.rint = 0; // WCS
    116. AcGeector3d normal(0, 0, 1);
    117. acedTrans(&(normal.x), &from, &to, Adesk::kTrue,&(normal.x));
    118. AcGeScale3d scale(scalex,scalex,scalex);
    119. pBlkRef->setScaleFactors(scale);
    120. AcGePoint3d insertPoint;
    121. insertPoint=basePoint;
    122. pBlkRef->setPosition(basePoint);
    123. pBlkRef->setRotation(fwj);
    124. pBlkRef->setNormal(normal);
    125. pBlkRef->setColorIndex(text1color);//按文本颜色设置改变颜色
    126. pBlkRef->setLayer(layerName);
    127. AcDbBlockTable *pBlockTable;
    128. acdbHostApplicationSerices()->workingDatabase()->getBlockTable(pBlockTable,AcDb::kForWrite);
    129. AcDbBlockTableRecord *pBlockTableRecord;
    130. pBlockTable->getAt(ACDB_MODEL_SPACE, pBlockTableRecord,AcDb::kForWrite);
    131. pBlockTableRecord->appendAcDbEntity(newEntId, pBlkRef);
    132. pBlockTable->close();
    133. pBlockTableRecord->close();

    134. acdbOpenObject(pBlockTableRecord, blockId, AcDb::kForRead);
    135. AcDbBlockTableRecordIterator *pIterator;
    136. pBlockTableRecord->newIterator(pIterator);
    137. AcDbEntity *pEnt;
    138. AcDbAttributeDefinition *pAttdef;
    139. for (pIterator->start(); !pIterator->done();pIterator->step())
    140. {
    141. pIterator->getEntity(pEnt, AcDb::kForWrite);
    142. //pEnt->setColorIndex(text1color);//按文本颜色设置改变颜色
    143. //pEnt->setLayer(layerName);//设置层
    144. if(pEnt->isKindOf(AcDbAttributeDefinition::desc()))
    145. {
    146. pAttdef = AcDbAttributeDefinition::cast(pEnt);
    147. if (pAttdef != NULL && !pAttdef->isConstant())
    148. {
    149. AcDbAttribute *pAtt = new AcDbAttribute();
    150. pAtt->setPropertiesFrom(pAttdef);
    151. pAtt->setInisible(pAttdef->isInisible());
    152. AcGePoint3d alignpoint;
    153. alignpoint=pAttdef->alignmentPoint();
    154. alignpoint+=pBlkRef->position().asector();
    155. AcDbObjectId TextStyleId;
    156. TextStyleId=createTextStyle(littleFont,bigFont,"xianlu");
    157. pAtt->setTextStyle(TextStyleId);
    158. pAtt->setHeight(pAttdef->height());
    159. pAtt->setTag("Tag");
    160. pAtt->setFieldLength(25);
    161. pAtt->setLayer(layerName);
    162. char *pStr = pAttdef->tag();
    163. pAtt->setTag(pStr);
    164. free(pStr);
    165. pAtt->setFieldLength(pAttdef->fieldLength());
    166. if(strcmp(pAtt->tag(),"标注1")==0)
    167. {
    168. AcGePoint3d gg(dx/scalex,0,0);
    169. alignpoint=alignpoint+gg.asector();
    170. AcGeector3d et(0,0,1);
    171. alignpoint=alignpoint.scaleBy(scalex,insertPoint);
    172. alignpoint=alignpoint.rotateBy(fwj,et,insertPoint);
    173. pAtt->setTextString(Text1.GetBuffer(Text2.GetLength()));
    174. pAtt->setRotation(PI/2+fwj);
    175. pAtt->setHorizontalMode(AcDb::kTextCenter);
    176. pAtt->seterticalMode(AcDb::kTextBottom);
    177. pAtt->setAlignmentPoint(alignpoint);
    178. pAtt->setColorIndex(text1color);
    179. pAtt->setHeight(text1height*scalex);
    180. pAtt->setWidthFactor(text1scator);
    181. }
    182. if(strcmp(pAtt->tag(),"标注2")==0)
    183. {
    184. AcGePoint3d gg(dx/scalex,0,0);
    185. alignpoint=alignpoint-gg.asector();
    186. AcGeector3d et(0,0,1);
    187. alignpoint=alignpoint.scaleBy(scalex,insertPoint);
    188. alignpoint=alignpoint.rotateBy(fwj,et,insertPoint);
    189. pAtt->setTextString(Text2.GetBuffer(Text2.GetLength()));
    190. pAtt->setRotation(PI/2+fwj);
    191. pAtt->setHorizontalMode(AcDb::kTextCenter);
    192. pAtt->seterticalMode(AcDb::kTextBottom);
    193. pAtt->setAlignmentPoint(alignpoint);
    194. pAtt->setColorIndex(text2color);
    195. pAtt->setHeight(text2height*scalex);
    196. pAtt->setWidthFactor(text2scator);
    197. }
    198. if(strcmp(pAtt->tag(),"标注3")==0)
    199. {
    200. AcGePoint3d gg(0,dy/scalex,0);
    201. alignpoint=alignpoint+gg.asector();
    202. AcGeector3d et(0,0,1);
    203. alignpoint=alignpoint.scaleBy(scalex,insertPoint);
    204. alignpoint=alignpoint.rotateBy(fwj,et,insertPoint);
    205. pAtt->setTextString(Text3.GetBuffer(Text3.GetLength()));
    206. pAtt->setRotation(fwj);
    207. pAtt->setHorizontalMode(AcDb::kTextCenter);
    208. pAtt->seterticalMode(AcDb::kTextBottom);
    209. pAtt->setAlignmentPoint(alignpoint);
    210. pAtt->setColorIndex(text3color);
    211. pAtt->setHeight(text3height*scalex);
    212. pAtt->setWidthFactor(text3scator);
    213. }
    214. AcDbObjectId attId;
    215. pBlkRef->appendAttribute(attId, pAtt);
    216. pAtt->close();
    217. }
    218. }
    219. // pEnt->setColorIndex(text1color);//按文本颜色设置改变颜色
    220. pEnt->close();
    221. }
    222. delete pIterator;
    223. pBlockTableRecord->close();
    224. pBlkRef->close();
    225. return TRUE;
    226. }


    227. //遍历多义线顶点坐标
    228. Acad::ErrorStatus CDrawFunction::IteratorPolyline(AcDbObjectId polylineID,AcGePoint3dArray& pointArray)
    229. {
    230. Acad::ErrorStatus es=Acad::eOk;
    231. AcDbObject* pObject=NULL;
    232. AcDbPolyline *pline=NULL;
    233. if((es=acdbOpenObject(pObject,polylineID,AcDb::kForRead))!=Acad::eOk)
    234. return es;
    235. if(!pObject->isKindOf(AcDbPolyline::desc()))
    236. {
    237. pObject->close();
    238. return Acad::eInalidInput;
    239. }
    240. pline=AcDbPolyline::cast(pObject);
    241. int num=pline->numerts();
    242. for (int i=0; i< num; i++)
    243. {
    244. AcGePoint3d temPt;
    245. if((es=pline->getPointAt(i, temPt))!=Acad::eOk)
    246. {
    247. pObject->close();
    248. return Acad::eInalidInput;
    249. }
    250. pointArray.append(temPt);
    251. }
    252. pObject->close();
    253. return es;
    254. }


    255. Acad::ErrorStatus CDrawFunction::createGroup(CString groupname,AcDbObjectIdArray IdArray)
    256. {
    257. Acad::ErrorStatus es=Acad::eOk;
    258. AcDbDictionary *pGroupDict=NULL;
    259. AcDbGroup *pGroup=NULL;
    260. if((es=acdbHostApplicationSerices()->workingDatabase()->getGroupDictionary(pGroupDict,AcDb::kForWrite))!=Acad::eOk)
    261. {
    262. return es;
    263. }
    264. AcDbObjectId groupId;
    265. es=pGroupDict->getAt(groupname,groupId);
    266. if(es==Acad::eInalidKey)
    267. {
    268. acutPrintf("\n输入的词典名无效!");
    269. pGroupDict->close();
    270. return es;
    271. }
    272. else if(es==Acad::eKeyNotFound)
    273. {
    274. pGroup=new AcDbGroup("GroupDiscription");
    275. if((es=pGroupDict->setAt(groupname,pGroup,groupId))!=Acad::eOk)
    276. {
    277. pGroup->close();pGroupDict->close();return es;
    278. }
    279. }
    280. else if(es==Acad::eOk )
    281. {
    282. if((es=acdbOpenObject(pGroup,groupId,AcDb::kForWrite))!=Acad::eOk)
    283. {
    284. pGroupDict->close();return es;
    285. }
    286. }
    287. for(int i=0;i pGroup->append(IdArray[i]);
    288. pGroup->setSelectable(FALSE);
    289. pGroupDict->close();
    290. pGroup->close();
    291. return es;
    292. }

    293. double CDrawFunction::getTextLength(AcDbObjectId textId)
    294. {
    295. Acad::ErrorStatus es=Acad::eOk;
    296. AcDbEntity *pEnt=NULL;
    297. if((es=acdbOpenObject(pEnt,textId,AcDb::kForRead))!=Acad::eOk)
    298. return -1;
    299. AcDbExtents Ext;
    300. pEnt->getGeomExtents(Ext);
    301. pEnt->close();
    302. AcGePoint3d minPt,maxPt;
    303. minPt=Ext.minPoint();
    304. maxPt=Ext.maxPoint();
    305. return acutDistance(asDblArray(minPt),asDblArray(maxPt));
    306. }



    307. oid CDrawFunction::highlightEdge(const AcDbObjectId& objId,const int marker)
    308. {
    309. char dummy[133];
    310. AcDbEntity *pEnt;
    311. acdbOpenObject(pEnt,objId,AcDb::kForRead);
    312. AcGePoint3d pickpnt;
    313. AcGeMatrix3d xform;
    314. int numIds;
    315. AcDbFullSubentPath *subentIds;
    316. pEnt->getSubentPathsAtGsMarker(AcDb::kEdgeSubentType,marker,pickpnt,xform,numIds,subentIds);
    317. if(numIds>0)
    318. {
    319. pEnt->highlight(subentIds[0]);
    320. ads_getstring(0,"\npressto continue...",dummy);
    321. pEnt->unhighlight(subentIds[0]);

    322. }
    323. delete []subentIds;
    324. pEnt->close();
    325. }


    326. Acad::ErrorStatus CDrawFunction::readXrecord(CString dictName,CString xrecordName,CString &message)
    327. {
    328. AcDbDictionary *pDict=NULL;
    329. pDict=openDictionaryForRead(dictName,acdbHostApplicationSerices()->workingDatabase());
    330. if(pDict)
    331. {
    332. AcDbXrecord *pXrec;
    333. pDict->getAt(xrecordName, (AcDbObject*&) pXrec,AcDb::kForRead);
    334. pDict->close();
    335. struct resbuf *pRbList;
    336. pXrec->rbChain(&pRbList);
    337. pXrec->close();
    338. message=pRbList->resal.rstring;
    339. acutRelRb(pRbList);
    340. return Acad::eOk;
    341. }
    342. else
    343. {
    344. return Acad::eInalidInput;
    345. }
    346. }


    347. //
    348. //
    349. //
    350. AcDbDictionary* CDrawFunction::openDictionaryForWrite(LPCTSTR dictName,
    351. bool createIfNotFound,AcDbDictionary* parentDict)
    352. {
    353. ASSERT(dictName != NULL);
    354. ASSERT(parentDict != NULL);
    355. ASSERT(parentDict->isWriteEnabled());
    356. AcDbDictionary* dict = NULL;
    357. AcDbObject* obj;
    358. Acad::ErrorStatus es;
    359. es = parentDict->getAt(dictName, obj, AcDb::kForWrite);
    360. if (es == Acad::eOk)
    361. {
    362. dict = AcDbDictionary::cast(obj);
    363. }
    364. else if (es == Acad::eKeyNotFound)
    365. {
    366. if (createIfNotFound)
    367. {
    368. dict = new AcDbDictionary;
    369. AcDbObjectId dictId;
    370. es = parentDict->setAt(dictName, dict, dictId);
    371. if (es != Acad::eOk)
    372. {
    373. delete dict;dict = NULL;
    374. }
    375. }
    376. }
    377. return dict;
    378. }
    复制代码
    回复


    http://www.mjgw.org/ 专业从事膜结构设计、制作加工、施工安装的膜结构工程服务,能够为客户提供专业的膜结构整体解决方案。做中国最好的膜结构综合服务平台。欢迎大家联系电话:198-7840-1958,QQ:463017170.
    相关关键词:膜结构车棚,膜结构车棚覆盖,膜结构车棚公司,膜结构车棚多少钱,膜结构车棚厂家,膜结构车棚价格,社区膜结构车棚,膜结构车棚膜布厂家 ,膜结构车棚哪家好,膜结构车棚多少钱一米,膜结构车棚报价,膜结构车棚哪里有,膜结构车棚定制,膜结构车棚安装,膜结构车棚设计,膜结构车棚电话,膜结构车棚加工,膜结构车棚膜布价格,膜结构车棚批发,膜结构车棚制造商,膜结构车棚生产厂家,膜结构车棚设计,膜结构车棚施工,膜结构车棚多少钱一平米,膜结构车棚订制,张拉膜车棚,张拉膜车棚覆盖,张拉膜车棚公司,张拉膜车棚多少钱,张拉膜车棚厂家,张拉膜车棚价格,社区张拉膜车棚,张拉膜车棚膜布厂家 ,张拉膜车棚哪家好,张拉膜车棚多少钱一米,张拉膜车棚报价,张拉膜车棚哪里有,张拉膜车棚定制,张拉膜车棚安装,张拉膜车棚设计,张拉膜车棚电话,张拉膜车棚加工,张拉膜车棚膜布价格,张拉膜车棚批发,张拉膜车棚制造商,张拉膜车棚生产厂家,张拉膜车棚设计,张拉膜车棚施工,张拉膜车棚多少钱一平米,张拉膜车棚订制,常用膜材品牌:德国杜肯、法国法拉利、德国海德斯、德国米乐、日本平岗、韩国秀博、比利时希运、美国赫虏伯、中国科宝、上海慧遥。

    使用道具 举报

    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    关闭

    推荐膜材品牌上一条 /6 下一条

    进口膜材 国产膜材 pvdf膜材ptfe膜材ETFE膜材
    最好的膜结构公司 一级膜结构资质 膜结构一级资质
    膜结构设计-膜结构十大品牌-etfe设计-充气膜结构
    诺科膜结构
    遨都膜结构设计
    中国膜结构网
    中国空间膜结构

    QQ|申请友链|手机版|中国膜结构论坛