Author Topic: errno ?? missed ss or Enter pressed  (Read 4710 times)

0 Members and 1 Guest are viewing this topic.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
errno ?? missed ss or Enter pressed
« on: August 06, 2004, 06:37:19 PM »
Having trouble getting this to work.
I want to be able to tell if the user presses ENTER
OR just missed any matching blocks.

Code: [Select]
(prompt
  "\n*-*  Select the Blocks to Check or ENTER for all blocks. *-*"
)
(setvar "errno" 0); reset error code
;;  get user selected set to process
(if (and (null (setq ss (ssget (list (cons 2 blkname) (cons 0 "insert")))))
         (= (getvar "errno") 52)
    )
  ;;  User pressed Enter, so get all blocks to check
  (setq ss (ssget "_X" (list (cons 2 blkname) (cons 0 "insert"))))
)
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.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
errno ?? missed ss or Enter pressed
« Reply #1 on: August 06, 2004, 09:01:59 PM »
CAB,

You may be making it a little more complicated than necessary.

SSGET returns the name of the created selection set if successful, or nil if no objects were selected.
... So ..

(test "SDS22PF")
Code: [Select]

(defun test (BlockName / ss sslist )
 
  (setq sslist (list (cons 0 "insert") (cons 2 BlockName)))
 
  (prompt (strcat "\nSelect Blocks '" BlockName "' : "))
  ;;
  ;;
  (if (not (setq ss (ssget sslist)))
(progn
(Alert "Enter Pressed.  \nAutoselecting all matching blocks .. ")
(setq ss (ssget "X" sslist))
)
  )
  (alert
(strcat (itoa (sslength ss)) " Blocks named " BlockName " selected.")
  )
)
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
errno ?? missed ss or Enter pressed
« Reply #2 on: August 06, 2004, 09:08:54 PM »
.. and you can still do this :

Command: (test "SDS22PF")

Select Block 'SDS22PF' :
Select objects: _prev
1 found

Select objects: _last
1 found, 2 total

Select objects:  < enter here >
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
errno ?? missed ss or Enter pressed
« Reply #3 on: August 06, 2004, 11:44:00 PM »
Kerry,
Thanks for the INPUT. :)

Although what I was trying to do is use the ENTER as a flag to get
blocks from all the database "X" and not if the user tried to select
a group of objects but failed to get any matching blocks. After some
more testing I see that the ssget with a filter returns a null set
when non matching objects are attempted to be selected. At that point
pressing the enter key is the same as no attempt to select and pressing
the enter key. Therefore there is no way to know if the user wants the
selection set of the entire database or actually missed in there attempt
at selecting matching objects. Using ssget without a filter pretty much
ensures that something will be selected. This makes it more likely that
a null section set was a user pressing enter as a signal to use the
entire database.

Because ssget does not honor keywords i don't see a way to clearly signal
the routine to use the entire database only when enter alone was pressed.

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

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
errno ?? missed ss or Enter pressed
« Reply #4 on: August 07, 2004, 12:11:19 AM »
This is how I ended up handling it.
IF selection set was nil a prompt [Y/N] determines if the entire database is used.


Code: [Select]
;;;  CAB 08/04/04
;;; Unmirror blocks selected by user
;;;
;;;
(defun c:bum (/ usercmd ss ent blkname yesno cnt i e ei)
  (setq usercmd (getvar "CMDECHO"))
  (setvar "CMDECHO" 0)
  (command "undo" "begin")
  (and
    (setq ent (entsel "\nSelect the block to unmirror."))
    (= (cdr (assoc 0 (setq ent (entget (car ent))))) "INSERT")
    (setq blkname (cdr (assoc 2 ent)))
    (null
      (prompt
        "\n*-*  Select the Blocks to Check or ENTER for all blocks. *-*"))
    (setvar "errno" 0) ; reset error code
    ;;  get user selected set to process
    (if (null (setq ss (ssget (list (cons 2 blkname) (cons 0 "insert")))))
      (progn
        (initget "Yes No")
        (setq yesno (getkword "Get blocks from entire drawing? <Yes>/No: "))
        (if (or (= yesno nil) (= yesno "Yes"))
          ;;  User pressed Enter, so get all blocks to check
          (setq ss (ssget "_X" (list (cons 2 blkname) (cons 0 "insert"))))
          ;;  ELSE return nil to end routine
          nil
        ) ;end if
      ) ; progn
      T
    ) ; endif
    (setq i 0
          cnt 0
    )
    (repeat (sslength ss) ;for each insert
      (setq e  (ssname ss i)
            i  (1+ i)
            ei (entget e))
      (if (and (assoc 41 ei) ; x scale
               (< (cdr (assoc 41 ei)) 0))
        (progn
          (setq cnt (1+ cnt))
          (entmod (subst (cons 41 (abs (cdr (assoc 41 ei)))) (assoc 41 ei) ei)))
      ); endif
    ); repeat
    (prompt (strcat "\n*-* " (itoa cnt) " Blocks changed. *-*"))
  ) ; and
  (command "undo" "end")
  (setvar "CMDECHO" usercmd)
  (princ)
) ;defun
(prompt "\nBlock Unmirror Loaded, Enter BUM to run..")
(princ)
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.

