Skip to content

Instantly share code, notes, and snippets.

@mario52a
Last active August 12, 2021 23:52
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mario52a/4b02a6db5e168eaa0d12 to your computer and use it in GitHub Desktop.
Save mario52a/4b02a6db5e168eaa0d12 to your computer and use it in GitHub Desktop.
This small macro create a circle or arc giving radius, diameter, circumference, area, startangle, endangle, arc, anglecenter, cord, arrow, center (point), placemObject on choice. The circle is still facing the screen (with getCameraOrientation) (or give the placement)
# -*- coding: utf-8 -*-
# creer un cercle ou un arc entierement parametrabel en utilisant :
# create a circle or arc fully parametrabel using:
# x x x coordinates
#with radius
#with diameter
#with circumference
#with area
#with startangle
#with endangle
#with [arc and anglecenter] in combination (angle in degrees)
#with [cord and arrow] in combination
#with center (if center as different 0 one point is created on center of circle)
#give placemObject
# ex :pl=FreeCAD.Placement()
# pl.Rotation.Q=(0.0,-0.0,-0.0,1.0)
# pl.Base=FreeCAD.Vector(-1.89847898483,-0.490152746439,0.0)
# placemObject = pl
# s'il n'y a pas de parametre "circle()" une liste des fonctions s'affiche dans la Vue rapport
# if there is no parameter "circle()" a list of functions is displayed in the report view
__title__ = "circle"
__author__ = "Mario52"
__date__ = "10/06/2018"
import Draft #, Part
def circle(x=0.0,y=0.0,z=0.0,radius=0.0,diameter=0.0,circumference=0.0,area=0.0,startangle=0.0,endangle=0.0,arc=0.0,anglecenter=0.0,cord=0.0,arrow=0.0,center=0,placemObject=""):
from math import sqrt, pi
if placemObject == "":
pl = FreeCAD.Placement()
pl.Rotation = FreeCADGui.ActiveDocument.ActiveView.getCameraOrientation()
pl.Base = FreeCAD.Vector(x,y,z)
else:
pl = placemObject # placement imposted
if diameter != 0: # with diameter
radius = diameter / 2.0
elif circumference != 0: # with circumference
radius = (circumference / pi) / 2.0
elif area != 0: # with area
radius = sqrt((area / pi))
elif (cord != 0) and (arrow != 0): # with cord and arrow
radius = ((arrow**2) + (cord**2) / 4.0) / (arrow*2)
elif (arc != 0) and (anglecenter != 0): # with arc and anglecenter central in degrees
radius = ((360/anglecenter)*arc) / pi/2.0
if endangle != 0:
startangle = endangle - anglecenter
endangle = anglecenter + startangle
startangle = endangle - anglecenter
if radius != 0:
try:
Draft.makeCircle(radius,placement=pl,face=False,startangle=startangle,endangle=endangle,support=None)
if center != 0:
Draft.makePoint(x,y,z)
except Exception:
App.Console.PrintError("Unexpected keyword argument" + "\n")
else:
App.Console.PrintMessage("Unexpected keyword argument" + "\n")
App.Console.PrintMessage("circle(x,y,z,radius,diameter,circumference,area,startangle,endangle,[arc,anglecenter],[cord,arrow],center,placemObject)" + "\n")
#example
#circle(arc=50,anglecenter=20,center=1)
#circle(x=65,y=-15,arc=3.5,anglecenter=40,startangle=20,center=1)
#circle(5)
#circle(cord=140,arrow=42)
@mario52a
Copy link
Author

mario52a commented Jan 2, 2016

This macro utility is intended for the use of the program FreeCAD http://www.freecadweb.org/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment