List of Text Styles as options

List of Text Styles as options

kenneth.smithV6QLC
Enthusiast Enthusiast
3,998 Views
13 Replies
Message 1 of 14

List of Text Styles as options

kenneth.smithV6QLC
Enthusiast
Enthusiast

Looking for a way to give the user a prompt of available text styles via the command line. I am looking at it from the angle of (getstring "Choose [Style1A/Style1B/Style1C]: ") for example. The text style names are fairly long and vary slightly between files. Would like to know if gathering a list of the available styles then offering as options is possible? Thank you!

Please be kind, rewind your exploding. Do not explode hatching, dimensions or text. Think of your fellow drafters! 🙂

https://www.youracclaim.com/badges/9aa4a1d5-0d02-4888-be6f-ed8f0653d8ad/public_url
0 Likes
Accepted solutions (1)
3,999 Views
13 Replies
Replies (13)
Message 2 of 14

Kent1Cooper
Consultant
Consultant

It doesn't do quite what you're describing, but are you at least aware of  the -STYLE command's ? option and the * option within that, to list all Styles?  Note the hyphen prefix, to get the command-line rather than dialog-box Style command:

 

Command: -STYLE
Enter name of text style or [?] <ARCH>: ?

Enter text style(s) to list <*>: {Enter to accept  * option}

Text styles:

Style name: ".... {lists them all}

 

You can get the same from the Style option  within the TEXT command

 

Command: TEXT

Current text style:  "ARCH"  Text height:  0'-0 3/32"  Annotative:  Yes  Justify:  Left
Specify start point of text or [Justify/Style]: S

Enter style name or [?] <ARCH>: ?

Enter text style(s) to list <*>:

Text styles:

Style name: "....

 

EDIT:

But to your question more directly:  That's probably possible, but with a proviso.  The way to do such a thing, if you want to be able to pick the choice from the prompt's options or type in abbreviated option letters to get a particular Style, would be using (initget) and (getkword ), rather than (getstring ).  The proviso is this question -- do any of the Style names ever have spaces  in them?  The (initget) function separates options with spaces, so spaces within  a Style name would throw it off.  Another question is this -- what is the nature of the Style names compared to each other, i.e. would it be possible to specify capitalized abbreviations that could work in the (initget)/(getkword) approach to differentiate each one uniquely?

Kent Cooper, AIA
0 Likes
Message 3 of 14

rkmcswain
Mentor
Mentor

You can find a sample function here. Use it like this:

 

(table "style")
("BOLD2" "CALIBRI" "TTF" "TXT" "ROMANSM" "ROMAND" "ABCD" "Legend" "Annotative" "Standard")
R.K. McSwain     | CADpanacea | on twitter
0 Likes
Message 4 of 14

ВeekeeCZ
Consultant
Consultant

Theoretically... try this if it works for you. 

In my testing we would need to exclude more characters... spaces for sure, maybe more...

It works for me in simple drawing... but not very good in the complex ones.

 

(vl-load-com)

