-
Is it possible to output images of specific entities/entities with a given layer assigned to them without saving the DXF file each time? My current approach is:
Is it possible to not use step no. 3? Perhaps by using some entity data as an input rather than a drawing? |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 2 replies
-
I am not sure I understand the question, because the simple way is:
|
Beta Was this translation helpful? Give feedback.
-
Here is a DXF with 4 polylines. I'd like to create an SVG image of each polyline. |
Beta Was this translation helpful? Give feedback.
-
Some of the code below is just for me to see which layers are available. from readDXF import readDxfEasy
from makeImage import createSvg
filename = "dxfEg.dxf"
layer_no = 1
dwg, msp = readDxfEasy(filename)
for e in msp:
if e.dxftype() == "LWPOLYLINE":
e.dxf.layer = f"part_{layer_no}"
layer_no += 1
for layer in dwg.layers:
print(layer.dxf.name)
#print(e.dxf.layer)
for num in range(1, layer_no):
if layer.dxf.name != f'layer_{num}':
layer.off()
# I think my issue is here. Specifically using 'filename' as an input.
createSvg(filename, num)
|
Beta Was this translation helpful? Give feedback.
-
You have to create layer table entries, to switch layers on and off. Despite the fact that the DXF format does not require a layer table entry to be valid, you should always create layer table entries for all layers you plan to use. Example The following script... import ezdxf
from ezdxf.addons.drawing.matplotlib import qsave
doc = ezdxf.readfile("shapes.dxf")
msp = doc.modelspace()
layer_names = ["Shape 1", "Shape 2", "Shape 3"]
for current_layer_name in layer_names:
for name in layer_names:
layer = doc.layers.get(name)
if layer.dxf.name == current_layer_name:
layer.on()
else:
layer.off()
qsave(msp, f"{current_layer_name}.png") creates these three images: Another option to use a filter function, which also works with the for current_layer_name in layer_names:
qsave(
msp,
f"{current_layer_name}.png",
filter_func=lambda e: e.dxf.layer == current_layer_name,
) |
Beta Was this translation helpful? Give feedback.
You have to create layer table entries, to switch layers on and off. Despite the fact that the DXF format does not require a layer table entry to be valid, you should always create layer table entries for all layers you plan to use.
Example
shapes.dxf
: each shape including the text has a different layershapes.zip
The following script...