Author Topic: Select objects with ssget: how detect Enter pressed?  (Read 935 times)

0 Members and 1 Guest are viewing this topic.

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1451
  • Marco
Select objects with ssget: how detect Enter pressed?
« on: October 29, 2021, 01:22:57 PM »
How exit if Enter pressed?

; Example:
;  (ALE_SsGetFilter "Select attibuted block(s)" '((0 . "INSERT") (66 . 1)))
;
(defun ALE_SsGetFilter (PrmStr FltLst / FlgSlt SelSet)
    (princ "\n_ ")
    (prompt (setq PrmStr (strcat "\n" PrmStr ": ")))
    (while (not FlgSlt)
      (if (setq SelSet (ssget FltLst))
        (setq FlgSlt T)
        (prompt (strcat "\nNo valid objects, try again!" PrmStr))
      )
    )
    SelSet
)

ribarm

  • Gator
  • Posts: 3225
  • Marko Ribar, architect
Re: Select objects with ssget: how detect Enter pressed?
« Reply #1 on: October 29, 2021, 01:35:26 PM »
If enter pressed then your sel. set variable will be empty... If you need to proceed with empty sel. set and exit while loop, then you don't need while and even if check...

Simply :

Code: [Select]
(defun _ssget ( message filter / ss )
  (prompt (strcat "\n" message))
  (setq ss (ssget filter))
)

Then in the main routine, you do check :

Code: [Select]
...
  (if (setq ss (_ssget "SELECT" '((0 . "LINE"))))
    (progn
      -then do stuff
    )
    (progn
      -else do stuff [but empty ss]
    )
  )
  (princ)
)
« Last Edit: October 29, 2021, 01:46:45 PM by ribarm »
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1451
  • Marco
Re: Select objects with ssget: how detect Enter pressed?
« Reply #2 on: October 30, 2021, 06:04:33 AM »
If enter pressed then your sel. set variable will be empty... If you need to proceed with empty sel. set and exit while loop, then you don't need while and even if check...
...
Thanks  :-)  ...I have modified my function to play with Anonimous Block, suggestions?
Code: [Select]
(defun ALE_SsGetFilter (PrmStr FltLst BitFlg / Countr EffNms EntNam SelSet Ss_Out VlaObj)
;   PrmStr = User prompt [STR]
;   FltLst = ssget filter list [LIST] or nil for no filter
;   BitFlg = T to filter Anonimous Block by EffectiveName
;
; Example:
;   (ALE_SsGetFilter "Select attibuted block(s)" '((0 . "INSERT") (2 . "FOO") (66 . 1)) T)
;
    (if (and BitFlg (setq EffNms (assoc 2 FltLst)))
      (setq FltLst (subst (cons 2 (strcat (cdr EffNms) ",`*U*")) EffNms FltLst))
      (setq BitFlg nil)
    )
    (princ "\n_ ") (prompt (setq PrmStr (strcat "\n" PrmStr ": ")))
    (cond
      ( (not (setq SelSet (ssget FltLst))) (prompt "\nNull selection or invalid objects selected!") )
      ( BitFlg
        (repeat (setq Countr (sslength SelSet))
          (and
            (setq VlaObj (vlax-ename->vla-object (setq EntNam (ssname SelSet (setq Countr (1- Countr))))))
            (vlax-property-available-p VlaObj 'EffectiveName)
            (not (vlax-property-available-p VlaObj 'Path))
            (wcmatch (strcase (vla-get-effectivename VlaObj)) (strcase (cdr EffNms)))
            (if Ss_Out (setq Ss_Out (ssadd EntNam Ss_Out)) (setq Ss_Out (ssadd EntNam)))
          )
        )
        (if Ss_Out Ss_Out (prompt (strcat "\nInvalid block(s) " (cdr EffNms) " selected!"))) ; edit 2021 10 31
      )
      ( SelSet )
    )
)
;see edit 2021 10 31