Jump to content

Combine multiple TBLSEARCH lines?


ILoveMadoka

Recommended Posts

Is it possible to make this more compact?

 

(DEFUN C:TEST ()

(if (/= (tblsearch "STYLE" "ROMANS"))
(COMMAND "-STYLE" "ROMANS" "ROMANS" "" "" "" "N" "N" "N")

(if (= (tblsearch "STYLE" "SLDTEXTSTYLE0"))
(COMMAND "-STYLE" "SLDTEXTSTYLE0" "ROMANS" "" "" "" "N" "N" "N")

(if (= (tblsearch "STYLE" "SLDTEXTSTYLE1"))
(COMMAND "-STYLE" "SLDTEXTSTYLE1" "ROMANS" "" "" "" "N" "N" "N")

(if (= (tblsearch "STYLE" "SLDTEXTSTYLE2"))
(COMMAND "-STYLE" "SLDTEXTSTYLE2" "ROMANS" "" "" "" "N" "N" "N")

(if (= (tblsearch "STYLE" "SLDTEXTSTYLE3"))
(COMMAND "-STYLE" "SLDTEXTSTYLE3" "ROMANS" "" "" "" "N" "N" "N")

(if (= (tblsearch "STYLE" "SLDTEXTSTYLE4"))
(COMMAND "-STYLE" "SLDTEXTSTYLE4" "ROMANS" "" "" "" "N" "N" "N")

(if (= (tblsearch "STYLE" "SLDTEXTSTYLE5"))
(COMMAND "-STYLE" "SLDTEXTSTYLE5" "ROMANS" "" "" "" "N" "N" "N")

(if (= (tblsearch "STYLE" "SLDTEXTSTYLE6"))
(COMMAND "-STYLE" "SLDTEXTSTYLE6" "ROMANS" "" "" "" "N" "N" "N")

(if (= (tblsearch "STYLE" "SLDTEXTSTYLE7"))
(COMMAND "-STYLE" "SLDTEXTSTYLE7" "ROMANS" "" "" "" "N" "N" "N")

(if (= (tblsearch "STYLE" "SLDTEXTSTYLE8"))
(COMMAND "-STYLE" "SLDTEXTSTYLE8" "ROMANS" "" "" "" "N" "N" "N")

(PRINC))

 

 

Guidance if so please?

Link to comment
Share on other sites

Is it possible to make this more compact?

 

Guidance if so please?

 

mapcar method


(defun c:test nil
([color="blue"]mapcar[/color] ''((x) (if ([color="red"]not[/color] (tblsearch "STYLE" x))
(COMMAND "-STYLE" x "ROMANS" "" "" "" "N" "N" "N")))
((lambda (i / l)
(vl-list* "ROMANS" (repeat 9 (setq l (cons (strcat "SLDTEXTSTYLE"(itoa(setq i (1- i)))) l)))))
 9))
(princ))

Edited by hanhphuc
Link to comment
Share on other sites

hanhphuc beat me to it, poor typist me...

 

(defun c:test ()
(mapcar 
(function 
  (lambda (x) 
    (if 
      (not (tblsearch "style" x))
       (COMMAND "-STYLE" x "ROMANS" "" "" "" "N" "N" "N")
      )
    )
  ) 
  '("ROMANS" "SLDTEXTSTYLE0" "SLDTEXTSTYLE1" "SLDTEXTSTYLE2" "SLDTEXTSTYLE2")
)
(princ)
)

Link to comment
Share on other sites

hanhphuc beat me to it, poor typist me...

 

long time no see jdiala !

nothing beats you, i learned from you too :)

 

another..

cond method

EDIT: This method only applies changes if current style matched

(defun [b]c:[u]test2[/u][/b] nil
[color="green"];switch current *style to ROMANS ,which styles are limited by user[/color]
 (eval
     (cons 'cond
    (mapcar ''((x)
	       (list
		[color="red"](equal (cdr(assoc 2 (tblsearch "STYLE" (getvar 'textstyle)))) x)[/color]
		(cons 'command (list "-STYLE" x "ROMANS" "" "" "" "N" "N" "N")))
	       ) ;_ end of lambda
	   		    ((lambda (i / l)
	       (vl-list* "ROMANS"
			 (repeat 9 (setq l (cons (strcat "STY" (itoa (setq i (1- i)))) l)))
			 ) ;_ end of vl-list*
	       ) ;_ end of lambda
	      9
	      )
	    ) ;_ end of mapcar
    ) ;_ end of cons
     ) ;_ end of eval
(princ)
)

 

This explains similarity of the above test2 before it's being evaluated

[color="green"];where [b][color="blue"]T[/color][/b]= [color="red"](tblsearch "STYLE" (getvar 'textstyle))[/color]
;assume [color="red"]"STY4"[/color] is current style, ie: only "STY4" is effected [/color]

(COND (nil (COMMAND "-STYLE" "ROMANS" "ROMANS" "" "" "" "N" "N" "N"))
     (nil (COMMAND "-STYLE" "STY0" "ROMANS" "" "" "" "N" "N" "N"))
     (nil (COMMAND "-STYLE" "STY1" "ROMANS" "" "" "" "N" "N" "N"))
     (nil (COMMAND "-STYLE" "STY2" "ROMANS" "" "" "" "N" "N" "N"))
     (nil (COMMAND "-STYLE" "STY3" "ROMANS" "" "" "" "N" "N" "N"))
     ([b][color="blue"]T[/color][/b]   (COMMAND "-STYLE" [color="red"]"STY4"[/color] "ROMANS" "" "" "" "N" "N" "N"))[color="green"]; <-- example curent style= T[/color]
     (nil (COMMAND "-STYLE" "STY5" "ROMANS" "" "" "" "N" "N" "N"))
     (nil (COMMAND "-STYLE" "STY6" "ROMANS" "" "" "" "N" "N" "N"))
     (nil (COMMAND "-STYLE" "STY7" "ROMANS" "" "" "" "N" "N" "N"))
     (nil (COMMAND "-STYLE" "STY8" "ROMANS" "" "" "" "N" "N" "N"))
     ) ;_ end of COND

 

This test3 is similar, it will change current style to ROMANS,

the difference where test2 only works with certain styles

(defun c:[u][b]test3[/b][/u] nil
 (COMMAND "-STYLE" (getvar 'textstyle) "ROMANS" "" "" "" "N" "N" "N")
 )

in fact both test2 & test3 are superfluous which only work for each single condition,

but i just hope that you could find the differences between cond & mapcar examples

HTH

Edited by hanhphuc
updated code & example
Link to comment
Share on other sites

mapcar method


(defun c:test nil
([color=blue]mapcar[/color] ''((x) (if (= (tblsearch "STYLE" x))
(COMMAND "-STYLE" x "ROMANS" "" "" "" "N" "N" "N")))
((lambda (i / l)
(vl-list* "ROMANS" (repeat 9 (setq l (cons (strcat "SLDTEXTSTYLE"(itoa(setq i (1- i)))) l)))))
 9))
(princ))

 

Thank you for the response and the code.

 

I know I didn't spell out all my criteria but I was just trying to get the function streamlined at the time.

 

This works perfectly but is producing an undesired side effect.

It creates the text style "SLDTEXTSTYLE0" thru "SLDTEXTSTYLE8" for the styles that didn't exist.

 

I never know how many of these "styles" will be in a drawing.

There may be 2 there may be 12 or more.

 

I just ran it on a test drawing with 4 styles:

"SLDTEXTSTYLE0" thru "SLDTEXTSTYLE3" and when it finished I had "SLDTEXTSTYLE0" thru "SLDTEXTSTYLE8"

 

 

This is further expounding on the original code but my design intent to get it to check and see

if a style exists and if so change the font if not, do nothing.

(could be any number of styles but they all are named "SLDTEXTSTYLExxx" Where xxx is a number 0-?)

 

I can live with the code as it sits. It does work. (Thanks again!)

If it didn't create new styes it would be better - if possible.

 

 

Can the results of the tblsearch be number?

I don't know how to add a counter.

If/then? While loop? foreach?

 

I'm pushing the limits of my very limited knowledge....

Edited by ILoveMadoka
Link to comment
Share on other sites

long time no see jdiala !

nothing beats you, i learned from you too :)

 

another..

cond method

   (eval
     (cons 'cond
    (mapcar ''((x)
	       (list (eval (cons '[color="red"]not[/color] (list '(tblsearch "STYLE" x) 'x)))
		     (cons 'command (list "-STYLE" x "ROMANS" "" "" "" "N" "N" "N")))
	       ) ;_ end of lambda
	   		    ((lambda (i / l)
	       (vl-list* "ROMANS"
			 (repeat 9 (setq l (cons (strcat "SLDTEXTSTYLE" (itoa (setq i (1- i)))) l)))
			 ) ;_ end of vl-list*
	       ) ;_ end of lambda
	      9
	      )
	    ) ;_ end of mapcar
    ) ;_ end of cons
     ) ;_ end of eval

 

 

I'm ashamed to admit that I don't know how to incorporate this into the other.....

 

 

:-\

Link to comment
Share on other sites

my apology, the logical key should be "not",

too bad i just showed the flow but not the contain working

 

in mapcar method 2nd line

''((x) (if ([color="red"]not [/color](tblsearch "STYLE" x))

in cond method 3rd line

 
(eval (cons '[color="red"]not[/color] (list '(tblsearch "STYLE" x) 'x)))

 

indeed i'm bad typist

jdiala beats me 8)

Link to comment
Share on other sites

I think I would lean towards ;

 

[b][color=BLACK]([/color][/b]defun c:rstyle [b][color=FUCHSIA]([/color][/b]/ i s[b][color=FUCHSIA])[/color][/b]

[b][color=FUCHSIA]([/color][/b]if [b][color=NAVY]([/color][/b]not [b][color=MAROON]([/color][/b]tblsearch [color=#2f4f4f]"STYLE"[/color] [color=#2f4f4f]"ROMANS"[/color][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b]
   [b][color=NAVY]([/color][/b]progn
    [b][color=MAROON]([/color][/b]command [color=#2f4f4f]"_.STYLE"[/color] [color=#2f4f4f]"ROMANS"[/color] [color=#2f4f4f]"ROMANS"[/color][b][color=MAROON])[/color][/b]
    [b][color=MAROON]([/color][/b]while [b][color=GREEN]([/color][/b]> [b][color=BLUE]([/color][/b]getvar [color=#2f4f4f]"CMDACTIVE"[/color][b][color=BLUE])[/color][/b] 0[b][color=GREEN])[/color][/b]
           [b][color=GREEN]([/color][/b]command [color=#2f4f4f]""[/color][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b]

[b][color=FUCHSIA]([/color][/b]setq i 0[b][color=FUCHSIA])[/color][/b]
[b][color=FUCHSIA]([/color][/b]repeat 9
  [b][color=NAVY]([/color][/b]setq s [b][color=MAROON]([/color][/b]strcat [color=#2f4f4f]"SLDTEXTSTYLE"[/color] [b][color=GREEN]([/color][/b]itoa i[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b]
  [b][color=NAVY]([/color][/b]if [b][color=MAROON]([/color][/b]tblsearch [color=#2f4f4f]"STYLE"[/color] s[b][color=MAROON])[/color][/b]
      [b][color=MAROON]([/color][/b]progn
        [b][color=GREEN]([/color][/b]command [color=#2f4f4f]"_.STYLE"[/color] s [color=#2f4f4f]"ROMANS"[/color][b][color=GREEN])[/color][/b]
        [b][color=GREEN]([/color][/b]while [b][color=BLUE]([/color][/b]> [b][color=RED]([/color][/b]getvar [color=#2f4f4f]"CMDACTIVE"[/color][b][color=RED])[/color][/b] 0[b][color=BLUE])[/color][/b]
               [b][color=BLUE]([/color][/b]command [color=#2f4f4f]""[/color][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b]
  [b][color=NAVY]([/color][/b]setq i [b][color=MAROON]([/color][/b]1+ i[b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b]

[b][color=FUCHSIA]([/color][/b]prin1[b][color=FUCHSIA])[/color][/b][b][color=BLACK])[/color][/b]

 

 

-David

Link to comment
Share on other sites

 

(could be any number of styles but they all are named "SLDTEXTSTYLExxx" Where xxx is a number 0-?)

 

Can the results of the tblsearch be number?

I don't know how to add a counter.

If/then? While loop?

 

I'm pushing the limits of my very limited knowledge....

 

This part is loop usung repeat, you example is 0~8

(repeat [color="red"]9[/color] (setq l (cons (strcat "SLDTEXTSTYLE" (itoa (setq i (1- i)))) l)))

 

EDIT:

Thanks David :)

ILoveMadoka, please notice mr David make style using repeat loop too

Link to comment
Share on other sites

my apology, the logical key should be "not",

 

You are helping me. No apology required!

 

Thanks much!

 

 

David,

 

I will check yours out too.

 

Thank you Sir!

Link to comment
Share on other sites

I'm ashamed to admit that I don't know how to incorporate this into the other.....

:-\

updated in post#4.

*For reference only

 

...

This works perfectly but is producing an undesired side effect.

It creates the text style "SLDTEXTSTYLE0" thru "SLDTEXTSTYLE8" for the styles that didn't exist.

 

Perhaps my confusion:

"Combine multiple TBLSEARCH lines?"

 

if you don't want to create unwanted *style0~8 as in post#2,

which means you refer to styles which already exist?

update this

(defun c:test ( / var old )
(setq var '(cmdecho textstyle ) old (mapcar 'getvar var))
(setvar 'cmdecho 0)
(if (/= (tblsearch "STYLE" "ROMANS"))
(COMMAND "-STYLE" "ROMANS" "ROMANS" "" "" "" "N" "N" "N"))
 
(mapcar ''((x) (if [color="red"](tblsearch "STYLE" x)[/color]
(COMMAND "-STYLE" x "" "" "" "" "N" "N" "N")))
((lambda (i / l)
(repeat 9 (setq l (cons (strcat "SLDTEXTSTYLE"(itoa(setq i (1- i)))) l))))
 9))
(mapcar 'setvar var old)
(princ))

Link to comment
Share on other sites

David,

 

This works perfectly! Thanks much.

 

 

 

 

[b][color=BLACK]([/color][/b]defun c:rstyle [b][color=FUCHSIA]([/color][/b]/ i s[b][color=FUCHSIA])[/color][/b]

[b][color=FUCHSIA]([/color][/b]if [b][color=NAVY]([/color][/b]not [b][color=MAROON]([/color][/b]tblsearch [color=#2f4f4f]"STYLE"[/color] [color=#2f4f4f]"ROMANS"[/color][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b]
   [b][color=NAVY]([/color][/b]progn
    [b][color=MAROON]([/color][/b]command [color=#2f4f4f]"_.STYLE"[/color] [color=#2f4f4f]"ROMANS"[/color] [color=#2f4f4f]"ROMANS"[/color][b][color=MAROON])[/color][/b]
    [b][color=MAROON]([/color][/b]while [b][color=GREEN]([/color][/b]> [b][color=BLUE]([/color][/b]getvar [color=#2f4f4f]"CMDACTIVE"[/color][b][color=BLUE])[/color][/b] 0[b][color=GREEN])[/color][/b]
           [b][color=GREEN]([/color][/b]command [color=#2f4f4f]""[/color][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b]

[b][color=FUCHSIA]([/color][/b]setq i 0[b][color=FUCHSIA])[/color][/b]
[b][color=FUCHSIA]([/color][/b]repeat 9
  [b][color=NAVY]([/color][/b]setq s [b][color=MAROON]([/color][/b]strcat [color=#2f4f4f]"SLDTEXTSTYLE"[/color] [b][color=GREEN]([/color][/b]itoa i[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b]
  [b][color=NAVY]([/color][/b]if [b][color=MAROON]([/color][/b]tblsearch [color=#2f4f4f]"STYLE"[/color] s[b][color=MAROON])[/color][/b]
      [b][color=MAROON]([/color][/b]progn
        [b][color=GREEN]([/color][/b]command [color=#2f4f4f]"_.STYLE"[/color] s [color=#2f4f4f]"ROMANS"[/color][b][color=GREEN])[/color][/b]
        [b][color=GREEN]([/color][/b]while [b][color=BLUE]([/color][/b]> [b][color=RED]([/color][/b]getvar [color=#2f4f4f]"CMDACTIVE"[/color][b][color=RED])[/color][/b] 0[b][color=BLUE])[/color][/b]
               [b][color=BLUE]([/color][/b]command [color=#2f4f4f]""[/color][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b]
  [b][color=NAVY]([/color][/b]setq i [b][color=MAROON]([/color][/b]1+ i[b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b]

[b][color=FUCHSIA]([/color][/b]prin1[b][color=FUCHSIA])[/color][/b][b][color=BLACK])[/color][/b]

Link to comment
Share on other sites

You're welcome. You could add some error trapping to ensure ROMANS styel can be made, but most systems haves ROMANS in a search path

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...