Annotated Assembly Step Screenshots #61
Replies: 4 comments 1 reply
-
First of all. Super cool. Some thoughts for taking this forward.
|
Beta Was this translation helpful? Give feedback.
-
@julianstirling In-progress PR for assembly lines is here. |
Beta Was this translation helpful? Give feedback.
-
@julianstirling The assembly line feature is still in the initial phases, but I put together two screenshots where the lines are used instead of the assembly arrows. line_diameter at the default of 0.5 mm Codefrom mechanical.components.cadquery.tray_6in import create_6in_shelf
import cadquery as cq
from cadquery.vis import show
from cq_annotate.views import explode_assembly
from cq_annotate.callouts import add_assembly_lines
def m2_5_screw(length=6.0):
"""
Generates a simplified model of an M2.5 screw for the assembly.
"""
# The threaded portion
screw = (
cq.Workplane()
.workplane(centerOption="CenterOfBoundBox")
.circle(2.5 / 2.0)
.extrude(length)
)
# Overall head shape
screw = (
screw.faces(">Z")
.circle(4.5 / 2.0)
.extrude(2.5)
)
# Add the hex drive cutout
screw = (
screw.faces(">Z")
.workplane(centerOption="CenterOfBoundBox")
.polygon(6, 2.0)
.cutBlind(-2.0)
)
# Tag the bottom face for an assembly line
screw.faces("<Z").tag("assembly_line")
return screw
def assemble(explode=False, annotate=True, export_format="png", rpi=None):
"""
Builds a sample assembly, explodes and annotates it.
"""
# The top-level assembly
assy = cq.Assembly()
# Generate the shelf
shelf = create_6in_shelf("raspi", 1).cq()
assy.add(shelf, name="shelf", color=cq.Color(0.996, 0.867, 0.0, 1.0))
# Add the Raspberry Pi to the assembly
rpi = rpi.rotateAboutCenter((1, 0, 0), 90).rotateAboutCenter((0, 0, 1), -90)
# rpi.faces("<Z").tag("assembly_line")
assy.add(rpi, name="rpi",
loc=cq.Location((-2.5, 24, 11)),
color=cq.Color(0.565, 0.698, 0.278, 1.0),
metadata={"explode_loc": cq.Location((0, 0, 30))},
)
# Add the mounting screws for the RPi
screw_length = 6.0
screw_starting_height = 1.0
screw_explode_height = 60.0
assy.add(
m2_5_screw(length=screw_length),
name="screw_1",
loc=cq.Location((-13.0, 23.5, screw_starting_height)),
color=cq.Color(0.04, 0.5, 0.67, 1.0),
metadata={"explode_loc": cq.Location((0, 0, screw_explode_height))},
)
assy.add(
m2_5_screw(length=screw_length),
name="screw_2",
loc=cq.Location((36.0, 23.5, screw_starting_height)),
color=cq.Color(0.04, 0.5, 0.67, 1.0),
metadata={"explode_loc": cq.Location((0, 0, screw_explode_height))},
)
assy.add(
m2_5_screw(length=screw_length),
name="screw_3",
loc=cq.Location((-13.0, 81.5, screw_starting_height)),
color=cq.Color(0.04, 0.5, 0.67, 1.0),
metadata={"explode_loc": cq.Location((0, 0, screw_explode_height))},
)
assy.add(
m2_5_screw(length=screw_length),
name="screw_4",
loc=cq.Location((36.0, 81.5, screw_starting_height)),
color=cq.Color(0.04, 0.5, 0.67, 1.0),
metadata={"explode_loc": cq.Location((0, 0, screw_explode_height))},
)
# Annotate with assembly lines, if requested
if annotate:
add_assembly_lines(assy, line_diameter=1.0)
# Created the exploded assembly, if requested
if explode:
explode_assembly(assy)
return assy
if __name__ == "__main__":
# Import the Raspberry Pi STEP model
# We do this here and pass it because it is a very detailed step and takes awhile to load
# Downloaded from https://grabcad.com/library/raspberry-pi-4-model-b-1#!
rpi = cq.importers.importStep("/home/jwright/Downloads/raspberry_pi_4_model_b.step")
# Exploded and annotated Raspberry Pi shelf-component combo
assy = assemble(explode=True, annotate=True, rpi=rpi)
# Use the same options to export each image
png_opts = {
"width": 600,
"height": 600,
"camera_position": (65, -50, 75),
"view_up_direction": (0, 0, 1),
"focal_point": (20, 10, 35),
"parallel_projection": True,
"background_color": (1.0, 1.0, 1.0),
"clipping_range": (0, 400),
}
svg_opts = {
"width": 600,
"height": 600,
"marginLeft": 75,
"marginTop": 100,
"showAxes": False,
"projectionDir": (0.1, 0.1, 0.1),
"strokeWidth": 0.75,
"strokeColor": (225, 225, 225),
"hiddenColor": (0, 0, 255),
"showHidden": False,
}
# 01 - Export an annotated and exploded assembly step to PNG
assy.save("./build/images/01_exploded_and_annotated.png", opt=png_opts)
# 02 - Export an annotated and exploded assembly step to SVG
assy_compound = assy.toCompound()
cq.exporters.export(assy_compound.rotate((0, 0, 0), (1, 0, 0), -90), "./build/images/02_exploded_and_annotated.svg", opt=svg_opts)
# Exploded but not annotated Raspberry Pi shelf-component combo
assy = assemble(explode=True, annotate=False, rpi=rpi)
# 03 - Export an exploded but not annotated assembly step to PNG
assy.save("./build/images/03_exploded_but_not_annotated.png", opt=png_opts)
# 04 - Export an exploded but not annotated assembly step to SVG
assy_compound = assy.toCompound()
cq.exporters.export(assy_compound.rotate((0, 0, 0), (1, 0, 0), -90), "./build/images/04_exploded_but_not_annotated.svg", opt=svg_opts)
# Assembled with annotation lines
assy = assemble(explode=False, annotate=True, rpi=rpi)
# 05 - Export an assembled and annotated assembly step to PNG
assy.save("./build/images/05_assembled_and_annotated.png", opt=png_opts)
# 06 - Export an assembed and annotated assembly step to SVG
assy_compound = assy.toCompound()
cq.exporters.export(assy_compound.rotate((0, 0, 0), (1, 0, 0), -90), "./build/images/06_assembled_and_annotated.svg", opt=svg_opts)
# Plain, unannotated assembly
assy = assemble(explode=False, annotate=False, rpi=rpi)
# 07 - Export a plain assembled assembly step to PNG
assy.save("./build/images/07_assembled_plain.png", opt=png_opts)
# 06 - Export an assembed and annotated assembly step to SVG
assy_compound = assy.toCompound()
cq.exporters.export(assy_compound.rotate((0, 0, 0), (1, 0, 0), -90), "./build/images/08_assembled_plain.svg", opt=svg_opts)
# show(assy) |
Beta Was this translation helpful? Give feedback.
-
Oh, and here are the SVG versions too. |
Beta Was this translation helpful? Give feedback.
-
Tagging @ericnitschke and @julianstirling
Introduction
I thought it might be helpful to have sample screenshots for re:publica to show things we could do with the annotated assembly steps. I have added some screenshots, followed by the code that generated the screenshots, and finally a listing of how to get the script running in the root of this repository. These exported screenshots use this codebase and libraries that we have talked about before, or already use (a branch of CadQuery with PNG export and the cq-annotate library). These screenshots alternate between PNG and SVG, and you can see the marked difference. It is important to note that I did not have to create each of these views manually. cq-annotate can automatically explode assemblies and add annotation arrows if the CadQuery metadata and tagging is set up correctly. Things like edge color, arrow size and more can be customized through the
*-opts
dictionaries or by changing the parameter values passed to methods.Generated Screenshots
Code
Here is the code that generated those screenshots.
Running the Code
python-tidy
branch of the nimble repositorypng
branch of CadQuery:pip install git+https://github.com/CadQuery/cadquery.git@png
pip install https://github.com/jmwright/cq-annotate.git
pip install 'cadscript>=0.5.2'
./build/images
directory existscq.importers.importStep
line in the code above to point to the path where the Grabcad file was placed./build/images
directory for the PNG and SVG imagesBeta Was this translation helpful? Give feedback.
All reactions