0

I am using ezdxf to read some .dxf files. The goal is to read the file using ezdxf and access each entity the the drawing's modelspace to find arc lengths.

import ezdxf

file_path = "IRREGULAR.dxf"
doc = ezdxf.readfile(file_path)

msp = doc.modelspace()
for entity in msp:
    print(entity.dxftype())
    
    # I have some more code for other line types

    if entity.dxftype() == 'ARC':
        center_point = entity.dxf.center
        radius = entity.dxf.radius
        start_angle = entity.dxf.start_angle
        end_angle = entity.dxf.end_angle
        print(arc_length(radius, start_angle, end_angle))

I have created a function called arc_length that calculates arc lengths based on each arc's dimensions.

This is the irregular shape I am currently working with.

shape

This shape is broken down into multiple arcs.

I am viewing the same drawing on a CAD software to see how the arc lengths between my code and the CAD software compare. The challenge is that out of the 6 arcs in this drawing, I am getting 5 dimensions that are exactly matching in both places. However, the rightmost arc length is way too off in my code. I verified and there are no additional layes or blocks that are unseen, and that I am looking at the same drawing in both places.

If I can get any help on how to fix this, or leads on what the potential issue could be, it would be extremely helpful. Thanks!

Something I tried was getting all arc dimensions and then recreating a shape using those. Surpringly, the shape after this reverse engineering turned out to be the correct shape that I started with. This is strange because if the arc dimensions were wrong, then I would have ended up with a weird shape.

3
  • I have been working on similar functions, I would like to help. Could you make a minimal reproducible example - see stackoverflow.com/help/minimal-reproducible-example - and post a link to your DXF? Commented Apr 3, 2024 at 15:38
  • 1
    Examine how your arc-length function is calculating lengths from angles. The "rightmost" strata-angle is approx 315 deg, end angle is approx 45 deg. In this case just end_angle - start_angle will not give the included angle, but rather 360 minus included angle. if it uses that value to compute an arc length, you will not get the correct result. I expect your "reverse engineered" shape was still correct because if arcs are created from Start, end, center parameters this does not depend on length or included angle. Commented Apr 7, 2024 at 14:13
  • 360 minus included angle totally worked!! thank you so so much Commented Apr 10, 2024 at 6:21

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.