Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

fastest way to check for a layer

9 REPLIES 9
Reply
Message 1 of 10
Anonymous
251 Views, 9 Replies

fastest way to check for a layer

What is the fastest way to check to see if a layer exists in the drawing? I am using tblsearch to do it now, can you do it with ActiveX faster? Or is there an even better way? Also, how do you check for an individual layer using ActiveX? I can only seem to do it in a foreach with my limited knowledge. Thanks!
9 REPLIES 9
Message 2 of 10
Anonymous
in reply to: Anonymous

Not sure about faster, but this is one way in ActiveX. Use like this: (layer? "0") or (layer? "thisprollydontexist") (defun layer? (lname / lays Aerr) (setq lays (vla-get-layers (vla-get-activedocument (vlax-get-acad-object)))) (setq Aerr (vl-catch-all-apply '(lambda (a) (vla-item Lays a)) (list lname))) (if (and (vl-catch-all-error-p Aerr) (= (vl-catch-all-error-message Aerr) "Automation Error. Key not found") ) (alert "\nLayer doesn't exist.");comment out to use as a test ;nil ;un-comment out to use as a test (alert "\nLayer exists.");comment out to use as test ;t ;un-comment out to use as a test ) ) HTH, Jeff "kemp" wrote in message news:4051021d_1@newsprd01... > What is the fastest way to check to see if a layer exists in the drawing? > > I am using tblsearch to do it now, can you do it with ActiveX faster? Or is > there an even better way? Also, how do you check for an individual layer > using ActiveX? I can only seem to do it in a foreach with my limited > knowledge. > > Thanks! > >
Message 3 of 10
Anonymous
in reply to: Anonymous

(tblsearch "layer" "") "kemp" wrote in message news:4051021d_1@newsprd01... > What is the fastest way to check to see if a layer exists in the drawing? > > I am using tblsearch to do it now, can you do it with ActiveX faster? Or is > there an even better way? Also, how do you check for an individual layer > using ActiveX? I can only seem to do it in a foreach with my limited > knowledge. > > Thanks! > >
Message 4 of 10
Anonymous
in reply to: Anonymous

Rudy, Did you miss the part of that large post that said: "I am using tblsearch to do it now.." ? ;-) And I'm surprised we didn't crash the news server, posting at exactly the same time like we did. Jeff "Rudy Tovar" wrote in message news:405109eb$1_2@newsprd01... > (tblsearch "layer" "") > > "kemp" wrote in message > news:4051021d_1@newsprd01... > > What is the fastest way to check to see if a layer exists in the drawing? > > > > I am using tblsearch to do it now, can you do it with ActiveX faster? Or > is > > there an even better way? Also, how do you check for an individual layer > > using ActiveX? I can only seem to do it in a foreach with my limited > > knowledge. > > > > Thanks! > > > > > >
Message 5 of 10
Anonymous
in reply to: Anonymous

I haven't tested in a long while, but I recall *way* back that vanilla lisp (i.e. tblsearch) outgunned vla* methods / properties. Anyway, here's how I might code an activeX version ... (defun LayerExists ( LayerName ) (null (vl-catch-all-error-p (vl-catch-all-apply 'vlax-invoke-method (list (vlax-get-property (vlax-get-property (vlax-get-acad-object) 'ActiveDocument ) 'Layers ) 'Item LayerName ) ) ) ) ) If you cache the active document you could obviously realize performance gains for subsequent calls. Caching the layers collection would be dangerous unless you were absolutely certain no changes would occur to said collection between calls. Cheers. "kemp" wrote in message news:4051021d_1@newsprd01... > What is the fastest way to check to see if a layer exists in the drawing? > > I am using tblsearch to do it now, can you do it with ActiveX faster? Or is > there an even better way? Also, how do you check for an individual layer > using ActiveX? I can only seem to do it in a foreach with my limited > knowledge. > > Thanks! > >
Message 6 of 10
Anonymous
in reply to: Anonymous

