Writing a relatively simple DXF file


I need to write out a relatively simple DXF for various CAM software.

I have 2 issues both regarding arcs:

  1. How to determine when to use which Sagitta formula.
  2. How to determine the direction of a single arc.



I am using this formula for directionality


a = curve.vertices[0].position
b = curve.vertices[-1].position

I run a second pass if it returns 0
b = curve.vertices[-2].position


I am currently checking the end_angle against 180 degrees which gives me the proper results providing the angle isn’t exactly 180


In an empty SKP make two Arcs - one reversed.
Write out those two simple Arcs from the SKP to a DXF.
Open that DXF in Notepad++ and read how each Arc is defined.
Import the DXF into an empty SKP to check it works.

Copy the DXF file.
Now delete one of that DXF file’s Arc definitions.
Import that changed DXF file into an empty SKP.
See which Arc gets made.

Now you know the difference between the two Arc definitions in the DXF.

Apply those differences to your Ruby code that is writing your own DXF…


Mitch helped me out. He provided an alternate way to determine arc direction and he provided an alternate way to calculate the sagitta.


One of the problems I was having was not being able to get good information from Sketchup on relatively tiny arcs. I’m using the CNC to label various cabinet parts and the cabinet numbers need to be very small.


In this case Sketchup displayed the 88 correctly but only the top arc of the 8 showed up as an entity ArcCurve. Checking out the bottom arc it returned a negative length, an incorrect normal, incorrect last vertex and a negative end_angle. I could select the top arc, but when I tried to select the bottom arc only 2 edges selected.

I stumbled across a solution that works for me. The solution is to have the script put the geometry inside a group which is inside a group. Then explode the inner most group. As we know Sketchup transforms geometry during an explode and the geometry inherits the layer. Now I can select the bottom arc and Sketchup returns the proper information.