Jump to content

How find a drawing with a specific layer name?


Guest

Recommended Posts

If you want just 1 layer look at your defun Getlayersproperties it can be shortened down to using a simple if, no need for sort etc Not tested.

(defun GetLayerProperties ( doc / lst )
 (vlax-for lay (vla-get-Layers doc)
(If  (= (vla-get-name lay) yourlayername)
(write-line dwgname ofile)
)  
)
)

 

The way to go would be do a IF want "name,color,ltype" or "name" so call Getlayersproperties2

 

A bit of rewriting. Sorry have to many to do's at moment.

Link to comment
Share on other sites

If using accoreconsole and a script calling a lisp (tblsearch "LAYER" yourlayer) will return true or nil, so write dwg name to file, use the "A" option when opening the file to append the answer. Look into Accoreconsole.

 

https://through-the-interface.typepad.com/through_the_interface/2012/02/the-autocad-2013-core-console.html

Edited by BIGAL
  • Like 1
Link to comment
Share on other sites

I found this thread in a search.
I'm trying to do the very thing as the OP, using Lee Mac's original version of the program, which outputs to a TEXT FILE.
Only down side is my brain has trouble with the vl-/vla-/vlax- syntax used in the program.
As originally written, The program lists all drawings in the chosen folder(and optionally, subs) and for each drawing, lists all layers alphabetically.

What I'd like to change the program to do:
List a drawing only if it contains the layer WATERMARK. This will leave a text file listing only those drawings containing that layer.
Seemed simple enough. Just toss in a "If layer =" or some such, but as stated above, vl-/vla-/vlax- syntax is my enemy here and the programming style is, well, way beyond my abilities.
The original program, as posted by @Lee Mac, is below for your viewing pleasure and to give credit to the author.

 


;; Posted by Lee Mac 15 Jan 2010
;; https://www.cadtutor.net/forum/topic/17420-listing-layers-in-multiple-drawings/


;; What changes are necessary to only list those DWGs that have layer "WATERMARK"?
;; GetLayers subroutine ??


