Simple part generation tutorial

TimN

Looking around for some CAD
Hi,

I'm wondering if anyone here knows of a tutorial anywhere on how to implement a simple part. (e.g. an upturned flange) from scratch.

I have a step file created in some other (commercial) cad software and I'm wondering how I could recreate it in OCC.

I'm using python but that's not a huge barrier so if there is a C tutorial that would be great.

I'm a total newbie to cad, so reaaaaal basic would be preferable.

Many thanks,

Tim
 

Jonathan

CAD community veteran
I am a noob and this is probably a poor way to do but it did produce a similar shape.
Standard_Real len = 6;
Standard_Real hei = 15;
Standard_Real wit = 10;
Standard_Real thk = 3;

Standard_Real outside_R = ((thk * 2) < len && (thk*2) < hei) ? (thk*2) : thk;
Standard_Real inside_R = ((thk * 2) < len && (thk * 2) < hei) ? (thk * 2) : thk/2;

gp_Pnt p1(0, 0, 0);
gp_Pnt p2(len, 0, 0);
gp_Pnt p3(len, thk, 0);
gp_Pnt p4(thk, thk, 0);
gp_Pnt p5(thk, hei, 0);
gp_Pnt p6(0, hei, 0);

Handle(Geom_TrimmedCurve) s1 = GC_MakeSegment(p1, p2);
Handle(Geom_TrimmedCurve) s2 = GC_MakeSegment(p2, p3);
Handle(Geom_TrimmedCurve) s3 = GC_MakeSegment(p3, p4);
Handle(Geom_TrimmedCurve) s4 = GC_MakeSegment(p4, p5);
Handle(Geom_TrimmedCurve) s5 = GC_MakeSegment(p5, p6);
Handle(Geom_TrimmedCurve) s6 = GC_MakeSegment(p6, p1);


TopoDS_Edge e1 = BRepBuilderAPI_MakeEdge(s1);
TopoDS_Edge e2 = BRepBuilderAPI_MakeEdge(s2);
TopoDS_Edge e3 = BRepBuilderAPI_MakeEdge(s3);
TopoDS_Edge e4 = BRepBuilderAPI_MakeEdge(s4);
TopoDS_Edge e5 = BRepBuilderAPI_MakeEdge(s5);
TopoDS_Edge e6 = BRepBuilderAPI_MakeEdge(s6);

TopoDS_Wire aWire = BRepBuilderAPI_MakeWire(e1, e2, e3);
TopoDS_Wire aWire2 = BRepBuilderAPI_MakeWire(e4, e5, e6);

BRepBuilderAPI_MakeWire mkWire;
mkWire.Add(aWire);
mkWire.Add(aWire2);
TopoDS_Wire myWireProfile = mkWire.Wire();

TopoDS_Face myFaceProfile = BRepBuilderAPI_MakeFace(myWireProfile);
gp_Vec aPrismVec(0, 0, wit);

TopoDS_Shape myBody = BRepPrimAPI_MakePrism(myFaceProfile, aPrismVec);

BRepFilletAPI_MakeFillet mkFillets(myBody);

ChFi3d_FilletShape FSH = ChFi3d_Rational;
mkFillets.SetFilletShape(FSH);

TopExp_Explorer anEdgeExplorer(myBody, TopAbs_EDGE);

while (anEdgeExplorer.More()) {
Standard_Real u0 = (std::numeric_limits<double>::min)();
Standard_Real u1 = (std::numeric_limits<double>::min)();

TopoDS_Edge theEdge = TopoDS::Edge(anEdgeExplorer.Current());

auto curve = BRep_Tool::Curve(theEdge, u0, u1);

gp_Pnt s = curve->Value(u0);
gp_Pnt e = curve->Value(u1);

if (s.Distance(p1) <= Precision::Confusion() &&
e.Distance(p1.Translated(aPrismVec)) <= Precision::Confusion())
{
Handle(AIS_Shape) edge = new AIS_Shape(theEdge);
mkFillets.Add(outside_R,theEdge);

}
if (s.Distance(p4) <= Precision::Confusion() &&
e.Distance(p4.Translated(aPrismVec)) <= Precision::Confusion())
{
Handle(AIS_Shape) edge = new AIS_Shape(theEdge);
mkFillets.Add(inside_R, theEdge);

}

anEdgeExplorer.Next();

}

if(mkFillets.IsDone())
TopoDS_Shape S2 = mkFillets.Shape();
 

Quaoar

Administrator
Staff member
I am a noob and this is probably a poor way to do but it did produce a similar shape.
Guess what? I copied and pasted your code to the `test` command of AS and it worked almost like a charm:

1661377178172.png
I only think that you might have forgotten this line

Code:
mkFillets.Build();

before checking if the fillets are done.
 

Quaoar

Administrator
Staff member
Thanks - I promise you I am noobier (the noobiest) so that's probably going to take a little while to work through and translate!
The hardest thing is probably just setting up the environment, including all libraries and headers, and then plugging in a decent visualization engine, so that your modeling is not blind. After that, you can learn quite a lot just by messing around with the API functions of OpenCascade.
 
Top