LISP - Automate ACAD commands

LISP - Automate ACAD commands

cool.stuff
Collaborator Collaborator
5,899 Views
14 Replies
Message 1 of 15

LISP - Automate ACAD commands

cool.stuff
Collaborator
Collaborator

Hi!!!

 

I am trying to write a LISP to run a set of commands that I have to run on some files.

What I want to do is this:

 

- Select all objects;

- Purge ("yes" to questions of command);

- Audit ("yes" to questions of command);

- Define ucs to current plan view;

- Flatten ("yes" to questions of command);

 

What I wrote is this (I'm trying to learn LISP recently, sorry for my bad code):

 

(defun C:test()
(command "_select" "_all" "")
); function

 

But it does not even select all objects after run it..

 

Many thanks in advance 🙂

0 Likes
Accepted solutions (2)
5,900 Views
14 Replies
Replies (14)
Message 2 of 15

hak_vz
Advisor
Advisor

Since you want to combine Autocad commands in a singe function, try to do it yourself.

For each of commands you listed there is a console run version that doesn't show dialogs that can be accessed like

(command "_.-command_name" switches).

Add appropriate switches by following how command asks you and that's it. All those commands work on whole drawing so you don't have to select anything.  If you jump into problems post your code and someone will help.

 

Also, you may search through older posts to this forum. Similar requests have been answered on regular basis at least once every month or two.

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
Message 3 of 15

Kent1Cooper
Consultant
Consultant

@cool.stuff wrote:

....

(defun C:test()

(command "_select" "_all" "")
); function

 

But it does not even select all objects after run it.. ....


It actually does -- you can call up any editing command and give it "P" for the Previous selection, and see.  But when used in a (command) function, by default it uses a more basic older version of the command functionality, and doesn't leave them selected/gripped/highlighted as it does when done at the command prompt in newer versions.  But you can force it to use the newer functionality, leaving them selected/gripped/highlighted:

 

  (initcommandversion)
  (command "_select" "_all" "")

Kent Cooper, AIA
Message 4 of 15

Sea-Haven
Mentor
Mentor

Just a quick one I would run audit 1st as it will attempt to fix errors, then run -purge as it may remove error objects found.

Message 5 of 15

cool.stuff
Collaborator
Collaborator

Many thanks for all the answers!!! 🙂

 

I'm writing my code 🙂

 

However, for what I've read in forum, flatten is a lisp (express tools).

I cant run it like the others commands..

So can anyone help me in writing flatten for all objects and with "no" options for remove hidden lines?

Here is what I have:

(c:flatten "_all" "_n")

 

But it gives me an error..

 

Many thanks!!

0 Likes
Message 6 of 15

cool.stuff
Collaborator
Collaborator

@Kent1Coopercould you explain how to pass as argument all objects in current drawing please?

I would like to pass "select all" selection to flatten..

 

Many thanks!

0 Likes
Message 7 of 15

Kent1Cooper
Consultant
Consultant

@cool.stuff wrote:

@Kent1Coopercould you explain how to pass as argument all objects in current drawing please?

I would like to pass "select all" selection to flatten..


I wish I could....  Since it's not a native AutoCAD command, it doesn't work in a (command) function in the way those do.  I think I've seen an approach used around here that involves stringing the pieces together in another way, but I don't remember how it's done -- I hope someone familiar with that will jump in, and if not, I'll see if I can find an example somewhere, later.

Kent Cooper, AIA
0 Likes
Message 8 of 15

Sea-Haven
Mentor
Mentor

Flatten.lsp calls flattensup.lsp

 

(FLATTENSUP.LSP"  ss hide) maybe hide "yes" or "No" I just found the lisps in c:\program files........\EXpress

 

NOT Tested

 

Ps Extrim is not that function name rather (Etrim .... for lisp.

 

  Directory of C:\Program Files\Autodesk\AutoCAD 2020\Express

01/08/2018  12:11 AM            35,070 acadinfo.lsp
01/08/2018  12:11 AM            42,975 acet-wmf.lsp
01/08/2018  12:11 AM            23,124 acetauto.lsp
01/08/2018  12:11 AM            12,901 acetess.lsp
01/08/2018  12:11 AM            31,729 acettxt.lsp
01/08/2018  12:10 AM            27,187 aceturl.lsp
01/08/2018  12:11 AM             4,242 aliasedit.lsp
01/08/2018  12:11 AM            10,116 aspace.lsp
01/08/2018  12:11 AM            17,389 attout.lsp
01/08/2018  12:10 AM             7,272 blockq.lsp
01/08/2018  12:11 AM            10,660 blocktoxref.lsp
01/08/2018  12:11 AM            17,677 blocktoxrefsup.lsp
01/08/2018  12:11 AM            23,244 breakl.lsp
01/08/2018  12:11 AM            17,154 bscale.lsp
01/08/2018  12:10 AM            11,318 burst.lsp
01/08/2018  12:11 AM            32,407 cdorder.lsp
01/08/2018  12:10 AM            30,080 clipit.lsp
01/08/2018  12:11 AM            16,289 copym.lsp
01/08/2018  12:10 AM             6,083 count.lsp
01/08/2018  12:10 AM            28,079 ddins2.lsp
01/08/2018  12:11 AM             5,290 dimassoc.lsp
01/08/2018  12:11 AM             4,802 dwglog.lsp
01/08/2018  12:11 AM            13,467 etbug.lsp
01/08/2018  12:11 AM            18,909 exoffset.lsp
01/08/2018  12:11 AM             7,545 explan.lsp
01/08/2018  12:10 AM            23,594 extrim.lsp
01/08/2018  12:11 AM            16,437 fastsel.lsp
01/08/2018  12:11 AM             4,588 flatten.lsp
05/12/2018  05:20 PM            87,787 flattensup.lsp
01/08/2018  12:10 AM             9,981 gatte.lsp
01/08/2018  12:10 AM             6,168 getsel.lsp
01/08/2018  12:11 AM            40,676 hatchutil.lsp
01/08/2018  12:11 AM            13,607 ix_edit.lsp
01/08/2018  12:10 AM            18,395 julian.lsp
01/08/2018  12:11 AM            23,517 layoutmerge.lsp
01/08/2018  12:10 AM            75,533 lman.lsp
01/08/2018  12:11 AM            75,022 lspdata.lsp
01/08/2018  12:11 AM             4,292 lspsurf.lsp
01/08/2018  12:10 AM            34,945 mkltype.lsp
01/08/2018  12:10 AM            51,135 mkshape.lsp
01/08/2018  12:11 AM             5,458 movebak.lsp
01/08/2018  12:10 AM            13,626 mpedit.lsp
01/08/2018  12:10 AM            19,430 mstretch.lsp
01/08/2018  12:11 AM            38,731 pljoinsup.lsp
01/08/2018  12:11 AM            10,367 plt2dwg.lsp
01/08/2018  12:11 AM             6,302 qquit.lsp
01/08/2018  12:10 AM            43,754 redir.lsp
01/08/2018  12:11 AM             6,059 revert.lsp
01/08/2018  12:10 AM            17,302 rtext.lsp
01/08/2018  12:11 AM            29,569 rtucs.lsp
01/08/2018  12:11 AM             5,466 saveall.lsp
01/08/2018  12:11 AM            17,534 shp2blk.lsp
01/08/2018  12:10 AM            74,945 sprhatch.lsp
01/08/2018  12:10 AM            11,302 ssx.lsp
01/08/2018  12:11 AM            35,627 tblname.lsp
01/08/2018  12:11 AM            12,172 tcase.lsp
01/08/2018  12:11 AM            10,580 tcaseSup.lsp
01/08/2018  12:10 AM             8,008 textfit.lsp
01/08/2018  12:10 AM            43,101 textmask.lsp
01/08/2018  12:11 AM             8,997 trex.lsp
01/08/2018  12:10 AM            23,943 trexblk.lsp
01/08/2018  12:11 AM            22,058 tscale.lsp
01/08/2018  12:10 AM            13,150 txtexp.lsp
01/08/2018  12:11 AM             7,494 vpscale.lsp
01/08/2018  12:11 AM            11,743 vpsync.lsp
01/08/2018  12:10 AM            19,950 xdata.lsp
01/08/2018  12:10 AM            11,375 xlist.lsp
01/08/2018  12:11 AM             5,595 yes_no.lsp
              68 File(s)      1,474,324 bytes
               
0 Likes
Message 9 of 15

cool.stuff
Collaborator
Collaborator

Many many thanks for your answer and help, but I stil can not make it work..

 

Just another question please:

It is possible to load a lisp and answer "load once" through command line/lisp code?

 

Many thanks again

0 Likes
Message 10 of 15

Anonymous
Not applicable

my ford benefits

 

All you have to do is type CUI in the command line. Next, find the LISP Files category in the Customization in All Files section of the CUI dialog box, right-click on it, and choose Load Lisp from the context menu. Navigate to the location of where your LISP file is, and it will appear in the list.

0 Likes
Message 11 of 15

Sea-Haven
Mentor
Mentor

You can appload a lisp and add it to the startup suite then its available straight away. You can appload 1 lisp and in that lisp it has the "AUTOLOAD" command this will load a lisp when required based on the command entered.

 

(autoload "Goto-LAYOUT" '("GOTO"))

(autoload "ZERO" '("ZERO")) 

(autoload "VPFREEZE" '("VPF"))

 

Try this

(setq ss (ssget))
(load "flattensup")
(acet-flatn  ss "Yes")

 

Message 12 of 15

john.uhden
Mentor
Mentor
Accepted solution

It's obvious that the c:Flatten function is not defined to accept input arguments.

Try this...

(vlax-add-cmd "Flatten" 'c:flatten 0)

Then you can run the function as though it were a native AutoCAD command, as in...

(command "flatten" "_all" "_n")

John F. Uhden

Message 13 of 15

Sea-Haven
Mentor
Mentor
Accepted solution

If you have  a look at flatten its a front end to Flattensup all the work is done in the 2nd lisp, hence (acet-flatn ss T)

Message 14 of 15

john.uhden
Mentor
Mentor
Well, that's a whole lot more direct!
Good sleuthing. You deserve a Foster's or whatever Jimmy Spithill drinks,
maybe a Dark & Stormy?

John F. Uhden

0 Likes
Message 15 of 15

Sea-Haven
Mentor
Mentor

Look at the list I posted of the express lisps. a good example is "EXTRIM" in a lisp use (ETRIM.

 

Ps Great Northern as advertised by the crocodile hunter a good drop.

0 Likes