Author Topic: Revisiting user insert block options - Blocks  (Read 211 times)

0 Members and 1 Guest are viewing this topic.

jlogan02

  • Newt
  • Posts: 96
Revisiting user insert block options - Blocks
« on: September 05, 2019, 06:45:38 PM »
I like this approach that Dlanor provided me a while back where the block names appear as "dynprompt" on screen.
Mind you, blk1, blk2 and blk3 are really named...
STA_BORD_CTL_STD
STA_BORD_CTL_MAX
STA_BORD_CTL_PLO

If I replace blk1, blk2, blk3 with the above block names, I get an "Invalid option keyword" when I run it.

At the command line the "STA" for each block name in the list is blue (keyword ?), while the rest of the text is black.
Code - Auto/Visual Lisp: [Select]
  1. [[color=blue]STA[/color]_BORD_CTL_STD/[color=blue]STA[/color]_BORD_CTL_MAX/[color=blue]STA[/color]_BORD_CTL_PLO]


If I change my blk_list to...
Code - Auto/Visual Lisp: [Select]
  1. (setq blk_lst '("STD" "MAX" "PLO"))

All works...
The block gets inserted and each option is blue at the command line for selecting, while also being able
to select on screen from the dynprompt.
[STD/MAX/PLO]STD

In this code below I see Dlanor using
Code - Auto/Visual Lisp: [Select]
I toyed with some simple "vl-string-trim" from one string of my block options "STA_BORD_CTL_STD" and was able to get it down to just STD as the return string.

How do I apply that result to each block name?
Orrrr, how do I resolve the "Invalid option keyword" when using the full block name in my blk_list"?

Code - Auto/Visual Lisp: [Select]
  1. (defun c:test ( / blk_lst bname)
  2.  
  3.   (setq dynp (getvar 'dynprompt)
  4.           dynm (getvar 'dynmode)
  5.   )
  6.   (setvar 'dynprompt 1)
  7.   (setvar 'dynmode 3)
  8.      
  9.   (setq blk_lst '("blk1" "blk2" "blk3"))
  10.  
  11.   (initget 1 (vl-string-right-trim " "(apply 'strcat (mapcar '(lambda (x) (strcat x " ")) blk_lst))))
  12.   (setq bname (getkword (strcat "["(vl-string-right-trim "/"(apply 'strcat (mapcar '(lambda (x) (strcat x "/")) blk_lst)))"]")))
  13.   (alert (strcat "You Selected " bname))
  14.  
  15. ;;reset sysvars
  16.   (setvar 'dynprompt dynp)
  17.   (setvar 'dynmode dynm)
  18. );end_defun
J. Logan
ACAD 2018

I am one with the Force and the Force is with me.

roy_043

  • Water Moccasin
  • Posts: 1715
  • BricsCAD 18
Re: Revisiting user insert block options - Blocks
« Reply #1 on: September 06, 2019, 02:42:59 AM »
Each keyword can contain only letters, numbers, and hyphens (-).

Dlanor

  • Newt
  • Posts: 165
Re: Revisiting user insert block options - Blocks
« Reply #2 on: September 06, 2019, 05:56:27 AM »
roy_043 is spot on.

This is a dirty fix that shoud take account of block names that contain "-" and "_". It is not extensively tested

Code - Auto/Visual Lisp: [Select]
  1. (defun no_ (lst / str n_lst)
  2.   (foreach str lst
  3.     (while (vl-string-search "_" str) (setq str (vl-string-subst "-" "_" str)))
  4.     (setq n_lst (cons str n_lst))
  5.   )
  6.   (reverse n_lst)
  7. )
  8.  
  9. (defun c:test ( / dynp dynm blk_lst k_lst bname)
  10.  
  11.   (setq dynp (getvar 'dynprompt)
  12.         dynm (getvar 'dynmode)
  13.   )
  14.   (setvar 'dynprompt 1)
  15.   (setvar 'dynmode 3)
  16.      
  17.   (setq blk_lst '("blk_1" "blk_2" "blk_3")
  18.         k_lst (no_ blk_lst)
  19.   )
  20.  
  21.   (initget 1 (vl-string-right-trim " "(apply 'strcat (mapcar '(lambda (x) (strcat x " ")) k_lst))))
  22.   (setq bname (getkword (strcat "["(vl-string-right-trim "/"(apply 'strcat (mapcar '(lambda (x) (strcat x "/")) k_lst)))"]")))
  23.   (setq bname (nth (vl-position bname k_lst) blk_lst))
  24.  
  25.   (alert (strcat "You Selected " bname))
  26.  
  27. ;;reset sysvars
  28.   (setvar 'dynprompt dynp)
  29.   (setvar 'dynmode dynm)
  30. );end_defun
  31.  

jlogan02

  • Newt
  • Posts: 96
Re: Revisiting user insert block options - Blocks
« Reply #3 on: September 06, 2019, 10:52:13 AM »
I'm so dumb...I read that page twice yesterday and that line twice yesterday and still didn't make the connection.

Roy_043

"Each keyword can contain only letters, numbers, and hyphens (-)."

Dlanor,

Code - Auto/Visual Lisp: [Select]
  1. vl-string-subst...
Makes perfect sense. Read that yesterday too.

Thanks for the explanation guys.

J. Logan
J. Logan
ACAD 2018

I am one with the Force and the Force is with me.

Lee Mac

  • Seagull
  • Posts: 12255
  • London, England
Re: Revisiting user insert block options - Blocks
« Reply #4 on: September 06, 2019, 06:33:50 PM »
FWIW, you could use vl-string-translate to convert all occurrences in one expression, e.g.:
Code: [Select]
(vl-string-translate "_" "-" str)