Jump to content

Beginner Macro Help


matma7

Recommended Posts

Not quite sure why the "program shortcut" part is there either.

 

I added the program shortcut as I wanted to call my function "erase_all" or a sensible name that someone could relate to, but I didn't want the user to have to type "erase_all" everytime they ran the LISP, so I added a "program shortcut", where the user only has to type "ea" to run the LISP.

 

Some great help there from Dave, nice one. Scripts are useful, (not that I have created one myself, so I am not too confident with them) but I have used one before to perform some batch plotting to PDF. The LISP I provided contains a lot of command calls, so a script would probably be more appropriate - but as Dave says, the script files are slightly more elusive than LISP.

 

You need to go into load application and add it to the startup suite.

 

You can add the LISP to the startup-suite, or a more reliable method would be to add a call for the LISP in the ACADDOC.lsp file.

 

I have to say that the code is a lot more complicated than i thought it would be.

 

I must admit, I have made it slightly more complicated than it could be by adding an error handler (in case something goes wrong!)...

 

Now i've got a taste for some advanced stuff it's really whetted my appetite for what AutoCAD can do. I'm thinking of getting the AutoCAD Bible to increase my meager knowledge.

 

There is some great material to learn from out there, but I must admit, I have learnt most from here on the forums - just analysing the LISP posts and how people structure their code is great to learn from.

 

Nearly there but the file is saved as .dwg.dxf because the function I used to get the name includes the file extension.

I also added a part to unlock all layers because the "cutting" layer was left locked at the end of the function.

 

I'll take I quick look at your LISP and see what I can do :)

 

Ok, thats all for now - nearly xmas people!

 

Merry Christmas and Happy New Year everyone!

 

Cheers

 

Lee

Link to comment
Share on other sites

  • Replies 24
  • Created
  • Last Reply

Top Posters In This Topic

  • Lee Mac

    9

  • dbgeek

    5

  • matma7

    5

  • dbroada

    3

Top Posters In This Topic

Ok try this:

 

(defun c:test ()
   (command "_saveas" "DXF" "12" pause)
   (princ)
) ;_  end defun

(defun c:ea () (c:erase_all)) ; Program Shortcut

(defun c:erase_all (/ *error* varlist oldvars laylist ss str len name)
   (defun *error* (msg) ; Error Trap
   (mapcar 'setvar varlist oldvars)
   (if (= msg "")
       (princ "\nFunction Complete.")
       (princ "\nError or Esc Pressed...")
   ) ;_  end if
   (princ)
   ) ;_  end defun
   (setq varlist (list "CMDECHO" "CTAB" "CLAYER")
     oldvars (mapcar 'getvar varlist)
   ) ;_  end setq
   (setvar "cmdecho" 0)
   (if    (not (tblsearch "LAYER" "tool path"))
   (command "-layer" "M" "tool path" "")
   ) ;_  end if
   (setq laylist (layoutlist))
   (foreach x laylist
   (command "-layout" "D" x)
   ) ;_  end foreach
   (setvar "ctab" "MODEL")
   (command "-layer" "LO" "tool path" "")
   (setq ss (ssget "X" (list (cons 410 "MODEL"))))
   (command "_erase" ss "")
   (command "-purge" "A" "*" "N")
   (command "_audit" "Y")
   (command "_.Layer" "unlock" "*" "")
   (setq str (strlen (getvar "dwgname")))
   (setq len (- str 4))
   (setq name (substr (getvar "dwgname") 1 len))
   (command "_.saveas" "DXF" "12" (strcat "c:\\" name))
   (*error* "") ; Force error to reset variables.
   (princ)
) ;_  end defun

 

(untested)

Link to comment
Share on other sites

I mentioned startup suite based upon my own experience of certain folders being access restricted.

 

As above, its best if you add to a default folder where CAD looks anyway.

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...