Jump to content

Radio Button for Project Phase Selection


CAD_Noob

Recommended Posts

4 minutes ago, mhupp said:

look to see where your temp files are being made. run the command but don't pick anything their will be a temp .dcl file there. nm ill just convert it for you. give me a sec.

 

Thank you so much!

 

Link to comment
Share on other sites

little help from a dragon

(defun c:foo (/ n)
  ;;(or (setq n (getint "\nEnter percent:<30>")) (setq n 30))
  (setq fo (open (setq fn (vl-filename-mktemp "" "" ".dcl")) "w"))
  (write-line "AHbutts : dialog \t{" fo)
  (write-line "  label =\"Choose revision\" ;" fo)
  (write-line "    : row\t{" fo)
  (write-line "      : boxed_radio_row\t{" fo)
  (write-line "        : radio_button\t{" fo)
  (write-line "        key = \"Rb1\";" fo)
  (write-line "        label = \"30%\";" fo)
  (write-line "        }" fo)
  (write-line "        spacer_1 ;" fo)
  (write-line "        : radio_button\t{" fo)
  (write-line "        key = \"Rb2\";" fo)
  (write-line "        label = \"60%\";" fo)
  (write-line "        }" fo)
  (write-line "        spacer_1 ;" fo)
  (write-line "        : radio_button\t{" fo)
  (write-line "        key = \"Rb3\";" fo)
  (write-line "        label = \"90%\";" fo)
  (write-line "        }" fo)
  (write-line "        spacer_1 ;" fo)
  (write-line "      } " fo)
  (write-line "  }" fo)
  (write-line "  spacer_1 ;" fo)
  (write-line "  ok_only;" fo)
  (write-line "}" fo)
  (close fo)
  (setq dcl_id (load_dialog fn))
  (new_dialog "AHbutts" dcl_id) 
  (set_tile "Rb1" "1")
  (action_tile "Rb1" "(setq n \"30%\")(done_dialog)")
  (action_tile "Rb2" "(setq n \"60%\")(done_dialog)")
  (action_tile "Rb3" "(setq n \"90%\")(done_dialog)")
  (action_tile "accept" "(setq n \"30%\")(done_dialog)")
  (start_dialog)
  (unload_dialog dcl_id)
  (vl-file-delete fn)  
  (foreach l '( "TEST-PP-30%_Design_Review" "TEST-PP-60%_Design_Review" "TEST-PP-90%_Design_Review")
    (vl-catch-all-apply
      'vla-put-freeze
      (list (vlax-ename->vla-object (tblobjname "layer" l))
        (if (wcmatch l (strcat "*" n "*"))
          0
          -1
        )
      )
    )
  )
  (command "_.regen")
  (princ)
)
Edited by mhupp
updated code
  • Like 2
Link to comment
Share on other sites

5 minutes ago, mhupp said:
(defun c:foo (/ n)
  ;;(or (setq n (getint "\nEnter percent:<30>")) (setq n 30))
  (setq fo (open (setq fn (vl-filename-mktemp "" "" ".dcl")) "w"))
  (write-line "AHbutts : dialog \t{" fo)
  (write-line "  label =\"Choose revision\" ;" fo)
  (write-line "    : row\t{" fo)
  (write-line "      : boxed_radio_row\t{" fo)
  (write-line "        : radio_button\t{" fo)
  (write-line "        key = \"Rb1\";" fo)
  (write-line "        label = \"30%\";" fo)
  (write-line "        }" fo)
  (write-line "        spacer_1 ;" fo)
  (write-line "        : radio_button\t{" fo)
  (write-line "        key = \"Rb2\";" fo)
  (write-line "        label = \"60%\";" fo)
  (write-line "        }" fo)
  (write-line "        spacer_1 ;" fo)
  (write-line "        : radio_button\t{" fo)
  (write-line "        key = \"Rb3\";" fo)
  (write-line "        label = \"90%\";" fo)
  (write-line "        }" fo)
  (write-line "        spacer_1 ;" fo)
  (write-line "      } " fo)
  (write-line "  }" fo)
  (write-line "  spacer_1 ;" fo)
  (write-line "  ok_only;" fo)
  (write-line "}" fo)
  (close fo)
  (new_dialog "AHbutts" (setq d (load_dialog fn)))
  (start_dialog)
  (unload_dialog d)
  (vl-file-delete fo)
  (foreach l '( "TEST-PP-30%_Design_Review" "TEST-PP-60%_Design_Review" "TEST-PP-90%_Design_Review")
    (vl-catch-all-apply
      'vla-put-freeze
      (list (vlax-ename->vla-object (tblobjname "layer" l))
        (if (wcmatch l (strcat "*" (itoa n) "*"))
          0
          -1
        )
      )
    )
  )
  (command "_.regen")
  (princ)
)

 

 

 

