Author Topic: xlines  (Read 2787 times)

0 Members and 1 Guest are viewing this topic.

krampaul82

  • Guest
xlines
« on: March 27, 2012, 01:50:50 PM »
 :-o

I use a bunch of xlines and I would like to be able to use a lisp routine to delete only xlines in a drawing. I have tried various selection set choices but cannot get xlines included. layer nuke would be a careful alternative but would like to avoid
that.

The following code works but i know there has to be a better way.  any help appreciated.

(defun c:clerase()(terpri)
   (command "-LAYER" "LOck" "*" "")
   (command "-LAYER" "Unlock" "Sketch" "")  ;all created xlines go on this layer
   (command "zoom" "extents" "")
   (command "zoom" "Scale" "0.5X" "")    ;so the user can see if anything other than x-lines will be deleted
   (alert "This will ERASE EVERYTHING on layer Sketch! \n non-faded items other than xlines will be gone!")
   (setvar "cmdecho" 0)
   (command "ERASE" "ALL"  "" )
   (command "-LAYER" "Unlock" "*" "")
   (command "-LAYER" "Set" "M-Field-Devices" "") ;The layer I usually work on
   (setvar "cmdecho" 1)
   (command "zoom" "Previous" "")
   (command "zoom" "Previous" "")
   (alert "You Can Press Undo repeatedly \n to get back, if any, lost data.")
   (princ)
)

danallen

  • Guest
Re: xlines
« Reply #1 on: March 27, 2012, 02:05:38 PM »
I use this.

-Dan

Code: [Select]
(defun-q c:EXLA ( / ss1)
  (princ "\nErase all xlines:")
  (if (setq ss1 (ssget "X" (list (cons 0 "XLINE")(cons 67 (if (xyz_is_paper) 1 0)))))
    (progn
      (command "erase" ss1 "")
      (princ (strcat "\nErased " (itoa (sslength ss1)) " xlines"))
    ) ;_progn
    (princ "\nNo xlines to erase")
  ) ;_if
  (princ)
)

;;;=========================================================================
;;; xyz_is_paper - returns nil for modelspace, T for paperspace
;;;  by Vladimir Nesterovsky
;;; use (cons 67 (if (xyz_is_paper) 1 0)) for ssget "X" of mspace vs. pspace
;;;  note that pspace will get all objects in layouts, not just current
;;;=========================================================================
(defun-q xyz_is_paper () (> 2 (getvar "cvport") (getvar "tilemode")))


Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: xlines
« Reply #2 on: March 27, 2012, 02:12:24 PM »
Quick one:

Code - Auto/Visual Lisp: [Select]
  1. (defun c:delxl nil (vl-load-com)
  2.         (vlax-for obj blk
  3.             (if (eq "AcDbXline" (vla-get-objectname obj))
  4.                 (vl-catch-all-apply 'vla-delete (list obj))
  5.             )
  6.         )
  7.     )
  8.     (princ)
  9. )

Will attempt to delete every XLine in every Layout, Block and nested Block (to any level)

krampaul82

  • Guest
Re: xlines
« Reply #3 on: March 27, 2012, 04:53:54 PM »
 :kewl:

Thank You LeeMac.

I am a Big Fan of your Code....
(No I am Not a Stalker :ugly:)

cudos to you as well danallen for your reply

krampaul82

  • Guest
Re: xlines
« Reply #4 on: March 27, 2012, 05:18:15 PM »
Could I trouble you one more time?
the following xline code works but is there a way to capture the current layer that this was executed from?

(defun c:claorg   ()(terpri)

     ;this is were i would like to capture the current layer before the script command sets a new layer
     ;i used various  getvar to no avail and i am sure i am missing somthing simple.  Any Help appreciated..Again...
 
   (command "-LAYER" "Set" "Sketch" "c" "cyan" "" "")
   (prompt "This puts a horizontal and vertical xlines at the current UCS origin...")
   (setvar "cmdecho" 0)
   (command "xline" "h" "0,0,0" "" )
   (command "xline" "v" "0,0,0" "")
   (command "-LAYER" "Set" "M-Field-Devices" "") ;I mostly use this layer
   (setvar "cmdecho" 1)
   (princ)
)

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: xlines
« Reply #5 on: March 27, 2012, 06:09:54 PM »
Thank You LeeMac.

I am a Big Fan of your Code....
(No I am Not a Stalker :ugly:)

Thanks krampaul!  :lol:

Could I trouble you one more time?
the following xline code works but is there a way to capture the current layer that this was executed from?

Give this a try:

Code - Auto/Visual Lisp: [Select]
  1. (defun c:claorg ( / *error* sysvar values )
  2.  
  3.     ;; Error Handler to reset System Variables if things go wrong
  4.     (defun *error* ( msg )
  5.         (mapcar 'setvar sysvar values)
  6.         (if (not (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*"))
  7.             (princ (strcat "\nError: " msg))
  8.         )
  9.         (princ)
  10.     )
  11.  
  12.     ;; Store current System Variables
  13.     (setq sysvar '(CMDECHO CLAYER OSMODE)
  14.           values  (mapcar 'getvar sysvar)
  15.     )
  16.  
  17.     ;; Set System Variables
  18.     (setvar 'CMDECHO 0)
  19.     (setvar 'OSMODE  0)
  20.  
  21.     ;; Tell user what's about to happen...
  22.     (prompt "This puts horizontal and vertical xlines at the current UCS origin...")
  23.  
  24.     ;; If "Sketch" layer exists...
  25.     (if (tblsearch "LAYER" "Sketch")
  26.         ;; Unlock it, Thaw it, Turn it On, and set it current
  27.         (command "_.-layer" "_U" "Sketch" "_T" "Sketch" "_ON" "Sketch" "_S" "Sketch" "")
  28.         ;; Otherwise create it (also sets it current)
  29.         (command "_.-layer" "_M" "Sketch" "_C" "_Cyan" "Sketch" "")
  30.     )
  31.  
  32.     ;; Create the XLines:
  33.     (command "_.xline" "_H" '(0.0 0.0 0.0) "" "_.xline" "_V" '(0.0 0.0 0.0) "")
  34.  
  35.     ;; Reset System Variables
  36.     (mapcar 'setvar sysvar values)
  37.  
  38.     ;; Exit Cleanly
  39.     (princ)
  40. )

You might also be interested in this old program of mine to automatically set the correct layer before a command:

http://lee-mac.com/layerdirector.html



By the way, regarding formatting code in your posts:

http://www.theswamp.org/index.php?topic=4429.0

efernal

  • Bull Frog
  • Posts: 206
Re: xlines
« Reply #6 on: March 27, 2012, 07:52:04 PM »
The old way...

Code - Auto/Visual Lisp: [Select]
  1. (defun c:delxl (/ s1)(if (setq s1 (ssget "_X" '((0 . "XLINE")(8 . "Sketch"))))(command "_.erase" s1 ""))(princ))
  2.  
e.fernal