(defun c:CheckLayers (/ *error* ObjRelease DirDialog Get_Subs ObjectDBXDocument GetLayers

                       DBX DWLST FILE FOLDER LAYER_LIST PATH SHELL)
 (vl-load-com)
 ;; Lee Mac  ~  15.01.10
 

 (defun *error* (msg)
   (ObjRelease (list Shell dbx))
   (and ofile (= (type ofile) 'FILE) (close ofile))
   
   (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")
       (princ (strcat "\n** Error: " msg " **")))
   (princ))


 (defun ObjRelease (lst)
   (mapcar
     (function
       (lambda (x)
         (if (and (eq (type x) 'VLA-OBJECT)
                  (not (vlax-object-released-p x)))
           (vl-catch-all-apply
             (function vlax-release-object) (list x))))) lst))


 (defun DirDialog (msg dir flag / Shell Fold Path)
   ;; Lee Mac  ~  07.06.09
   
   (setq Shell (vla-getInterfaceObject *acad "Shell.Application")
         Fold  (vlax-invoke-method Shell 'BrowseForFolder
                 (vla-get-HWND *acad) msg flag dir))
   (vlax-release-object Shell)
   
   (if Fold
     (progn
       (setq Path (vlax-get-property
                    (vlax-get-property Fold 'Self) 'Path))
       (vlax-release-object Fold)
       
       (and (= "\\" (substr Path (strlen Path)))
            (setq Path (substr Path 1 (1- (strlen Path)))))))
   
   Path) 


 (defun Get_Subs (folder / file) ;; CAB
   (mapcar
     (function
       (lambda (x) (setq file (strcat folder "\\" x))
                   (cons file (apply (function append) (get_subs file)))))
       (cddr (vl-directory-files folder nil -1))))

 
 (defun ObjectDBXDocument (/ acVer)
   
   (vla-GetInterfaceObject *acad
     (if (< (setq acVer (atoi (getvar "ACADVER"))) 16) "ObjectDBX.AxDbDocument"
       (strcat "ObjectDBX.AxDbDocument." (itoa acVer)))))
 

 (defun GetLayers (doc / lst)
   (vlax-for lay (vla-get-Layers doc)
     (setq lst (cons (vla-get-name lay) lst)))
 (acad_strlsort lst))
 

 (setq *acad (cond (*acad) ((vlax-get-acad-object)))
       *doc  (cond (*doc ) ((vla-get-ActiveDocument *acad))))

 (or *def* (setq *def* "Yes"))
 

 (if (and (setq Path (DirDialog "Select Directory" nil 0))
          (vl-file-directory-p Path)
          (setq outfile (getfiled "Output File" "" "txt" 1)))
   (progn

     (initget "Yes No")
     (setq *def* (cond ((getkword
                          (strcat "\nProcess SubDirectories? <" *def* "> : "))) (*def*)))

     (princ "\n>> Processing...")

     (foreach dwg  (setq dwLst (apply (function append)
                                      (vl-remove 'nil
                                        (mapcar
                                          (function
                                            (lambda (Path)
                                              (mapcar
                                                (function
                                                  (lambda (File)
                                                    (strcat Path "\\" File)))
                                                (vl-directory-files Path "*.dwg" 1))))
                                          (append (list Path)
                                                  (apply (function append)
                                                         (if (= "YES" (strcase *def*))
                                                           (Get_Subs Path))))))))      

       (vlax-for doc (vla-get-Documents *acad)
         (and (eq (strcase (vla-get-fullname doc)) (strcase dwg))
              (setq dbx doc)))

       (and (not dbx) (setq dbx (ObjectDBXDocument)))
       

       (if (not (vl-catch-all-error-p
                   (vl-catch-all-apply
                     (function vla-open) (list dbx dwg))))
         (progn
           (princ (chr 46))

           (setq Layer_List (cons (cons dwg (GetLayers dbx)) Layer_List))

         ) ; Progn

       ))

     (princ (strcat "\n<< " (itoa (length dwLst)) " Drawings Processed >>")))
   
   (princ "*Cancel*"))

 (ObjRelease (list Shell dbx)) (gc) (gc)

 (if (and Layer_List
         (setq ofile (open outfile "w")))
   (progn
     
     (mapcar
       (function
         (lambda (x)
           (write-line (car x) ofile)
           (mapcar
             (function
               (lambda (y)
                 (write-line y ofile))) (cdr x))
           (write-line "\n" ofile)))

       Layer_List)

     (close ofile))

   (princ "\n*Cancel*"))

 (princ))


Any helpful hints and ideas are appreciated.
Thanks,
Steve

Edited by StevJ
Link to comment
Share on other sites

had an idea (not necessarily a good one) but tried to add search for layers to a program I wrote a little while back My BFF. Have only tested it once though so hope for the best & plan for the worst...

 

(1) Put Routine in layer mode , add names of layer(s) to search for.

(2) Save the search list

(3) select folder with drawings to scan

(4) click on create

(5) click on ok

 

you should get new dialog with drawings containing layers you specified (if any). You can click on one item in list box and full path is displayed below the list box. You can then click on ok to open the drawing , or click on edit button to open notepad with list of all drawings found. You can also click on multiple lines in the listbox and click ok. Hope it works, if not , will try to fix later...

 

🐉

 

 

 

Remco Koedoot.jpg

 

 

RlxMyBFF.lsp

Edited by rlx
killed another bug
  • Like 1
Link to comment
Share on other sites

31 minutes ago, rlx said:

had an idea (not necessarily a good one) but tried to add search for layers to a program I wrote a little while back My BFF. Have only tested it once though so hope for the best & plan for the worst...

 

(1) Put Routine in layer mode , add names of layer(s) to search for.

(2) Save the search list

(3) select folder with drawings to scan

(4) click on create

(5) click on ok

 

you should get new dialog with drawings containing layers you specified (if any). You can click on one item in list box and full path is displayed below the list box. You can then click on ok to open the drawing , or click on edit button to open notepad with list of all drawings found. You can also click on multiple lines in the listbox and click ok. Hope it works, if not , will try to fix later...

 

🐉

 

 

 

Remco Koedoot.jpg

RlxMyBFF.lsp 53.58 kB · 0 downloads

 

This is impressive, but unfortunately, at step 4, I get this error.

RLXMYBFF-error.png.e4d05af1a3c660aaff5d70c81341a924.png

 

My drawings do not have a title block.

 

Steve

 

 

 

 

 

 

Link to comment
Share on other sites

ah yes , have'nt thought about that one. 😳 Just switch of layer mode , type in any string for blockname , same for attributes and switch back to layer mode, maybe this will work. I will fix this later.

  • Like 1
Link to comment
Share on other sites

7 hours ago, rlx said:

ah yes , have'nt thought about that one. 😳 Just switch of layer mode , type in any string for blockname , same for attributes and switch back to layer mode, maybe this will work. I will fix this later.

 

OK. That got the program to run -

Image1.png.ce62663ca4f32d933c32c29157b7a67a.png

 

There are  indeed 13 drawings in the folder. Some have HIDDEN layer.

But when I selected OK button to see results,

Image2.png.9b5bd9bd7d3226ff371bf1cf50329d25.png

 

then, selecting OK on that message  gives

Image3.png.893c87f24292399c852ab8a3c18e356d.png

 

This last window was to give the user the results of the search for all drawings with , in this case, a HIDDEN layer?

Also, the Folder Index List index file was never created.

 

Steve

 

 

Edited by StevJ
spellin
Link to comment
Share on other sites

maybe try to use saveas index list and then use edit to see if list contains all your files. Sometimes its to do with IT and write permissions and sometimes just not enough safeguards built in. Not sure if you have to use 'Ignore case' too, else post a sample drawing so I can check if at least retrieving your layers is working as is intended. Its always a risk trying to change an existing routine that was originally meant to do something else. 

Link to comment
Share on other sites

JACKPOT!

Following your numbered steps, as posted above, now gives expected results.

I have been volunteered to search thousands of drawings for a certain layer that is no longer part of our standards, then remove it and everything on it.

Your program will shave many days off this task.

 

Thank you for your programming time and effort.

Cheers!

:beer:

 

Steve

Link to comment
Share on other sites

  • 2 weeks later...

With a script working with AcCoreConsole.

Choose the folder where you want find layer in dwg
You enter the name of the desired layer.
If the wildcard "*" is used and at the beginning of the chain the XREF layers (if present), the layer names will also be returned.
Elsewhere the affected layers will be returned. Example "Layer*" could return Layer1, Layer2, Layer3 etc...
At the end of the execution of AcCoreConsole, the following line will return the result in the notepad.

(startapp "notepad" (strcat (getvar "ROAMABLEROOTPREFIX") "support\\find_layer.txt"))

 

find_layerbydwg.lsp

Edited by Tsuky
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...