2D CAD - shapes are fused on export #699
-
I am testing out build123d for 2D CAD with export to DXF and SVG. My first (very simple) test is drawing a floor plan of a rectangular building with three rooms.
For this first test I am drawing three rectangles and exporting the sketch. But in the exported drawings, the rectangles fuse together into a single rectangle instead of 3 separate rectangles. Following the patterns in the example docs I wrote the following code: from build123d import *
bldg_width, bldg_length = [50, 225]
room1_width, room2_width = [60, 60]
room3_width = bldg_length - room1_width - room2_width
room_height = bldg_width
with BuildSketch() as MySketch:
Rectangle(room1_width, room_height, align=(Align.MIN, Align.MIN))
with Locations((room1_width,0)):
Rectangle(room2_width, room_height, align=(Align.MIN, Align.MIN))
with Locations((room1_width+room2_width,0)):
Rectangle(room3_width, room_height, align=(Align.MIN, Align.MIN))
exporter = ExportDXF(unit=Unit.FT, line_weight=0.5)
exporter.add_layer("Layer 1")
exporter.add_shape(MySketch.sketch, layer="Layer 1")
exporter.write("Simple_Building.dxf")
# Since the real life drawing extents are too large for inkscape in this case,
# we scale the sketch so the SVG drawing scale will be 1/16in = 1ft
ScaledSketch = scale(MySketch.sketch, by=1/16)
exporter = ExportSVG(unit=Unit.IN, line_weight=0.2)
exporter.add_layer("Layer 1")
exporter.add_shape(ScaledSketch, layer="Layer 1")
exporter.write("Simple_Building.svg")
show_object(MySketch) #syntax to show the sketch in CQ-Editor Thanks for any help. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
I found a way (in discussion) by using "Algebra Mode" and creating a Sketch with "children": room1 = Rectangle(room1_width, room_height, align=Align.MIN)
room2 = Pos(room1_width, 0) * Rectangle(room2_width, room_height, align=Align.MIN)
room3 = Pos(room1_width + room2_width, 0) * Rectangle(room3_width, room_height, align=Align.MIN)
#MySketch = room1 + room2 + room3 # this adds the shapes using Mode.ADD which fuses them together
MySketch = Sketch(children=[room1, room2, room3]) #this adds the shapes to a sketch such that they stay separate Can the same thing be accomplished in "Builder Mode"? |
Beta Was this translation helpful? Give feedback.
@WayneSherman your approach in algebra mode is to essentially create a
Compound
by usingSketch
(in build123dSketch
is a type ofCompound
also known as an assembly). In general, the builders are designed to by default automatically fuse objects together, so what you observed is expected behavior (n.b. see themode
parameters of the objects e.g.Rectangle
in this case and also of the builders). If the objects "don't touch" then they will remain as separate shapes, but they will be (by default) automatically "merged" otherwise. When talking aboutBuildPart
, I often say that it is intended for "single solid design" but it can be used for multiple solids subject to the above constraints.Bac…