Skip to content

Instantly share code, notes, and snippets.

@dov
Created March 14, 2024 07:56
Show Gist options
  • Save dov/a88df9453e85bef54bf1778e392206d1 to your computer and use it in GitHub Desktop.
Save dov/a88df9453e85bef54bf1778e392206d1 to your computer and use it in GitHub Desktop.
Creating fillets with OCP
#!/usr/bin/python
######################################################################
# Example of how to use ChFi2d_FilletAPI to create fillets.
#
# 2024-03-14 Thu
# Dov Grobgeld <[email protected]>
#
# This file is in the public domain
######################################################################
import OCP
from OCP.ChFi2d import ChFi2d_FilletAPI
from OCP.gp import gp,gp_Pnt,gp_Dir,gp_Ax1,gp_Ax2,gp_Trsf,gp_Vec,gp_Pln
from OCP.BRepBuilderAPI import (BRepBuilderAPI_MakeEdge,
BRepBuilderAPI_MakeWire,
BRepBuilderAPI_MakeFace,
)
from OCP.BRepPrimAPI import BRepPrimAPI_MakePrism
import cadquery as cq # Just for display of the output
# Input consists of a triangle. We want to fillet
# the corner at aPnt2
aPnt1 = gp_Pnt(0,0,0)
aPnt2 = gp_Pnt(5,5,0)
aPnt3 = gp_Pnt(10,0,0)
seg1 = BRepBuilderAPI_MakeEdge(aPnt1,aPnt2).Edge()
seg2 = BRepBuilderAPI_MakeEdge(aPnt2,aPnt3).Edge()
seg3 = BRepBuilderAPI_MakeEdge(aPnt3,aPnt1).Edge()
# Create the fillet maker
aPln = gp_Pln()
fillet_maker = ChFi2d_FilletAPI(seg1, seg2, aPln)
radius = 2
ok = fillet_maker.Perform(radius)
print(f'{ok=}')
# The res returns the result, and seg1 and seg2 are modified
# due to the fillet
res = fillet_maker.Result(aPnt2, seg1, seg2)
print(f'{res=}')
# Build a wire with the result
mkWire = BRepBuilderAPI_MakeWire(seg1,res,seg2,seg3)
myWireProfile = mkWire.Wire()
# Create a solid body in order to easily export the result
# and use cad query's stl output.
# Body : Prism the Profile
myFaceProfile = BRepBuilderAPI_MakeFace(myWireProfile).Face()
aPrismVec = gp_Vec(0, 0, 1)
res = BRepPrimAPI_MakePrism(myFaceProfile, aPrismVec).Shape()
comp = cq.Compound.makeCompound(cq.occ_impl.shapes.Solid(res))
comp.exportStl('fillet-edge.stl')
print('ok')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment