Author Topic: keywords and SSGET  (Read 7820 times)

0 Members and 1 Guest are viewing this topic.

vladimirzm

  • Guest
keywords and SSGET
« on: July 26, 2006, 02:24:55 PM »
is there any way to get a message like:

Code: [Select]
Select objects or [opt1/opt2/opt3]:

through SSGET... or any other way

T.Willey

  • Needs a day job
  • Posts: 5251
Re: keywords and SSGET
« Reply #1 on: July 26, 2006, 02:52:59 PM »
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?
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

vladimirzm

  • Guest
Re: keywords and SSGET
« Reply #2 on: July 26, 2006, 05:24:58 PM »
I want to select an object in a specific layer to modify it:

Code: [Select]
(ssget '((8 . "LAYER1")))
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]
Select objects or [Layer]:

have you seen the EXOFFSET command?


CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: keywords and SSGET
« Reply #3 on: July 26, 2006, 05:43:22 PM »
Here is an old routine I made. May be of some use to you.

Code: [Select]
;;;=======================[ 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
)
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.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: keywords and SSGET
« Reply #4 on: July 26, 2006, 05:47:24 PM »
I want to select an object in a specific layer to modify it:

Code: [Select]
(ssget '((8 . "LAYER1")))
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]
Select objects or [Layer]:

have you seen the EXOFFSET command?



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: [Select]
(if
 (and
  (setq Sel (entsel "\n Select object: "))
  (setq EntData (entget (car Sel)))
  (= (cdr (assoc 8 EntData)) "0")
 )
 ... do what you want....
)

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: [Select]
(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 ....
 )
)
Hope that makes sense.  Or you can use Alan's code, or parts thereof.
« Last Edit: July 26, 2006, 05:48:35 PM by T.Willey »
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

vladimirzm

  • Guest
Re: keywords and SSGET
« Reply #5 on: July 27, 2006, 12:42:33 AM »
thnx
T.Willey that's the idea... but i need to select objects not only one entity.
it's a very simple command that obtains the total length of the selected objects, but only if they are on the rigth layer.

Code: [Select]
Select objects or [Layer]: ---> if object are selected and right clic, will show the total lenght in an alert message. End of command.
But the layer change on every drawing:
Code: [Select]
Select objects or [Layer]: ---> L Enter
Select object to get layer [Type]: ---> the layer is obtained, and shows the first message.


I can do it with a "previous" option:

Code: [Select]
Select an option [Add lengths/Layer] <Add lengths>:
but it's such a simple command that this is not necessary



ronjonp

  • Needs a day job
  • Posts: 7526
Re: keywords and SSGET
« Reply #6 on: July 27, 2006, 08:46:23 AM »
Maybe you could use this:

