-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathget_DWG_layers.py
More file actions
executable file
·37 lines (31 loc) · 1.09 KB
/
get_DWG_layers.py
File metadata and controls
executable file
·37 lines (31 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import sys
import numpy as np
import ezdxf
def get_DWG_layers(dxf_data_or_fn):
"""
% (C) Nick Holschuh - Amherst College - 2022 ([email protected])
% This will read the structure of a dwg / dxf file and exctract the layer names
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% The inputs are as follows:
%
% dxf_data_or_fn -- The filename or dataobject to be read.
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% The outputs are as follows:
%
% layers -- the set of all possible layers
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% This is mostly a subroutine for "read_DWG"
"""
if isinstance(dxf_data_or_fn,type('')) == 1:
data = ezdxf.readfile(dxf_data_or_fn)
else:
data = dxf_data_or_fn
layers = []
msp = data.modelspace()
for e in msp.query("LINE"):
layers.append(e.dxf.layer)
for e in msp.query("LWPOLYLINE"):
layers.append(e.dxf.layer)
return set(layers)