找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 968|回复: 3

[每日一码] 转换POLYLINE,LINE,ARC,CIRCLE,3DFACE到3DPOLYLINE

[复制链接]

已领礼包: 20个

财富等级: 恭喜发财

发表于 2018-5-13 00:02:38 | 显示全部楼层 |阅读模式

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

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

×
  1. ; 3D Utility             3Pedit.LSP          Ver 1.3           E Batson
  2. ; Convert 2d polyline, 3dface, line, arc, & circle to 3d polyline
  3. ; 1. Join 3Dpoly's (ends should meet).
  4. ; 2. If you accidently pick a 3DPoly, it is just drawn over again.
  5. ; 3. The Join function will replace the two 3DPolys with a single 3dPoly.
  6. ; 4. The Change function will just draw over the existing entity.
  7. ; 5. For a mesh , first explode it into faces, then change to 3dpoly(s).
  8. ; 6. Resolution will control smoothnes of curves, also make various shapes
  9. ;    such as... 6 = hex,  3 = triangle,  4 = square,  etc....
  10. ;*****************************************************************************
  11. (princ "\nLoading...")
  12. ;..............................................................................
  13. ; Join two 3dpoly lines
  14. (defun join3d
  15. (/ en flag1 flag2 en1 list1 list2 p1a p1b p2a p2b)
  16. (princ "\nJoin two 3DPolys.")
  17. (setq ss1 (entsel "\nSelect first 3dPoly.."))
  18. (redraw (car ss1) 3)
  19. (setq ss2 (entsel "....select second 3dPoly.."))
  20. (redraw (car ss2) 3)
  21. (setvar "blipmode" 0)
  22. (setq en1 (car ss1)
  23.      poly1 (entget en1)
  24.      flag1 (cdr(assoc 70 poly1))
  25.        en2 (car ss2)
  26.      poly2 (entget en2)
  27.      flag2 (cdr(assoc 70 poly2))
  28. )
  29. (if (and (= (logand flag1 8) 8)(= (logand flag2 8) 8))  ; both 3D Polys ?
  30.   (progn
  31.     (setq lyr    (cdr(assoc 8 (entget en1)))             ; get first 3dpoly
  32.           en     (entnext en1)                           ; stuff.
  33.           list1 (cdr(assoc 10 (entget en)))
  34.           chk1   (cdr(assoc 10 (entget en)))
  35.           p1a    list1
  36.     )
  37.     (setq list1 (list list1))
  38.     (while (= (cdr(assoc 0(entget(setq en(entnext en)))))"VERTEX")
  39.        (setq list1 (append list1 (list(cdr(assoc 10(entget en))))))
  40.        (setq p1b (cdr(assoc 10(entget en))))
  41.     )
  42.     (setq en     (entnext en2)                           ; get second 3dpoly
  43.           list2 (cdr(assoc 10 (entget en)))              ; stuff.
  44.           p2a list2
  45.           chk2   (cdr(assoc 10 (entget en)))
  46.     )
  47.     (setq list2 (list list2))
  48.     (while (= (cdr(assoc 0(entget(setq en(entnext en)))))"VERTEX")
  49.       (setq list2 (append list2 (list(cdr(assoc 10(entget en))))))
  50.       (setq p2b (cdr(assoc 10(entget en))))
  51.     )
  52. ;-check for alignment of endpoints
  53.     (cond
  54.      ((equal p1b p2b 0.0001)                    ;if ---1----> <---2----
  55.       (setq list2 (reverse list2)))             ; reverse #2.

  56.      ((equal p1a p2a 0.0001)                    ;if <---1---- ---2---->
  57.       (setq list1 (reverse list1)))             ; reverse #1.

  58.      ((equal p1a p2b 0.0001)                    ;if ----2---> ---1---->
  59.         (setq tmp list1 list1 list2 list2 tmp)) ; swap them.
  60.     );end cond

  61.     ;---------- do the ends meet ? ---------------------------
  62.     (if (or                                     ; Check to see if the two
  63.          (equal p1a p2a 0.0001)                 ; 3Dpolys meet.
  64.          (equal p1b p2b 0.0001)
  65.          (equal p1a p2b 0.0001)
  66.          (equal p1b p2a 0.0001)
  67.          )
  68.      (progn                                      ; ok, they meet.
  69.    ;-erase old stuff
  70.        (entdel en1);<&#196;&#196;&#196;&#196;&#196;&#196;&#196;&#196;&#196;&#196;&#196;&#196;&#196;&#196;&#196;&#196;&#196;&#196;&#196;&#196;&#196;&#196;&#196;&#196;&#196;&#194;&#196;&#196;&#196; remove these two commands
  71.        (entdel en2);<&#196;&#196;&#196;&#196;&#196;&#196;&#196;&#196;&#196;&#196;&#196;&#196;&#196;&#196;&#196;&#196;&#196;&#196;&#196;&#196;&#196;&#196;&#196;&#196;&#196;ù    if you wish NOT to erase
  72.        (princ "\nWorking, please wait.....");      the original entities.
  73.    ;-draw new 3dPoly
  74.        (command "layer" "s" lyr "")               ; draw the new 3dpoly in the
  75.        (command "3dpoly")                         ; layer of the first selection.
  76.        (foreach n list1 (command n))
  77.        (setq list2 (cdr list2))                    ; remove the first point of
  78.        (foreach n list2 (command n))               ; list2
  79.        (command)
  80.      )
  81.      (progn
  82.        (princ "\nEnds do not meet.")               ; not ok
  83.        (redraw en1)
  84.        (redraw en2)
  85.        (exit)
  86.      )
  87.     );endif ends meet
  88.     ;-----------------------------------------------------------
  89.   );end main PROGN
  90.   (progn
  91.    (princ "\nAt least one of the lines selected was not a 3dPoly.")
  92.    (redraw en1)
  93.    (redraw en2)
  94.   )
  95. );end if 3dPoly
  96. (prin1)
  97. );end join3d

  98. ; Circle function
  99. (defun cir (e / ia p1 eg cn rd step za)
  100. (princ " Circle")
  101. (setq eg    (entget e)
  102.        za    (cdr(assoc 210 eg))
  103.        cn    (cdr(assoc 10 eg))
  104.        rd    (cdr(assoc 40 eg))
  105.        step  (/ (* 2 pi) #res)
  106.        p1    (polar cn pi rd)
  107.        ia    (angle cn p1)
  108. )
  109. (command "UCS" "ZA" "" ZA)                          ; set to entity's ucs
  110. (command "3dpoly")
  111. (command p1)
  112. (repeat #res                                         ; follow curve
  113.    (setq p1 (polar cn (setq ia (+ ia step)) rd))      ; with 3dpoly
  114.    (command  p1)
  115. )
  116. (command)
  117. (command "ucs" "w")
  118. )

  119. ; Line function
  120. (defun lin (e)                                  ; simple stuff
  121. (princ " Line")
  122. (command "3dpoly")
  123.   (command
  124.    (cdr(assoc 10(entget e))))
  125.   (command
  126.    (cdr(assoc 11(entget e))))
  127. (command)
  128. )

  129. ; 3dface function
  130. (defun 3df (e)                                  ; simple stuff
  131. (princ " 3DFace")
  132. (command "3dpoly")
  133.   (command
  134.    (cdr(assoc 10(entget e))))
  135.   (command
  136.    (cdr(assoc 11(entget e))))
  137.   (command
  138.    (cdr(assoc 12(entget e))))
  139.   (command
  140.    (cdr(assoc 13(entget e))))
  141.   (command "c")
  142. )

  143. ; Bulge function. Draws short 3DPolys along curve..resolution in #res
  144. (defun bulge
  145.   (p1 p2 bulge / ia step chd anga ica rad cha cen)
  146.   (setq ica    (* 4 (atan bulge))                      ; included angle
  147.         chd    (distance p1 p2)
  148.         anga   (- (/ pi 2) (/ ica 2))                  ; 180&#248;- &#171; of incl. ang.
  149.         rad    (abs (/ (/ chd 2) (cos anga)))          ; radius
  150.         cha    (angle p1 p2)
  151.         step   (/ ica #res)
  152. );endsetq
  153. (if (minusp bulge)
  154.    (setq cen (polar p2 (- cha anga) rad))             ; curve direction ??
  155.     (setq cen (polar p1 (+ cha anga) rad)))
  156. (setq ia (angle cen p1))                             ; incrementing angle
  157. (command p1)
  158. (repeat #res                                         ; follow curve
  159.    (setq p1 (polar cen (setq ia (+ ia step)) rad))    ; with 3dpoly
  160.    (command  p1))
  161. );end bulge function

  162. ; polyline function
  163. (defun poly (e / za cl fp en vx cv nx)
  164. (princ " Polyline")
  165. (setq en e
  166.        za (cdr(assoc 210(entget en)))                     ; get ucs data
  167.        cl (if(=(cdr(assoc 70(entget en)))1)1)             ; closed flag 1=yes
  168.        fp (cdr(assoc 10(entget(entnext en))))             ; save first point
  169.        en (entnext en))                                   ; leave header
  170. (command "UCS" "ZA" "" za)                               ; set to entity's ucs
  171. (command "3dpoly")
  172. (command fp)                                             ; id first vertex
  173. (while (=(cdr(assoc 0(setq el(entget en))))"VERTEX")     ; do while not end
  174.   (setq vx (cdr(assoc 10 el))                             ; this vertex
  175.         cv (cdr(assoc 42 el))                             ; bulge
  176.         nx (cdr(assoc 10(entget(entnext en)))))           ; next vertex
  177.   (if (/= cv 0.0)
  178.     (if nx (bulge vx (if nx nx (if cl fp)) cv))           ; a curve? (closed?)
  179.     (command (if nx nx (if cl fp))))                      ; a line? (closed?)
  180.     (setq en (entnext en))                                ; loop thru database
  181. );endwhile
  182. (command)
  183. (command "ucs" "w")
  184. );end poly

  185. (defun name (e / name)                                   ; tired of typing.
  186. (setq name (cdr(assoc 0(entget e))))
  187. (eval name)                                             ; return
  188. )

  189. (defun change_to_3d (/ res ss ssl e cnt)
  190. (setvar "blipmode" 0)
  191. (setq #res (if #res #res 20))                          ; initialize resolution
  192. (setq res (getint (strcat "\nCurve Resolution<"(itoa #res)">: ")))
  193. (if(boundp 'res)(setq #res res))
  194. (setq cnt -1)
  195. (setq ss (ssget))                                      ; get the stuff
  196. (princ "\nChanging..")
  197. (setq ssl (sslength ss))
  198. (repeat ssl                                            ; do 'em all.
  199.   (setq e (ssname ss (setq cnt (1+ cnt))))
  200.   (cond
  201.    ((= (name e) "POLYLINE")(poly e))                    ; choices
  202.    ((= (name e) "CIRCLE")(cir e))
  203.    ((= (name e) "LINE")(lin e))
  204.    ((= (name e) "ARC")                                  ; If its an ARC,
  205.      (progn(command "pedit" e "y" "")(poly (entlast)))) ; change to polyline.
  206.    ((= (name e) "3DFACE")(3df e))
  207.   )
  208. )
  209. )

  210. ;..........Main function....................
  211. ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  212. ; Global variable = #res  (curve resolution)
  213. ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  214. (defun c:3pedit (/ choice)
  215. (initget "C J")
  216. (setq choice (getkword "\nChange/Join <J>: "))
  217. (cond
  218.   ((= choice "C")
  219.     (change_to_3d))
  220.   (T
  221.     (join3d))
  222. )
  223. (setvar "blipmode" 0)
  224. (command "ucs" "w")
  225. (princ)
  226. );end c:3pedit
  227. (princ "\n3Pedit.LSP    - Ver 1.3 -     Compliments of Batson Tool Corp.")
  228. (princ "\nUsage -> Command: 3Pedit ")
  229. (prin1)

论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!

已领礼包: 6056个

财富等级: 富甲天下

发表于 2018-5-13 00:20:41 | 显示全部楼层
沙发支持!
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复

使用道具 举报

已领礼包: 219个

财富等级: 日进斗金

发表于 2018-5-14 07:02:32 | 显示全部楼层
谢谢分享!拜读了!
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

发表于 2018-6-7 08:10:18 | 显示全部楼层
学习
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-9-26 21:17 , Processed in 0.198009 second(s), 35 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

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