(defun c:foo (/ Table abcs stlss keys tag)
  
  (defun Table (s / d r)
    (while (setq d (tblnext s (null d)))
      (setq r (cons (cdr (assoc 2 d)) r))
      )
    )
  
  
  (if (and (setq stls (table "STYLE"))
           (setq stls (vl-sort stls '<))
           (setq stls (vl-remove-if '(lambda (x) (= x "")) stls))
           (setq abcs '("A" "B" "C" "D" "E" "F" "G" "H" "I" "J" "K" "L" "M" "N" "O" "P" "Q" "R" "S" "T" "U"  "V" "W" "X" "Y" "Z"))
           (setq keys (vl-string-right-trim " " (apply 'strcat (mapcar '(lambda (a b) (strcat a ":" (strcase b T) " "))
                                                                       abcs stls))))
           )
    (progn
      (initget keys)
      (getkword (strcat "\nPick style [" (vl-string-translate " " "/" keys) "]: "))))
  
  )

 

Anyway, I would probably use the Input Search, see the SCREENCAST how it works for layers. The same could be set for Text Styles.

 

0 Likes
Message 5 of 14

ronjonp
Mentor
Mentor

Here is another example where you can use numbers to pick your style:

(defun c:foo (/ _getstyles a b c r)
  ;; RJP » 2019-03-14
  (defun _getstyles (/ l x)
    (while (setq l (tblnext "style" (null l)))
      (or (wcmatch (cdr (assoc 2 l)) "*|*") (setq x (cons (cdr (assoc 2 l)) x)))
    )
    x
  )
  (setq a -1)
  (setq	b
	 (apply
	   'strcat
	   (mapcar '(lambda (x) (strcat (itoa (setq a (1+ a))) "-" (vl-string-translate " " "&" x) " "))
		   (setq c (vl-sort (_getstyles) '<))
	   )
	 )
  )
  (alert (cond ((> (length c) 1)
		(setvar 'dynmode 1)
		(initget 0 b)
		(if (setq r (getkword (strcat "\nChoose [" (vl-string-translate " " "/" b) "]: ")))
		  (nth (fix (atof r)) c)
		)
	       )
	       ((car c))
	 )
  )
)

image.png

0 Likes
Message 6 of 14

Kent1Cooper
Consultant
Consultant

@ВeekeeCZ wrote:

Theoretically... try this if it works for you. 

In my testing we would need to exclude more characters... spaces for sure, maybe more...

It works for me in simple drawing... but not very good in the complex ones.

....


 

Interesting....  It definitely has a problem with Style names that include spaces -- I don't know what could be done about those except to Rename the Styles to omit the spaces, or replace them with underscore characters or something.  And those that are nested in Xrefs are another problem, but that raises the question of what this would be used for.  If it's [for example -- the most likely scenario, it seems to me] to set the chosen Style current, then Xref-nested ones should be left out of consideration entirely, and even in a simple situation, the prefixing letter and colon in the returned string would need to be stripped away.

Kent Cooper, AIA
0 Likes
Message 7 of 14

ronjonp
Mentor
Mentor

@Kent1Cooper wrote:

@ВeekeeCZ wrote:

Theoretically... try this if it works for you. 

In my testing we would need to exclude more characters... spaces for sure, maybe more...

It works for me in simple drawing... but not very good in the complex ones.

....


 

Interesting....  It definitely has a problem with Style names that include spaces -- I don't know what could be done about those except to Rename the Styles to omit the spaces,....


This is accounted for in my example:

(vl-string-translate " " "_" x)

 Although after actually testing this out I needed to replace those spaces with a different character other than "_".

Changed to: 

(vl-string-translate " " "&" x) 

 

0 Likes
Message 8 of 14

ВeekeeCZ
Consultant
Consultant

Even your version fails in my complex drawing. It will take some time to figure out why... if you up to it, here is the one.

 

/ I didn't do that myself because I wanted some feedback from the OP first.

0 Likes
Message 9 of 14

ronjonp
Mentor
Mentor
Accepted solution

Yowza .. perhaps a dcl popup_list is more appropriate for this. If I get time I'll try and figure out what is messing with my other code.

 

Actually quick check and this change seems to work .. does not like the "_" since it's use for localizing keywords:

(defun c:foo (/ _getstyles a b c r)
  ;; RJP » 2019-03-14
  (defun _getstyles (/ l x)
    (while (setq l (tblnext "style" (null l)))
      (or (wcmatch (cdr (assoc 2 l)) "*|*") (setq x (cons (cdr (assoc 2 l)) x)))
    )
    x
  )
  (setq a -1)
  (setq
    b (apply
	'strcat
	(mapcar
	  '(lambda (x) (strcat (itoa (setq a (1+ a))) "-" (vl-string-translate "_ " "--" x) " "))
	  (setq c (vl-sort (_getstyles) '<))
	)
      )
  )
  (alert (cond ((> (length c) 1)
		(setvar 'dynmode 1)
		(initget 0 b)
		(if (setq r (getkword (strcat "\nChoose [" (vl-string-translate " " "/" b) "]: ")))
		  (nth (fix (atof r)) c)
		)
	       )
	       ((car c))
	 )
  )
)

 

Message 10 of 14

ВeekeeCZ
Consultant
Consultant

Nice catch!

I would also exclude "" styles, not sure where they came from. But I have 5 of them...

 

image.png

0 Likes
Message 11 of 14

ronjonp
Mentor
Mentor

Is that in the same drawing you posted? This is what I see:

image.png

0 Likes
Message 12 of 14

ВeekeeCZ
Consultant
Consultant

Yeah they were, before I removed and purged all the content but the STYLEs. 

0 Likes
Message 13 of 14

kenneth.smithV6QLC
Enthusiast
Enthusiast

This works great! Thank you a bunch @ronjonp.

Please be kind, rewind your exploding. Do not explode hatching, dimensions or text. Think of your fellow drafters! 🙂

https://www.youracclaim.com/badges/9aa4a1d5-0d02-4888-be6f-ed8f0653d8ad/public_url
0 Likes
Message 14 of 14

ronjonp
Mentor
Mentor

@kenneth.smithV6QLC wrote:

This works great! Thank you a bunch @ronjonp.


Glad to help! 🙂

0 Likes