Direction of a Draft circular arc

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
jreinhardt
Posts: 329
Joined: Mon Sep 09, 2013 6:08 pm

Direction of a Draft circular arc

Post by jreinhardt »

Hi,

I am trying to write a macro that replaces a polygonal approximation of a circular arc in a draft by a real one. I got the geometry figured out, but I have some problems on the final stages. The current state of the macro is attached below.

It is supposed to work as follows. You have to break down the wire that contains the polygonal arc into edges using the downgrade tool from draft. Then you select the edges that are part of the arc that you want to convert and execute the macro.

The macro finds the start and end points and angles and determines the center and radius of the arc by a steepest descent search.

Now I want to construct a circular Arc to replace the linear segments.

I looked at the python console commands that result from using the arc tool, and read a bit in the code, but couldn't figure out how to specify the direction of the arc. It always seems to be clockwise and I found no way to change that.

Another problem is that I have problems to incorporate the arc into the wire, not even manually. I delete the edges of the polygonal arc, mark all remaining edges and the arc and click on upgrade, but get the message "Unable to upgrade these objects.

OS: Ubuntu 13.04
Platform: 64-bit
Version: 0.14.2913 (Git)
Branch: master
Hash: d77d672cfb3cc57a92b5549ec7386dbbb16bfd86
Python version: 2.7.4
Qt version: 4.8.4
Coin version: 3.1.3
SoQt version: 1.5.0
OCC version: 6.5.0
Attachments
edgesmacro.zip
(962 Bytes) Downloaded 92 times
BOLTS, standard parts library for FreeCAD Thread, Help with Translation
User avatar
yorik
Founder
Posts: 13640
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels
Contact:

Re: Direction of a Draft circular arc

Post by yorik »

Hi,
there might be many reasons why the upgrade tool doesn't want to upgrade your objects... Hard to tell without seeing the file.

About arcs direction: the opencascade kernel doesn't care about the direction of things. So in a same wire, you can have a lot of components with different orientations. So you can never be too sure about which direction an element will have. MyArc.Curve.Axis will give you the normal of the arc (MyArc being an edge).

One method I usually use to make sure I have the arc I want, is to use the Part.Arc() method with 3 points: start, middle, end. There is the method DraftGeomUtils.findMidpoint() which will return you the midpoint of an arc, so you can recreate an exact same arc, no matter its original direction.
jreinhardt
Posts: 329
Joined: Mon Sep 09, 2013 6:08 pm

Re: Direction of a Draft circular arc

Post by jreinhardt »

Thanks, this hint was very valuable.

By using the three point Arc constructor, I could get rid of my slightly dodgy center finder code, and avoid the upgrade problems.

I put the finished macro on the wiki here.
BOLTS, standard parts library for FreeCAD Thread, Help with Translation
Post Reply