📜 ⬆️ ⬇️

Writing a script for arranging elements in a circle for Eagle CAD


Some time ago I wondered about the uniform circular arrangement of elements on a printed circuit board. First I set it manually through the polar coordinates, then I generated a sequence of commands for all 30 elements and at once executed everything in the command line of the Eagle. Today I will touch on the topic of writing your own ULP script Eagle Cad for uniform and automatic arrangement of elements in a circle.


For the convenience of writing a script, all elements must have consecutive indexes, follow this at the stage of drawing up the concept. As you have probably guessed from the “attention drawing picture”, I will work with ws2812b diodes. It is necessary to arrange 30pcs evenly along the radius of 40mm.


')
Commands in Orel are executed either relative to the origin of coordinates, or relative to the marker Mark. We set the marker in the right place. For clarity, I drew an auxiliary circle with a radius of 40mm.



First we need to understand the syntax of the two commands. They can be executed in the command line Eagle. Practice it.

Item move command:
move <> (<>) 

Pivot command:
 rotate =r<> <> 

<name> is the name of our element L1..L30
<parameter> - in our case, the parameter will be the polar coordinate (p <radius> <angle>) .
<angle> is respectively the angle at which we move the element.

If before the value of the angle of rotation is the sign “=”, then we will set the absolute angle of rotation for the part. If without the “=” sign, the angle is added to the current value of the part angle.

Next, you need to create a * .ulp file that will house our script. I will give the whole script, the benefit is small.

 int N = 30; //  int Radius = 40 ; //   int Step = 360/N; //         ( 360 /   ) string cmd = ""; //     string h = ""; //  for (int Count = 1; Count <= N; Count++) { //  N  sprintf(h, "move L%d (p %d %d); rotate =r%d L%d;", Count, Radius, Step*Count, Step*Count+90, Count); //  ,       %d cmd += h; // ,    } exit(cmd); //   

Everything is simple, in a cycle from 1 to 30 we form pairs of the move and rotate commands. As the angle of the polar coordinate and the angle of rotation, the angle is Count * 360 / N , where Count is the iteration number and N is the number of elements. I will pay attention that 90 ° is added to the angle of rotation. This is so that the diodes are located along the ring, and not across.

We execute the script through the ULP button in the PCB editor.



Result immediately. By canceling the result with the keyboard shortcut Ctrl + Z , you can see the sequence of the commands.

All beaver!

Source: https://habr.com/ru/post/254861/


All Articles