Parametric Parts is a parametric, web-based 3D modeling application. The application requires a web-gl enabled browser.
You can customize, download, and print parametric models or create models with an easy to use API called CadQuery.
Parametric Parts uses a Model Script, which is a python script that builds a 3D model in response to user input. Model Scripts can use FreeCAD Scripts or CadQuery. In fact CadQuery is based on FreeCAD, which is in turn based on the OpenCascade modelling kernel, which uses Boundary Representations ( BREP ) for objects. Basically, objects are defined by their enclosing surfaces. CadQuery/FreeCAD scripts share many features with OpenSCAD, a popular open source, script based, parametric model generator.
For more information see Parametric Parts' examples and the CadQuery API Reference
Parametric Parts uses a Model Script, which is a python script that builds a 3D model in response to user input. Model Scripts can use FreeCAD Scripts or CadQuery. In fact CadQuery is based on FreeCAD, which is in turn based on the OpenCascade modelling kernel, which uses Boundary Representations ( BREP ) for objects. Basically, objects are defined by their enclosing surfaces. CadQuery/FreeCAD scripts share many features with OpenSCAD, a popular open source, script based, parametric model generator.
Advantages of CadQuery
- CadQuery scripts use a standard programming language, python.
- OpenCascade is more powerful than CGAL. Features supported natively by OCC include NURBS, splines, surface sewing, STL repair, STEP import/export, and other complex operations, in addition to the standard CSG operations supported by CGAL
- CadQuery allows you to import/export STEP models, created in a CAD package.
- It takes less code to create most objects, because it is possible to locate features based on the position of other features, workplanes, vertices, etc.
- CadQuery scripts can build STL, STEP, and AMF faster than OpenSCAD.
- Many scripting langauges do not provide a way to capture design intent. CadQuery allows you to locate features relative to others and preserve the design intent.
ModelScript
- Before modeling you should describe your objective in words. An example, "A rectangular block 60mm x 60mm x 25mm , with countersunk holes for M3 socket head cap screws at the corners, and a circular pocket 22mm in diameter in the middle for a bearing.
- Sign up or sign in:
- If you are just joining select Jump Right in
If you are already logged in select Parts>Create - When you start a model, the application starts with a placeholder. Change the name of your model by clicking on the pencil.
- You can navigate the the space above the model parameters with your mouse.
- Change the length and thickness parameters under Model Parameters. Pressing ENTER will update the image after you change the values.
- Change the preset configuration value from default to short to see what it does.
-
Edit the model script itself. Change the hard-coded width and thickness values and click click Save Changes to re-display the model.
- Every model should have a Unit of Measure (UOM). Make sure your UOM is set to "mm"
- Add a VERSION to your script:
VERSION=1.0
- Parameters are placeholders that a user can modify separately from the script itself. The default model has two parameters. Modify the script so that width is another parameter.
- Add width so it is parametric.
- Remove the assignment statement where width is hard coded.
- Update the def build() so that you use width.value. value property always returns the user-adjusted value of the parameter.
Each parameter has a particular type ( Float, Integer, Boolean ).
Parameters also have optional attributes, which are provided as keyword arguments:desc: A description of the parameter, displayed to the user if help is needed [Optional] min: The minimum value ( not applicable to Boolean ) [Optional] max: The maximum value ( not applicable to Boolean ) [Optional] presets: A dictionary containing key-value pairs. Each key is the name of a preset, and the value is the value the parameter will take when the preset is selected by the user.
Example: presets={'default':80.0, 'short':10}
When a model defines presets, the user is presented with a choice of available presets in a drop-down-list. Selecting a preset changes the values of all parameters to their associated values.
If it exists, the special preset named ‘default’ will be used to populate the default values when the user is initially presented with the model. When the model is built, the parameters are checked to ensure they meet the constraints. If they do not, an error occurs.group: If provided, parameters will be grouped together when displayed to the user. Any ungrouped parameters will display in a special group named default. Groups help divide a long list of parameters to make them easier to understand. Examples might include ‘basics’ and ‘advanced’ - Add width so it is parametric.
- The heart of your model is the build method.
The following code would draw a model with a 1mm3:
Your build method can use any combination of FreeCAD, python, and CadQuery to construct objects, but it must return either a CadQuery or FreeCAD object.
def build(): return Workplane("XY").box(1,1,1)
- The block needs to have a thickness of 25mm and to have a 22mm diameter hole in the center. Add the following to the def build():
Workplane.faces() selects the top-most face in the Z direction, and Workplane.workplane() begins a new workplane located on this face Workplane.hole() drills a hole through the part 22mm in diameter
.faces(">Z").workplane().hole(22.0)
- An M3 Socket head cap screw has these dimensions:
- Head Diameter : 3.8 mm
- Head height : 3.0 mm
- Clearance Hole : 3.4 mm
- CounterBore diameter : 4.4 mm
Save the changes..faces(">Z").workplane().rect(length.value-8.0,width.value-8.0,forConstruction=True) .vertices().cboreHole(3.4,4.4,3.1)
The Workplane.rect() function draws a rectangle.
forConstruction=True tells CadQuery that the rectangle will not form a part of the solid, but will be used to help define some other geometry.
The center point of a workplane on a face is always at the center of the face. Unless you specifiy otherwise, a rectangle is drawn with its center on the current workplane center– in this case, the center of the top face of the block.
The CQ.vertices() function selects the corners of the rectangle.
The Workplane.cboreHole() function makes a counterbored hole. cboreHole, like most other CadQuery functions, operates on the values on the stack. In this case, since selected the four vertices before calling the function, the function operates on each of the four points– which results in a counterbore hole at the corners.
If you want to use carriage returns for better usability use the escape character \:def build() return Workplane("XY").box(length.value,height.value,thickness)\ .faces(">Z").workplane().hole(22.0)\ .faces(">Z").workplane()\ .rect(length.value-8.0,width.value-8.0,forConstruction=True)\ .vertices().cboreHole(3.4,4.4,3.1)
- Modify the parameters so that
- Small will generate the same part with the following dimensions 30 mm x 40mm
- Square-Medium will generate the same part with the following dimensions 50 mm x 50mm
- default will be 80mm, 60mm
- Remove the Short option.
length = FloatParam(min=2.0,max=500.0,presets={'default':80.0, 'Small':30, 'Square-Medium' :50},group="Basics", desc="Length of the box")
- Click on the Public View button
- Change model Parameters and click on the Preview button
- Select one of the presets
- Want to edit the script? Click on the Edit button
- To download an stl file click on the Download button and then select STL
For more information see Parametric Parts' examples and the CadQuery API Reference