app
AI Flow
Public Made by Adomby adom
Adom's AI Flow: a tool to help the AI follow all of the steps it takes to build a board.
← Commit history
Publish 0.1.45
3 files changed
+6−2
bin/adom-aiflowtools/laser-etch/etch_part.pytools/laser-etch/rotate_step_xcaf.py+6−2@@ -1,7 +1,9 @@ #!/usr/bin/env python3 """Rotate a STEP about Z through its bbox centre, keeping colours and names (XCAF): used to lay a laser-etch mark along a part's long axis when the etch service writes across X only.-Usage: rotate_step_xcaf.py <in.step> <out.step> <degrees> [x|y|z, default z]"""+Usage: rotate_step_xcaf.py <in.step> <out.step> <degrees> [x|y|z, default z] [px,py,pz]+The optional pivot fixes the rotation centre (the side-face etch rotates forward and back about the SAME+point, so a mark that grows the bbox cannot shift the undo); without it the old behaviour is kept.""" import sys, math from OCP.STEPCAFControl import STEPCAFControl_Reader, STEPCAFControl_Writer from OCP.STEPControl import STEPControl_AsIs@@ -15,6 +17,7 @@ from OCP.Bnd import Bnd_Box from OCP.BRepBndLib import BRepBndLib src, out, deg = sys.argv[1], sys.argv[2], float(sys.argv[3]) axis = sys.argv[4] if len(sys.argv) > 4 else "z"+pivot = [float(v) for v in sys.argv[5].split(",")] if len(sys.argv) > 5 else None doc = TDocStd_Document(TCollection_ExtendedString("doc")) r = STEPCAFControl_Reader(); r.SetColorMode(True); r.SetNameMode(True); r.SetLayerMode(True) r.ReadFile(src); r.Transfer(doc)@@ -30,7 +33,8 @@ b = Bnd_Box() for l in labs: BRepBndLib.Add_s(st.GetShape_s(l), b) mn, mx = b.CornerMin(), b.CornerMax() d = {"x": gp_Dir(1, 0, 0), "y": gp_Dir(0, 1, 0), "z": gp_Dir(0, 0, 1)}[axis]-t = gp_Trsf(); t.SetRotation(gp_Ax1(gp_Pnt((mn.X()+mx.X())/2, (mn.Y()+mx.Y())/2, (mn.Z()+mx.Z())/2 if axis != "z" else 0), d), math.radians(deg))+pc = gp_Pnt(*pivot) if pivot else gp_Pnt((mn.X()+mx.X())/2, (mn.Y()+mx.Y())/2, (mn.Z()+mx.Z())/2 if axis != "z" else 0)+t = gp_Trsf(); t.SetRotation(gp_Ax1(pc, d), math.radians(deg)) # wrap the untouched shapes in a new assembly carrying the rotation: the colours stay on the originals asm = st.NewShape() for lab in labs: