Wouldyou want it to be truly random, which includes the possibility that more than one Layer [even potentially all of them, however unlikely that is] will be given the same color? Or would you want colors that have been assigned already to be passed over in later assignments?
Related questions: Would you ever have enough Layers that it would be necessary to give the same one to more than one Layer? If so, would you want to resort to TrueColor assignments, not just the integer-designated colors, so that you can have actually-different colors for a far greater number of Layers?
[And a comment: By "between 0 and 256" you must mean non-inclusive, i.e. from a minimum of 1 to a maximum of 255, but not either 0 [ByBlock] or 256 [By Layer], since those cannot be assigned as colors to Layers, but only to objects.]
Here's one [lightly tested] that doesn't duplicate numbers [keeping a list of those it's used already], but that therefore is limited to 255 Layers. It could be enhanced to start using colors over again if there are more than 255 Layers, but if you ever get even close enough to that many, it might also need to be altered to approach it a little differently. Consider -- when it's already used all but, say, 3 or 4 colors, how long might it take for the random number generator to "hit" one of the remaining available numbers? It could use a list of the numbers from 1 to 255, and take out the ones it uses as it goes, with the random number being used as a position in the list of the remaining available numbers, rather than as a color number per se.
It uses a random number generator I came up with a few years ago, but there are entirely different approaches to that available. This one gets the last 7 [the most rapidly changing] digits from the DATE System Variable, and from them calculates an integer from 1 to 255. But even those last 7 digits could be the same in consequent calls to it that are close enough in time [these things happen pretty fast], so it shifts around the digits it pulls each time to further randomize the result. [It could also be made to force a little time between calls by using a Layer command rather than the (vla-put...) approach.]
Another thing -- it includes assigning random colors to Layers 0 and DEFPOINTS, but could easily be made to avoid those, if you like. Similarly, it doesn't differentiate Xref-dependent Layers, if present, but it could be made to skip those if appropriate.
How I will use this is twofold...
For my color elevations, I create each level (general planes of building depth) for my elevation with each plane stacked on top of ea other about 50' apart. I put all of the "brick" elements on the same "brick" layer for level, then all of the "glass" on the glass, etc... So Maybe I have 6 levels to my building. I then copy clip each level into a new drawing, rename all of the layers to being with their level number, 01-Brick, 01-glass, etc... using the rename tool & paste back into my original drawing. Then repeat for each level. At this point, I will randomize the layers so that visually, once I take them into Photoshop, through illustrator, I can see the difference between each similar element and now your lisp will do this for me.
Also, when I build models in AutoCad, I like to put my different elements on different layers for ease of organization & isolation and again, the layer color randomizer will just help me to easily differentiate between objects without having to manually change the color of all of my layers.
You're welcome. Given your description, I would be inclined to not use fully random color numbers, but to limit it to colors that are easily visible and distinguishable. For instance, leave out the multi-digit ones ending in 6/7/8/9, as well as 250/251 [the darkest ones], because depending on your background color, they're too hard to tell apart or too hard to see, and leave out the ones that look just like the first 6 or 7 [e.g. color 10 is visibly indistinguishable from 1] or just leave out the first 6 or 7 instead, and some of the grays are too similar, etc. That would, of course, reduce the number of Layers you could cover this way, and would require some difference in approach such as a list of color numbers as mentioned before. But it might serve the purpose as you describe it better.
But also consider standard Layers for the typical materials, with "appropriate" colors assigned. Compared to Layer colors randomized differently in every drawing, you would not merely be able to tell Layers apart, but could know by sight which Layer is which.
@Kent1Cooper my intention is to assign quasi-random colours to each layer, while explicitly avoiding certain colours (colours which would be difficult to see on a black background), with as few duplicate colours as possible. I understand that in situations where my layer count is high... duplication of some layer colours will be unavoidable.
Do you believe that if I were to reformulate my colour selections, that would solve my issue? Or would there be a better way, perhaps by providing a list of black-listed colours that are off limits to the 'r01' function?
This online random number generator offers different methods of creating lists of random numbers, XY or XYZ coordinates. It can be used for CAD applications as well as for pure mathematical modelling. You can choose from a variety of preset probability distributions. By default it uses a pseudo-random number generator, but you can switch it to better cryptographic methods of random number generation (requires JavaScript).
This calculator generates the .DXF and .SVG files for making external spur gears, rack and pinion sets, and internal spur gears. DXF files are accepted by most machines that cut 2D shapes such as CNC wood routers, laser cutters, waterjets, and CNC plasma tables. A DXF is also the starting point for various CNC machines that require CAM software. Standard spur gear calculations, graphics, and .DXF files have never been more accurate, accessible, or easy. Involute tooth form only. Clocks use the cycloidal or triangular tooth forms.
To calculate a spur gear, simply decide and input your tooth count, gear module, and pressure angle and the online spur gear DXF generator will do the rest. A spur gear calculator uses these parameters to generate the involute tooth form that's the right size and shape to take into your CAD software, or straight to a CNC router or laser cutter.
The live output lets you visualize your spur gear to ensure you have the right fit and to manage the undercut and gear size, while the .DXF and .SVG outputs will fit into your CAD software or graphics software. If you're looking to make the right gear blank for your gear, you can use our free Gear Dimension Calculator to find the key dimensions of your external spur gear.
Spur gears can be used in a wide variety of applications. Having a DXF or SVG file for your gear is the first step to building your new gear project. After you have your 2D model of your spur gear, you can use this file for a range of applications.
One of the more common mistakes we see in simplified gear software is the lack of undercut in small tooth count gears. This can make gears bind or function poorly. We also see low resolution involute shapes that could function better if they had the correct geometry with sufficient data points defining the involute.
Being members of the American Gear Manufacturers Association (AGMA) and having manufactured gears in most plastics and metals, the details count. So we put the same attention to detail and mathematical skill to work for everyone. For measuring and inspecting gears, using a Measurement Over Pins Calculator is one of the best methods to ensure your gears are perfectly in-spec.
Pro-Tip! Notes for the wood shop or anyone using an endmill to make the cut:
The bit size is a very important consideration! Depending on your software, if the cutter is too large it will either over-cut the root and weaken the tooth, or leave a radius and not finish the involute profile or undercut. When using your CAD program, compare the cutter diameter to the gear's root space to make sure it's small enough and has some clearance
Spur gears transmit power through parallel shafts. The ratio of tooth count between two gears changes the relative speed of those gears by that ratio. Spur gears can increase or decrease the speed of a mechanical system, increase or decrease its available torque, or change direction from forward to reverse.
The module of a gear controls its size. Module is the ratio of the reference diameter divided by the number of teeth; so that a gear with a larger module will have a larger diameter. Small module gears (0.1-0.5) are found in watches and clocks, while larger module (1+) may be found in machine transmissions. More here
If there is a specific task that you wish to automate using custom programming, feel free to contact me to hire my services. Want to know what you're missing out on? Read the testimonials of those who have worked with me and my programs.
This site is primarily aimed towards utilising the AutoLISP & Visual LISP APIs to create custom programs which may be run within full versions of AutoCAD (not LT versions) and many of its derivative programs.
In addition to my custom programming services, I offer a plethora of free LISP programs available for you to download, covering a huge range of applications: from text manipulation to attribute extraction and everything inbetween.
AutoLISP is a dialect of the LISP programming language engineered to enable manipulation & customisation of AutoCAD and many of its derivative programs such as Civil 3D, MEP, Architecture, Electrical etc. Other applications such as BricsCAD and IntelliCAD also offer the ability to run AutoLISP programs. Historically, AutoLISP was only supported by full versions of AutoCAD and could not be run on any version of AutoCAD LT; however, whilst AutoCAD LT 2024 introduced support for LISP, the LISP API in this release has several restrictions and consequently a number of my programs may not be compatible on this platform.
3a8082e126