Author Topic: <Help>How Add a transparent command (can be invoked when other command is runnin  (Read 2992 times)

0 Members and 1 Guest are viewing this topic.

chlh_jd

  • Guest
Hi all master , how to add a command can be invoked when other command is running not though type in "'cmd" .
In the following Example ,  it can be use like --->"MOVE"--->"'SS"..., but how can I use it like osnap command  method  --->"MOVE"--->"SS"
Code: [Select]
(defun SS_SS (/ ss1 i lst s1 layer_fili ss2 filiter pt)
  ;;layer-filter
  (defun ss-sel-grread (/ is_go_on)
     (setq is_go_on T)
      (while (and
       is_go_on
       (setq pt (grread t 4 2))
       (/= 3 (car pt))
       (/= 25 (car pt))
     )
(cond
  ((and (= 2 (car pt))
(eq (strcase (chr (cadr pt))) "N")
   )
   (prompt "Select Characteristic Objects :")
   (setq ss1 (ssget))
   (setq is_go_on nil)
  )
  (t
   (if (= (car PT) 5)
     (setq id_go_on nil)
   )
  )
)
      )
  )
  (if ss-filiter-old-ss
    (progn
      (prompt "Existing layer filters, Need to be rebuilt please type N:")
      (ss-sel-grread)
    )
    (progn
      (prompt "Select Characteristic Objects :")
      (setq ss1 (ssget))
    )
  )
  (if ss1
    (progn
      (setq
i   -1
lst nil
      )
      (while (setq s1 (ssname ss1 (setq i (1+ i))))
(setq lst (append lst (list (cdr (assoc 8 (entget s1))))))
      )
      (setq
layer_fili
  (vl-string-right-trim
    ","
    (apply (function strcat)
   (mapcar (function (lambda (x) (strcat x ","))) lst)
    )
  )
filiter   (list (cons 8 layer_fili))
ss-filiter-old-ss filiter
      )
    )
    (setq filiter ss-filiter-old-ss)
  )
  (if filiter
    (progn
      (setq pt (cadr pt))
      (if (and pt (listp pt))
(SendKeys (ss-pt->str pt))
      )
      (setq ss2 (ssget filiter))
    )
    (ss_ss)
  )
  (prompt
    (strcat (rtos (sslength ss2) 2 0) " Objects are selected .")
  )
  ss2
)
(defun SendKeys (keys / ws)
  ;;Send keys to command-line
  (setq ws (vlax-create-object "WScript.Shell"))
  (vlax-invoke-method ws (quote sendkeys) keys)
  (vlax-release-object ws)
  (princ)
);_end SendKeys
(defun ss-pt->str (pts / str)
  ;;translate point into string for command-line
  (if (numberp (car pts))
    (progn
      (setq str "")
      (foreach a pts
(setq str (strcat str (strcat (rtos a 2 6) ",")))
)
      (setq str (vl-string-right-trim "," str))
      (strcat str " ")
      )   
    (mapcar (function ss-pt->str) pts)
    )
  )
;;;ADD command ,which can be invoked when other command is running .
(vlax-add-cmd "SS" 'ss_ss "SS" 7)
;;;Use method in command-line , e.g.
;;;                                 "MOVE" "'SS"

or this way will be better
Code: [Select]
(defun C:SS (/ ss1 i lst s1 layer_fili ss2 filiter pt)
  ;;layer-filter
  (defun ss-sel-grread (/ is_go_on)
     (setq is_go_on T)
      (while (and
       is_go_on
       (setq pt (grread t 4 2))
       (/= 3 (car pt))
       (/= 25 (car pt))
     )
(cond
  ((and (= 2 (car pt))
(eq (strcase (chr (cadr pt))) "N")
   )
   (prompt "Select Characteristic Objects :")
   (setq ss1 (ssget))
   (setq is_go_on nil)
  )
  (t
   (if (= (car PT) 5)
     (setq id_go_on nil)
   )
  )
)
      )
  )
  (if ss-filiter-old-ss
    (progn
      (prompt "Existing layer filters, Need to be rebuilt please type N:")
      (ss-sel-grread)
    )
    (progn
      (prompt "Select Characteristic Objects :")
      (setq ss1 (ssget))
    )
  )
  (if ss1
    (progn
      (setq
i   -1
lst nil
      )
      (while (setq s1 (ssname ss1 (setq i (1+ i))))
(setq lst (append lst (list (cdr (assoc 8 (entget s1))))))
      )
      (setq
layer_fili
  (vl-string-right-trim
    ","
    (apply (function strcat)
   (mapcar (function (lambda (x) (strcat x ","))) lst)
    )
  )
filiter   (list (cons 8 layer_fili))
ss-filiter-old-ss filiter
      )
    )
    (setq filiter ss-filiter-old-ss)
  )
  (if filiter
    (progn
      (setq pt (cadr pt))
      (if (and pt (listp pt))
(SendKeys (ss-pt->str pt))
      )
      (setq ss2 (ssget filiter))
    )
    (C:SS)
  )
  (prompt
    (strcat (rtos (sslength ss2) 2 0) " Objects are selected .")
  )
  ss2
)
« Last Edit: February 09, 2012, 07:25:14 AM by chlh_jd »

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Code - Auto/Visual Lisp: [Select]

?

VovKa

  • Water Moccasin
  • Posts: 1631
  • Ukraine
it can be use like --->"MOVE"--->"'SS"..., but how can I use it like osnap command  method  --->"MOVE"--->"SS"
you just don't want to type in an apostrophe? am i right?

chlh_jd

  • Guest
Hi Lee , I've try the vlax-add-cmd method .

it can be use like --->"MOVE"--->"'SS"..., but how can I use it like osnap command  method  --->"MOVE"--->"SS"
you just don't want to type in an apostrophe? am i right?

Hi VovKa , You're right .

VovKa

  • Water Moccasin
  • Posts: 1631
  • Ukraine
Hi VovKa , You're right .
MOVE command is expecting a certain set of keywords, but SS is not in that set. so i don't think you can avoid an apostrophe (for command) or a parentheses (for function)
as to your code, why not make it simpler?
Code: [Select]
(defun c:SS (/ EntName)
    (if (setq EntName (car (entsel "\nselect filter object: ")))
(ssget (list (assoc 8 (entget EntName))))
    )
)

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Yes, I also don't think you can get away from the apostrophe. You could of course add the macro (including the apostrophe) as a keyboard shortcut in CUI.

BTW, your code seems to do a subset of my old Select Similar: http://forums.augi.com/showthread.php?t=66329

It also works as transparent, but also only with the apostrophe.
« Last Edit: February 08, 2012, 03:57:15 AM by irneb »
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

codered8x

  • Guest
Thank Lee for Auto/Visual lisp online help ! useful for reading on phone.

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Thank Lee for Auto/Visual lisp online help ! useful for reading on phone.

Thank Se7en for that - its certainly a nice feature  :-)

chlh_jd

  • Guest
MOVE command is expecting a certain set of keywords, but SS is not in that set. so i don't think you can avoid an apostrophe (for command) or a parentheses (for function)
as to your code, why not make it simpler?
Code: [Select]
(defun c:SS (/ EntName)
    (if (setq EntName (car (entsel "\nselect filter object: ")))
(ssget (list (assoc 8 (entget EntName))))
    )
)
It can be simply . but before you select objects , you must select char objects every time . So I save the filter as global variable .