明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
12
返回列表 发新帖
楼主: QUAN2518

LISP算法该怎么写

  [复制链接]
发表于 2011-7-24 15:03:31 | 显示全部楼层
50个单位以下的线段认为是倒角

  1. (defun c:tt ( / cut ent )
  2.   (command "_.undo" "BE")
  3.   (princ "\n请选择边界")
  4.   (princ "\n假定50个单位长度以下的线段为切角")
  5.   (setq cut 50)
  6.   (setq ent (car (entsel)))
  7.   (if (eq "LWPOLYLINE" (cdr (assoc 0 (entget ent))))
  8.     (entsurf ent cut)
  9.     )
  10.   (command "_.undo" "E")
  11.   )
  12. (defun entsurf (ent cut  /   segment  alpha    bulge    endPoint
  13.   startPoint   r    br     sr      obj
  14.   sArea  orArea
  15.         )
  16.   (setq eget (entget ent))
  17.   (setq curList nil
  18. startPoint
  19.   nil
  20. i 0
  21.   )
  22.   (foreach segment eget
  23.     (if (= 42 (car segment))
  24.       (progn
  25. (if (= 0.0 (cdr segment))
  26.    (setq alpha 0.0)
  27.    (progn
  28.      (setq bulge (cdr segment))
  29.      (setq alpha (abs (* 2 (atan bulge))))
  30.    )
  31. )
  32.       )
  33.     )
  34.     (if (= 10 (car segment))
  35.       (progn
  36. (setq endPoint (cdr segment))
  37. (if startPoint
  38.    (progn
  39.      (setq midPoint (mapcar '(lambda (a b) (/ (+ a b) 2))
  40.        startPoint
  41.        endPoint
  42.       )
  43.      )
  44.      (if
  45.        (or (/= 0.0 alpha) (> cut (distance startPoint endPoint)))
  46.         (progn
  47.    (setq dis (distance startPoint endPoint))
  48.    (if (/= 0.0 alpha)
  49.      (setq r (/ (* dis 0.5) (sin alpha)))
  50.      (setq r (- 0 (distance startPoint endPoint)))
  51.    )
  52.         )
  53.         (setq r 0.0)
  54.      )
  55.      (setq curList (cons (list r midPoint) curList))
  56.    )
  57. )
  58. (setq startPoint endPoint)
  59.       )
  60.     )
  61.   )
  62.   (setq len (length curList))
  63.   (setq firs (car curList))
  64.   (setq curList (cons (last curList) curList))
  65.   (setq curList (append curList (list firs)))
  66.   (while (< (setq i (1+ i)) len)
  67.     (if (/= 0.0 (car (nth i curList)))
  68.       (if (> (car (nth i curList)) 0.0)
  69.       (progn
  70. (setq r (car (nth i curList)))
  71. (setq startPoint (cadr (nth (1- i) curList)))
  72. (setq endPoint (cadr (nth (1+ i) curList)))
  73. (setq br (+ 1 r))
  74. ;;大半径和小半径跟据自已的需要定
  75. (setq sr (+ -1 r))
  76. (setq obj (vlax-ename->vla-object ent))
  77. (setq orArea (abs (vla-get-area obj)))
  78. (vla-update obj)
  79. (command "_.fillet" "R" sr)
  80. (command "_.fillet" startPoint endPoint)
  81. (setq sArea (abs (vla-get-area obj)))
  82. (vla-update obj)
  83. (if (> sArea orArea)
  84.    (progn
  85.      (command "_.fillet" "R" br)
  86.      (command "_.fillet" startPoint endPoint)
  87.    )
  88. )
  89.       )
  90. (progn
  91. (setq r (* -0.707107 (car (nth i curList))))
  92. (setq startPoint (cadr (nth (1- i) curList)))
  93. (setq endPoint (cadr (nth (1+ i) curList)))
  94. (setq br (+ 1 r))
  95. ;;大半径和小半径跟据自已的需要定
  96. (setq sr (+ -1 r))
  97. (setq obj (vlax-ename->vla-object ent))
  98. (setq orArea (abs (vla-get-area obj)))
  99. (vla-update obj)
  100. (command "_.chamfer" "D" sr sr)
  101. (command "_.chamfer" startPoint endPoint)
  102. (setq sArea (abs (vla-get-area obj)))
  103. (vla-update obj)
  104. (if (> sArea orArea)
  105.    (progn
  106.      (command "_.chamfer" "D" br br)
  107.      (command "_.chamfer" startPoint endPoint)
  108.    )
  109. )
  110.       )
  111. )
  112.     )
  113.   )     ;progn
  114. )



 楼主| 发表于 2011-7-25 10:13:55 | 显示全部楼层
本帖最后由 QUAN2518 于 2011-7-25 10:17 编辑

回复 yarp 的帖子

感谢你的代码。
测试还有点小问题,我自己解读下看看先。
还有C角的判定可能需要假如相邻两段为直线,不然出现小与5的线段可能会有益处问题。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-6-9 23:38 , Processed in 0.158138 second(s), 19 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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