SMadsen

  • Guest
errno ?? missed ss or Enter pressed
« Reply #5 on: August 07, 2004, 07:49:52 AM »
Good job, CAB

FYI, error 52 only works for explicit single selection, ":S". The other sset error codes (2-4) are not issued on empty picks.

David Bethel

  • Swamp Rat
  • Posts: 656
errno ?? missed ss or Enter pressed
« Reply #6 on: August 07, 2004, 08:49:54 AM »
I prefer (cond) testing:  -David

Code: [Select]

(defun ssbn (bn / bl ss)
  (setq bl (list (cons 0 "INSERT")(cons 2 bn)))
  (cond ((setq ss (ssget bl))
         (alert (strcat "(" (rtos (sslength ss) 2 0) ") "
                        (strcase bn) " Inserts Found")))
        ((setq ss (ssget "X" bl))
         (alert (strcat "(" (rtos (sslength ss) 2 0) ") "
                        (strcase bn) " Inserts Found")))
        (alert (strcat "No " (strcase bn) " Inserts Found")))
  ss)
R12 Dos - A2K

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
errno ?? missed ss or Enter pressed
« Reply #7 on: August 07, 2004, 10:19:25 AM »
Thanks David,
Here is another revision.

Code: [Select]
;;;  CAB 08/04/04  Version 1.2
;;;  Unmirror blocks selected by user
;;;  changes x scale to a positive number
;;;
(defun c:bum (/ usercmd ss ent blkname yesno cnt i e ei)
  (setq usercmd (getvar "CMDECHO"))
  (setvar "CMDECHO" 0)
  (command "undo" "begin")
  (if (and (setq ent (entsel "\nSelect the block to unmirror."))
           (= (cdr (assoc 0 (setq ent (entget (car ent))))) "INSERT"))
     (progn
       (setq blkname (cdr (assoc 2 ent)))
       (prompt "\n*-*  Select the Blocks to Check or ENTER for all blocks. *-*")
       (cond
         ;;  get user selected set to process
         ((setq ss (ssget (list (cons 2 blkname) (cons 0 "insert"))))
         ) ; end cond 1
         ((progn ; returns nil if user says no, or nil if no matching blocks
            ;;   in database or returns matching blocks in ss
            (initget "Yes No")
            (setq yesno (getkword "Get blocks from entire drawing? <Yes>/No: "))
            (if (or (= yesno nil) (= yesno "Yes"))
              ;;  User pressed Enter, so get all blocks to check
              (setq ss (ssget "_X" (list (cons 2 blkname) (cons 0 "insert"))))
              ;;  ELSE return nil to end routine
            ) ;end if
          ) ; progn
         ) ; end cond 2
         ;; nil response from above, prompt always returns nil
         ((prompt "\nUser quit or nothing selected."))
       ) ; end cond stmt
       (if ss
         (progn
           (setq i 0
                 cnt 0
           )
           (repeat (sslength ss) ;for each insert
             (setq e  (ssname ss i)
                   i  (1+ i)
                   ei (entget e)
             )
             (if (and (assoc 41 ei) ; x scale
                      (< (cdr (assoc 41 ei)) 0)
                 )
               (progn
                 (setq cnt (1+ cnt))
                 (entmod (subst (cons 41 (abs (cdr (assoc 41 ei)))) (assoc 41 ei) ei)
                 )
               )
             ) ; endif
           ) ; repeat
           (prompt (strcat "\n*-* " (itoa cnt) " Blocks changed. *-*"))
         ) ; progn
      ) ; endif
     ) ; progn
  ) ; endif
  (command "undo" "end")
  (setvar "CMDECHO" usercmd)
  (princ)
) ;defun
(prompt "\nBlock Unmirror Loaded, Enter BUM to run..")
(princ)
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.

