找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 512|回复: 0

[ARX程序]:创建简单实体对象的例子,

[复制链接]
发表于 2002-12-26 20:12:19 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

×
创建简单实体对象的例子,

  1. [font=courier new]

  2. /////////////////////////////////////////////
  3. // ObjectARX defined commands

  4. #include "StdAfx.h"
  5. #include "StdArx.h"
  6. #include "GeAssign.h"
  7. #include "llin.h"
  8. #include "cirvl.h"
  9. // This is command 'CIR'
  10. void cir()
  11. {

  12.         drw_cir();
  13.         /*
  14.         AcDbDatabase *pCurDb;
  15.         AcDbBlockTable *pBlkTable;
  16.         AcDbBlockTableRecord *pBlkTableRec;
  17.         AcDbObjectId circId;

  18.         AcDbCircle *pCirc;

  19.         AcGePoint3d cen;
  20.         AcGeVector3d normal(0.0, 0.0, 1.0);        // Plane orientation
  21.         ads_point cp;
  22.         double rad;

  23.         acedInitGet(RSG_NONULL, NULL);
  24.         acedGetPoint(NULL, "\nPick circle center point: ", cp);
  25.         cen = asPnt3d(cp);        // convert the ads_point to AcGePoint3d

  26.         acedInitGet(RSG_NONULL + RSG_NOZERO + RSG_NONEG, NULL);
  27.         acedGetDist(cp, "\nCircle radius: ", &rad);

  28.         // Create the circle entity
  29.         pCirc = new AcDbCircle(cen, normal, rad);


  30.         // We are going to add the entity to the
  31.         // Model Space Block Table Record of the
  32.         // Block Table
  33.         pCurDb = acdbHostApplicationServices()->workingDatabase();
  34.         // Open the Block Table for a read operation
  35.         pCurDb->getBlockTable(pBlkTable, AcDb::kForRead);
  36.         // Get the Model Space Block Table record of the Block Table
  37.         pBlkTable->getAt(ACDB_MODEL_SPACE, pBlkTableRec, AcDb::kForWrite);
  38.         // Add the newly crated circle entity to the
  39.         // Block Table Record
  40.         pBlkTableRec->appendAcDbEntity(circId, pCirc);


  41.         // Close the Block Table, the Block Table Record
  42.         // and the Entity

  43.         pBlkTable->close();
  44.         pBlkTableRec->close();
  45.         pCirc->close();
  46.         */

  47. }

  48. // This is command 'LIN'
  49. void lin()
  50. {
  51. /*        AcDbDatabase *pCurDb;
  52.         AcDbBlockTable *pBlkTable;
  53.         AcDbBlockTableRecord *pBlkTableRec;
  54.         AcDbObjectId lineId;

  55.         AcDbLine *pLn;

  56.         AcGePoint3d sp, ep;

  57.         acedInitGet(RSG_NONULL, NULL);
  58.         // Note how we convert an ads_point to a AcGePoint3d
  59.         // using the mechanism (double*)(&point)
  60.         acedGetPoint(NULL, "\nPick line start point: ", (double*)(&sp));

  61.         acedInitGet(RSG_NONULL, NULL);
  62.         acedGetPoint((double*)(&sp), "\nPick line end point: ", (double*)(&ep));

  63.         // Create the line entity
  64.         pLn = new AcDbLine(sp, ep);


  65.         // We are going to add the entity to the
  66.         // Model Space Block Table Record of the
  67.         // Block Table
  68.         pCurDb = acdbHostApplicationServices()->workingDatabase();
  69.         // Open the Block Table for a read operation
  70.         pCurDb->getBlockTable(pBlkTable, AcDb::kForRead);
  71.         // Get the Model Space Block Table record of the Block Table
  72.         pBlkTable->getAt(ACDB_MODEL_SPACE, pBlkTableRec, AcDb::kForWrite);
  73.         // Add the newly crated circle entity to the
  74.         // Block Table Record
  75.         pBlkTableRec->appendAcDbEntity(lineId, pLn);


  76.         // Close the Block Table, the Block Table record
  77.         // and the enity

  78.         pBlkTable->close();
  79.         pBlkTableRec->close();
  80.         pLn->close();
  81.         */
  82.         linne();
  83. }

  84. // This is command 'ARK'
  85. void ark()
  86. {
  87.         //变量声明
  88.         AcDbDatabase *pCurDb;
  89.         AcDbBlockTable *pBlkTable;
  90.         AcDbBlockTableRecord *pBlkTableRec;
  91.         AcDbObjectId arkId;
  92.         AcDbArc *pArc;

  93.         // The AcDbArc constructors deal in terms of
  94.         // a center point, start angle, end angle and
  95.         // radius. There are no constructors for 3 point
  96.         // arcs. The AcGe geometry classes allows us to
  97.         // create a mathematical arc using 3 points from
  98.         // which we can get the center, radius and
  99.         // calculate the start and end angles.

  100.         AcGePoint2d p1, p2, p3, cen;        // location points
  101.         AcGePoint3d cenark;                                // center location
  102.         AcGeLine2d lineEnt;        // 2d infinite line
  103.         AcGeTol tol;                // tolerance used by isOn() function
  104.         double rad, eang, sang;

  105.         ads_point sp, ap, ep;

  106.         acedInitGet(RSG_NONULL, NULL);
  107.         acedGetPoint(NULL, "\nPick arc start point: ", sp);
  108.         acedInitGet(RSG_NONULL, NULL);
  109.         acedGetPoint(sp, "\nPick second point of arc: ", ap);
  110.         acedGrDraw(sp, ap, 1, 0);
  111.         // acedGrDraw draws temporary vectors from
  112.         // start point to end point in color, with/without highlight
  113.         acedInitGet(RSG_NONULL, NULL);
  114.         acedGetPoint(ap, "\nPick arc end point: ", ep);
  115.         acedGrDraw(ap, ep, 1, 0);

  116.         p1[X] = sp[X];
  117.         p1[Y] = sp[Y];

  118.         p2[X] = ap[X];
  119.         p2[Y] = ap[Y];

  120.         p3[X] = ep[X];
  121.         p3[Y] = ep[Y];

  122.         lineEnt.set(p1, p3);        // create the infinite mathematical line

  123.         // Create the mathematical arc
  124.         AcGeCircArc2d geark(p1, p2, p3);
  125.         rad = geark.radius();
  126.         cen = geark.center();

  127.         cenark.set(cen[X], cen[Y], 0.0);

  128.         tol.setEqualPoint(0.001);        // set tolerance value
  129.                                                                 // default is 1.e-10

  130.         // Look at how we test to see if geometry point
  131.         // p2 in on the infinite line defined by p1 and p3
  132.         if(lineEnt.isOn(p2, tol))
  133.         {
  134.                 acutPrintf("\nPoints picked are colinear - invalid arc. ");
  135.                 return;
  136.         }


  137.         // Calculate the start and end angles
  138.         // Notice how we convert the AcGePoint2d to
  139.         // an ads_point using the cast mechanism
  140.         // (double*) (&point)
  141.         sang = acutAngle((double*) (&cen), sp);
  142.         eang = acutAngle((double*) (&cen), ep);


  143.         // Dependant on the arc direction switch
  144.         // the start and end angles
  145.         if(geark.isClockWise())
  146.         {
  147.                 pArc = new AcDbArc(cenark, rad, eang, sang);
  148.         }
  149.         else
  150.         {
  151.                 pArc = new AcDbArc(cenark, rad, sang, eang);
  152.         }

  153.         pCurDb = acdbHostApplicationServices()->workingDatabase();
  154.         pCurDb->getBlockTable(pBlkTable, AcDb::kForRead);
  155.         pBlkTable->getAt(ACDB_MODEL_SPACE, pBlkTableRec, AcDb::kForWrite);
  156.         pBlkTableRec->appendAcDbEntity(arkId, pArc);

  157.         pBlkTableRec->close();
  158.         pBlkTable->close();
  159.         pArc->close();
  160. }
  161. [/font]
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|申请友链|Archiver|手机版|小黑屋|辽公网安备|晓东CAD家园 ( 辽ICP备15016793号 )

GMT+8, 2024-9-28 11:18 , Processed in 0.331955 second(s), 33 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表