Automated Random Hatch Pattern and Colour Creation

Automated Random Hatch Pattern and Colour Creation

MaccyDee
Enthusiast Enthusiast
2,017 Views
10 Replies
Message 1 of 11

Automated Random Hatch Pattern and Colour Creation

MaccyDee
Enthusiast
Enthusiast

hi all, i m looking for a lisp that will take from a selection of colours or a colour book and the standard hatch patterns in autocad and mix and randomise them, they need to be singular hatch entities with solid background and colour on top, i attached some examples of what i mean and the colour pallete it needs to choose from.

 

thanks in advance much appreciated

0 Likes
2,018 Views
10 Replies
Replies (10)
Message 2 of 11

3wood
Advisor
Advisor

Random for all 3 properties of "Color", "Type" and "Background Color"?

Capture.JPG

0 Likes
Message 3 of 11

Sea-Haven
Mentor
Mentor

There is lots of examples about random numbers so 1st answer is Lee-mac.com random number lisp. It allows you to get say a number using Autocad color numbers from a list of available, the hatch pattern same  again make a list of hatch pattern names in current dwg. 

 

You need to run with solid and a random color then a pattern with color, need a check color not same or nothing appears. May need draw order also.

 

 

;; Rand  -  Lee Mac
;; PRNG implementing a linear congruential generator with
;; parameters derived from the book 'Numerical Recipes'

(defun LM:rand ( / a c m )
    (setq m   4294967296.0
          a   1664525.0
          c   1013904223.0
          $xn (rem (+ c (* a (cond ($xn) ((getvar 'date))))) m)
    )
    (/ $xn m)
)


;; Random in Range  -  Lee Mac
;; Returns a pseudo-random integral number in a given range (inclusive)

(defun LM:randrange ( a b )
    (+ (min a b) (fix (* (LM:rand) (1+ (abs (- a b))))))
)


(setq lst1 (list "NET" "ANSI31" "ANSI32" "ANSI33" "BRASS"))
(setq lst2 (list 255 252 170 160 152 175 173 151))

(repeat 5
(princ (setq col (nth (- (LM:randrange 1  1) lst2)))
(princ "\n")
(princ (setq pat (nth (- (LM:randrange 1 5) 1) lst1)))
(princ "\n")
)

 

 

 

 

 

The hatch is 2 steps hatch solid color 1, random hatch pat2 and change its color, then use draworder if necessary.

 

0 Likes
Message 4 of 11

Kent1Cooper
Consultant
Consultant

@Sea-Haven wrote:

....

You need to run with solid and a random color then a pattern with color, need a check color not same or nothing appears. May need draw order also.

....


I don't know in which version this was introduced, but you can now Hatch with a background color, in one Hatch object.  [The sample drawing uses that feature.]  That means there's no need to use the SOLID pattern separately, nor to worry about draw order.  But you still would need to verify that the background color is not the same as that of the pattern [unless "random" means truly random, accepting the possibility that they could be the same].

Kent Cooper, AIA
Message 5 of 11

Kent1Cooper
Consultant
Consultant

@3wood wrote:

Random for all 3 properties of "Color", "Type" and "Background Color"?


[I think that should really be "Color", "Pattern name" and "Background Color."  @MaccyDee, is that correct?]

Kent Cooper, AIA
0 Likes
Message 6 of 11

Kent1Cooper
Consultant
Consultant

Further questions arise:

 

The sample drawing uses only 5 patterns, which all seem to work comparatively at the same scale factor [though the ANGLE patterns has a noticeably less "dense" appearance than the others].  Would there be other patterns in addition, and if so, would the scale need to be different for any of them to keep a similar visual density?

 

They're not all at the same angle.  Should they all be the same, or should the angle also be randomized?  If so, randomized among only 45°-multiple angles as all of them in the sample are, or at any random angles?

 

Some are Associative, but not all.  Should they all be the same?

 

Are you after a similar stack of rectangular ones, all at the same size and shape, and spaced as in the sample?  How many, or should that be asked of the User?  Multiple columns of them if more than a certain amount?  Or would you be picking existing boundary objects?

 

Do you need the rectangle Polyline boundaries [which somehow are all doubled]?  Hatches can be defined without a pre-drawn boundary, and when the boundary is drawn inside the command, you have the choice of whether or not to keep it.

Kent Cooper, AIA
0 Likes
Message 7 of 11

john.uhden
Mentor
Mentor

@Sea-Haven 

Here's one I just thought up.  It creates a random number (integer) within a given range.

Of course it will not work as hoped for high highs because millisecs are apparently 10 digits long, but it should work for a high up to 1000.  You also can't repeat it rapidly as the time will not have changed enough.

But if you lower the high and raise the 6, the results will be more disparate.

(defun @random# (low high / #)
  (setq # (atoi (substr (itoa (getvar "millisecs")) 6)))
  (setq # (fix (+ low (rem # (- high low -1)))))
)

The -1 is to allow for a #  equal to the high (at least I think so without hours of testing).

John F. Uhden

0 Likes
Message 8 of 11

john.uhden
Mentor
Mentor

I think this is improved.

If low is higher than high, it swaps high and low.

But low and high cannot be equal.

Yes, either or both numbers can be negative and can be reals, but it always returns an integer.

(defun @Anonymous# (low high / #)
  (setq # (atoi (substr (itoa (getvar "millisecs")) 6)))
  (if (> low high)(mapcar 'set '(low high)(list high low)))
  (if (or (= # high)(= # low))
    #
    (fix (+ low (rem # (- high low))))
  )
)

 

John F. Uhden

0 Likes
Message 9 of 11

MaccyDee
Enthusiast
Enthusiast

correct.

0 Likes
Message 10 of 11

MaccyDee
Enthusiast
Enthusiast

good points didn't really think much about the particulars of the hatching, I've attached a dwg of what i'm actually trying to achieve (autohatch (2)).

- these drawings aren't shown to scale (not necessary)

- the hatching should be associative

- angles aren't super important to control (i change them sometimes to help differentiate similar patterns and colours)

- its not essential to fill a boundary or a pre defined area, even just printing out a random selection of colours and patterns on the dwg somewhere (if i could chose how many to create that'd be really handy, as the amount of stages always differs) that'd be more than fine.

 

thanks again.

 

the white case outlines (colour_outline) are already there before starting so that removes one step i guess

the colour table on the right is the colours i have available to use and the random pattern swatch is something i created to quickly select a "random" one

 

dwg 'autohatch(1)' is a colour/pattern table i've made, perhaps some one could even put those into a randomly selectable table (careful this file can be a bit sluggish on some computers)

0 Likes
Message 11 of 11

timothy_crouse
Collaborator
Collaborator

I saw this reply about hatch background color and thought HOLY @#$ :), that's nice to know.  I had no I idea that was a thing.

 

Thanks,

-Tim C.

0 Likes