Copy and Paste in place all filtered plines

Copy and Paste in place all filtered plines

vporrash141089
Advocate Advocate
468 Views
7 Replies
Message 1 of 8

Copy and Paste in place all filtered plines

vporrash141089
Advocate
Advocate

Hi every one!

 

I'm trying to create a lisp which will create "Border" layer then filter plines and run an if statement to paste all pline in same place.

 

I get an error saying that my sset is wrong... would appreciate it very much if someone could point me in the right direction...

 

I'm starting to learn so the code is probably all wrong... 😕 

 

 

(defun c:sp (/ ss1 )

(command "-layer" "make" "Border" "color" "6" "" "lt" "Continuous" "" "")  
  
(setq ss1 (ssget "x" (list '(cons 0 . "*POLYLINE") (cons 8 . "Polygon"))))
	(if (/= ss1 nil)
	 (progn
    	(command "COPYBASE" "0,0,0" ss1)
    	(command "PASTECLIP" "0,0,0")
    	(command ".chprop" ss1 "" "la" "Border" ""))
    )
  (princ)
)

 

 

Appreciate every comment

Regards,

0 Likes
Accepted solutions (3)
469 Views
7 Replies
Replies (7)
Message 2 of 8

ronjonp
Advisor
Advisor
Accepted solution

Try this .. you had dots in your CONS filters and the first on was quoted:

ronjonp_0-1665675898456.png

 

 

(defun c:sp (/ ss1)
  (command "-layer" "make" "Border" "color" "6" "" "lt" "Continuous" "" "")
  (if (setq ss1 (ssget "_" '((0 . "*POLYLINE") (8 . "Polygon"))))
    (progn (command "COPYBASE" "0,0,0" ss1)
	   (command "PASTECLIP" "0,0,0")
	   (command ".chprop" ss1 "" "la" "Border" "")
    )
  )
  (princ)
)

 

Message 3 of 8

vporrash141089
Advocate
Advocate

Thank you @ronjonp 

 

I'm still getting this error... Do you happen to know why?

Specify base point: 0,0,0
Select objects:   1 found

Select objects: PASTECLIP

*Invalid selection*
Expects a point or Window/Last/Crossing/BOX/ALL/Fence/WPolygon/CPolygon/Group/Add/Remove/Multiple/Previous/Undo/AUto/SIngle
; error: Function cancelled

 

Thank you so much for looking into it

0 Likes
Message 4 of 8

vporrash141089
Advocate
Advocate

Never mind I got it!

(defun c:sp (/ ss1)
(command "-layer" "make" "Border" "color" "6" "" "lt" "Continuous" "" "")
(if (setq ss1 (ssget "x" '((0 . "*POLYLINE") (8 . "Polygon"))))
(progn (command "COPYBASE" "0,0" ss1)
(command)
(command "PASTECLIP" "0,0" ss1)
(command ".chprop" ss1 "" "la" "Border" "")
)
)
(princ "\n Sucess...")
(princ)
)

Thanks alot!!!

0 Likes
Message 5 of 8

marko_ribar
Advisor
Advisor
Accepted solution

Here are 2 versions for you to look and study... First is based on your example using command functions, but then after execution you'll get memory occupied with entities - polylines... To avoid this I'd suggest second one - using (vla-copy) function - Visual Lisp extensions...

(defun c:sp ( / cmdfun cmderr ss )

  (defun cmdfun ( tokenslist flag ) ;;; tokenslist - command parameters list of strings ;;; flag - if "t" specified, upon successful execution returns t, otherwise if "nil" specified, return is always nil no matter what outcome of function execution is - it should be successful anyway if specified tokenslist was hardcoded correctly... ;;;
    (if command-s
      (if flag
        (if (not (vl-catch-all-error-p (vl-catch-all-apply (function command-s) tokenslist)))
          flag
        )
        (apply (function command-s) tokenslist)
      )
      (if flag
        (apply (function vl-cmdf) tokenslist)
        (apply (function command) tokenslist)
      )
    )
  )

  (defun cmderr ( linenum ) ;;; linenum - integer representing line number at which used (cmdfun) failed with success execution ;;;
    (prompt (strcat "\ncommand execution failure... error at line " (itoa linenum) " ..."))
  )

  (if (not (tblsearch "LAYER" "Border"))
    (if (not (cmdfun (list "_.-LAYER" "_make" "Border" "color" "6" "" "lt" "Continuous" "" "") t))
      (cmderr 24)
    )
  )
  (if (setq ss (ssget "_x" (list (cons 0 "*POLYLINE") (cons 8 "Polygon"))))
    (progn
      (if (not (cmdfun (list "_.COPYBASE" "_non" "0,0,0" ss "") t))
        (cmderr 30)
      )
      (if (not (cmdfun (list "_.PASTECLIP" "_non" "0,0,0") t))
        (cmderr 33)
      )
      (if (not (cmdfun (list "_.CHPROP" ss "" "la" "Border" "") t))
        (cmderr 36)
      )
    )
  )
  (princ)
)
(defun c:sp ( / ss i ex )

  (if (vl-catch-all-error-p (vl-catch-all-apply (function vlax-get-acad-object) nil)))
    (vl-load-com)
  )

  (if (not (tblsearch "LAYER" "Border"))
    (entmake (list (cons 0 "LAYER") (cons 2 "Border") (cons 62 6)))
  )
  (if (setq ss (ssget "_x" (list (cons 0 "*POLYLINE") (cons 8 "Polygon"))))
    (repeat (setq i (sslength ss))
      (setq ex (entget (vlax-vla-object->ename (vla-copy (vlax-ename->vla-object (ssname ss (setq i (1- i))))))))
      (entupd (cdr (assoc -1 (entmod (subst (cons 8 "Border") (assoc 8 ex) ex)))))
    )
  )
  (princ)
)

I hope it's now a little clearer to you... Keep going with study...

M.R.

Marko Ribar, d.i.a. (graduated engineer of architecture)
Message 6 of 8

vporrash141089
Advocate
Advocate

I will study that, thanks so much for the 2 versions!!

 

Regards,

0 Likes
Message 7 of 8

Kent1Cooper
Consultant
Consultant
Accepted solution

A small thing....

It's not necessary to specify Continuous linetype when Making a Layer.  That's the default.  [After all, you don't specify all the other default possibilities -- lock/unlock, plot/not, transparency, etc.]  It would be worth the code only if it's possible that the Layer already exists with some other linetype, and if so, you want to force it to the standard.

 

A less-small thing....

You can do more than one command within one (command) function.  That, combined with concluding the Copybase command's selection with a simple Enter instead of a (command) function with no arguments, means that you don't need the (progn) '"wrapper" for the 'then' argument, because it can all be done within one function:

....

(if (setq ss1 (ssget "x" '((0 . "*POLYLINE") (8 . "Polygon"))))
  (command ; then

    "_.COPYBASE" "0,0" ss1 ""
    "_.PASTECLIP" "0,0" ;;; removed your ss1 ;;;
    "_.chprop" ss1 "" "_layer" "Border" ""

  ); command
); if

....

Kent Cooper, AIA
0 Likes
Message 8 of 8

vporrash141089
Advocate
Advocate

Wow that's very interesting, did not know either one, thank you so much for your comments.

 

Regards,

0 Likes