+ Reply to Thread
Results 1 to 4 of 4
  1. #1
    Full Member benhubel's Avatar
    Computer Details
    benhubel's Computer Details
    Operating System:
    Windows 7
    Discipline
    Manufacture
    benhubel's Discipline Details
    Occupation
    Waterjet Programmer
    Discipline
    Manufacture
    Using
    AutoCAD 2012
    Join Date
    Dec 2015
    Location
    Dallas, Texas
    Posts
    76

    Default Lisp to create numbered folders based on selection

    Registered forum members do not see this ad.

    I have some drawings which contain hundreds of numbers (example: 1-218b), each of which is on geometry which will be written as a block into its own folder. I am trying to write a Lisp that will create all of the folders based on the selected text. I have found a few posts about writing a directory, but it's all super confusing to me.

    General routine process:
    1. Get selected text objects
    2. Prompt for directory to create new folders in
    3. Create a folder for each selected text object, named based on the text

    It's ok to assume that the text is already selected when the Lisp starts. If no text is selected, I'd just send an error message to the console and end the routine.

    It's preferable that the directory prompt is GUI based so that I can navigate to the directory, but I am absolutely clueless here. If needed, I can just copy and paste the directory path into the console.

    The routine doesn't have to work with MText. The files contain only single line text.

    If I can get any code working, I'll post it, but I think it's going to take a good long while.

  2. #2
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    19,322

    Default

    Here's a start:
    Code:
    (defun c:createfolders ( / dir idx sel )
        (if (and (setq sel (ssget '((0 . "TEXT") (1 . "~*[\\/:*?\"<>|]*"))))
                 (setq dir (LM:browseforfolder "Select the output directory:" nil 0))
            )
            (repeat (setq idx (sslength sel))
                (vl-mkdir (strcat dir "\\" (cdr (assoc 1 (entget (ssname sel (setq idx (1- idx))))))))
            )
        )
        (princ)
    )
    
    ;; Browse for Folder  -  Lee Mac
    ;; Displays a dialog prompting the user to select a folder.
    ;; msg - [str] message to display at top of dialog
    ;; dir - [str] [optional] root directory (or nil)
    ;; bit - [int] bit-coded flag specifying dialog display settings
    ;; Returns: [str] Selected folder filepath, else nil.
    
    (defun LM:browseforfolder ( msg dir bit / err fld pth shl slf )
        (setq err
            (vl-catch-all-apply
                (function
                    (lambda ( / app hwd )
                        (if (setq app (vlax-get-acad-object)
                                  shl (vla-getinterfaceobject app "shell.application")
                                  hwd (vl-catch-all-apply 'vla-get-hwnd (list app))
                                  fld (vlax-invoke-method shl 'browseforfolder (if (vl-catch-all-error-p hwd) 0 hwd) msg bit dir)
                            )
                            (setq slf (vlax-get-property fld 'self)
                                  pth (vlax-get-property slf 'path)
                                  pth (vl-string-right-trim "\\" (vl-string-translate "/" "\\" pth))
                            )
                        )
                    )
                )
            )
        )
        (if slf (vlax-release-object slf))
        (if fld (vlax-release-object fld))
        (if shl (vlax-release-object shl))
        (if (vl-catch-all-error-p err)
            (prompt (vl-catch-all-error-message err))
            pth
        )
    )
    
    (vl-load-com) (princ)
    The above uses my Browse for Folder function.
    Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

  3. #3
    Full Member benhubel's Avatar
    Computer Details
    benhubel's Computer Details
    Operating System:
    Windows 7
    Discipline
    Manufacture
    benhubel's Discipline Details
    Occupation
    Waterjet Programmer
    Discipline
    Manufacture
    Using
    AutoCAD 2012
    Join Date
    Dec 2015
    Location
    Dallas, Texas
    Posts
    76

    Default

    That is EXACTLY what I was trying to do!
    I wonder if I can convince my boss to hire you to do some coding for us. You've already saved me a good amount of time. I'll throw the idea his way.
    Thank you very much for writing this!

  4. #4
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    19,322

    Default

    Registered forum members do not see this ad.

    You're welcome! - I'm glad it helps, and I look forward to hearing from you.

    Lee
    Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

Similar Threads

  1. Using Bat How to create Folders...
    By suryatry26 in forum .NET, ObjectARX & VBA
    Replies: 4
    Last Post: 25th Jun 2014, 05:27 am
  2. Selection Set based on handle
    By MJLM in forum AutoLISP, Visual LISP & DCL
    Replies: 25
    Last Post: 21st Mar 2014, 09:19 pm
  3. Lisp to create tabs from Selection Window
    By nlao in forum AutoLISP, Visual LISP & DCL
    Replies: 5
    Last Post: 7th Jan 2013, 06:00 pm
  4. DCL - starting a different function based on radio selection error.
    By yonderbob in forum AutoLISP, Visual LISP & DCL
    Replies: 0
    Last Post: 24th Aug 2011, 10:20 am
  5. How do i create an app online CAD based???
    By lua_roxita in forum AutoCAD Drawing Management & Output
    Replies: 3
    Last Post: 5th Jul 2006, 09:43 am

Tags for this Thread

Bookmarks

Posting Permissions

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