I want to know how to turn off the property print setting using ezdxf.
I can hide, freeze and lock on and off. However, printing cannot be set on or off.
my_lines.on()
my_lines.off() # switch layer off, will not shown in CAD programs/viewers
my_lines.lock() # layer is not editable in CAD programs
my_lines.freeze()
Can you turn printing on and off like this?
The plotting (i.e. printing) flag for the layer is represented by DXF group 290, which accepts a value of 0
(meaning the layer is not plotted) or 1
(meaning the layer is plotted).
This DXF group is represented in ezdxf by the plot
property - as such, you can disable plotting for a layer using the code:
my_lines.dxf.plot = 0
To turn off or freeze layers which are not set to plot, you can use the following basic for loop:
for lay in dwg.layers:
if lay.dxf.plot = 0: # if layer is not plotted
lay.off() # turn layer off
lay.freeze() # freeze layer
However, since ezdxf does not test whether or not a layer is current before enabling bit 1
for DXF group 70
, you may want to include this check prior to invoking the freeze
method, as the current layer cannot be frozen:
for lay in dwg.layers:
if lay.dxf.plot = 0: # if layer is not plotted
lay.off() # turn layer off
if dwg.header['$CLAYER'] != lay.dxf.name: # current layer cannot be frozen
lay.freeze() # freeze layer
Obviously it would be more efficient to bound the current layer name to a local variable outside of the for
loop, since this value will not change within the loop, but I'll leave that to you.