- This macro not only writes out a file of layer names (with a name containing the
document name plus the date and placed in the same directory) but also
highlights any unnamed layers containing entities.
- The output file is tab-delimited so that it easily be read by Excel.
- If there ARE any unnamed layers containing entities, a message is displayed warning
the user.
- To save time, not all 1000 layers are checked each time the macro is run. Change the
parameter called MaxLayer to set your own maximum depending on the number of layers
your files tend to use.
- The assumption is that you will want the output file to contain a line with the name (or lack of)
for EACH layer up until the last one you have named: this being the working range for
that particular file.
- Thereafter, you only want to know if you have any unnamed layers
containing entities up to the layer number you have set in the MaxLayer parameter.
written by Andrew Sanderson and last update 12 Nov 03

MaxLayer = 150 ' see notes above re use of this parameter
if sys$(2) = "" then
message "You are working on a dw3 file so the filename is not automatically picked up"
input "Either enter the fully qualified file name here (without the extension) or enter x to exit", filename$
if filename$ = "x" then
stop
else
Outfile$ = filename$,"Layer names as at", mid$(SYS$(8),4,2), left$(SYS$(8),2), right$(SYS$(8),2)+".txt"
end if
message outfile$
else
'Set output file name to the same as the drawing file with standard text and date added on:
Outfile$ = left$(SYS$(2),len(sys$(2))-4),"Layer names as at", mid$(SYS$(8),4,2), left$(SYS$(8),2), right$(SYS$(8),2)+".txt"
end if
' Truncate numbers to the right of the decimal.
Precision 0
'
' Open the Data file, it's created in the same directory as the current drawing
open "o", 1, Outfile$
message "Parsing first", MaxLayer, "layers to ascertain the highest numbered layer named"
' Loop through the required layers to determine last-named layer
for a = 1 to MaxLayer
Sys(3) = a ' Set the Current Layer to a and check for a layer name
if SYS$(93) <> "" then b = Sys(3)
next a
message "Layer number", b, "is the last layer named; can now create output file"
' Now loop to produce output file containing the
' layer numbers followed by either the name or a hyphen (to indicate an unnamed layer)
' separated with a tab character so the file can be easily read by Excel
p = 0 ' use this variable to count the number of unnamed layers containing entities
for a = 1 to b
Sys(3) = a
if SYS$(93) <> "" then
LayName$ = Sys$(93)
else
if odd(layer(a)) = 0 then ' ie no entities in that layer
LayName$ = "-"
else
LayName$ = "<<<Unnamed layer with entities in it>>>"
p = p + 1
end if
end if
print #1, a, chr$(9), LayName$
next a
' now loop through remaining (unnamed) layers to check for any containing entities
if b < MaxLayer then
for a = b + 1 to MaxLayer
Sys(3) = a
if odd(layer(a)) = 1 then ' ie there are entities in that layer
LayName$ = "<<<Unnamed layer with entities in it>>>"
p = p + 1
print #1, a, chr$(9), LayName$
else
' do nothing
end if
next a
else
' do nothing
end if
' Remember to close the file
Close #1
if p > 0 then message "CARE: there are", p, "unnamed layers in this file containing entities"
Message "File", outfile$, "created"
End
 |