明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
楼主: BDYCAD

学习ARX,编个初组的命令,呵呵

  [复制链接]
 楼主| 发表于 2008-9-27 09:25:00 | 显示全部楼层
本帖最后由 作者 于 2008-9-27 9:30:47 编辑
  1. //返回椭圆的长半轴和短半轴长度
  2. //编程:包达勇
  3. //2008-09-27 上午9:16
  4.    ads_real Dist1,Dist2;
  5.    ads_name Ename,Ename1;
  6.    ads_point pt,p1,p2;
  7.    AcDbObjectId ObjID,NewID;
  8.    AcDbEllipse *pEll;
  9.    AcGePoint3d Spt,Ept;
  10.    if (acedEntSel("\n请您选取要椭圆对象:",Ename,p1)!=RTNORM)return;
  11.    if (acdbGetObjectId(ObjID,Ename)!=eOk)return;
  12.    acdbOpenObject(pEll,ObjID,AcDb::kForRead);
  13.    Spt=(AcGePoint3d&)pEll->minorAxis();
  14.    Ept=(AcGePoint3d&)pEll->majorAxis();
  15.    pEll->close();
  16.    pt[X]=pt[Y]=pt[Z]=0;
  17.    ads_point_set(asDblArray(Spt),p1);
  18.    ads_point_set(asDblArray(Ept),p2);
  19.    Dist1=acutDistance(pt,p1);
  20.    Dist2=acutDistance(pt,p2);
  21.    acutPrintf("\n报告:\n椭圆的长半轴=%fmm\n椭圆的短半轴=%fmm\n编程:BDYCAD <2008-09-27>",Dist2,Dist1);
复制代码
 楼主| 发表于 2008-10-10 16:00:00 | 显示全部楼层
本帖最后由 作者 于 2008-10-10 16:04:42 编辑

  
  1. ;功    能: 加载或卸载ARX程序
  2. ;作    用: 提供给开发ARX开发的朋友,方便大家在开发调试ARX时,调试ARX程序频繁执行APPLOAD命令卸载ARX程序再加载新编译的ARX程序文件
  3. ;开发语言: Auto LISP
  4. ;开    发: 包达勇<BDYCAD>
  5. ;日    期: 2008-10-10
  6. ;执行命令: BRX
  7. ;开发用时: 10分钟
  8. ;F:\Program\ARX\ObjectEdit\Debug\ObjectEdit.arx
  9. (defun c:brx(/ ARXFILE DCL_F DCL_ID DD PATH)
  10.   (IF(NOT(SETQ Path (vl-registry-READ "HKEY_CURRENT_USER\\Software\\Autodesk\\BDYCAD" "ArxTestPath")))
  11. (SETQ Path (vl-registry-WRITE "HKEY_CURRENT_USER\\Software\\Autodesk\\BDYCAD" "ArxTestPath" "第一次用请加入ARX路径和ARX文件名")))
  12.   (setq dcl_F(BDYCAD->Create-ArxProgramTestDCL));;;生成DCL文件
  13.   (setq dcl_id (load_dialog dcl_F)) ;载入对话框
  14.   (if (not (new_dialog "BDYCAD001" dcl_id))(exit)) ;_ 结束if
  15.   (Set_tile "ArxFile" Path)
  16.   (action_tile "Find" "(BDYCAD->FindFileArxProgram)")
  17.   (action_tile "AddArx""(setq Path(get_tile "ArxFile"))(done_dialog 1)")
  18.   (action_tile "ULArx""(setq Path(get_tile "ArxFile"))(done_dialog 2)")
  19.   (action_tile "ExitDcl""(done_dialog 0)")
  20.   (SETQ DD(start_dialog))
  21.   (unload_dialog dcl_id)
  22.   (vl-file-delete dcl_F)
  23.   (vl-registry-WRITE "HKEY_CURRENT_USER\\Software\\Autodesk\\BDYCAD" "ArxTestPath" Path)
  24.   (cond
  25.     ((= DD 0)
  26.      (Princ "\n报告:你退出对话框,没有做任可操作:)")
  27.      )
  28.     ((= DD 1)
  29.      (if(findfile Path)
  30.        (progn
  31.   (if(and(VL-FileName-Base Path)(vl-filename-extension Path))
  32.        (progn
  33.        (setq ArxFile(strcase(strcat(VL-FileName-Base Path)(vl-filename-extension Path)) T))
  34.        (if(member ArxFile(arx))(arxunload ArxFile))
  35.        ))
  36.   (arxload Path)
  37.   (Princ"\n报告: 我测试的ARX程序成功加载喽,请你努力测试并改进程序吧:)")
  38.   )
  39.        (Princ"\n报告: 没有找到要加载的ARX程序文件,请查一下是不是该路径不对或该程序文件不存在再试过."))
  40.      )
  41.     ((= DD 2)
  42.      (IF(findfile Path)
  43.      (if(and(VL-FileName-Base Path)(vl-filename-extension Path))
  44.        (progn
  45.        (setq ArxFile(strcase(strcat(VL-FileName-Base Path)(vl-filename-extension Path))t))
  46.        (if(member ArxFile(arx))
  47.   (progn
  48.     (arxunload ArxFile)
  49.     (Princ(strcat"\n报告: 成功卸载了"ArxFile"程序"))
  50.     )
  51.   )
  52.        )
  53.        )(Princ"\n报告: 没有找到要加载的ARX程序文件,请查一下是不是该路径不对或该程序文件不存在再试过."))
  54.      ))
  55.   (princ)
  56.   )
  57. (defun BDYCAD->FindFileArxProgram()
  58.   (IF(setq Path (GETFILED "选择ARX程序文档" "" "ARX" 4))
  59.   (Set_tile "ArxFile" Path))
  60.   )
  61. (defun BDYCAD->Create-ArxProgramTestDCL(/ FILE FINDF NEEW x)
  62. (setq findf(findfile "acad.dcl")
  63.     neew (strcat (substr findf 1 (- (strlen findf) 8)) "BDYCAD.DCL")
  64.     file (open neew "w"))
  65. (foreach x (list
  66. "BDYCAD001:dialog{label="BDYCAD软件开发调试VC++,ARX";"
  67. ":boxed_radio_column{label="";"
  68. ":row{:edit_box{ label="ARX文件"; key="ArxFile";edit_width=50;}"
  69. ":button{label="设定ARX";key="Find";}}"
  70. ":row{:button{label="加载ARX";key="AddArx";is_default=true;}"
  71. ":button{label="卸载ARX";key="ULArx";is_default=true;}"
  72. ":button{label="退出";key="ExitDcl";is_default=true;}}}}"
  73.                  )
  74.        (princ(strcat x"\n") file)
  75.      )
  76.   (close file)
  77.   neew)

本帖子中包含更多资源

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

x
发表于 2008-12-28 10:48:00 | 显示全部楼层
太好了
发表于 2009-2-19 12:58:00 | 显示全部楼层
楼主真棒啊,我要向你都多学习!
 楼主| 发表于 2009-3-10 08:34:00 | 显示全部楼层
