+ Reply to Thread
Page 1 of 3 1 2 3 LastLast
Results 1 to 10 of 22
  1. #1
    Full Member
    Discipline
    Mechanical
    Using
    Mechanical 2015
    Join Date
    Mar 2018
    Posts
    25

    AutoCAD Lisp to Run a command Automatically when opened the file

    Registered forum members do not see this ad.

    Hi All
    I have a bunch of files in a folder, I have to do the purging process on several files.
    I have a lisp file to open the file automatically,
    So my idea is, after open the file, if the file name having 7 digits then the purge command should run automatically, if the file name less/greater than 7 digits then command should not run. can we do through lisp if possible.?

  2. #2
    Luminous Being Tharwat's Avatar
    Discipline
    Mechanical
    Tharwat's Discipline Details
    Occupation
    MEP AutoCAD Draughtsman
    Discipline
    Mechanical
    Details
    HVAC, Drainage, Water Supply, Fire Fighting and a little about Electricity.
    Using
    AutoCAD 2015
    Join Date
    Oct 2009
    Location
    Great Syria , Living in Abu Dhabi
    Posts
    6,152

    Default

    Hi,

    Create a acaddoc.lsp file if its not already existed into your AutoCAD support folder then add your codes into the fore-said file then within your codes you would need to have a few codes checking for the file name then do the job if your criteria matched.

  3. #3
    Full Member
    Discipline
    Mechanical
    Using
    Mechanical 2015
    Join Date
    Mar 2018
    Posts
    25

    Default

    Hi Tharwat
    Thanks for your reply, If i add my code into acaddoc.lsp, this will run all the files whenever open my AutoCAD, but need if the file name having seven digits (ex. 1234_A3) then only purge command should run automatically.

  4. #4
    Quantum Mechanic
    Using
    Civil 3D 2016
    Join Date
    Dec 2005
    Location
    GEELONG AUSTRALIA
    Posts
    10,400

    Default

    A simple check (getvar "dwgname") and have a look at is least 7 long does it have some pattern

    Code:
    (getvar 'dwgname)
    strlen is it 11
    subtract .dwg of end dont forget the 4 end characters .dwg
    substr in a loop 7 times check each character is it a number
    asscii 47-59 is 0-9 
    Drawing1.dwg is 12 long so Drawing1 is 8 long
    A man who never made mistakes never made anything

  5. #5
    Full Member
    Discipline
    Mechanical
    Using
    Mechanical 2015
    Join Date
    Mar 2018
    Posts
    25

    Default

    Hey Bigal
    Can you please give me the code.. I'm not a expert in lisp. But I'm interested to learn. So please help me.

  6. #6
    Super Member rlx's Avatar
    Computer Details
    rlx's Computer Details
    Operating System:
    W10
    Computer:
    i74ghz/ssd500/2tbhdd
    Discipline
    Electrical
    rlx's Discipline Details
    Occupation
    electrical designer dragon
    Discipline
    Electrical
    Details
    I dont excel in anything but I rearly give up
    Using
    AutoCAD 2016
    Join Date
    Nov 2014
    Location
    Bergen op Zoom , Netherlands
    Posts
    943

    Default

    this should help you on your way :

    Code:
    (defun c:tst ( / dwgn letters numbers)
      (vl-load-com)
      ; dwgname without path and extension
      (setq dwgn (vl-filename-base (getvar 'dwgname)))
      (princ (strcat "\nDrawing name is : " dwgn))
      (princ (strcat "\nDrawing name has " (itoa (strlen dwgn)) " characters"))
      ; Total number of letters in filename
      (if (> (setq letters (length (vl-remove-if '(lambda(x)(and (< x 58)(> x 47)))(vl-string->list dwgn)))) 0)
        (princ (strcat "\nTotal of letters in drawing name : " (itoa letters)))
        (princ "\nNo letters in dwgname")
      )
      ; total number of numbers in filename
      (if (> (setq numbers (length (vl-remove-if '(lambda(x)(or (< x 48)(> x 57)))(vl-string->list dwgn)))) 0)
        (princ (strcat "\nTotal of numbers in drawing name : " (itoa numbers)))
        (princ "\nNo numbers in dwgname")
      )
      (princ)
    )
    
    ; a few tiny lisp functions for more general use :
    
    ; remove letters from string (ripcar "123abc456def") -> "123456"
    (defun ripcar (s)
      (vl-list->string (vl-remove-if '(lambda(x)(or (< x 48)(> x 57)))(vl-string->list s))))
    ; remove numbers from string (ripnum "123abc456def") -> "abcdef"
    (defun ripnum (s)
      (vl-list->string (vl-remove-if '(lambda(x)(and (< x 58)(> x 47)))(vl-string->list s))))
    gr. Rlx
    Last edited by rlx; 17th Mar 2018 at 11:45 am.

  7. #7
    Quantum Mechanic
    Using
    Civil 3D 2016
    Join Date
    Dec 2005
    Location
    GEELONG AUSTRALIA
    Posts
    10,400

    Default

    Thanks rlx, nice descriptions, the question could cause other problems like purging a dwg you did not mean to. So acad1985 make sure you have a continue yes or no at start and for your info dcl supports a Ok Cancel button only, making a nice screen input rather than typing Y N etc. Which has prompted me to add to my library.
    A man who never made mistakes never made anything

  8. #8
    Luminous Being Tharwat's Avatar
    Discipline
    Mechanical
    Tharwat's Discipline Details
    Occupation
    MEP AutoCAD Draughtsman
    Discipline
    Mechanical
    Details
    HVAC, Drainage, Water Supply, Fire Fighting and a little about Electricity.
    Using
    AutoCAD 2015
    Join Date
    Oct 2009
    Location
    Great Syria , Living in Abu Dhabi
    Posts
    6,152

    Default

    Quote Originally Posted by acad1985 View Post
    if the file name having seven digits (ex. 1234_A3)
    A is a letter and not a digit.
    Can you explain your different file names in order to know how to check and run a program when a certain criteria meets.

  9. #9
    Luminous Being Tharwat's Avatar
    Discipline
    Mechanical
    Tharwat's Discipline Details
    Occupation
    MEP AutoCAD Draughtsman
    Discipline
    Mechanical
    Details
    HVAC, Drainage, Water Supply, Fire Fighting and a little about Electricity.
    Using
    AutoCAD 2015
    Join Date
    Oct 2009
    Location
    Great Syria , Living in Abu Dhabi
    Posts
    6,152

    Default

    Hi rlx,
    Code:
    (length nil) ;; = 0

  10. #10
    Super Member rlx's Avatar
    Computer Details
    rlx's Computer Details
    Operating System:
    W10
    Computer:
    i74ghz/ssd500/2tbhdd
    Discipline
    Electrical
    rlx's Discipline Details
    Occupation
    electrical designer dragon
    Discipline
    Electrical
    Details
    I dont excel in anything but I rearly give up
    Using
    AutoCAD 2016
    Join Date
    Nov 2014
    Location
    Bergen op Zoom , Netherlands
    Posts
    943

    Default

    Registered forum members do not see this ad.

    Quote Originally Posted by Tharwat View Post
    Hi rlx,
    Code:
    (length nil) ;; = 0
    oh darn , I realized that right after I posted but hoped nobody would notice , but there's no fooling you is there ...haha

Similar Threads

  1. Replies: 6
    Last Post: Today, 04:16 pm
  2. Replies: 1
    Last Post: 18th Sep 2014, 05:45 pm
  3. Execute lisp automatically while a command is running?
    By fathihvac in forum AutoLISP, Visual LISP & DCL
    Replies: 6
    Last Post: 29th May 2013, 05:01 pm
  4. Replies: 0
    Last Post: 5th Nov 2008, 07:06 am
  5. Automatically goes to plot when a drawing is opened.
    By jrobpong in forum AutoCAD Drawing Management & Output
    Replies: 2
    Last Post: 26th Apr 2007, 12:54 pm

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