"michael puckett" wrote in message news:4051101c_1@newsprd01... > If you cache the active document you could obviously > realize performance gains for subsequent calls. Caching > the layers collection would be dangerous unless you > were absolutely certain no changes would occur to said > collection between calls. > Michael, the nice thing about ActiveX is the "active" part. Observe..... _$ (setq *acad* (vlax-get-acad-object) *doc* (vla-get-activedocument *acad*)) # _$ (setq lays (vla-get-layers *doc*)) #NOTE THIS OBJECT _$ (vl-catch-all-apply '(lambda (a)(vla-item Lays a)) (list "testy1"))) #<%catch-all-apply-error%> _$ (vla-add lays "testy1") # _$ (setq lays (vla-get-layers *doc*)) # NOTE THE SAME OBJECT _$ (vl-catch-all-apply '(lambda (a)(vla-item Lays a)) (list "testy1")) # _$ SO you can set a reference to your layers, blocks, styles, etc. at startup and they references to them will still be good after adding, deleting, modifying them. HTH, Jeff
Message 7 of 10
Anonymous
in reply to: Anonymous

You're absolutely right, I don't know what I was thinking, it's not like the collection is static. Call DumbStatments.Add ("My last one.") "Jeff Mishler" wrote in message news:40511393$1_1@newsprd01... > > "michael puckett" wrote in message > news:4051101c_1@newsprd01... > > > Michael, the nice thing about ActiveX is the "active" part.
Message 8 of 10
Anonymous
in reply to: Anonymous

Since the main advantage of ActiveX is that you can address multiple documents, it would make sense to write a function that takes the layer argument and the document as: (defun getlayer (name document / result) ;D. C. Broad, Jr. Demonstration 3/11/04 (vl-catch-all-apply '(lambda ()(setq result (vla-item (vla-get-layers document) name))) nil ) result) "michael puckett" wrote in message news:4051101c_1@newsprd01... > I haven't tested in a long while, but I recall *way* > back that vanilla lisp (i.e. tblsearch) outgunned > vla* methods / properties. > > Anyway, here's how I might code an activeX version ... > > (defun LayerExists ( LayerName ) > (null > (vl-catch-all-error-p > (vl-catch-all-apply > 'vlax-invoke-method > (list > (vlax-get-property > (vlax-get-property > (vlax-get-acad-object) > 'ActiveDocument > ) > 'Layers > ) > 'Item > LayerName > ) > ) > ) > ) > ) > > If you cache the active document you could obviously > realize performance gains for subsequent calls. Caching > the layers collection would be dangerous unless you > were absolutely certain no changes would occur to said > collection between calls. > > Cheers. > > "kemp" wrote in message > news:4051021d_1@newsprd01... > > What is the fastest way to check to see if a layer exists in the drawing? > > > > I am using tblsearch to do it now, can you do it with ActiveX faster? Or > is > > there an even better way? Also, how do you check for an individual layer > > using ActiveX? I can only seem to do it in a foreach with my limited > > knowledge. > > > > Thanks! > > > > > >
Message 9 of 10
Anonymous
in reply to: Anonymous

If that's what you need / want sure, might as well take advantage :) ( We only run SDI ) "Doug Broad" wrote in message news:40511890$1_3@newsprd01... > Since the main advantage of ActiveX is that you > can address multiple documents, it would make > sense to write a function that takes the layer > argument and the document as: > > (defun getlayer (name document / result) > ;D. C. Broad, Jr. Demonstration 3/11/04 > (vl-catch-all-apply > '(lambda ()(setq result (vla-item (vla-get-layers document) name))) > nil > ) > result)
Message 10 of 10
Anonymous
in reply to: Anonymous

Interesting. I haven't used SDI since R14. I tend to keep numerous drawings open. I rarely address more than one drawing via lisp however (almost exclusively the activedocument.) If this is part of a larger program, it would make sense that the document had already been accessed and be available as an argument. "michael puckett" wrote in message news:40511ab3$1_2@newsprd01... > ( We only run SDI )

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost