Simple routine to create an array of elements with subsequent RGB color values.

Simple routine to create an array of elements with subsequent RGB color values.

Anonymous
Not applicable
2,154 Views
9 Replies
Message 1 of 10

Simple routine to create an array of elements with subsequent RGB color values.

Anonymous
Not applicable

Hey VLisp Folks,

 

I'm glad to write my first post in this forum.

I started to learn VLisp about 2 weeks ago to execute (as I thought) a simple routine.

I want to create an array of squares filled with hatching that have subsequent RGB color values.

So first square is filled with (R:0 G:0 B:0), second (R:0 G:0 B:1), third (R:0 G:0 B:2) ... last (R:0 G:0 B:255).

I want to start with this simple task in order to create a larger color gradient.

 

The reason for that task is that we are always having a trouble to print correct colors on our company plotter.

I want to create a sample plot for everyone in my office to match screen colors with plotter colors easier.

 

So far I wrote the piece of code below, but the last line of code (setting color property to the last created object) is not working.

 

Please, let me know where are my bugs. Also, I'd be glad to get some reasonable advices as for a beginner into VLisp.

I'm not looking for an advanced solution, that I'll perhaps do not understand. I just want someone to guide me a little bit. Thanks for understanding!

 

(defun c:RGB_Array ()
		(setq repetition (getint "\nNumber of repetitions: "))
		(setq count 0)
		(setq basepoint (list 0 0))
		(setq dist 100)
		(while 	(< count repetition)
			(setq count (1+ count))
			(setq basepoint (list dist 0))
			(setq curcol count)
			(setq current_object (entlast))
			(command "copy" current_object "" "" basepoint (list dist 0))
			(setpropertyvalue current_object "color" 0 0 curcol)
		)	
)

So this piece of code is creating an array but does not change the color of the object.

 

Cheers,

Krzysztof

 

0 Likes
Accepted solutions (1)
2,155 Views
9 Replies
Replies (9)
Message 2 of 10

Sea-Haven
Mentor
Mentor
Accepted solution
(command "chprop" (entlast) "" "c" "TrueColor" col "")

But col must be R,G,B  "0,0,count" (strcat "0,0," (rtos count 2 0))

Message 3 of 10

Anonymous
Not applicable

Thank you for great hint!
The last row of code would look like this then:

(command "chprop" (entlast) "" "c" "TrueColor" (strcat "0,0," (rtos count 2 0)) "")

It works exactly as I wanted. Now I need perhaps to create a nested loop to make 2-dimensional array...

 

0 Likes
Message 4 of 10

Sea-Haven
Mentor
Mentor

RGB has approx. 256*256*256 combinations not sure how many squares you plan, have seen color cards ? Its like 50mm thick of colours you need to work out what you want.

 

Thinking about it now.

 

The Colorwh,dwg has two sets 2nd is rgb. will try to find does not appear in 2020.

 

Found, zoom in click on small squares this is what you want.

 

 

0 Likes
Message 5 of 10

Anonymous
Not applicable

@Sea-Haven Thank you for the color wheels.

For sure those are useful. Unfortunately they do not cover the brightest tones of whites.

 

I imagine 256x256x256 it's over 16 Mio. colors...

Though, I had in mind to create some sort of an array out of 32 array grids from 32x32 colors (32,768 combinations).

 

Another thing, I started to learn programming since one year and I find myself in situations where someone else already solved the problems that I wanted to approach. It's no fun to use shortcuts 🙂

0 Likes
Message 6 of 10

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

.... The last row of code would look like this then:

... (rtos count 2 0)....

The 'count' variable is an integer, so there's no need for mode and precision arguments if you use the more appropriate function.  That (rtos) function can be replaced with:


(itoa count)

Kent Cooper, AIA
Message 7 of 10

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:
.... Please, let me know where are my bugs. ....
....
			(command "copy" current_object "" "" basepoint (list dist 0))
....

So this piece of code is creating an array ....


Apart from the color-assignment correction, are there any error messages as it's creating the array?  It seems to me the red part there is after the command is completed, so I would expect an unknown command message.

 

Further comment:  You have some things going on that you don't need.  Any variable that's set to a fixed value and never changed may as well just have that fixed value used instead of the variable [i.e. dist].  And you don't need the basepoint, curcol or current_object variables, if you structure it something like this [minimally tested]:

(defun c:RGB_Array (/ repetition count)
  (setq
    repetition (getint "\nNumber of repetitions: ")
    count 0
  ); setq
  (while (< count repetition)
    (setq count (1+ count))
    (command "_.copy" "_last" "" "" "_none" "100,0")
    (setpropertyvalue (entlast) "color" (strcat "0,0," (itoa count)))
  ); while
); defun

[You can  use your (setpropertyvalue) approach instead of switching to CHPROP, if you have reason to prefer it, such as that it's a little shorter.  It should also be faster, if the quantities involved are large enough that you would notice the difference.]

 

Kent Cooper, AIA
0 Likes
Message 8 of 10

Anonymous
Not applicable

@Kent1Cooper 
Thank you for your tip!

0 Likes
Message 9 of 10

Anonymous
Not applicable

@Kent1Cooper 

 

Thank you for your help under my posts.

I learned basic Autolisp within a month and already found a solution to my RGB Array matrices.

The code is still a mess but 4096 colorul rectangles are real 🙂

See the outcome as an attachement

 

THANK YOU!

 

0 Likes
Message 10 of 10

Kent1Cooper
Consultant
Consultant

[For a more concise solution, see >this< on the other thread.]

Kent Cooper, AIA
0 Likes