Author Topic: how to carry out the Copy Element?  (Read 1791 times)

0 Members and 1 Guest are viewing this topic.

2e4lite

  • Guest
how to carry out the Copy Element?
« on: October 19, 2013, 11:13:22 PM »
    The following is Specific requirements: 
    Specify an element that you want to copy. Able to polyline part of the specified segment copied out, but also can choose other line or polyline to copy.Specify a base point for the target figure or enter the base point coordinate. Finally,specify a destination point.

ribarm

  • Water Moccasin
  • Posts: 2091
  • Marko Ribar, architect
Re: how to carry out the Copy Element?
« Reply #1 on: October 20, 2013, 03:13:46 AM »
I didn't understand everything you asked, but for copying elements (segments) of polylines I have this code... Not fully tested, so please inform if something isn't as it should...

Code - Auto/Visual Lisp: [Select]
  1. (defun c:C2P (/ *error* cmd ss pt pl ptpar pt1 pt2 pll)
  2.  
  3.  
  4.   (defun *error* ( msg )
  5.     (if cmd (setvar 'cmdecho cmd))
  6.     (command "_.ucs" "p")
  7.   )
  8.  
  9.   (command "_.ucs" "w")
  10.   (setq cmd (getvar "CMDECHO"))
  11.   (setvar "CMDECHO" 0)
  12.  
  13.   (if (and (not (prompt "\nSelect polyline to copy with touching"))
  14.            (setq ss (ssget "_+.:S:L" '((0 . "LWPOLYLINE"))))
  15.            (setq pt (cadr (cadddr (car (ssnamex ss 0)))))
  16.            (setq pt (vlax-curve-getclosestpointto (setq pl (ssname ss 0)) pt))
  17.            (setq ptpar (vlax-curve-getparamatpoint pl pt))
  18.            (setq pt1 (vlax-curve-getpointatparam pl (float (fix ptpar))))
  19.            (setq pt2 (vlax-curve-getpointatparam pl (float (fix (+ ptpar 1.0)))))
  20.       )
  21.       (progn
  22.         (command "_.copy" pl "" '(0.0 0.0 0.0) '(0.0 0.0 0.0))
  23.         (setq pll (entlast))
  24.         (if (/= (float (fix ptpar)) 0.0)
  25.           (progn
  26.             (command "_.break" (car (nentselp pt)) pt1 pt1)
  27.             (command "_.break" (car (nentselp pt)) pt2 pt2)
  28.             (command "_.move" (entnext pll) "" pause pause)
  29.             (entdel pll)
  30.             (entdel (entnext (entnext pll)))
  31.           )
  32.           (progn
  33.             (command "_.break" (car (nentselp pt)) pt1 pt1)
  34.             (command "_.break" (car (nentselp pt)) pt2 pt2)
  35.             (command "_.move" pll "" pause pause)
  36.             (entdel (entnext pll))
  37.           )
  38.         )
  39.       )
  40.   )
  41.   (*error* nil)
  42.   (princ)
  43. )
  44.  

M.R.
« Last Edit: October 20, 2013, 05:32:51 AM by ribarm »
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

2e4lite

  • Guest
Re: how to carry out the Copy Element?
« Reply #2 on: October 20, 2013, 04:21:31 AM »
     Thanks for your reply,I have tested your C2P.lsp.  The code is no error but not what I want. Firstly, I need it can selected in different pline segments. Secondly, it preferably with window or crossing selection mode (e.g. (command "._select" (ssget "C" xx yy) pause) ). Of course, also need sigle selection mode in processing.

ribarm

  • Water Moccasin
  • Posts: 2091
  • Marko Ribar, architect
Re: how to carry out the Copy Element?
« Reply #3 on: October 20, 2013, 05:37:07 AM »
     Thanks for your reply,I have tested your C2P.lsp.  The code is no error but not what I want. Firstly, I need it can selected in different pline segments. Secondly, it preferably with window or crossing selection mode (e.g. (command "._select" (ssget "C" xx yy) pause) ). Of course, also need sigle selection mode in processing.

I can't follow you what do you request, but this is my revision of the code posted above... It should work and for old-heavy 2d polylines as well as 3d polylines... I thought you just wanted copying of pline segments...

Code - Auto/Visual Lisp: [Select]
  1. (defun c:C2P (/ *adoc* *error* cmd ss pt pl ptpar pt1 pt2 pll)
  2.  
  3.  
  4.   (defun *error* ( msg )
  5.     (if cmd (setvar 'cmdecho cmd))
  6.     (command "_.ucs" "p")
  7.     (vla-endundomark *adoc*)
  8.   )
  9.  
  10.   (vla-startundomark *adoc*)
  11.   (command "_.ucs" "w")
  12.   (setq cmd (getvar "CMDECHO"))
  13.   (setvar "CMDECHO" 0)
  14.  
  15.   (if (and (not (prompt "\nSelect polyline to copy with touching"))
  16.            (setq ss (ssget "_+.:S:L" '((0 . "LWPOLYLINE,POLYLINE"))))
  17.            (setq pt (cadr (cadddr (car (ssnamex ss 0)))))
  18.            (setq pt (vlax-curve-getclosestpointto (setq pl (ssname ss 0)) pt))
  19.            (setq ptpar (vlax-curve-getparamatpoint pl pt))
  20.            (setq pt1 (vlax-curve-getpointatparam pl (float (fix ptpar))))
  21.            (setq pt2 (vlax-curve-getpointatparam pl (float (fix (+ ptpar 1.0)))))
  22.       )
  23.       (progn
  24.         (command "_.copy" pl "" '(0.0 0.0 0.0) '(0.0 0.0 0.0))
  25.         (setq pll (entlast))
  26.         (if (eq (cdr (assoc 0 (entget pl))) "LWPOLYLINE")
  27.           (progn
  28.             (if (/= (float (fix ptpar)) 0.0)
  29.               (progn
  30.                 (command "_.break" (car (nentselp pt)) (osnap pt1 "_end") (osnap pt1 "_end"))
  31.                 (command "_.break" (car (nentselp pt)) (osnap pt2 "_end") (osnap pt2 "_end"))
  32.                 (command "_.move" (entnext pll) "" pause pause)
  33.                 (entdel pll)
  34.                 (entdel (entnext (entnext pll)))
  35.               )
  36.               (progn
  37.                 (command "_.break" (car (nentselp pt)) (osnap pt1 "_end") (osnap pt1 "_end"))
  38.                 (command "_.break" (car (nentselp pt)) (osnap pt2 "_end") (osnap pt2 "_end"))
  39.                 (command "_.move" pll "" pause pause)
  40.                 (entdel (entnext pll))
  41.               )
  42.             )
  43.           )
  44.           (progn
  45.             (if (and (/= (float (fix ptpar)) 0.0) (not (equal pt1 (vlax-curve-getendpoint pl) 1e-8)) (not (equal pt2 (vlax-curve-getendpoint pl) 1e-8)))
  46.               (progn
  47.                 (command "_.break" (car (nentselp pt)) (osnap pt1 "_end") (osnap pt1 "_end"))
  48.                 (command "_.break" (car (nentselp pt)) (osnap pt2 "_end") (osnap pt2 "_end"))
  49.                 (entdel (entlast))
  50.                 (command "_.move" (car (nentselp pt)) "" pause pause)
  51.                 (entdel (ssname (ssget "_X") 1))
  52.               )
  53.               (cond
  54.                 ( (and (not (equal pt1 (vlax-curve-getendpoint pl) 1e-8)) (= (float (fix ptpar)) 0.0))
  55.                   (progn
  56.                     (command "_.break" (car (nentselp pt)) (osnap pt2 "_end") (osnap pt2 "_end"))
  57.                     (entdel (entlast))
  58.                     (command "_.move" (car (nentselp pt)) "" pause pause)
  59.                   )
  60.                 )
  61.                 ( (equal pt1 (vlax-curve-getendpoint pl) 1e-8)
  62.                   (progn
  63.                     (command "_.break" (car (nentselp pt)) (osnap pt2 "_end") (osnap pt2 "_end"))
  64.                     (entdel (entlast))
  65.                     (command "_.move" (car (nentselp pt)) "" pause pause)
  66.                   )
  67.                 )
  68.                 ( (equal pt2 (vlax-curve-getendpoint pl) 1e-8)
  69.                   (progn
  70.                     (command "_.break" (car (nentselp pt)) (osnap pt1 "_end") (osnap pt1 "_end"))
  71.                     (entdel (ssname (ssget "_X") 1))
  72.                     (command "_.move" (car (nentselp pt)) "" pause pause)
  73.                   )
  74.                 )
  75.               )
  76.             )
  77.           )
  78.         )
  79.       )
  80.   )
  81.   (*error* nil)
  82.   (princ)
  83. )
  84.  

M.R.
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

Lee Mac

  • Seagull
  • Posts: 12225
  • London, England
Re: how to carry out the Copy Element?
« Reply #4 on: October 20, 2013, 08:47:51 AM »
Try the following quick draft:
Code - Auto/Visual Lisp: [Select]
  1. ;; Copy LWPolyline Segment  -  Lee Mac
  2. ;; Allows the user to copy a single selected LWPolyline segment, retaining all properties
  3. ;; of the LWPolyline parent.
  4. ;; Works under all UCS & View settings.
  5.  
  6. (defun c:cseg ( / *error* c e h l n s )
  7.  
  8.     (defun *error* ( msg )
  9.         (if (= 'ename (type c)) (entdel c))
  10.         (if (not (wcmatch (strcase msg t) "*break,*cancel*,*exit*"))
  11.             (princ (strcat "\nError: " msg))
  12.         )
  13.         (princ)
  14.     )
  15.    
  16.     (while
  17.         (progn (setvar 'errno 0) (setq s (nentsel "\nSelect LWPolyline segment to copy: "))
  18.             (cond
  19.                 (   (= 7 (getvar 'errno))
  20.                     (princ "\nMissed, try again.")
  21.                 )
  22.                 (   (vl-consp s)
  23.                     (setq e (entget (car s)))
  24.                     (cond
  25.                         (   (/= "LWPOLYLINE" (cdr (assoc 0 e)))
  26.                             (princ "\nObject is not an LWPolyline segment.")
  27.                         )
  28.                         (   (= 4 (logand 4 (cdr (assoc 70 (tblsearch "layer" (cdr (assoc 8 e)))))))
  29.                             (princ "\nObject is on a locked layer.")
  30.                         )
  31.                         (   (cddr s)
  32.                             (princ "\nObject is nested.")
  33.                         )
  34.                     )
  35.                 )
  36.             )
  37.         )
  38.     )
  39.     (if s
  40.         (progn
  41.             (setq n (fix (vlax-curve-getparamatpoint (car s) (vlax-curve-getclosestpointto (car s) (trans (cadr s) 1 0))))
  42.                   h (reverse (cons (assoc 210 e) (member (assoc 39 e) (reverse e))))
  43.                   h (subst (cons 70 (boole 4 1 (cdr (assoc 70 h)))) (assoc 70 h) h)
  44.                   h (subst '(90 . 2) (assoc 90 h) h)
  45.                   l (LM:LWVertices e)
  46.             )
  47.             (if (= 1 (logand 1 (cdr (assoc 70 e))))
  48.                 (setq l (append l (list (car l))))
  49.             )
  50.             (if (setq c (entmakex (append h (nth n l) (nth (1+ n) l))))
  51.                 (progn
  52.                     (command "_.move" c "")
  53.                     (while (= 1 (logand 1 (getvar 'cmdactive))) (command "\\"))
  54.                 )
  55.                 (princ "\nUnable to generate polyline segment.")
  56.             )
  57.         )
  58.     )
  59.     (princ)
  60. )
  61.  
  62. ;; LW Vertices  -  Lee Mac
  63. ;; Returns a list of lists in which each sublist describes the position,
  64. ;; starting width, ending width and bulge of a vertex of an LWPolyline
  65.  
  66. (defun LM:LWVertices ( e )
  67.     (if (setq e (member (assoc 10 e) e))
  68.         (cons
  69.             (list
  70.                 (assoc 10 e)
  71.                 (assoc 40 e)
  72.                 (assoc 41 e)
  73.                 (assoc 42 e)
  74.             )
  75.             (LM:LWVertices (cdr e))
  76.         )
  77.     )
  78. )
  79.  

CAB

  • Global Moderator
  • Seagull
  • Posts: 10339
Re: how to carry out the Copy Element?
« Reply #5 on: October 20, 2013, 06:24:04 PM »
     Thanks for your reply,I have tested your C2P.lsp.  The code is no error but not what I want. Firstly, I need it can selected in different pline segments. Secondly, it preferably with window or crossing selection mode (e.g. (command "._select" (ssget "C" xx yy) pause) ). Of course, also need sigle selection mode in processing.

Welcome to the Swamp.

Do you have any programing experience in LISP?
I've reached the age where the happy hour is a nap. ()
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

2e4lite

  • Guest
Re: how to carry out the Copy Element?
« Reply #6 on: October 21, 2013, 07:19:38 AM »
     In order to let you a deeper understanding of my request.The Gif format has been attached. in the animation, I can use the window selection and pickup selection method, the polyline segments and line entities are copied out. The methods and steps can be different with the animation, but to be able to achieve the same result very convenient.
« Last Edit: August 10, 2014, 12:27:09 AM by 2e4lite »

Lee Mac

  • Seagull
  • Posts: 12225
  • London, England
Re: how to carry out the Copy Element?
« Reply #7 on: October 21, 2013, 07:23:37 AM »
Looks like you either already possess such a program, or you want us to reverse engineer functionality offered by another program - either way, I'm out.