Code: [Select]
(defun c:plen
      (/ u-clayer index ent lay ents keyw sl XX obj len output
       defsel2 fn keyw3)
(defun get-center (obj / ll ur)
  (vla-getboundingbox obj 'll 'ur)
  (setq ll (vlax-safearray->list ll)
ur (vlax-safearray->list ur)
  )
  (trans (vlax-safearray->list
   (vlax-variant-value
     (vlax-3d-point
       (polar ll (angle ll ur) (/ (distance ll ur) 2.0))
     )
   )
)
0
1
  )
)
(defun rjp-addtext (ins hgt txt /)
  (entmake (list (cons 0 "TEXT")
(cons 10 (trans ins 1 0))
(cons 40
       (if (= (getvar 'tilemode) 1)
(* (getvar 'dimscale) hgt)
hgt
       )
)
(cons 1 txt)
   )
  )
)
  (command ".undo" "begin")
  (defun *error* (msg)
    (if
      (not
(member
  msg
  '("console break"
    "Function cancelled"
    "quit / exit abort"
    ""
   )
)
      )
       (princ (strcat "\nError: " msg))
    )
    (setvar 'clayer u-clayer)
    (princ)
  )
  (setq u-clayer (getvar 'clayer))
  (setq index 0)
  (while
    (= ent nil)
     (setq ent (entsel "\n Select object to set layer filter: "))
     (if (= ent nil)
       (Alert "\nNothing Selected!")
     )
  )
  (setq lay (cdr (assoc 8 (entget (car ent)))))
  (setq ents "LINE,LWPOLYLINE,POLYLINE,SPLINE,ARC,CIRCLE")
  (if (not *defsel3*)
    (setq *defsel3* "Yes")
  )
  (initget 0 "Yes No")
  (setq keyw3
(cond
   ((getkword
      (strcat "\nInsert length text for each object? (Yes / No): <<"
      *defsel3*
      ">>: "
      )
    )
   )
   (*defsel3*)
)
  )
  (setq *defsel3* keyw3)
  (if (not *defsel*)
    (setq *defsel* "Select")
  )
  (initget 0 "Select All")
  (setq keyw
(cond
   ((getkword
      (strcat "\nEnter selection option (Select / All): <<"
      *defsel*
      ">>: "
      )
    )
   )
   (*defsel*)
)
  )
  (setq *defsel* keyw)
  (cond
    ((= Keyw "Select")
     (setq sl (ssget (list (cons '0 ents) (cons '8 lay))))
    )
    ((= Keyw "All")
     (setq sl (ssget "X" (list (cons '0 ents) (cons '8 lay))))
    )
  )
  (progn
    (setq XX (1- (sslength sl)))
    (while (>= XX 0)
      (setq ent (ssname sl XX))
      (setq obj (vlax-ename->vla-object ent))
      (setq pt (get-center obj))
      (setq
len
(vlax-curve-getdistatparam obj (vlax-curve-getendparam obj))
      )
      (setq index (+ index len)
    XX   (1- XX)
      )
      (if (= Keyw3 "Yes")
(progn
  (if (or (= (getvar 'lunits) 3) (= (getvar 'lunits) 4))
    (rjp-addtext pt 0.15 (rtos (/ len 12) 3 0))
    (rjp-addtext pt 0.15 (rtos (/ len 1) 2 2))
  )
)
      )
    )
    (if (or (= (getvar 'lunits) 3) (= (getvar 'lunits) 4))
      (setq output
     (strcat "\n"
     (rtos (sslength sl) 2 0)
     " objects on layer ''"
     lay
     "'' have a total length of  -  "
     (rtos (/ index 1) 3 0)
     "\n"
     "Current drawing units are set to architectural."
     )
      )
      (setq output
     (strcat "\n"
     (rtos (sslength sl) 2 0)
     " objects on layer ''"
     lay
     "'' have a total length of  -  "
     (rtos (/ index 1) 2 0)
     "\n"
     "Current drawing units are set to decimal."
     )
      )
    )
    (alert output)
    (princ output)
    (command ".undo" "end")
  )
  (princ)
  (if (not *defsel2*)
    (setq *defsel2* "Yes")
  )
  (initget 0 "Yes No")
  (setq keyw
(cond
   ((getkword
      (strcat "\nExport results to "
      (getvar "dwgprefix")
      "length.txt? (Yes / No): <<"
      *defsel2*
      ">>: "
      )
    )
   )
   (*defsel2*)
)
  )
  (setq *defsel2* keyw)
  (cond
    ((= Keyw "Yes")
     (setq fn (open (strcat (getvar "dwgprefix") "length.txt") "a"))
     (write-line output fn)
     (close fn)
    )
    ((= Keyw "No")
     (prompt "Maybe next time..")
     (princ)
    )
  )
  (*error* "")
  (setvar 'clayer u-clayer)
  (princ)
)





Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: keywords and SSGET
« Reply #7 on: July 27, 2006, 09:48:40 AM »
vladimirzm
To do as you want you will need a grread routine.
Look around here to see some examples.
I'd help but mom's have her gall bladder out in a few hours so I'm out of the loop the rest of today.


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.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: keywords and SSGET
« Reply #8 on: July 27, 2006, 11:26:30 AM »
vladimirzm
To do as you want you will need a grread routine.
Look around here to see some examples.
I'd help but mom's have her gall bladder out in a few hours so I'm out of the loop the rest of today.



Hope everything goes smoothly Alan.

So you want to keep selecting plines until enter is hit.  Once you have your layer, I would do it like

Code: [Select]
(setq TotArea 0)
(setvar "errno" 0)
(while (not (equal (getvar "errno") 52))
 (if
  (and
   (setq Sel (entsel "\n Select pline to get area: "))
   (= (cdr (assoc 0 (entget (car Sel)))) "LWPOLYLINE")
   (= (cdr (assoc 8 (entget (car Sel)))) LayName)
   (setq Obj (vlax-name->vla-object (car Sel))
  )
  (setq TotArea (+ (vla-get-Area Obj) TotArea))
 )
 )
(alert (strcat "Total area = " (rtos TotArea 2 2)))
Where the variable LayName is the layer name you want to filter for.
« Last Edit: July 27, 2006, 11:27:33 AM by T.Willey »
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

vladimirzm

  • Guest
Re: keywords and SSGET
« Reply #9 on: July 30, 2006, 05:35:15 PM »
ronjonp
that was what i wanted to avoid, it's nice but it's so complicated for a simple command.

vladimirzm
To do as you want you will need a grread routine.
Look around here to see some examples.
I'd help but mom's have her gall bladder out in a few hours so I'm out of the loop the rest of today.

Yes! i think this is the way, but how to show a context menú (to select Layer option)? this is the way i work.

i think my bad english is not helping  :| . Here's my routine:

Code: [Select]
(defun c:metrar (/ objs n dstt ep obj dst)

  (prompt "\nSelect objects: ")
  (setq objs (ssget '((8 . "METRAR"))))
 
  (setq n 0 dstt 0)
  (repeat (if (null objs) 0 (sslength objs))
    (if (metrar_vdat)
(progn  
  (setq dst (vlax-curve-getDistAtPoint obj ep)
dstt (+ dstt dst)
  )
  (setq n (1+ n))
)
        (setq n (1+ n))
    )
  )

  (if (> dstt 0)
    (alert (strcat "  Total length: \t" (rtos dstt 2 6) "         "))
    (alert "  Total length: \t 0.00         ")
  )
 
(princ)
)

(defun metrar_vdat ()
  (setq obj (vlax-ename->vla-object (ssname objs n)))
  (if (vl-catch-all-error-p
(setq ep (vl-catch-all-apply 'vlax-curve-getendPoint (list obj)))
      )
      (setq obj nil ep nil)
  )
  ep
)

I want to be able to change the layer to filter

Code: [Select]
Select objects or [Layer]:

and continue normally.