PDA

View Full Version : Layer search upon each drawing OPEN


Coolmo
2006-08-04, 03:46 PM
Is there a niffty way to search a drawing for a specific layer upon opening a drawing and determine whether or not the layer is OFF/ON or FROZEN/THAWED? I've done the table search thing for "LAYERS" but the layer I want will always be embedded inside of an xref so it's impossible to know what the prefix of the layer name will be. I've tried wildcards in the "LAYER NAME" portion but they didn't work... at least the way I used them. Any suggestions?

Avatart
2006-08-04, 03:54 PM
To do this automatically, you would need some sort of reactor. Personally I am not too keen on reactors, if you getthem worng they can make one hell of a mess of you drawings.

What have you done re wildcard searching the layer table?

T.Willey
2006-08-04, 04:16 PM
If you want to check upon opening a drawing, you just need to have the routine autoload, and run it. You can have it autoload serval different ways. If the layer if going to be in a xref ALWAYS, then maybe something like


(defun LayExist (LayName)

(vl-catch-all-error-p
(vl-catch-all-apply
'(lambda ()
(vlax-for Lay (vla-get-Layers (vla-get-ActiveDocument (vlax-get-Acad-Object)))
(if (wcmatch (strcase (vla-get-Name Lay)) (strcase (strcat "*|" LayName)))
(exit)
)
)
)
)
)
)



Edit: Didn't see the other part.

(defun LayExist (LayName)

(vl-catch-all-error-p
(vl-catch-all-apply
'(lambda ()
(vlax-for Lay (vla-get-Layers (vla-get-ActiveDocument (vlax-get-Acad-Object)))
(if (wcmatch (strcase (vla-get-Name Lay)) (strcase (strcat "*|" LayName)))
(progn
(prompt (strcat "\n Layer on status = " (vl-princ-to-string (vla-get-LayerOn Lay))))
(prompt (strcat "\n Layer froze status = " (vl-princ-to-string (vla-get-Freeze Lay))))
(exit)
)
)
)
)
)
)
(princ)
)

Coolmo
2006-08-04, 04:46 PM
I'll have the Lisp code automatically load from my own acad.lsp file so that's not a problem. I'm kinda old school when it comes to AutoLisp so I'm not familiar with the whole VisualLisp syntax. I'm using the old "tblsearch" code to search the dictionaries. See below. Then I'll go through the dotted pairs to list the status of each. The problem I'm having is the Xref name changing every time. Does anyone have an "old school" suggestion?


(setq wmlayer (tblsearch "layer" "watermark"))

The problem here is that the text "watermark" will always have the xref name in front of it.

Avatart
2006-08-04, 05:01 PM
You could scroll through the layer table and apply a conditional test, if "true" return a value, a bit like:

(setq laynam (tblnext "layer"))
(wcmatch (cdr (assoc 2 laynam)) "*|watermark*")

The "*|watermark*" should find a layer called watermark on an xref layer. You would have to scroll this through the whole layer table obviously.

Coolmo
2006-08-04, 06:31 PM
So the * (star) is a valid wildcard within the code? I tried using this in the tblsearch code and it just kicks it out with an error.

miff
2006-08-04, 08:06 PM
The star is valid when used with (wcmatch). It is NOT valid when using (tblsearch)