Code Red > AutoLISP (Vanilla / Visual)

keywords and SSGET

(1/2) > >>

vladimirzm:
is there any way to get a message like:


--- Code: ---Select objects or [opt1/opt2/opt3]:
--- End code ---


through SSGET... or any other way

T.Willey:
Not with ssget, but if you use entsel.. or others like it, then yes.  You can prompt before you use ssget, if they want to do other options, or methods of selecting.  What are you trying to do?

vladimirzm:
I want to select an object in a specific layer to modify it:


--- Code: ---(ssget '((8 . "LAYER1")))
--- End code ---

at the same time i want to allow type the name of the layer or select another object to obtain their layer for the next selection:


--- Code: ---Select objects or [Layer]:
--- End code ---


have you seen the EXOFFSET command?

CAB:
Here is an old routine I made. May be of some use to you.


--- Code: ---;;;=======================[ LayerMatch.lsp ]=======================
;;; Author: Copyright© 2005 Charles Alan Butler
;;; Version:  1.0 Dec. 12, 2005
;;; Purpose: Match Layer Property, Select or enter layer name
;;; Sub_Routines: -None
;;; Requirements: -Mone
;;; Returns: -nothing
;;;==============================================================
(defun c:LayerMatch (/ en ss entlst)
  (while (not en)
    (or (setq en
               (getpoint_or_text 2 "\nFor layer select entity or enter layer name: ")
        )
        (setq en t)
    )
    (if (listp en) ; point list
      (if (setq en (nentselp en)) ; get object
        (if (listp en) ; got something
          (progn
            (if (= (length en) 2)
              (setq en (car en))
              (setq en (last (nth 3 en)))
            )
            (setq redrawen en
                  en       (cdr (assoc 8 (entget en)))
            )
            (redraw redrawen 3)
          )
        )
      )

      (if (and (= (type en) 'str) ; else got a string
               (setq entlst (tblsearch "LAYER" en))
          ) ; valid layer?
        (cond
          ((= 1 (logand 1 (cdr (assoc 70 entlst))))
           (prompt "\n***  Layer is Frozen.")
          )
          ((= 4 (logand 4 (cdr (assoc 70 entlst))))
           (prompt "\n***  Layer is Locked.")
          )
        )
        (if (= (type en) 'str)
          (progn
            (setq en nil)
            (prompt "\n***  invalid layer name.")
          )
        )
      )
    )
  )

  (if (= (type en) 'str)
    (progn
      (prompt (strcat "\n** Changeing layer to " en))
      (while (not ss)
        (princ "\nSelect entities to change:   ")
        (setq ss (ssget))
      )
      (command "_.CHPROP" ss "" "_LA" en "")
      (and redrawen (redraw redrawen 4))
    )
    (prompt "\nInvalid layer choice, exit.")
  )
  (prin1)
)
(prompt "\nChange layer loaded, Enter ChangeLayer to run.")
(princ)


;;;=======================[ getpoint_or_text.lsp ]=======================
;;; Author: Copyright© 2005 Charles Alan Butler
;;; Version:  1.0 Dec. 12, 2005
;;; Purpose: To get user entered text or picked point
;;; Sub_Routines: -None
;;; Requirements: -ctype is the cursor type
;;;                      0  Display the normal crosshairs.
;;;                      1  Do not display a cursor (no crosshairs).
;;;                      2  Display the object-selection "target" cursor
;;;               -prmpt is the user prompt, start it with \n
;;; Returns: -the user entered text or picked point or nil
;;;==============================================================
(defun getpoint_or_text (ctype prmpt / char code data result flag p str)
  (vl-load-com)
  (vl-catch-all-apply
    '(lambda ()
       (setq flag t
             str ""
       )
       (princ prmpt)
       (while flag
         (setq p    (grread t 15 ctype)
               code (car p)
               data (cadr p)
         )
         (cond
           ((= code 3) ; clicked point
            (setq result data
                  flag nil
            )
           )
           ((= code 2) ; keyboard
            (setq char data)
            (cond
              ((<= 32 char 126)
               (princ (chr char))
               (setq str (strcat str (chr char)))
              )
              ((= char 8)
               ;; backspace was hit .. go chop off a character
               (and (> (strlen str) 0)
                    (princ (strcat (chr 8) " " (chr 8)))
                    (setq str (substr str 1 (1- (strlen str))))
               )
              )
              ((= char 13)
               (setq result str
                     flag nil
               )
              )
            )
           )
         )
       ) ;_ while
     )
  )
  result
)
--- End code ---

T.Willey:

--- Quote from: vladimirzm on July 26, 2006, 05:24:58 PM ---I want to select an object in a specific layer to modify it:


--- Code: ---(ssget '((8 . "LAYER1")))
--- End code ---

at the same time i want to allow type the name of the layer or select another object to obtain their layer for the next selection:


--- Code: ---Select objects or [Layer]:
--- End code ---


have you seen the EXOFFSET command?



--- End quote ---

If you want to select an object, use (entsel.... if you want to make sure it is on the right layer, use and (if... with an (and... statement.  If you want the user to be able to select an object for a layer for the next part of the operation, then use (initget... with (entsel... which will let you use kwords (can't think of a better way word to use).

So say you want to select something that is only one layer 0 first.

--- Code: ---(if
 (and
  (setq Sel (entsel "\n Select object: "))
  (setq EntData (entget (car Sel)))
  (= (cdr (assoc 8 EntData)) "0")
 )
 ... do what you want....
)

--- End code ---

Now if you want to be able to give the use an option to type in the layer, or pick an object.  You could code it like

--- Code: ---(if
 (and
  (not (initget "Layer"))
  (setq Sel2 (entsel "\n Select object on desired layer [Layer]: "))
 )
  (if (= Sel2 "Layer")
   .... prompt for a layer name ...
   .... do what you want if selected and object ....
 )
)

--- End code ---
Hope that makes sense.  Or you can use Alan's code, or parts thereof.

Navigation

[0] Message Index

[#] Next page

Go to full version