How many colors in a mtext

How many colors in a mtext

msarqui
Collaborator Collaborator
1,365 Views
7 Replies
Message 1 of 8

How many colors in a mtext

msarqui
Collaborator
Collaborator

Hi guys,

 

I am wondering if there is a way to know if a MTEXT has more than one color assigned?

 

Thanks for helping.

 

Marcelo

0 Likes
Accepted solutions (2)
1,366 Views
7 Replies
Replies (7)
Message 2 of 8

pbejse
Mentor
Mentor

 

 

(Defun _colorsofthewind (str_ l )
	(if (and
	    	(setq p (vl-string-search "\\C" str_))
		(setq str_ (substr str_ (+ 2 p)))
		(vl-some (function (lambda (s)
            			(if (wcmatch str_ s) s)))
				 '("*C#;*"  "*C##;*" "*C###;*"))
		)
	    		(_colorsofthewind str_ (cons
				(substr str_ 2 (1- (vl-string-position 59 str_))) l ))	    	
      		l	
	    )
      )
Message 3 of 8

pbejse
Mentor
Mentor
or (setq digits ( vl-some ... ( strcat “*C” s “;*”) s) .. ‘(“#” “##” “###”) and use digits as (strlen digits) for substr str_ ... instead of vl-string-position 59...

oh well, you guys know what i mean 🙂
0 Likes
Message 4 of 8

pbejse
Mentor
Mentor
Accepted solution

@pbejse wrote:
or (setq digits ( vl-some ... ( strcat “*C” s “;*”) s) .. ‘(“#” “##” “###”) and use digits as (strlen digits) for substr str_ ... i

My bad, I realize duplicates should be considered as well.

 

(Defun _colorsofthewind (str_ l  / p d f)
	(if (and
		str_  
	    	(setq p (vl-string-search "\\C" str_))
		(setq str_ (substr str_ (+ 2 p)))
		(setq d (vl-some (function (lambda (s)
            			(if (wcmatch str_ (strcat "C" s ";*")) s)))
			       '("#"  "##" "###")))
			)
	    		(_colorsofthewind str_
			      (if (member (setq f (atoi (substr str_ 2 (strlen d)))) l)
				  l (cons f l))
				    )	    	
      		l	
	    )
      )

HTH

0 Likes
Message 5 of 8

msarqui
Collaborator
Collaborator

Sorry for the dumb question but:

(Defun _colorsofthewind (str_ / p d f)

str_  = text string

l = ? Entity name?

0 Likes
Message 6 of 8

pbejse
Mentor
Mentor
Accepted solution

@msarqui wrote:

Sorry for the dumb question but:

(Defun _colorsofthewind (str_ / p d f)

str_  = text string

l = ? Entity name?


Sorry as well msarqui, I did not explain the usage, l is a type LIST.

What i intended to do with the code is count ALL the colors that are used on selected MTEXT's , so 

 

_$ (setq colordata (_colorsofthewind str colordata))
(6 67 9 175)

colordata as the collected colors after processing the selection sets.

 

Passing a nil value would also work if the user is intending to count colors per selected MTEXT.

 

_$ (setq colordata (_colorsofthewind str nil))
(6 67 9 175)

 Anyway, here's the iterative version

 

 

(Defun _colorsofthewind (str_ / l p d f)
	(while
              (and
		str_  
	    	(setq p (vl-string-search "\\C" str_))
		(setq str_ (substr str_ (+ 2 p)))
		(setq d (vl-some (function (lambda (s)
            			(if (wcmatch str_ (strcat "C" s ";*")) s)))
			       '("#"  "##" "###")))
			)
              	 (if (member (setq f (atoi (substr str_ 2 (strlen d)))) l)
				  l (setq l (cons f l))
				    )	    	
      		l	
	    )
      )

(setq colordata (_colorsofthewind str)) $ 
(6 67 9 175)

 

HTH

 

0 Likes
Message 7 of 8

msarqui
Collaborator
Collaborator

@pbejse wrote:

What i intended to do with the code is count ALL the colors that are used on selected MTEXT's , so 

 

_$ (setq colordata (_colorsofthewind str colordata))
(6 67 9 175)

colordata as the collected colors after processing the selection sets.

 

Passing a nil value would also work if the user is intending to count colors per selected MTEXT.

 

_$ (setq colordata (_colorsofthewind str nil))
(6 67 9 175)

 

 


I see now!

Many thanks,

Marcelo

0 Likes
Message 8 of 8

pbejse
Mentor
Mentor

msarqui wrote:

I see now!

Many thanks,

Marcelo


Good for you Marcelo. and You are welcome.

 

Cheers

0 Likes