Author Topic: Moving points by selecting polyline  (Read 3643 times)

0 Members and 1 Guest are viewing this topic.

Scott

  • Bull Frog
  • Posts: 244
Moving points by selecting polyline
« on: January 29, 2004, 05:24:05 PM »
Original Post:

Okay, I asked this question on the other forum, but got limitted response. So I thought I would try it here. I need a lisp routine to move all objects within a polyline to a layer that is off. Does anyone have a lisp that will do this or can someone please write one for me. The lisp should create the layer then move all objects to this layer and then turn the layer off. I guess the lisp would have to move any objects touching the polyline as well. I need this to move survey points so I can do a proposed tin after I draw in a pond. Is this possible?

Thanks in advance
Scott

Okay, above is my original post.  After reading the other posts associated with this, I am confused.  First, I would love to learn to write "code", but I don't have a lot of time on my hands, I'm only about 6 months behind on my work.  I've tried to learn by reading other posts and asking questions, but I still don't get it.  So, if someone could help me out on this little problem I would appreciate it.  

The lisp I need will have to create a layer and move all points within or touching the polyline to this layer.  Then turn the layer off.  I'm not that familiar with autocad, so please bear with me.  I draw my top of berm elevations with a regular polyline.  I then use a program called ezysurf to create polyline back to original grade.  Basically it draws in the back slope of the berms.  This is the polyline I would like to be able to select, however, ther are times when this polyline is not closed, if that makes a difference.  I could use the polyline that denotes the top outside edge of my berm, this probably won't pickup all the points, but it would at least get the majority of them.  As for the points, they are plane jane autocad points.  Nothing fancy about them.  

Any help is greatly appreciated

Scott

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Moving points by selecting polyline
« Reply #1 on: January 29, 2004, 08:56:05 PM »
Well I'll give it a try.
Stealing Keith's code, I do that so well, I put it together as
shown below & tweaked it a bit.
I did not test the polyline but I did test the lwpolyline.
How do you make an old style polyline in ACAD2000?

The selection gets the lwpolyline too so it is turned off as well.
Can you filter it in the ssget? Or would you have to change it back
to it's original layer?


CAB


Code: [Select]
(defun move_to_layer (/ pl newlayer lwpolyline_data_list pline_vertice_list
     pline_data_list pline_vertice_list)

  (setq newlayer "My Layer");; change to your layer name

  (if
    (setq pl (entsel "\nSelect polyline that surrounds points to move."))
     (progn
       (setq pl (entget (car pl)))
       (cond
((= (cdr(assoc 0 pl)) "LWPOLYLINE")
 ;;select a lwpolyline and put the entity data in a list
 (setq lwpolyline_data_list pl)
 ;;as long as there is another point in the data list
 (while (setq lwpolyline_data_list
(member (assoc 10 lwpolyline_data_list)
lwpolyline_data_list))
   ;;add the point to the vertice list
   (setq pline_vertice_list
  (append pline_vertice_list
  (list (cdr (assoc 10 lwpolyline_data_list)))
  )
   )
   (setq lwpolyline_data_list (cdr lwpolyline_data_list))
 ); end while
) ; end cond lwpline


((= (cdr(assoc 0 pl)) "POLYLINE")
 ;;select a polyline and put the entity data in a list
 (setq pline_data_list pl)
 ;;as long as we have not reached the end of the complex polyline object
 (while (/= (cdr (assoc 0 pline_data_list)) "SEQEND")
   ;;grab the point data of the vertice
   (setq pline_vertice_list
  (append pline_vertice_list
    (list (cdr (assoc 10 pline_data_list)))
  )
   )
   ;;then find the next entry in the complex polyline
   (setq pline_data_list
  (entget (entnext (cdr (assoc -1 pline_data_list)))
  )
   )
 )
) ; end cond POLYLINE

((setq pline_vertice_list nil))
;; flag object selected was not a pline
       ) ; end cond stmt

       (if pline_vertice_list
(progn
  (command "_zoom" "E")
  ;; make sure all of the objects are visable
  ;;crossing polygon, select all objects crossed by and in the polygon
  (if (setq ss (ssget "_cp" pline_vertice_list))
    (progn
      (command "-layer" "M" newlayer "")
      (command ".change" ss "" "P" "LA" newlayer "" "")
      (command "-layer" "OFF" newlayer "")
    )
  )
  (command "_zoom" "P")
  ;; return view to previous
) ; end progn
(alert "\nObject selected was not a polyline.\t\n")
       ) ; endif
     ) ; end progn
  ) ; endif
) ; end defun
(princ)

(defun c:mtl ()
  (move_to_layer)
)
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.

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Moving points by selecting polyline
« Reply #2 on: January 29, 2004, 09:27:42 PM »
Damn CAB,  you are really taking off with this lisp thing aren't you.....

Anyway,  you CAN filter for objects in the SSGET call....

