TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: diego65 on December 06, 2012, 03:52:47 PM
-
Hello,
I need help on creating a routine that will allowed me to turn ON or Off a specific layer on a bunch of drawings.
The point is for not to open every single drawing and turn the layer off manually.
Any help will be appreciate it...
Thank you...
-
You'll want to iterate a list of valid Drawings using ObjectDBX, then within each DBXDocument Object, iterate the Layers Collection, checking for matching Layer Names, if a valid match, then toggle that Layer Object's LayerOn Property accordingly.
-
Hi RenderMan,
That is exactly what I am lookng for, however, I am very familiar with LISP.
I am looking for help on creating one from scratch if I can get some help...
-
Hi RenderMan,
That is exactly what I am lookng for, however, I am very familiar with LISP.
I am looking for help on creating one from scratch if I can get some help...
Any routine involving ObjectDBX (appropriately) requires a bit more effort and error handling than a typical requests for help. I, or someone more knowledgeable than I, will post back as time permits.
-
This function will do all of the ObjectDBX work for you:
http://lee-mac.com/odbxbase.html (http://lee-mac.com/odbxbase.html)
Load it and call it with the following program (change the layer name to suit):
(defun c:frzlay ( )
(LM:ODBX
(function
(lambda ( doc / lay )
(if
(not
(vl-catch-all-error-p
(setq lay
(vl-catch-all-apply 'vla-item
(list (vla-get-layers doc) "Your-Layer-Here")
)
)
)
)
(vla-put-layeron lay :vlax-true)
)
)
)
nil t
)
(princ)
)
The above is untested.
-
Lee your ObjectDBX helper routine is a real time saver. 8-)
-
Lee your ObjectDBX helper routine is a real time saver. 8-)
Thanks Alan! :-)
-
Lee, I have not been over to your site for some time. I really, really, really like option to preview the code in HTML. Very sweet.
And the code looks sweet too. Filed that in back of my brain for when a future need arises. ;-)
-
Thank you Lee Mac for helping me out on the script for “Turning specific layer ON or Off in multiples files without opening them”
It works wonderful, however, I forgot to mentioned that, this specific layer is located on an xreference file, sorry.
Would you be able to help me on this one please?
Thank you…
Joselo…
-
Lee, I have not been over to your site for some time. I really, really, really like option to preview the code in HTML. Very sweet.
And the code looks sweet too. Filed that in back of my brain for when a future need arises. ;-)
Cheers Krushert! I'm glad you like it 8-)
I hope the program is of use to you :-)
-
Thank you Lee Mac for helping me out on the script for “Turning specific layer ON or Off in multiples files without opening them”
You're welcome Joselo :-)
It works wonderful, however, I forgot to mentioned that, this specific layer is located on an xreference file
Although XRefs are not loaded when interfacing with a drawing using ObjectDBX, the XRef-dependent Layers should still be present in the drawing's Layers Collection, hence, you should be able to use the program for your case and specify the name of your XRef-dependent Layer.
-
This function will do all of the ObjectDBX work for you:
http://lee-mac.com/odbxbase.html (http://lee-mac.com/odbxbase.html)
Load it and call it with the following program (change the layer name to suit):
(defun c:frzlay ( )
(LM:ODBX
(function
(lambda ( doc / lay )
(if
(not
(vl-catch-all-error-p
(setq lay
(vl-catch-all-apply 'vla-item
(list (vla-get-layers doc) "Your-Layer-Here")
)
)
)
)
(vla-put-layeron lay :vlax-true)
)
)
)
nil t
)
(princ)
)
The above is untested.
Lee
Is it possible to use the following in place of "your-layer-here"?
(list (vla-get-layers doc) "*AREA*,UT*|*PATT*,UT*|*DIMS*,UT*|*NOTE*,UT*|*SYMB*,UT*|*SHTT*,BL-0*|*SHTT*,*|A-CLNG-HEAD,*|A-DOOR-CODE,*|*-2,*|*-3")
-
Is it possible to us the following in place of "your-layer-here"?
(list (vla-get-layers doc) "*AREA*,UT*|*PATT*,UT*|*DIMS*,UT*|*NOTE*,UT*|*SYMB*,UT*|*SHTT*,BL-0*|*SHTT*,*|A-CLNG-HEAD,*|A-DOOR-CODE,*|*-2,*|*-3")
The OP actually posed this question via PM, here was my response:
The current function is looking for an exact layer name match, and cannot accept wildcards.
To use wildcards, the code must be changed to:
(defun c:frzlay ( )
(LM:ODBX
(function
(lambda ( doc / lay )
(vlax-for lay (vla-get-layers doc)
(if (wcmatch (strcase (vla-get-name lay)) "wildcard-match-here")
(vla-put-layeron lay :vlax-true)
)
)
)
)
nil t
)
(princ)
)
In future, please reply to the forum thread rather than sending a personal message, as the replies will then benefit the whole forum community.
-
Thank you Lee Mac,
This routine is a life saver, that was exactly what we were looking for.
Very well done...
Joselo...
-
Lee
Thanks for your response. I have a more specific question and help needed. I will ask it on your website. I will pay for your services for this help. You can then post the solution here to benefit the forum.
Gary
-
Lee Mac,
This routine works great and does what we were looking for, however, the wildcard was there due that is an old code for a layer on an xref file, and this wildcard can be omitted.
My intension here is not to only be hard coded a specific layer name, meaning if we can use this routine to turn other layers on as well by just changing the layer’s name.
My initial idea was to turn on a specific layer, perhaps our Engineer name on and off with the same routine, so we can just turn on one engineer name and turn another engineer off.
Example: Marc’s is on one layer and it is use for specific project, so I want to turn Marc’s layer on in a bunch of drawing.
Jess is another engineer name in the same xref file, when Marc’s name is no longer needed for this project, I would like to turn Marc’s layer off and turn Jess layer on, can this be done with the same routine?
Thank you…
-
...can this be done with the same routine?
Yes, most things are possible - though, with more time and modifications...
-
Thank you Lee for your help, I really appreciated it.
Lee,
On your routine, when I change to a different xref layer name, perhaps from "*|ManU_NAME") to "*|WestHam_NAME"), the routine doesn’t recognized that layer.
I have no issue running the routine with "*|ManU_NAME"), would it be nice to just to be able to change layer name and run the routine.
Any idea why isn’t working that way?
(defun c:frzlay ( )
(LM:ODBX
(function
(lambda ( doc / lay )
(vlax-for lay (vla-get-layers doc)
(if (wcmatch (strcase (vla-get-name lay)) "*|your_layer_name_here")
(vla-put-layeron lay :vlax-true)
)
)
)
)
nil t
)
(princ)
)
-
Make your search pattern all uppercase.
(wcmatch (strcase (vla-get-name lay)) "*|YOURLAYERNAMEHERE")
-
Hi ron,
Thank you for your help.
I have already asked Lee, maybe you can help me...
My intension here is not to only be hard coded a specific layer name, meaning if we can use this routine to turn other layers on as well by just changing the layer’s name.
My initial idea was to turn on a specific layer, perhaps our Engineer name on and off with the same routine, so we can just turn on one engineer name and turn another engineer off.
Example: Marc’s is on one layer and it is use for specific project, so I want to turn Marc’s layer on in a bunch of drawing.
Jess is another engineer name in the same xref file, when Marc’s name is no longer needed for this project, I would like to turn Marc’s layer off and turn Jess layer on, can this be done with the same routine?
Thank you…
-
Just look for the other layer name and turn it off ... something like so:
(lm:odbx
;; Turn the layer on
)
;; Turn the layer off
)
)
)
)
nil
t
)
)