1

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?

Lee Mac
  • 15,615
  • 6
  • 32
  • 80
leez
  • 85
  • 8

1 Answers1

2

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 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.

Lee Mac
  • 15,615
  • 6
  • 32
  • 80
  • Thank you. I was able to execute it. Another question, Can I search for a layer that is not plotted from the layer list and hide that layer if applicable?Please let me know if possible. – leez Sep 27 '19 at 00:31
  • You're welcome. When you state *"hide that layer"*, do you want to freeze the layer or turn the layer off? Could you elaborate on what you mean by *"if applicable"*? – Lee Mac Sep 27 '19 at 17:03
  • I'm sorry I didn't explain it well. I can turn a layer off or freeze by specifying the layer name. Here's what I want to do: First, a layer that is not plotted is searched from among several layers. Next, I want to perform layer off / freeze operations on the found layer. – leez Sep 28 '19 at 02:49
  • I have updated my answer above - I hope I have correctly understood your intentions. @mozman Kudos on the ezdxf library. – Lee Mac Sep 28 '19 at 21:48
  • I tried to execute the code I said but received an error (ezdxf.lldxf.const.DXFValueError: 290, ezdxf.lldxf.const.DXFValueError: DXFAttrib 'plot' does not exist.). – leez Sep 30 '19 at 06:46
  • @leez Sorry, I missed out the `dxf` in the code - I have updated the above. – Lee Mac Sep 30 '19 at 22:33
  • I tried with the code that taught me, but I just got an error. It works well for the plot = 0 layer, but there is an error for the plot = 1 layer. For the time being, try: ... except: None I was able to execute the process. Thank you! – leez Oct 01 '19 at 01:20