Use this ....
Code: [Select]
(ssget "_cp" pline_vertice_list '((0 . "POINT")))

Now two more bits of fixing needed ....

1.  Do not specify MAKE for a layer ... instead use NEW .. MAKE turns the new layer into the current layer, which cannot be turned off without a few more arguments later, and rightly so, why would you want the current layer OFF.

2. There is one too many carriage returns specified for the "change" command

and one final note ....
Turn off CMDECHO anytime you are using COMMAND with all of the arguments supplied, ,then turn it back on (or set to previous state) at the end of the function.
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Moving points by selecting polyline
« Reply #3 on: January 29, 2004, 11:35:33 PM »
Ok here are the changes & a few more.
Thanks Keith. :)  There are a lot of good teacher around here.

I had to kick it up a notch, added error routine, etc.

Just for my info, can you select all except the poly line in the ssget?

CAB

Edited:
Ok added
Code: [Select]
(ssdel (car plent) ss) ;remove this point from the selection set
Thanks to Guest for the idea

Code: [Select]
(defun move_to_layer (/        plent            pl
                      newlayer             lwpolyline_data_list
                      pline_vertice_list   pline_data_list
                      pline_vertice_list
                     )

  (defun *error* (msg)
    ;; error function & Routine Exit
    (if
      (not
        (member
          msg
          '("console break" "Function cancelled" "quit / exit abort" "")
        )
      )
       (princ (strcat "\nError: " msg))
    ) ; if

    ;;reset all variables here
    (setvar "CMDECHO" usercmd)
    (princ)
  ) ; end error function

  (setq newlayer "My Layer")  ;; change to your layer name
  (setq usercmd (getvar "CMDECHO"))
  (setvar "CMDECHO" 0)

  (if
    (setq
      plent (entsel "\nSelect polyline that surrounds points to move.")
    )
     (progn
       (setq pl (entget (car plent)))
       (cond
         ((= (cdr (assoc 0 pl)) "LWPOLYLINE")
          ;;select a lwpolyline and put the entity data in a list
          (setq lwpolyline_data_list pl)
          ;;as long as there is another point in the data list
          (while (setq lwpolyline_data_list
                        (member (assoc 10 lwpolyline_data_list)
                                lwpolyline_data_list
                        )
                 )
            ;;add the point to the vertice list
            (setq pline_vertice_list
                   (append pline_vertice_list
                           (list (cdr (assoc 10 lwpolyline_data_list)))
                   )
            )
            (setq lwpolyline_data_list (cdr lwpolyline_data_list))
          ) ; end while
         ) ; end cond lwpline


         ((= (cdr (assoc 0 pl)) "POLYLINE")
          ;;select a polyline and put the entity data in a list
          (setq pline_data_list pl)
          ;;as long as we have not reached the end of the complex polyline object
          (while (/= (cdr (assoc 0 pline_data_list)) "SEQEND")
            ;;grab the point data of the vertice
            (setq pline_vertice_list
                   (append pline_vertice_list
                           (list (cdr (assoc 10 pline_data_list)))
                   )
            )
            ;;then find the next entry in the complex polyline
            (setq pline_data_list
                   (entget (entnext (cdr (assoc -1 pline_data_list)))
                   )
            )
          )
         ) ; end cond POLYLINE

         ((setq pline_vertice_list nil))
         ;; flag object selected was not a pline
       ) ; end cond stmt

       (if pline_vertice_list
         (progn
           (command "_zoom" "E")
           ;; make sure all of the objects are visable
           ;;crossing polygon, select all POINTS crossed by and in the polygon
           (if ;; get a selection set of only the points
             (setq ss (ssget "_cp" pline_vertice_list '((0 . "POINT"))))
              (progn
                (if (not (tblsearch "LAYER" newlayer))
                  (command "-layer" "n" newlayer "")
                )
                ;; use the next line if the point filter is not used
                ;(ssdel (car plent) ss) ;remove this point from the selection set
                (command ".change" ss "" "P" "LA" newlayer "")
                (command "-layer" "OFF" newlayer "")
                (prompt (strcat "\nPoints have been moved to layer " newlayer)
                )
              )
           )
           (command "_zoom" "P") ;; return view to previous
         ) ; end progn
         (alert "\nObject selected was not a polyline.\t\n")
       ) ; endif
     ) ; end progn
  ) ; endif
  (*error* "");; call error routine to reset system vars (Stig:)
) ; end defun
(prompt "\nMove to Layer loaded, Enter MTL to run.")
(princ)

(defun c:mtl ()
  (move_to_layer)
)
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.

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Moving points by selecting polyline
« Reply #4 on: January 29, 2004, 11:53:13 PM »
Sure can ....

To exempt a specific item type, layer, color, linetype etc .... essentially ANY attribute of an entity hat has a DXF value associated with it, use this:

Code: [Select]

(ssget "_cp" pline_vertice_list '((-4 . "<NOT")(NUM . VALUE) (-4 . "NOT>")))


Now this will select EVERYTHING in the area defined by the pline_vertice_list EXCEPT any item with DXF code NUM and value of VALUE ....

For example this will select everything EXCEPT points:
Code: [Select]

(ssget "_cp" pline_vertice_list '((-4 . "<NOT")(0 . "POINT") (-4 . "NOT>")))


This will select everything that is not on layer 0
Code: [Select]

(ssget "_cp" pline_vertice_list '((-4 . "<NOT")(8 . "0") (-4 . "NOT>")))


and this will select everything that has an overridden color that is not red

Code: [Select]

(ssget "_cp" pline_vertice_list '((-4 . "<NOT")(62 . 1) (-4 . "NOT>")))


You can also use  <AND AND> <OR OR> <NOR NOR> and combinations of them.

Cool huh
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

Anonymous

  • Guest
Moving points by selecting polyline
« Reply #5 on: January 29, 2004, 11:53:28 PM »
This is my kick at the can!

;|  1) Create the layer you want to move the points to. Why not use "0" as
       there probably isn't (shouldn't) be anything on there anyway and you
       wouldn't have to create anything.
    2) Select the polygon, or create it first then select it.
    3) Make sure the polygon you are going to use is closed.
    4) Grab the points inside the polygon.
    5) Move them to your new layer.
    Word of Warning. If the point is not a point like this . but one of
    the fancy ones, then if it appears to cross the polygon, even though
    its insetion point is within the polygon it won't be selected.|;

