See the top rated post in this thread. Click here

Page 1 of 2 12 LastLast
Results 1 to 10 of 16

Thread: How can I batch/search a database of cad drawings for ONE specific layout TAB?

  1. #1
    Member
    Join Date
    2015-09
    Posts
    7
    Login to Give a bone
    0

    Default How can I batch/search a database of cad drawings for ONE specific layout TAB?

    Hi everyone,

    I'm trying to accomplish a task, but don't have the relevant experience to put it all together. I'm using Autocad Map 3d 2006 (with Retail Focus overlay) and approximately 1500 drawing files that have multiple layout tabs setup for various sheet sizes and layer states. I want to be able to run a script, routine, or utility (either inside or outside of cad) that will allow me to batch/search the database of drawings, identify which drawings have a layout tab named "x", and print out a result reflecting any drawing file names that DO NOT have the layout tab "x".

    After some poking around, I did find a small lisp routine (below) that when used in collaboration with Autodesk's ScriptPro will spit out a list of ALL tabs from EACH drawing to a txt file, but all the text files are named the same thing (layoutlist.txt) and they are all separate, so there's no way to connect which txt file belongs to which drawing file. It would be more beneficial if the results could be compiled onto one sheet. My lisp, scripting, and coding skills are basic at best but I can patch things together when given clear direction.

    If anyone has ideas on how to accomplish the above, I would be very appreciative.

    Thanks!



    LISTLAYOUTS.lsp
    =========================================
    (vl-load-com)
    (setq fn (strcat (getenv "temp") "\\" "layoutlist.txt")
    fp (open fn "w")
    )
    (vlax-for x
    (vla-get-Layouts
    (vla-get-ActiveDocument
    (vlax-get-acad-object)
    )
    )
    (princ (vla-get-Name x) fp)
    (princ "\n" fp)
    )
    (close fp)
    (startapp "notepad" fn)
    =========================================

  2. #2
    All AUGI, all the time
    Join Date
    2010-10
    Posts
    535
    Login to Give a bone
    0

    Default Re: How can I batch/search a database of cad drawings for ONE specific layout TAB?

    Since you are looking for a specific Tab Name, might as well create one file with drawing names that layouts matches the Target Tab name. Use ONE file name throughout the script , use "a" instead of "w"

    like so: [Filename is Layoutlist.txt]
    d:\dwgpath\Onedrawing.dwg
    d:\dwgpath\Anotherdrawing.dwg
    d:\otherdwgpath\Someotherdrawing.dwg

    sample code
    Code:
    (defun
       LayoutFind (name / fn fp)
      (vl-load-com)
      (if (and name
            (not (member (strcase name) (mapcar 'strcase (layoutlist))))
            )
        (progn
          (setq
            fn (strcat (getenv "temp") "\\" "layoutlist.txt")
            fp (open fn "a")
            )
          (princ (strcat "\n" (getvar 'dwgprefix)(getvar 'Dwgname)) fp)
          (close fp)
          )
        )
      )
    USAGE:

    _.open "C:\Folderpath\sample1.dwg" (layoutfind "TargetTab") _.save _close

    then throw this line at the very end of the script
    Code:
    (startapp "notepad"  (strcat (getenv "temp") "\\" "layoutlist.txt"))
    If you still want to use your original approach
    Code:
    (setq fn (strcat (getenv "temp") "\\" (getvar 'Dwgname))
    fp (open fn "w")
    )
    Last edited by pbejse; 2012-10-01 at 02:14 PM.

  3. #3
    Member
    Join Date
    2015-09
    Posts
    7
    Login to Give a bone
    0

    Default Re: How can I batch/search a database of cad drawings for ONE specific layout TAB?

    Thanks pbejse for the response - much appreciated. I hate to be someone that needs hand holding through a task, but due to my limited experience with all things script/lisp related, I'm not clear on what each part of your code does or how to assemble the parts of your solution into action. A few questions:

    1) Should I be saving text file "Layoutlist.txt" explicitly as you described after "like so:"?

    2) Should the "sample code" you provided be saved as a lisp file?

    3) I'm not sure how to incorporate what you describe in the "Usage" section.

    Clearly, I need to brush up on the simple basics for this and any other future scripting tasks. If you are able to clarify further it will definitely be appreciated.

    Thanks.

  4. #4
    All AUGI, all the time
    Join Date
    2010-10
    Posts
    535
    Login to Give a bone
    0

    Default Re: How can I batch/search a database of cad drawings for ONE specific layout TAB?

    Quote Originally Posted by mattstaples View Post
    A few questions:
    1) Should I be saving text file "Layoutlist.txt" explicitly as you described after "like so:"?
    You can name it whatever you please. i only suggested using one filename and the "Verified" drawing path and names as the contents. no need to compile.

    We can modify the code to different file names as another argument for each set of drawings.
    Say per project/discipline
    Architectural.txt
    Structural.Txt
    ......

    P.S. i mis-read your post that i code it to write the drawing names if "X' (sample only) exist. I modified the code above to do the opposite.

    Quote Originally Posted by mattstaples View Post
    2) Should the "sample code" you provided be saved as a lisp file?
    Yes, and should be pre-loaded via either acaddoc.lsp (load/autoload) or via startup-suite. And you can name the file as you please.

    Quote Originally Posted by mattstaples View Post
    3) I'm not sure how to incorporate what you describe in the "Usage" section.
    You mentioned on your first post " Autodesk's ScriptPro", so i assumed you know how to handle the script part, I myself have never use ScriptPro so i wouldnt know the correct syntax. AAMOF i more inclined to use ODBX (but that's another matter altogether)

    Unlike the code you posted. that "spit out a list of ALL tabs from EACH drawing to a txt file", the snippet above writes the drawing name and path ONLY of those found with target tab name.

    Quote Originally Posted by mattstaples View Post
    Clearly, I need to brush up on the simple basics for this and any other future scripting tasks. If you are able to clarify further it will definitely be appreciated.

    Thanks.
    I wrote a code some time ago to search for drawings with multiple layout tabs. (a clear violation of our company standards). what i did then was open a drawing list (txt) and check each and every file and save the result into a CSV file. and all that without opening a single file.

    I (ahem ... we) can assist you if you need more help.

  5. #5
    Past Vice President / AUGI Volunteer peter's Avatar
    Join Date
    2000-09
    Location
    Honolulu HI
    Posts
    1,109
    Login to Give a bone
    0

    Default Re: How can I batch/search a database of cad drawings for ONE specific layout TAB?

    This is a job for dbx module.

    Able to search drawing files from lisp with a single command.



    Hope it helps.

    P-


    Code:
    ;******************************************************************************
    ;
    ; Written BY: Peter Jamtgaard copyright 2012 all rights reserved
    ; Search folders and subfolders for drawings with a specific layout name.
    ; 
    ;******************************************************************************
    
    
    (defun C:DBXSearchForLayouts (/ ; lstFiles
                                    strDirectory 
                                    strFile
                                    strTextFile
                                    strWCLayout                                   
                                    objDBX
                                    objLayout
                                    z
                                 )
     (setq lstFiles nil)
     (setq strDirectory (code:BrowseForFolder "\nSelect Base Folder: "))
     (setq strWCLayout  (getstring "\nEnter WC Layout name: "))
     (foreach strDirectory (getsubdirlist strDirectory)
      (foreach strFile (vl-directory-files strDirectory "*.dwg" 1)
       (if (wcmatch strFile "*.dwg")
        (setq lstFiles (cons (strcat strDirectory "\\" strFile) lstFiles)) 
       )
      )
     ) 
     (setq z (open (setq strTextFile (strcat (vl-filename-directory 
                                        (getvar "dwgprefix") 
                                       )
                                       "\\DBXSearch.txt"                        
                               ) 
                   )
                    "w"
                   
             )
     )
     (foreach strDWGName lstFiles 
      (vlax-for objLayout (vla-get-layouts (code:open_dbxobj strDWGName))
       (if (wcmatch (strcase (vla-get-name objLayout)) 
                    (strcase strWCLayout)
           )
        (progn
         (princ (setq STR (strcat "\n" (vla-get-name objDBX) " - " (vla-get-name objLayout))))
         (write-line STR z)
        )
       ) 
      )
     )
     (vlax-release-object objDBX)  
     (close z)
     (getstring "\nPress Enter: ")
     (command "notepad" strTextFile)
    )
    
    
    (defun CODE:OPEN_DBXOBJ (strDWGName /)
     (if (not objDBX)
      (setq objDBX  (vla-GetInterfaceObject
                     (vlax-get-acad-object)
                     (strcat "ObjectDBX.AxDbDocument." (substr (getvar "acadver") 1 2))
                    )
      )
     )
    
     (vla-open objDBX (findfile strDWGName))
     (print (vla-get-name objDBX))
     objDBX
    )
    
    (defun code:BrowseForFolder (strMessage / objShellApp objFolder objParentFolder strPath)
     (setq objShellApp (vla-getInterfaceObject 
                        (vlax-get-acad-object) 
                        "Shell.Application" 
                       )  
     )
     (setq objFolder   (vlax-invoke objShellApp
                                    'BrowseForFolder  
                                    0
                                    strMessage
                                    0
                                    ""
                       )
     )
     (if objFolder 
      (and
       (setq strTitle (vlax-get objFolder "Title"))
       (setq objParentFolder (vlax-get objFolder 'ParentFolder))
       (setq strPath (vlax-get (vlax-invoke objParentFolder "Parsename" strTitle) "Path"))
       (vlax-release-object objParentFolder)
       (vlax-release-object objFolder)
      )
      (vlax-release-object objShellApp)
     )
     strPath
    )
    
    (defun GetSubDirList (strPath / lstDirectories)
     (setq lstDirectories (SearchSubDirectories strPath (list strPath)) )
    )
    
    (defun SearchSubDirectories (strPath lstDirectories )
     (foreach strDirectory (vl-directory-files strPath nil -1)
      (if (not (member strDirectory (list "." ".." "...")))
       (progn
        (setq lstDirectories (cons (strcat strPath "\\" strDirectory) lstDirectories))
    ;    (print (strcat strPath "\\" strDirectory))
        (setq lstDirectories (SearchSubDirectories (strcat strPath "\\" strDirectory) lstDirectories))
       )
      )
     )
     (reverse lstDirectories)
    )
    
    (print "C:DBXSearchForLayouts")
    (prin1)
    AutomateCAD

  6. #6
    Member
    Join Date
    2015-09
    Posts
    7
    Login to Give a bone
    0

    Default Re: How can I batch/search a database of cad drawings for ONE specific layout TAB?

    Ok, I fumbled through this a few times with no success and so awkwardly admit more openly my inexperience.

    Quote Originally Posted by pbejse View Post
    You can name it whatever you please. i only suggested using one filename and the "Verified" drawing path and names as the contents. no need to compile.

    We can modify the code to different file names as another argument for each set of drawings.
    Say per project/discipline
    Architectural.txt
    Structural.Txt
    ......
    Ok, so if I name the script "Script1.scr", and have it print out to a text file called "Text1.txt" should the contents of the script be the following?:

    _.open "C:\Folderpath\sample1.dwg" (layoutfind "TargetTab") _.save _close
    (startapp "notepad" (strcat (getenv "temp") "\\" "Text1.txt"))


    AND if I name the lisp file "Lisp1.lsp" should it contain the following?:

    (defun
    LayoutFind (name / fn fp)
    (vl-load-com)
    (if (and name
    (not (member (strcase name) (mapcar 'strcase (Text1))))
    )
    (progn
    (setq
    fn (strcat (getenv "temp") "\\" "Text1.txt")
    fp (open fn "a")
    )
    (princ (strcat "\n" (getvar 'dwgprefix)(getvar 'Dwgname)) fp)
    (close fp)
    )
    )
    )


    You mentioned on your first post " Autodesk's ScriptPro", so i assumed you know how to handle the script part, I myself have never use ScriptPro so i wouldnt know the correct syntax. AAMOF i more inclined to use ODBX (but that's another matter altogether)
    Ok, so the ScriptPro program basically allows you to select a script file to run and apply it to a list of drawings (that you add/load into ScriptPro). It's pretty basic. It's the actual coding of the script and lisps that I'm most unfamiliar with and uncertain how to piece together.


    I (ahem ... we) can assist you if you need more help.

    Thank you. I really do appreciate the time and effort offered - especially considering my lack of basics on the subject.


    ========================================================================================


    Quote Originally Posted by peter View Post
    This is a job for dbx module.

    Able to search drawing files from lisp with a single command.



    Hope it helps.

    P-
    Peter, thank you for the code you have offered. ALSO very appreciated. As noted above, I'm at a bit of a loss how to apply the code, however. If you have time to elaborate, that is fantastic. Otherwise, I will try to fit in the appropriate research to learn how to get this all working.

    Thanks!

  7. #7
    Past Vice President / AUGI Volunteer peter's Avatar
    Join Date
    2000-09
    Location
    Honolulu HI
    Posts
    1,109
    Login to Give a bone
    0

    Default Re: How can I batch/search a database of cad drawings for ONE specific layout TAB?

    This DBX routine will query drawing files in a selected folder and its sub-folders
    looking to see if they have layouts that match the search criteria.

    To use this code...

    Download attachments and save into your lisp directory in your search path.

    At the command line.

    (load "DBXSearchForLayouts")

    DBXSearchForLayouts


    In the browse folder dialog select the folder with the drawings you want to search.

    When you start it enter the Wild Card layout name like "LAYOUT*"

    The program will open and look through all of the drawings in the selected folder and its sub-folders.

    ***Make sure you are not in one of the drawings in the selected folders when you run this.***

    It will return a list (in a text file) of all drawings and layouts that match your search criteria.

    P-
    Attached Files Attached Files
    AutomateCAD

  8. #8
    Member
    Join Date
    2015-09
    Posts
    7
    Login to Give a bone
    0

    Default Re: How can I batch/search a database of cad drawings for ONE specific layout TAB?

    Wow. And Awesome.

    Peter, thank you so much! This works great and is very appreciated.
    I'm curious if there is a simple tweak to the code that I can do to get it do the same search, but print a list of the drawings that DO NOT have the specified tab. If it's a whole new lisp routine, then no worries-this one still works great.

    Thanks for your generosity and time!

    Matt

  9. #9
    Administrator rkmcswain's Avatar
    Join Date
    2004-09
    Location
    Earth
    Posts
    9,805
    Login to Give a bone
    0

    Default Re: How can I batch/search a database of cad drawings for ONE specific layout TAB?

    Quote Originally Posted by mattstaples View Post

    I want to be able to run a script, routine, or utility (either inside or outside of cad) that will allow me to batch/search the database of drawings, identify which drawings have a layout tab named "x"
    If your question stopped there (and I know it doesn't, but this may help someone else in the future....)
    You could go into DesignCenter, click the search button (looks like a globe), which opens the dialog below.
    Set the various parameters and click "Search Now" to search a directory, or even an entire drive.

    searchme.png
    R.K. McSwain | CAD Panacea |

  10. #10
    Past Vice President / AUGI Volunteer peter's Avatar
    Join Date
    2000-09
    Location
    Honolulu HI
    Posts
    1,109
    Login to Give a bone
    0

    Default Re: How can I batch/search a database of cad drawings for ONE specific layout TAB?

    Try that.

    (I fixed the fullname to name)

    P-
    Attached Files Attached Files
    Last edited by peter; 2012-10-03 at 06:44 PM.
    AutomateCAD

Page 1 of 2 12 LastLast

Similar Threads

  1. Non User Specific search paths
    By autocad.wishlist1734 in forum AutoCAD Wish List
    Replies: 3
    Last Post: 2012-05-18, 11:43 AM
  2. Search file in a specific drive
    By Dubweisertm in forum AutoLISP
    Replies: 15
    Last Post: 2011-09-11, 04:52 AM
  3. search sets for linked database
    By nnikitine in forum NavisWorks - General
    Replies: 11
    Last Post: 2010-06-01, 08:23 AM
  4. Can I search for a specific block name?
    By pmedina in forum AutoLISP
    Replies: 8
    Last Post: 2009-02-24, 12:47 PM
  5. Search text within drawings, without actually opening drawings
    By Animesh Kundu in forum AutoCAD General
    Replies: 3
    Last Post: 2008-02-29, 05:34 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •