TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: diego65 on December 06, 2012, 03:52:47 PM

Title: Help on turning off specific xref layer
Post 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...
Title: Re: Help on turning off specific xref layer
Post by: BlackBox on December 06, 2012, 04:52:29 PM
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.
Title: Re: Help on turning off specific xref layer
Post by: diego65 on December 06, 2012, 05:13:56 PM
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...
Title: Re: Help on turning off specific xref layer
Post by: BlackBox on December 06, 2012, 05:35:51 PM
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.
Title: Re: Help on turning off specific xref layer
Post by: Lee Mac on December 06, 2012, 06:12:51 PM
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):

Code: [Select]
(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.
Title: Re: Help on turning off specific xref layer
Post by: CAB on December 06, 2012, 08:43:23 PM
Lee your ObjectDBX helper routine is a real time saver.  8-)
Title: Re: Help on turning off specific xref layer
Post by: Lee Mac on December 07, 2012, 05:56:55 AM
Lee your ObjectDBX helper routine is a real time saver.  8-)

Thanks Alan!  :-)
Title: Re: Help on turning off specific xref layer
Post by: Krushert on December 07, 2012, 11:20:05 AM
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.  ;-)
Title: Re: Help on turning off specific xref layer
Post by: diego65 on December 07, 2012, 01:06:50 PM
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…
Title: Re: Help on turning off specific xref layer
Post by: Lee Mac on December 07, 2012, 04:33:30 PM
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 :-)
Title: Re: Help on turning off specific xref layer
Post by: Lee Mac on December 07, 2012, 04:36:46 PM
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.
Title: Re: Help on turning off specific xref layer
Post by: GDF on December 10, 2012, 09:27:07 AM
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):

Code: [Select]
(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")
Title: Re: Help on turning off specific xref layer
Post by: Lee Mac on December 10, 2012, 09:34:02 AM
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:

Quote from: Response to PM from OP
The current function is looking for an exact layer name match, and cannot accept wildcards.
To use wildcards, the code must be changed to:


Code: [Select]
(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.
Title: Re: Help on turning off specific xref layer
Post by: diego65 on December 10, 2012, 10:05:49 AM
Thank you Lee Mac,
This routine is a life saver, that was exactly what we were looking for.

Very well done...
Joselo...
Title: Re: Help on turning off specific xref layer
Post by: GDF on December 10, 2012, 10:16:14 AM
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
Title: Re: Help on turning off specific xref layer
Post by: diego65 on December 10, 2012, 11:02:19 AM
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…
Title: Re: Help on turning off specific xref layer
Post by: Lee Mac on December 10, 2012, 11:14:40 AM
...can this be done with the same routine?

Yes, most things are possible - though, with more time and modifications...
Title: Re: Help on turning off specific xref layer
Post by: diego65 on December 10, 2012, 02:25:55 PM
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)
)
Title: Re: Help on turning off specific xref layer
Post by: ronjonp on December 10, 2012, 02:55:07 PM
Make your search pattern all uppercase.

(wcmatch (strcase (vla-get-name lay)) "*|YOURLAYERNAMEHERE")
Title: Re: Help on turning off specific xref layer
Post by: diego65 on December 10, 2012, 04:04:34 PM
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…
Title: Re: Help on turning off specific xref layer
Post by: ronjonp on December 10, 2012, 04:17:11 PM
Just look for the other layer name and turn it off ... something like so:

Code - Auto/Visual Lisp: [Select]
  1. (defun c:frzlay ()
  2.   (lm:odbx
  3.     (function (lambda (doc / lay)
  4.                 (vlax-for lay (vla-get-layers doc)
  5.                   (if (wcmatch (strcase (vla-get-name lay)) (strcase "*MARC*"))
  6.                     ;; Turn the layer on
  7.                     (vla-put-layeron lay :vlax-true)
  8.                   )
  9.                   (if (wcmatch (strcase (vla-get-name lay)) (strcase "*JESSE*"))
  10.                     ;; Turn the layer off
  11.                     (vla-put-layeron lay :vlax-false)
  12.                   )
  13.                 )
  14.               )
  15.     )
  16.     nil
  17.     t
  18.   )
  19.   (princ)
  20. )