David Bethel

  • Swamp Rat
  • Posts: 656
errno ?? missed ss or Enter pressed
« Reply #8 on: August 07, 2004, 11:06:50 AM »
I took a look see at tho whole deal:

Code: [Select]


;;  CAB 08/04/04  Version 1.2
;;;  Unmirror blocks selected by user
;;;  changes x scale to a positive number
;;;
;| MODIFIED 08-07-2004 |;

(defun c:bum (/ usercmd sst bn ss en ed i)
  (setq usercmd (getvar "CMDECHO"))
  (setvar "CMDECHO" 0)
  (command "undo" "begin")
  (while (or (not sst)
             (> (sslength sst) 1))
         (princ "\nSelect Block To UnMirror")
         (setq sst (ssget '(( 0 . "INSERT")
                            (-4 . "<")
                            (41 . 0)))))
  (setq bn (strcase (cdr (assoc 2 (entget (ssname sst 0))))))

  (princ (strcat "\n*-*  Select the INSERTs "
                  bn " to Unmirror or ENTER for all blocks. *-*"))

  (cond ((setq ss (ssget (list (cons 2 bn)
                              '( 0 . "INSERT")
                              '(-4 . "<")
                              '(41 . 0)))))
        ((setq ss (ssget "X" (list (cons 2 bn)
                                  '( 0 . "INSERT")
                                  '(-4 . "<")
                                  '(41 . 0))))))
  (setq i (sslength ss))
  (while (not (minusp (setq i (1- i))))
         (setq en (ssname ss i)
               ed (entget en)
               ed (subst (cons 41 (abs (cdr (assoc 41 ed))))
                                  (assoc 41 ed) ed))
         (entmod ed)
         (entupd en))
  (princ (strcat "\n*-* " (rtos (sslength ss) 2 0) " Block(s) changed. *-*"))

  (command "undo" "end")
  (setvar "CMDECHO" usercmd)
  (princ))

(prompt "\nBlock Unmirror Loaded, Enter BUM to run..")
(princ)




1)  Filter out  unmirrored blocks

2) Your prompt says to hit enter to select all blocks.  Why ask again.  If the user needs to quit, then escape or cancel out.

3) If selection sst is T, then ss must always return T

4) I prefer (not (minusp ...)) decremental counters.  Personal prefrence

5) A large slection set ( over 32,767 ) returns a REAL ( don't ask me why, ask ADESK )
R12 Dos - A2K

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
errno ?? missed ss or Enter pressed
« Reply #9 on: August 07, 2004, 01:14:14 PM »
Quote from: David
I took a look see at the whole deal:

Thanks David,
I like your solution. Although I have read Stigs tutorial on ssget filters but
I have yet to use the -4 feature myself.
Your item 2, yes I just could not figure a way around it. That was the original reason
for the post. Thanks for the solution.
4. actually I do to, but I borrowed that portion of code & was too lazy to re write it.
5. good to know.

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.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
errno ?? missed ss or Enter pressed
« Reply #10 on: August 07, 2004, 01:53:25 PM »
My reason for creating this routine was to fix the electrical plans
when reversing the house. It drove me crazy looking at the switch
symbols and recess cans where they were obviously backwards.
This routine works well for symmetrical blocks but I was thinking about
how to deal with blocks where the insertion point is lower left.
To get them to revert to the un-mirrored state and remain in the same
location it would seem like using the GetBoundingBox function and
determine the center. Then mirror the insert based on that point.
I suppose there would be a problem with the method if the insert was
rotated other that 90 degree increments?
Any thoughts? Has this already been done?
Not that I have an immediate need for the routine, just curious.

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.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
errno ?? missed ss or Enter pressed
« Reply #11 on: August 07, 2004, 02:06:40 PM »
Ok, did some testing & looks like the mirrored, rotated block has a -1 x scale
and the rotation is not zero.
So all there is to it is use the command ucs to match the block rotation, determine
the center point via getboundingbox, mirror from that point using the ( / pi 2 )
angle. Sound like a plan?

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.

David Bethel

  • Swamp Rat
  • Posts: 656
errno ?? missed ss or Enter pressed
« Reply #12 on: August 07, 2004, 03:49:03 PM »
I'm an R12DOS kinda guy.  ( getboundingbox ) doesn't exist in my world.  Sorry.  -David
R12 Dos - A2K