Am getting an error : 

; error: bad argument type: stringp #<FILE internal>

 

Link to comment
Share on other sites

26 minutes ago, mhupp said:

Oops little more in "Multi radio buttons.lsp" then making the dcl should be fixed now.

 

Thanksso much for your assistance....

 

am getting this error now  :

; error: bad argument type: fixnump: "60%"

 

Link to comment
Share on other sites

oops again didn't look closely at @ronjonp super clean code.  😬

 

just change the following since I'm setting strings with the dcl instead of a number

(if (wcmatch l (strcat "*" (itoa n) "*"))
to
(if (wcmatch l (strcat "*" n "*"))

 

It will be a little harder to "add" things

 

  (write-line "        : radio_button\t{" fo)
  (write-line "        key = \"Rb#\";" fo)     ;replace # with a number 1-3 are taken 
  (write-line "        label = \"@@@@\";" fo)   ;what it will show
  (write-line "        }" fo)
  (write-line "        spacer_1 ;" fo)
....
  (action_tile "Rb#" "(setq n \"@@@@\")(done_dialog)")
  also add the layer name to the l list

 

Edited by mhupp
  • Like 1
Link to comment
Share on other sites

56 minutes ago, mhupp said:

oops again didn't look closely at @ronjonp super clean code.  😬

 

just change the following since I'm setting strings with the dcl instead of a number

(if (wcmatch l (strcat "*" (itoa n) "*"))
to
(if (wcmatch l (strcat "*" n "*"))

 

It will be a little harder to "add" things

 

  (write-line "        : radio_button\t{" fo)
  (write-line "        key = \"Rb#\";" fo)     ;replace # with a number 1-3 are takeng
  (write-line "        label = \"@@@@\";" fo)   ;what it will show
  (write-line "        }" fo)
  (write-line "        spacer_1 ;" fo)
....
  (action_tile "Rb#" "(setq n \"@@@@\")(done_dialog)")
  also add the layer name to the l list

 

 

Am thinking that if I add more choices...i may need to convert to to vertical.

let me see i can try to understand how it works...

 

thanks again

Link to comment
Share on other sites

Column version

 

(defun c:foo (/ n)
  (setq fo (open (setq fn (vl-filename-mktemp "" "" ".dcl")) "w"))
  (write-line "AHbutts : dialog {" fo)
  (write-line "  label =\"Choose revision\" ;" fo)
  (write-line "    : row{" fo)
  (write-line "      : boxed_radio_column {" fo)
 

 

  • Like 3
Link to comment
Share on other sites

IMO DCL is not needed for this simple task. If you format the input correctly and have DYNMODE set to 1, it makes for a pretty clean interface.

image.png.8144f2eef7d3a7281372742510b611cf.png

 

(defun c:foo (/ a n)
  (initget 0 (setq a "30 60 90"))
  (setq
    n (cond ((getkword (strcat "\nSelect Option [" (vl-string-translate " " "/" a) "] <30>: ")))
	    ("30")
      )
  )
  (foreach l '("TEST-PP-30%_Design_Review" "TEST-PP-60%_Design_Review" "TEST-PP-90%_Design_Review")
    (vl-catch-all-apply
      'vla-put-freeze
      (list (vlax-ename->vla-object (tblobjname "layer" l))
	    (if	(wcmatch l (strcat "*" n "*"))
	      0
	      -1
	    )
      )
    )
  )
  (command "_.regen")
  (princ)
)

 

Edited by ronjonp
  • Like 4
Link to comment
Share on other sites

6 hours ago, ronjonp said:

IMO DCL is not needed for this simple task. If you format the input correctly and have DYNMODE set to 1, it makes for a pretty clean interface.

image.png.8144f2eef7d3a7281372742510b611cf.png

 

(defun c:foo (/ a n)
  (initget 0 (setq a "30 60 90"))
  (setq
    n (cond ((getkword (strcat "\nSelect Option [" (vl-string-translate " " "/" a) "] <30>: ")))
	    ("30")
      )
  )
  (foreach l '("TEST-PP-30%_Design_Review" "TEST-PP-60%_Design_Review" "TEST-PP-90%_Design_Review")
    (vl-catch-all-apply
      'vla-put-freeze
      (list (vlax-ename->vla-object (tblobjname "layer" l))
	    (if	(wcmatch l (strcat "*" n "*"))
	      0
	      -1
	    )
      )
    )
  )
  (command "_.regen")
  (princ)
)

 

 

Thanks @ronjonp

 

i have DYNMODE set to 0 as it slows down my computer...

still working great though.

 

edit :

when i tested on a xref'd title block it return an error

 

Select Option [30/60/90] <30>:
bad argument type: VLA-OBJECT nil

 

When working on the native file it's working fine...

 

Edited by CAD_Noob
Link to comment
Share on other sites

5 hours ago, CAD_Noob said:

i have DYNMODE set to 0 as it slows down my computer...

So toggle it for just this command. 🤣

 

The error "bad argument type: VLA-OBJECT nil" is probably because the layer doesn't exist in that drawing. added an if statement to check for layer. if missing will let you know.

 

--edit

Quote

when i tested on a xref'd title block it return an error : 

 

Layers that are in the xref have the name of the xref in front like this xref named "typical-motel-room"

image.png.25ca40bef29e50f1e1ebd2b0c90c41f2.png

 

--edit

had to build a list of layers that contain the strings in check (old l list) from there builds a new l list of the layers that need to be frozen or thawed.

 

(defun c:foo (/ a n check lay match l)
  (setvar 'DYNMODE 1)  ;set dynmode @ pointer
  (initget 0 (setq a "30 60 90"))
  (setq n
    (cond
      ((getkword (strcat "\nSelect Option [" (vl-string-translate " " "/" a) "] <30>: "))) ( "30")
    )
  )
  (setvar 'DYNMODE 0)  ;turn off dynmode
  (foreach check '("TEST-PP-30%_Design_Review" "TEST-PP-60%_Design_Review" "TEST-PP-90%_Design_Review")
    (foreach lay (Table "layer")
      (if (wcmatch lay (strcat "*" check "*"))
        (setq match (cons lay match)) 
      )
    )
  )
  (foreach l match
    (vl-catch-all-apply 'vla-put-freeze
      (list (vlax-ename->vla-object (tblobjname "layer" l))
        (if (wcmatch l (strcat "*" n "*")) 0 -1)
      )
    )
  )
  (command "_.regen")
  (princ)
)
;Written By Michael Puckett.
(defun Table (s / d r)
  (while (setq d (tblnext s (null d)))
    (setq r (cons (cdr (assoc 2 d)) r))
  )
)

 

Edited by mhupp
  • Like 2
Link to comment
Share on other sites

1 hour ago, mhupp said:

So toggle it for just this command. 🤣

 

The error "bad argument type: VLA-OBJECT nil" is probably because the layer doesn't exist in that drawing. added an if statement to check for layer. if missing will let you know.

 

--edit

 

Layers that are in the xref have the name of the xref in front like this xref named "typical-motel-room"

image.png.25ca40bef29e50f1e1ebd2b0c90c41f2.png

 

This will fix that

(if (tblsearch "Layer" (strcat "*" l))

so instead of searching for layers names that only match whats in quotes "TEST-PP-30%_Design_Review" it will search for layers that end whats in quotes.

 

(defun c:foo (/ a n)
  (setvar 'DYNMODE 1) ;set dynmode @ pointer
  (initget 0 (setq a "30 60 90"))
  (setq n 
    (cond 
      ((getkword (strcat "\nSelect Option [" (vl-string-translate " " "/" a) "] <30>: "))) ("30")
    )
  )
  (setvar 'DYNMODE 0)  ;turn off dynmode
  (foreach l '("TEST-PP-30%_Design_Review" "TEST-PP-60%_Design_Review" "TEST-PP-90%_Design_Review")
    (if (tblsearch "Layer" (strcat "*" l));check if layer exists 
      (vl-catch-all-apply 'vla-put-freeze
        (list (vlax-ename->vla-object (tblobjname "layer" (strcat "*" l)))
          (if (wcmatch l (strcat "*" n "*")) 0 -1)
        )
      )
      (prompt (strcat "\nLayer " l " not in drawing"))
    ) 
  )
  (command "_.regen")
  (princ)
)

 

 

the layers are there...but reports show that its not...

 

capture.PNG

Link to comment
Share on other sites

lol this is what happens when you don't test code before posting.

 

Had to build a list of layers that contain the strings in check (old l list) from there builds a new l list of the layers that need to be frozen or thawed.

 

--edit

no more missing message

code updated above

Edited by mhupp
Link to comment
Share on other sites

30 minutes ago, mhupp said:

lol this is what happens when you don't test code before posting.

 

Had to build a list of layers that contain the strings in check (old l list) from there builds a new l list of the layers that need to be frozen or thawed.

 

--edit

no more missing message

code updated above

 

thank you so much! working perfectly now.

 

Link to comment
Share on other sites

Multi Radio buttons supports vertical or horizontal choice no need to redo code.

 

(ah:butts ahdef "V"

(ah:butts ahdef "H"

 

 

  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...