三点画弧ARX源代码:
  1. AcDbBlockTableRecord *GetModelSpace(AcDb::OpenMode Mode){
  2. AcDbDatabase *pDwg = acdbHostApplicationServices()->workingDatabase();
  3. AcDbBlockTable *pBlockTable;
  4. AcDbBlockTableRecord *pModelSpace;
  5. pDwg->getSymbolTable(pBlockTable, AcDb::kForRead);
  6. pBlockTable->getAt(ACDB_MODEL_SPACE, pModelSpace, Mode);
  7. pBlockTable->close();
  8. return pModelSpace;
  9. }
  10. //功能:三点画弧
  11. //编程:包达勇
  12. //时间:20080812
  13. AcDbObjectId CreateArc(ads_point pt1,ads_point pt2,ads_point pt3){
  14. bool LongARC=FALSE;
  15. AcDbCurve *pCur;
  16. AcDbArc *pArc;
  17. ads_point /*pt1,pt2,pt3,*/cpt,mp1,mp2,mp3,mp4;
  18. ads_real GDist1,GDist2,Dist,Angle1,Angle2,Radius,StartAngle,EndAngle;
  19. GDist1=GDist2=0;
  20. AcGePoint3d Mid,Mp1,Mp2,Cpt;
  21. AcGePoint3d Spt,Mpt,Ept;
  22. Spt=asPnt3d(pt1);Mpt=asPnt3d(pt2);Ept=asPnt3d(pt3);
  23. Mid=Mpt;
  24. Dist=acutDistance(pt1,pt2);
  25. Angle1=acutAngle(pt1,pt2);
  26. Angle2=acutAngle(pt3,pt2);
  27. acutPolar(pt1,Angle1,acutDistance(pt1,pt2)*0.5,mp1);
  28. acutPolar(pt3,Angle2,acutDistance(pt3,pt2)*0.5,mp2);
  29. acutPolar(mp1,Angle1+(pi*0.5),Dist,mp3);
  30. acutPolar(mp2,Angle2+(pi*0.5),Dist,mp4);
  31. acdbInters(mp1,mp3,mp2,mp4,FALSE,cpt);
  32. Cpt=asPnt3d(cpt);
  33. Radius=acutDistance(cpt,pt2);
  34. StartAngle=acutAngle(cpt,pt1);
  35. EndAngle=acutAngle(cpt,pt3);
  36. AcDbObjectId ObjID,ObjID1,ObjID2;
  37. AcDbBlockTableRecord *pModelSpace =GetModelSpace(AcDb::kForWrite);
  38. AcDbArc *Narc1=new AcDbArc(Cpt,Radius,StartAngle,EndAngle);
  39. AcDbArc *Narc2=new AcDbArc(Cpt,Radius,EndAngle,StartAngle);
  40. pModelSpace->appendAcDbEntity(ObjID1,Narc1);
  41. pModelSpace->appendAcDbEntity(ObjID2,Narc2);
  42. Narc1->close();
  43. Narc2->close();
  44. pModelSpace->close();
  45. acdbOpenObject(pCur,ObjID1,AcDb::kForRead);
  46. pCur->getDistAtPoint(Mid,GDist1);
  47. pCur->close();
  48. acdbOpenObject(pCur,ObjID2,AcDb::kForRead);
  49. pCur->getDistAtPoint(Mid,GDist2);
  50. pCur->close();
  51. if (GDist1>GDist2) {
  52.   EraseEntity(ObjID2);
  53.   ObjID=ObjID1;
  54. }else{
  55.   EraseEntity(ObjID1);
  56.   ObjID=ObjID2;
  57. }
  58. return ObjID;
  59. }
复制代码
发表于 2009-3-10 21:27:00 | 显示全部楼层

我也发发,最简单的jig

