What you have there is the command scripting method - i.e. sending commands to ACad. Note the -LAYER command uses the same wildcards as the
wcmatch function does, but fortunately it's case insensitive so no need to worry about capital / lower case letters. So you can prefix the layer names with "*|" (use
strcat to concatenate 2 or more strings together) to catch all the XRef layer names which match the current name read from the file. E.g. change your LayerThaw function to something like this:
(defun XRefLayerThaw
(Name
)
This is good to start off with, but it's limited since your program doesn't have much feedback about what's inside the DWG or what is happening. You either need to mix it with portions from the stuff below, or rather use one of the next 2 ideas. Going this route you have lots more control over what's happening, and also your program runs faster most of the time. Not to mention you don't clutter your command line with needless sends from the command function and messages from the commands.
(1) Original AutoLisp would be
tblnext to step through tables - the layers are stored in a "table" (same as block definitions). That's a data-table structure inside the DWG (non-visual), not to be confused with a table entity which is a new entity type only available in later acads. (2) Or you could use the vlax/vla functions to step through the
ActiveX layers collection of the active document, but then you need to convert the VBA samples to vla code (not too difficult once you get the hang of it).
I'm going to explain the original lisp method (I'll leave ActiveX for another time, or for you to try on your own):
Next, the returned value of tblnext gives a DXF data-list. Check the
help for which code means what. Then you use
assoc and
cdr to extract the layer's name to check through the
wcmatch. Note wcmatch is case sensitive so "Layer1" is not equal to "LAYER1" - you can convert text to upper/lower case using
strcase. To include wildcard characters like "*" into the search string, you use
strcat.
To change something through DXF codes you need its ename. But the list returned by tblnext does not include this. For that you need
tblobjname, and you can then send that to
entget to get the full DXF list. Then to change an item in a list you use
subst to substitute a new item for an old one, the new one you generate using
cons. And then finally you send the modified DXF list to
entmod to actually modify the "entity" (in this case it's the layer).
Now in both ideas (DXF/ActiveX/even through command calls) it might be faster to read the entire file into a wcmatch pattern using
strcat. Then remember to convert to upper case for in case the layer name is saved slightly different. Note a wc pattern can be separated by commas for multiple patterns in one. Here's what I mean:
(defun XRefLayerThawFromFile
(FileName
/ file line pattern LayData
) (progn (setq pattern
"") ;Initialize the pattern to an empty string (setq pattern
(strcat pattern
",*|" (strcase str
)))) ;Add to the pattern with wildcard prefix (close file
) ;Always close files as soon as possible (setq pattern
(substr pattern
2)) ;Remove the 1st comma from the pattern ;; Run through all layers in the DWG
;; Modify the entity
(assoc 70 LayData
) ;Get the old dxf code 70 from the list )))))))
Note each standard function has a link to a page describing it. I've also added some comments so you can understand better.