Code: [Select]
(defun c:grabpts (/ wp thepoints entitylist ename)
  (setq ename (car (entsel "Select the polygon")));obvious

  (setq thepoints (ssget ;make the selection set (thepoints)
   "wp" ;change this to "cp" for a crossing polygon
   (LWPlineCList ename) ;get the vertex list of the pline
   (list (cons 0 "POINT")) ; a filter to grab points only
 )
  )
;for each of the points
  (while (and thepoints (> (sslength thepoints) 0))
    (setq ename  (ssname thepoints 0))  ;get it's ename
    (setq entitylist (entget ename))    ;get the list of its' properties
    (setq entitylist                    ;setup change - 8 is the dxf code for layer
  (subst (cons 8 "0") (assoc 8 entitylist) entitylist)
    )
    (entmod entitylist) ;make the change to layer "0"
    (ssdel ename thepoints)             ;remove this point from the selection set
  ) ;end while
  (princ)
)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun LWPlineCList (ename /   len      n
    ecode coords   windowpolygon
    entitylist NVertices
   )
  (setq
    entitylist (entget ename) ;get the entity list
    len       (length entitylist) ;get the length of the list
    n       0 ;set counter to zero
  )
  (repeat len ;repeat for the length of the entity list
    (setq ecode (car (nth n entitylist)))
;get each item in the entity list
;and strip the entity code number
    (if (= ecode 90) ;check for code 90 (number of vertices)
      (setq NVertices (list (cdr (nth n entitylist))))
;get the number of vertices as a list
    ) ;end if
    (if (= ecode 10) ;check for code 10 (vertex)
      (progn ;if it's group 10 do the following
(setq coords (cdr (nth n entitylist)))
;get the vertex (a list)
(setq windowpolygon (append windowpolygon coords))
      ) ;end progn
    ) ;end if
    (setq n (1+ n)) ;increment the counter
  ) ;end repeat
  (setq wp (xyList->ListOfPoints windowpolygon))
;make a list of vertices
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun xyList->ListOfPoints (coordList / ptlist)
  (while coordList
    (setq ptlist    (append ptlist ;make the list
   (list (list (car coordList) (cadr coordList)))
   ) ;end of append
 coordList (cddr coordList) ;drop the coords just put in list
    ) ;end of setq
  ) ;end of while
  ptlist ;return the point list
) ;end of defun
[/code]

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Moving points by selecting polyline
« Reply #6 on: January 30, 2004, 12:16:52 AM »
Thanks Keith.

That jogged my memory.
I remember reading something like that.
Never used it though.


Guest, you did it with out a single "command", very good.
I'll have to study you code a bit.

Glad you pointed the ssget point thingie out :)

CAB
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.

mohobrien

  • Guest
ToCab
« Reply #7 on: January 30, 2004, 08:11:55 PM »
Can't take credit for the last two functions. The extract vertices came from Rakesh Rao's download page and the list of points to coord pairs I think is from the acad garden path tutorial.

ahsattarian

  • Newt
  • Posts: 112
Re: Moving points by selecting polyline
« Reply #8 on: December 03, 2016, 05:50:04 AM »
hello
if your problem isn't solved tell me : ahsattarian3@gmail.com
i've written the same lisp
+989126049289
Amir