class CRectJig :public AcEdJig
{
public:
 CRectJig()
 {
  pLine = 0;
  nColor = 1;
 }
 ~CRectJig()
 {
  if (pLine)
  {
   delete pLine;
   pLine = 0;
  }
 }
 void setColor(int Color){nColor = Color;}
 bool doIt()
 {
  if(!pLine)
   pLine = new AcDbPolyline;
 
  ads_point pt1;
  
  if(ads_getpoint(NULL,str,pt1)!=RTNORM)
  {
   return FALSE;
  }
  ptS = TransUcs2Wcs(asPnt3d(pt1),FALSE);
  ptE = AcGePoint3d(ptS.x+1,ptS.y+1,0);

  pLine->addVertexAt(0,AcGePoint2d(ptS.x,ptS.y));
  pLine->addVertexAt(1,AcGePoint2d(ptS.x,ptE.y));
  pLine->addVertexAt(2,AcGePoint2d(ptE.x,ptE.y));
  pLine->addVertexAt(3,AcGePoint2d(ptE.x,ptS.y));
  pLine->setClosed(Adesk::kTrue);
  pLine->setColorIndex(nColor);
  setDispPrompt("一些描述");
  AcEdJig::DragStatus stat = drag();
  if (stat != AcEdJig::kNormal)
   return false;
  return TRUE;
 }
    DragStatus sampler()
 {
  DragStatus stat;
  setUserInputControls((UserInputControls)
   (AcEdJig::kAccept3dCoordinates
    | AcEdJig::kNoNegativeResponseAccepted
    | AcEdJig::kNoZeroResponseAccepted));
  AcGePoint3d pt;
  stat = acquirePoint(pt);
  if (!pt.isEqualTo(ptE))
            ptE = pt;
        else if (stat == AcEdJig::kNormal)
            return AcEdJig::kNoChange;
  return stat;
 }
    Adesk::Boolean update()
 { 
  pLine->setPointAt(0,AcGePoint2d(ptS.x,ptS.y));
  pLine->setPointAt(1,AcGePoint2d(ptS.x,ptE.y));
  pLine->setPointAt(2,AcGePoint2d(ptE.x,ptE.y));
  pLine->setPointAt(3,AcGePoint2d(ptE.x,ptS.y));
  return Adesk::kTrue;
 }
    AcDbEntity* entity() const
 {
  return pLine;
 }
public:
 AcDbPolyline * pLine;
 AcGePoint3d ptS,ptE;
 int nColor;
};

TransUcs2Wcs()是一个函数转换点的,UCS到世界坐标的

发表于 2010-9-29 14:08:00 | 显示全部楼层
ARX代码如何实现创建多段线,急~~~~~~
 楼主| 发表于 2010-10-7 13:22:00 | 显示全部楼层
  1. AcDbBlockTableRecord *GetModelSpace(AcDb::OpenMode Mode){
  2. AcDbDatabase *pDwg = acdbHostApplicationServices()->workingDatabase();
  3. AcDbBlockTable *pBlockTable;
  4. AcDbBlockTableRecord *pModelSpace;
  5. pDwg->getSymbolTable(pBlockTable, AcDb::kForRead);
  6. pBlockTable->getAt(ACDB_MODEL_SPACE, pModelSpace, Mode);
  7. pBlockTable->close();
  8. return pModelSpace;
  9. }
  10. //生成PLINE线。 CreatePline(点表,是否封闭)
  11. //编程: BDYCAD 20080408
  12. AcDbObjectId CreatePline(AcGePoint3dArray PTlist,int CloseModel/* =FALSE */){
  13. AcDbObjectId ObjID;
  14. AcDbBlockTableRecord *pModelSpace =GetModelSpace(AcDb::kForWrite);
  15. Adesk::Boolean pltype;
  16. if (CloseModel==FALSE) {
  17.   pltype=Adesk::kFalse;//曲线打开
  18. }else if(CloseModel==TRUE){
  19.   pltype=Adesk::kTrue;//曲线封闭
  20. }
  21. //AcDbPolyline
  22. AcDb2dPolyline *nPl=new AcDb2dPolyline(AcDb::k2dSimplePoly,PTlist,0.0,pltype);//AcDb::k2dCubicSplinePoly
  23. nPl->setLayer(_T("0"));
  24. pModelSpace->appendAcDbEntity(ObjID,nPl);
  25. nPl->close();
  26. pModelSpace->close();
  27. return ObjID;
  28. }
复制代码

评分

参与人数 1金钱 +20 收起 理由
吾将醉 + 20 非常好,谢谢师傅!

查看全部评分

发表于 2011-4-21 14:47:23 | 显示全部楼层
雪中送炭啊!
发表于 2011-5-21 20:04:03 | 显示全部楼层
LISP如何调用ARX画一条线的子程序呢... ...
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-11-24 12:52 , Processed in 0.174494 second(s), 19 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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