Reputation: 418
Maybe this will help others trying to learn through tutorials/documentation/stackoverflow.
How can I rotate or translate a TopoDS_Shape (or any object), providing coordinates, angles, and axis? For Example: If my part is at (5.0, 1.0, 0.0), can I move it to (0.0, 0.0, 0.0)? Or make it face a new direction?
Attempted methods (not including what I think is unimportant code). I've tried to include some of the stuff I've spent most of my time on. Can't recall all of the other attempts I've made. Maybe someone experienced with PythonOCC or OpenCascade can see where I'm going wrong.
display, start_display, add_menu, add_function_to_menu = init_display()
aResShape = openFile.open(fileToOpen) #RETURNS SHAPE FROM STEP FILE
aResShape.Orientable(True)
#EXAMPLE
aResShape.Location().Transformation().SetRotation(gp_Quaternion(1., 1., 0., 1.))
#EXAMPLE
aResShape.Location().Transformation().SetTransformation(a,b)
#EXAMPLE
aResShape.Move(TopLoc_Location(gp_Trsf( gp_Trsf2d(1., 0.) )))
#EXAMPLE
aResShape.Reverse()
#EXAMPLE
p1 = gp_Pnt(700., 10., 80.)
d1 = gp_Dir(50., 50., 60.)
a = gp_Ax3(p1, d1)
p2 = gp_Pnt(2., 3., 4.)
d2 = gp_Dir(4., 5., 6.)
b = gp_Ax3(p2, d2)
print(aResShape.Location().Transformation().Transforms())
aResShape.Location().Transformation().SetTransformation(a,b)
print(aResShape.Location().Transformation().Transforms()) #RETURNS SAME VALUES
#EXAMPLE (TRYING TO SEE WHAT WORKS)
transform = gp_Trsf
transform.SetRotation(
gp_Ax1(
gp_Pnt(0.,0.,0.),
gp_Dir(0.,0.,1.)
),
1.570796
)
print(transform)
display.DisplayShape(aResShape, color='Black', update=True)
display.FitAll()
display.SetModeWireFrame()
start_display()
Sometimes I'll get errors like this:
NotImplementedError: Wrong number or type of arguments for overloaded function 'new_gp_Trsf2d'.
Possible C/C++ prototypes are:
gp_Trsf2d::gp_Trsf2d()
gp_Trsf2d::gp_Trsf2d(gp_Trsf const &)
But most of the time I get nothing and the shape doesn't change in the display.
Spent days in here: https://cdn.rawgit.com/tpaviot/pythonocc-core/804f7f3/doc/apidoc/0.18.1/index.html
https://dev.opencascade.org/doc/refman/html/index.html
https://github.com/tpaviot/pythonocc-demos/tree/master/examples
So I know what functions to pass I think, but nothing seems to work out.
Maybe the display simply isn't showing me changes that are actually happening?
I asked a different PythonOCC question earlier (pythonOCC set default units to inches) but I think I'm really just missing something basic.
Can anyone think of why I'm not managing to make any real changes? Thanks for your time!
Upvotes: 1
Views: 2793
Reputation: 1
I used Open Cascade with C++ and BRepBuilderAPI_Transform(const TopoDS_Shape &S, const gp_Trsf &T, const Standard_Boolean Copy=Standard_False)
is achieving transformation. See:
https://www.opencascade.com/doc/occt-6.9.1/refman/html/class_b_rep_builder_a_p_i___transform.html
This is how i used it:
gp_Trsf trsf;
trsf.SetTransformation(gp_Quaternion(gp_Mat(gp_XYZ(d.x1, d.y1, d.z1), gp_XYZ(d.x2, d.y2, d.z2), gp_XYZ(d.x1, d.y1, d.z1).Crossed(gp_XYZ(d.x2, d.y2, d.z2)))), gp_Vec(d.x, d.y, d.z));
*d.shape = BRepBuilderAPI_Transform(*d.shape, trsf, true);
Upvotes: 0