明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1329|回复: 9

[资源] 二维多段线转为三维多段线

[复制链接]
发表于 2015-11-20 19:36 | 显示全部楼层 |阅读模式
购买主题 已有 11 人购买  本主题需向作者支付 1 个明经币 才能浏览
发表于 2015-11-20 20:06 | 显示全部楼层
很讨厌看到这种需要先支付才能浏览的贴子!

这种2D polyline 转 3D polyline 的贴子多的是 ,没必要这么神秘
随便贴几个吧

Convert 3D Polylines To 2D Polylines
  1. ;;CADALYST 09/03 AutoLISP Solutions
  2. ;;; PLINE-3D-2D.LSP - a program to convert
  3. ;;; 3D polylines to 2D
  4. ;;; Program by Tony Hotchkiss

  5. (defun pline-3d-2d ()
  6.   (vl-load-com)
  7.   (setq  *thisdrawing* (vla-get-activedocument
  8.       (vlax-get-acad-object)
  9.           ) ;_ end of vla-get-activedocument
  10.   *modelspace*  (vla-get-ModelSpace *thisdrawing*)
  11.   ) ;_ end of setq
  12.   (setq  3d-pl-list
  13.    (get-3D-pline)
  14.   ) ;_ end of setq
  15.   (if 3d-pl-list
  16.     (progn
  17.       (setq vert-array-list (make-list 3d-pl-list))
  18.       (setq n (- 1))
  19.       (repeat (length vert-array-list)
  20.   (setq vert-array (nth (setq n (1+ n)) vert-array-list))
  21.   (setq lyr (vlax-get-property (nth n 3d-pl-list) 'Layer))
  22.   (setq obj (vla-AddPolyline *modelspace* vert-array))
  23.   (vlax-put-property obj 'Layer lyr)
  24.       ) ;_ end of repeat
  25.       (foreach obj 3d-pl-list (vla-delete obj))
  26.     ) ;_ end of progn
  27.   ) ;_ end of if
  28. ) ;_ end of pline-3d-2d

  29. (defun get-3D-pline ()
  30.   (setq  pl3dobj-list nil
  31.   obj       nil
  32.   3d       "AcDb3dPolyline"
  33.   ) ;_ end of setq
  34.   (setq selsets (vla-get-selectionsets *thisdrawing*))
  35.   (setq ss1 (vlax-make-variant "ss1"))
  36.   (if (= (vla-get-count selsets) 0)
  37.     (setq ssobj (vla-add selsets ss1))
  38.   ) ;_ end of if
  39.   (vla-clear ssobj)
  40.   (setq Filterdata (vlax-make-variant "POLYLINE"))
  41.   (setq no-ent 1)
  42.   (while no-ent
  43.     (vla-Selectonscreen ssobj)
  44.     (if  (> (vla-get-count ssobj) 0)
  45.       (progn
  46.   (setq no-ent nil)
  47.   (setq i (- 1))
  48.   (repeat  (vla-get-count ssobj)
  49.     (setq
  50.       obj  (vla-item ssobj
  51.         (vlax-make-variant (setq i (1+ i)))
  52.     ) ;_ end of vla-item
  53.     ) ;_ end of setq
  54.     (cond
  55.       ((= (vlax-get-property obj "ObjectName") 3d)
  56.        (setq pl3dobj-list
  57.         (append pl3dobj-list (list obj))
  58.        ) ;_ end of setq
  59.       )
  60.     ) ;_ end-of cond
  61.   ) ;_ end of repeat
  62.       ) ;_ end of progn
  63.       (prompt "\nNo entities selected, try again.")
  64.     ) ;_ end of if
  65.     (if  (and (= nil no-ent) (= nil pl3dobj-list))
  66.       (progn
  67.   (setq no-ent 1)
  68.   (prompt "\nNo 3D-polylines selected.")
  69.   (quit)
  70.       ) ;_ end of progn
  71.     ) ;_ end of if
  72.   ) ;_ end of while  
  73.   (vla-delete (vla-item selsets 0))
  74.   pl3dobj-list
  75. ) ;_ end of get-3D-pline


  76. (defun get-3D-pline-old ()
  77.   (setq no-ent 1)
  78.   (setq  filter '((-4 . "<AND")
  79.      (0 . "POLYLINE")
  80.      (70 . 8)
  81.      (-4 . "AND>")
  82.     )
  83.   ) ;_ end of setq
  84.   (while no-ent
  85.     (setq ss         (ssget filter)
  86.     k         (- 1)
  87.     pl3dobj-list nil
  88.     obj         nil
  89.     3d         "AcDb3dPolyline"
  90.     ) ;_ end-of setq
  91.     (if  ss
  92.       (progn
  93.   (setq no-ent nil)
  94.   (repeat  (sslength ss)
  95.     (setq  ent (ssname ss (setq k (1+ k)))
  96.     obj (vlax-ename->vla-object ent)
  97.     ) ;_ end-of setq
  98.     (cond
  99.       ((= (vlax-get-property obj "ObjectName") 3d)
  100.        (setq pl3dobj-list
  101.         (append pl3dobj-list (list obj))
  102.        ) ;_ end of setq
  103.       )
  104.     ) ;_ end-of cond
  105.   ) ;_ end-of repeat
  106.       ) ;_ end-of progn
  107.       (prompt "\nNo 3D-polylines selected, try again.")
  108.     ) ;_ end-of if
  109.   ) ;_ end-of while
  110.   pl3dobj-list
  111. ) ;_ end of get-3D-pline-old

  112. (defun make-list (p-list)
  113.   (setq  i (- 1)
  114.   vlist nil
  115.   calist nil
  116.   ) ;_ end of setq
  117.   (repeat (length p-list)
  118.     (setq obj   (nth (setq i (1+ i)) p-list)
  119.     coords (vlax-get-property obj "coordinates")
  120.     ca   (vlax-variant-value coords)
  121.     ) ;_ end-of setq
  122.     (setq calist (append calist (list ca)))
  123.   ) ;_ end-of repeat
  124. ) ;_ end-of make-list

  125. (defun c:pl32 ()
  126.   (pline-3d-2d)
  127.   (princ)
  128. ) ;_ end of pl32

  129. (prompt "Enter PL32 to start: ")


Convert 2-D polyline(s) (pline) to 3-D polyline(s) (3dpoly)
  1. ;###############################################################################
  2. ;
  3. ; poly2to3.lsp
  4. ;
  5. ; Convert 2-D polyline(s) (pline) to 3-D polyline(s) (3dpoly) using
  6. ; user-specified z-value for 3-D polyline.  Creates new 3-D polyline and
  7. ; erases old 2-D polyline.
  8. ;
  9. ; User is prompted for:
  10. ;    1) the z-value to assign to the 3-D polyline(s)
  11. ;    2) the selection set
  12. ;
  13. ; NOTE:  this may not properly handle all possible combination of attributes.
  14. ;
  15. ; Please feel free to direct any comments, criticisms, and/or suggestions to
  16. ; me at one of the below listed locations.
  17. ;
  18. ; by:  Michael J. Read               Compuserve:  71571,2073
  19. ;      Read Engineering
  20. ;      1714 Ben Crenshaw Way
  21. ;      Austin, TX 78746
  22. ;      (512)327-9776
  23. ;
  24. ; January 5, 1990
  25. ;
  26. ;#############################  Revision History  ##############################
  27. ; mjr 900105 - V1.00 - initial release
  28. ; mjr 911026 - V1.10 - cleaned up, added selection set capability, attribute
  29. ;                      handling
  30. ; mjr 911031 - V1.20 - added capability of assigning a user-specified z-value
  31. ;                      for each vertex.  User is given choice of 3D z-value as
  32. ;                      1) global z-value, 2) manually supplying z-value for each
  33. ;                      vertex of each polyline, or 3) assigning existing 2D
  34. ;                      z-value.
  35. ;###############################################################################


  36. (princ "\n\n Lisp by:  Michael J. Read - READ ENGINEERING - (512)327-9776\tLoading...")

  37. (defun header(/ verd vern)                       ; display header info
  38.    (setq vern 1.20)
  39.    (setq verd "01-Nov-91")
  40.    (princ "\n READ ENGINEERING:  ")
  41.    (princ (strcat "poly2to3 (V" (rtos vern 2 2) " " verd ") - change 2D polyline(s) to 3D\n"))
  42. )

  43. (defun cls()
  44.    (repeat 24 (princ
  45. "                                                                               \n"))
  46. )

  47. ; return the value associated with a particular entity field
  48. (defun fld (num list)
  49.    (cdr (assoc num list))
  50. )

  51. ; save specified mode settings
  52. (defun MODES (a)
  53.    (setq MLST '())
  54.    (repeat (length a)
  55.       (setq MLST (append MLST (list (list (car a) (getvar (car a))))))
  56.       (setq a (cdr a)))
  57. )

  58. ; restore saved mode settings
  59. (defun MODER ()
  60.    (repeat (length MLST)
  61.       (setvar (caar MLST) (cadar MLST))
  62.       (setq MLST (cdr MLST))
  63.    )
  64. )

  65. (defun explain()
  66. (textscr)
  67. (princ "\n\n")
  68. (princ
  69. "Constructs a 3D polyline using 3dpoly with exactly the same vertices as the\n")
  70. (princ
  71. "selected 2D polyline.  The 2D polyline is then deleted leaving only the 3D\n")
  72. (princ "polyline.\n\n")
  73. (princ
  74. "Options available for assigning the z-value to the new 3D polyline(s) are:\n\n")
  75. (princ "   1  -  user-specified global z-value for all 3D polylines\n")
  76. (princ "   2  -  user-specified z-value for each vertex of each 3D polyline\n")
  77. (princ "   3  -  existing 2D polyline z-value assigned to the 3D polyline\n\n")
  78. )

  79. ; main routine
  80. ; convert 2-d polyline to 3-d polyline
  81. ;
  82. (defun c:poly2to3(/ e1 ec ed emax en et el f1 f2 nent nver ss1 x y xyz zopt zval)
  83.    (cls)                              ; clear the text screen
  84.    (header)                           ; display header info
  85.    (modes '("BLIPMODE" "CMDECHO" ))   ; save modes
  86.    (setvar "cmdecho" 0)               ; turn off command echo
  87.    (setvar "blipmode" 0)              ; turn off blips

  88.    (explain)                          ; explain what program does and options
  89.    (initget 1 "1 2 3")
  90.    (setq zopt (getkword "Enter option for assigning z-value to 3D polyline (1, 2 or 3):  "))

  91.    (if (equal zopt "1")               ; global z-value option
  92.       (progn
  93.       (initget (+ 1 4))
  94.       (setq zval (getreal "\nEnter global z-value:  "))       ; get z-value
  95.       );end progn
  96.    );end if

  97.    (graphscr)
  98.    (princ "\nSelect 2-D polyline(s) to convert to 3-D polylines(s)...\n")
  99.    (if (setq ss1 (ssget))             ; ask the user to build a selection set
  100.       ; if the set isn't empty
  101.       ;   build selection set of polylines only
  102.       ;   by deleting all of the non-polylines in the set
  103.       (progn
  104.       (setq nent 0
  105.             emax (sslength ss1))
  106.       (prompt (strcat "\n" (itoa emax) " entitie(s) selected.\n"))
  107.       (while (< nent emax)
  108.          (setq en (ssname ss1 nent)
  109.                ed (entget en))
  110.          (if (/= "POLYLINE" (fld 0 ed))
  111.             (progn
  112.             (ssdel en ss1)
  113.             (setq nent (1- nent)
  114.                   emax (1- emax))
  115.             )
  116.          )
  117.          (setq nent (1+ nent))
  118.       ); end while

  119.       (setq nent 0
  120.             emax (sslength ss1))               ; number of polylines
  121.       (prompt (strcat (itoa emax) " polyline(s) found.\n"))

  122.       ; loop through polylines
  123.       ; add 3-D 3dpoly vertex for each 2-D vertex
  124.       
  125.       (if (> emax 0)
  126.          (progn
  127.          (setq nent 0
  128.                emax (sslength ss1))            ; number of polylines

  129.          (while (< nent emax)
  130.             (setq en (ssname ss1 nent))
  131.             (setq e1     en
  132.                   ed     (entget en)
  133.                   nver 0
  134.                   ec     (fld 62 ed)
  135.                   et     (fld  0 ed)
  136.                   f1     (fld 70 ed)
  137.             )

  138.             (if (= et "POLYLINE" )
  139.                (princ (strcat "Converting pline to 3dpoly <using "
  140.                                (cond ((equal zopt "1") (strcat
  141.                                                         "GLOBAL z-value: "
  142.                                                         (rtos zval 2 2)))
  143.                                      ((equal zopt "2") "VERTEX z-value")
  144.                                      ((equal zopt "3") "2D z-value")
  145.                                )
  146.                               ">...\n")
  147.                )
  148.             );end if

  149.             (while (and (setq en (entnext en))
  150.                         (setq ed (entget en))
  151.                         (/= "SEQEND" (fld 0 ed)))
  152.                (setq xyz    (fld 10 ed)
  153.                      x      (car   xyz)
  154.                      y      (cadr  xyz)
  155.                      z      (caddr xyz)
  156.                      el     (fld  8 ed)
  157.                      et     (fld  0 ed)
  158.                      f2     (fld 70 ed)
  159.                )
  160. ;               (princ (strcat "### f1=" (itoa f1) ", f2=" (itoa f2) "\n"))
  161.                ;
  162.                ; add 3dpoly vertex for each ACTUAL 2-D vertex
  163.                ; ignore spline or curve fit vertices
  164.                (if (cond
  165.                      ((and (= et "VERTEX") (= 0 f2)) 1)
  166.                      ((and (= et "VERTEX") (= 2 (logand f1 2)) (= 0 f2)) 1)
  167.                      ((and (= et "VERTEX") (= 4 (logand f1 4)) (= 16 f2)) 1)
  168.                      (t nil)
  169.                    )
  170.                   (progn
  171.                   (redraw en 3)                         ; highlight segment
  172.                   (cond ((equal zopt "2")               ; vertex z-value option
  173.                            (initget (+ 1 4))
  174.                            (setq zval (getreal "Enter vertex z-value:  "))
  175.                         )
  176.                         ((equal zopt "3")               ; 2D z-value option
  177.                            (setq zval z)                ; assign 2D z-value
  178.                         )
  179.                   );end cond
  180.                   (setq nver (+ nver 1))
  181.                   (if (= 1 nver) (command "3dpoly"))    ; start 3dpoly
  182.                   (command (list x y zval))             ; add vertex
  183.                   );end progn
  184.                );end if
  185.                (redraw en 4)                            ; de-highlight segment
  186.             ); end while entnext

  187.             (setq nent (1+ nent))
  188.             (redraw e1 1)
  189.             (if (> nver 0)                     ; if we had any valid vertices
  190.                (progn
  191.                (command "")                    ; end 3dpoly
  192.                ;
  193.                ; assign attributes of old polyline to new polyline
  194.                ;
  195.                (if (= (logand 1 f1) 1) (command "pedit" "last" "c" ""))
  196.                (if (= (logand 2 f1) 2) (command "pedit" "last" "s" ""))
  197.                (if (= (logand 4 f1) 4) (command "pedit" "last" "s" ""))
  198.                (entdel e1)                     ; delete old polyline
  199.                (command "change" "last" "" "prop" "layer" el "")   ;change layer
  200.                (if (not (null ec))
  201.                   (command "change" "last" "" "prop" "color" ec "");change color
  202.                )
  203.                (princ (strcat "   added 3dpoly with " (itoa nver)
  204.                               " vertices \n"))
  205.                );end progn
  206.             ;else
  207.                (princ "Can't change polyline!\n")
  208.             );end if nver

  209.          );end while entity
  210.          );end progn

  211.       );end if emax > 0
  212.       );end progn

  213.    );end if ss1

  214.    (moder)                                     ; reset modes
  215.    (princ)
  216. ) ;end of poly2to3

  217. (header)                                       ; display header info
  218. (princ)

点评

长老说话很有大侠风范,为你点赞。  发表于 2021-12-3 10:46

评分

参与人数 2明经币 +2 收起 理由
USER2128 + 1 很给力!
donghuidong2003 + 1 很给力!霸气侧露。

查看全部评分

回复 支持 1 反对 0

使用道具 举报

发表于 2015-11-20 21:04 | 显示全部楼层

本帖子中包含更多资源

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

x
发表于 2015-11-21 14:04 | 显示全部楼层
lucas_3333 发表于 2015-11-20 20:06
很讨厌看到这种需要先支付才能浏览的贴子!

这种2D polyline 转 3D polyline 的贴子多的是 ,没必要这么神 ...

支持,很给力。
发表于 2017-9-4 17:24 | 显示全部楼层
支持,很给力。
发表于 2017-9-4 19:25 | 显示全部楼层
问下,二维多段线和三维多段线的区别是什么?
发表于 2021-12-2 10:11 | 显示全部楼层
chenjieq1990 发表于 2017-9-4 19:25
问下,二维多段线和三维多段线的区别是什么?

坐标点不一样,二维只有xy坐标,再加上一个标高来确定二维多段线的空间位置,三维多段线坐标点有xyz
发表于 2021-12-4 19:01 | 显示全部楼层
谢谢楼主分享
发表于 2021-12-11 20:04 | 显示全部楼层
请教大家,二维多段线中有圆弧怎么提取出其半径和凸度?
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-5-4 05:30 , Processed in 0.220852 second(s), 32 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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