Create a section of an assembly and export it as a DXF file #1568
-
I'm looking through the code and documentation but cannot find how I can create a section from an assembly and export it as a DXF file. I have an assembly and want to create a new plane and use that to 'cut' through the assembly. The result then has to be exported to a DXF file (I hope it will be possible to go further and add dimensions to it before exporting). Can anyone give me some direction how to accomplish this? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 6 replies
-
@Jopie01 I would wait to hear from one of the other devs because they will likely know of a cleaner way to do this. However, you can round-trip the assembly through the fused STEP exporter to get what you want. import cadquery as cq
assy = cq.Assembly()
assy.add(cq.Workplane().box(10, 10, 10), color=cq.Color(1.0, 0, 0), name="box1")
assy.add(cq.Workplane().box(5, 5, 5), color=cq.Color(0, 1.0, 0), loc=cq.Location((5.0, 5.0, 5.0), (0, 1, 0), 45), name="box2")
# Round-trip to STEP to completely fuse the assembly
assy.save(
path=str("temp_assy.step"),
exportType=cq.exporters.ExportTypes.STEP,
mode=cq.exporters.assembly.ExportModes.FUSED,
)
fused_assy = cq.importers.importStep("temp_assy.step")
# Do the section
sect = fused_assy.section(3.0)
cq.exporters.export(sect, "temp_dxf.dxf")
show_object(sect)
show_object(assy) |
Beta Was this translation helpful? Give feedback.
-
Not ideal, but maybe like this: cq.Workplane().add(assy.toCompound()).section() |
Beta Was this translation helpful? Give feedback.
-
Thank you both! I'm going with the answer of @adam-urbanczyk because then the parts are not fused into one. I made it even a bit more complex 😄 result = cq.Workplane("YZ").workplane(offset=100).add(assy.toCompound()).section()
cq.exporters.export(result, "temp_dxf.dxf") To be honest I thought it would be a cross-section, but this only shows what's on the plane. For now it doesn't matter, but is there a function to do a cross-section? |
Beta Was this translation helpful? Give feedback.
Not ideal, but maybe like this: