cadquery
cadquery copied to clipboard
Scaling a STEP file in one dimension
I want to perform a scaling operation to a STEP file that i imported.
The problem is, i want to be scaled only on one dimension. Searching the docs (https://cadquery.readthedocs.io/en/latest/classreference.html), i found the scale() function.
However, looking at the source code,
def scale(self, factor: float) -> "Shape":
"""
Scales this shape through a transformation.
"""
T = gp_Trsf()
T.SetScale(gp_Pnt(), factor)
return self._apply_transform(T)
it does not accept axis information.
So, is it possible to scale an item only on one axis?
Maybe i can do this using a scaling matrix?
t = cq.Matrix([
[x, 0, 0, 0],
[0, y, 0, 0],
[0, 0, z, 0],
[0, 0, 0, 1]
])
Any help with how this can be incorporated?
There is some code in this issue that might help you.
Thanks. I tried the code there, but CadQuery has trouble importing the libraries. I get ModuleNotFoundError: No module name 'OCC'
.
I am using the CQ-Editor, standalone application, so how come OCC is not recognized?
Those references should be to OCP now since we've moved away from PythonOCC.
import cadquery as cq
from OCP.gp import gp_Mat, gp_Trsf, gp_GTrsf
# from OCP.Precision import precision_Angular, precision_Confusion
from OCP.BRepBuilderAPI import (BRepBuilderAPI_GTransform,
BRepBuilderAPI_Transform)
from OCP.BRepPrimAPI import BRepPrimAPI_MakeBox
z_delta = -20
xs = 4
#scaleM = cq.Matrix([
#[ xs, 0.0, 0.0, 0.0],
#[0.0, 1.0, 0.0, 0.0],
#[0.0, 0.0, 1.0, 0.0]])
R = cq.Solid.makeBox(10,10,10)
# R1 = R.transformGeometry(scaleM)
#R1 = cq.Shape.cast(BRepBuilderAPI_GTransform(R.wrapped, gp_GTrsf(scaleM.wrapped), True).Shape())
#show_object(R1)
#show_object(R.translate((50,0,0)))
#shape = BRepPrimAPI_MakeBox(10., 10., 10.).Shape()
xform = gp_GTrsf()
xform.SetVectorialPart(gp_Mat(
xs, 0, 0,
0, 1, 0,
0, 0, 1,
))
brep = BRepBuilderAPI_GTransform(R.wrapped, xform, False)
brep.Build()
fshape = brep.Shape()
R1 = cq.Shape.cast(fshape)
show_object(R1)
Thank you! How exactly do i select the axis and where do i change the scaling factor?
The xs is the scaling factor and its location on the identity matrix changes the scaling axis?
The xs is the scaling factor and its location on the identity matrix changes the scaling axis?
See this https://en.wikipedia.org/wiki/Scaling_(geometry) and this https://en.wikipedia.org/wiki/Affine_transformation
I tried this:
imported_STEP = cq.importers.importStep('./CQ/model.STEP')
xs = 4
xform = gp_GTrsf()
xform.SetVectorialPart(gp_Mat(
xs, 0, 0,
0, 1, 0,
0, 0, 1,
))
brep = BRepBuilderAPI_GTransform(imported_STEP.wrapped, xform, False)
brep.Build()
fshape = brep.Shape()
R1 = cq.Shape.cast(fshape)
show_object(R1)
but i get this error:
AttributeError: 'Workplane' object has no attribute 'warped'
Are you sure that the error says warped
? It should say wrapped
. I think you want imported_STEP.wrapped
to become imported_STEP.val().wrapped
You were right, it was wrapped
. Thank you very much! This worked. As far as i can tell, CQ can run all the functions of the OpenCascade library? Do you have any good documentation reference for them? Once again, thanks a lot!
For the OCP layer, I rely on the OpenCASCADE documentation. https://dev.opencascade.org/doc/overview/html/