Re-write this LISP to execute faster

Re-write this LISP to execute faster

nrz13
Advisor Advisor
2,163 Views
14 Replies
Message 1 of 15

Re-write this LISP to execute faster

nrz13
Advisor
Advisor

Below is a LISP we are currently using in our office for AutoCAD 2015, since 2015 bogs down way more than previous versions.  We find that constantly cleaning up the drawing helps the performance when working in the drawing.  Is there a better way to re-write this so it will hopefully cut down the time it takes to execute (I'm hoping to take it down from 2 seconds to 1 second per save).  We don't want layers and linetypes purged.  Thanks!

(DEFUN C:SV ()
    (COMMAND "-PURGE" "BLOCKS" "*" "N")
    (COMMAND "-PURGE" "DETAILVIEWSTYLES" "*" "N")
    (COMMAND "-PURGE" "DIMSTYLES" "*" "N")
    (COMMAND "-PURGE" "GROUPS" "*" "N")
    (COMMAND "-PURGE" "MATERIALS" "*" "N")
    (COMMAND "-PURGE" "MLINESTYLES" "*" "N")
    (COMMAND "-PURGE" "MULTILEADERSTYLES" "*" "N")
    (COMMAND "-PURGE" "PLOTSTYLES" "*" "N")
    (COMMAND "-PURGE" "SECTIONVIEWSTYLES" "*" "N")
    (COMMAND "-PURGE" "SHAPES" "*" "N")
    (COMMAND "-PURGE" "TABLESTYLES" "*" "N")
    (COMMAND "-PURGE" "TEXTSTYLES" "*" "N")
    (COMMAND "-PURGE" "VISUALSTYLES" "*" "N")
    (COMMAND "AUDIT" "Y")
    (COMMAND "QSAVE")
    (PRINC)
)


Work:  AutoCAD 2022.1.3, Windows 10 Pro v22H2 64-bit, Intel Core i7-8700K, 32GB RAM, Samsung 960 Pro SSD, AMD Radeon Pro WX 5100, 3 Dell Monitors (3840x2160)
Home: AutoCAD 2022.1.3, Windows 10 Pro v22H2 64-bit, Intel Core i7-11700, 64GB RAM, Samsung 980 Pro SSD, NVIDIA Quadro P2200, Dell Monitor (3840x2160)
0 Likes
Accepted solutions (3)
2,164 Views
14 Replies
Replies (14)
Message 2 of 15

Kent1Cooper
Consultant
Consultant
Accepted solution

If you were Purging [or would be willing to Purge] all categories of things, you can do it with the All option:

 

(DEFUN C:SV ()
    (COMMAND "-PURGE" "ALL" "*" "N")
    (COMMAND "AUDIT" "Y")
    (COMMAND "QSAVE")
    (PRINC)
)

 

However, it looks like you're not Purging Layers or Linetypes, in which case that won't do.  But it may speed it up if you combine those commands into one (command) function, because I think getting in and out of (command) takes a certain amount of time:

 

(DEFUN C:SV ()
  (COMMAND

    "-PURGE" "BLOCKS" "*" "N"
    "-PURGE" "DETAILVIEWSTYLES" "*" "N"
    "-PURGE" "DIMSTYLES" "*" "N"
    "-PURGE" "GROUPS" "*" "N"
    "-PURGE" "MATERIALS" "*" "N"
    "-PURGE" "MLINESTYLES" "*" "N"
    "-PURGE" "MULTILEADERSTYLES" "*" "N"
    "-PURGE" "PLOTSTYLES" "*" "N"
    "-PURGE" "SECTIONVIEWSTYLES" "*" "N"
    "-PURGE" "SHAPES" "*" "N"
    "-PURGE" "TABLESTYLES" "*" "N"
    "-PURGE" "TEXTSTYLES" "*" "N"
    "-PURGE" "VISUALSTYLES" "*" "N"
    "AUDIT" "Y"
    "QSAVE"

  ); command
  (PRINC)
)

Kent Cooper, AIA
0 Likes
Message 3 of 15

Jonathan3891
Advisor
Advisor

I agree with Kent's solution.


Jonathan Norton
Blog | Linkedin
Message 4 of 15

nrz13
Advisor
Advisor

Kent:

Thanks for the reply.  That's just what I was looking for, but I didn't know the syntax.  It seemed wasteful exiting and re-entering the Command function.  Unfortunately, I didn't notice any improved time to run the LISP, but at least the code is cleaner now.  That must just be the fastest my computer can execute the purge, audit, and save.


Work:  AutoCAD 2022.1.3, Windows 10 Pro v22H2 64-bit, Intel Core i7-8700K, 32GB RAM, Samsung 960 Pro SSD, AMD Radeon Pro WX 5100, 3 Dell Monitors (3840x2160)
Home: AutoCAD 2022.1.3, Windows 10 Pro v22H2 64-bit, Intel Core i7-11700, 64GB RAM, Samsung 980 Pro SSD, NVIDIA Quadro P2200, Dell Monitor (3840x2160)
0 Likes
Message 5 of 15

Jonathan3891
Advisor
Advisor
Due to the simple fact that you do not want to purge layers or linetypes, you have to list every item you want removed which takes time.

Jonathan Norton
Blog | Linkedin
0 Likes
Message 6 of 15

nrz13
Advisor
Advisor

DSM_dude:

Thanks.  I think what I'll do is purge only the blocks as part of the SV command and break out the full purge as a separate command.  It's the excess blocks that really drag the program down.  Purging just the blocks improves the run time slightly.


Work:  AutoCAD 2022.1.3, Windows 10 Pro v22H2 64-bit, Intel Core i7-8700K, 32GB RAM, Samsung 960 Pro SSD, AMD Radeon Pro WX 5100, 3 Dell Monitors (3840x2160)
Home: AutoCAD 2022.1.3, Windows 10 Pro v22H2 64-bit, Intel Core i7-11700, 64GB RAM, Samsung 980 Pro SSD, NVIDIA Quadro P2200, Dell Monitor (3840x2160)
0 Likes
Message 7 of 15

phanaem
Collaborator
Collaborator
Accepted solution
Since you are using AutoCAD2015, you can use command-s instead of command, which is faster. But you have to complete a single command in a command-s call, like in your sample.
0 Likes
Message 8 of 15

scot-65
Advisor
Advisor
Consider placing a user_flag (session gremlin) in the program that will
execute the purging and auditing the first time and subsequent "SV" to
skip over all the purging/audit and just do the save. From there one can
nest code that will check for and remove unreferenced images,
unreferenced xref's, groups, layer filters, etc.

Variations may include using the gremlin as a counter and to execute a full
"SV" every other time, every 5th time, 10th time, etc.

(if (not USER_SV)
(progn
(setq USER_SV T)
...purge purge purge... audit...
);progn
);if
(command ".QSAVE")

???

Scot-65
A gift of extraordinary Common Sense does not require an Acronym Suffix to be added to my given name.

0 Likes
Message 9 of 15

nrz13
Advisor
Advisor

Phanaem:

Thanks for that tip. Using command-s sped things up noticeably, and we're all on 2015 so compatibility shouldn't be an issue.  Now I'm very close to my desired target time.  I seem to recall seeing something about command-s when 2015 came out, but I can't find any documentation on it (the Help file just pulls up forum posts on it).  What makes it so much faster than command?

Here's what I ended up with:

(DEFUN C:SV ()
    (COMMAND-S "-PURGE" "BLOCKS" "*" "N")
    (COMMAND-S "-PURGE" "DETAILVIEWSTYLES" "*" "N")
    (COMMAND-S "-PURGE" "DIMSTYLES" "*" "N")
    (COMMAND-S "-PURGE" "GROUPS" "*" "N")
    (COMMAND-S "-PURGE" "MATERIALS" "*" "N")
    (COMMAND-S "-PURGE" "MLINESTYLES" "*" "N")
    (COMMAND-S "-PURGE" "MULTILEADERSTYLES" "*" "N")
    (COMMAND-S "-PURGE" "PLOTSTYLES" "*" "N")
    (COMMAND-S "-PURGE" "SECTIONVIEWSTYLES" "*" "N")
    (COMMAND-S "-PURGE" "SHAPES" "*" "N")
    (COMMAND-S "-PURGE" "TABLESTYLES" "*" "N")
    (COMMAND-S "-PURGE" "TEXTSTYLES" "*" "N")
    (COMMAND-S "-PURGE" "VISUALSTYLES" "*" "N")
    (COMMAND-S "AUDIT" "Y")
    (COMMAND-S "QSAVE")
    (PRINC)
)


Work:  AutoCAD 2022.1.3, Windows 10 Pro v22H2 64-bit, Intel Core i7-8700K, 32GB RAM, Samsung 960 Pro SSD, AMD Radeon Pro WX 5100, 3 Dell Monitors (3840x2160)
Home: AutoCAD 2022.1.3, Windows 10 Pro v22H2 64-bit, Intel Core i7-11700, 64GB RAM, Samsung 980 Pro SSD, NVIDIA Quadro P2200, Dell Monitor (3840x2160)
0 Likes
Message 10 of 15

nrz13
Advisor
Advisor

Scot-65:

I get the gist of what you're saying, although the programming part is beyond me.  In any case, I think it's probably a moot point because I'm pretty much where I want to be using command-s.  Thanks, though!


Work:  AutoCAD 2022.1.3, Windows 10 Pro v22H2 64-bit, Intel Core i7-8700K, 32GB RAM, Samsung 960 Pro SSD, AMD Radeon Pro WX 5100, 3 Dell Monitors (3840x2160)
Home: AutoCAD 2022.1.3, Windows 10 Pro v22H2 64-bit, Intel Core i7-11700, 64GB RAM, Samsung 980 Pro SSD, NVIDIA Quadro P2200, Dell Monitor (3840x2160)
0 Likes
Message 11 of 15

Kent1Cooper
Consultant
Consultant

@nrz13 wrote:

....  I seem to recall seeing something about command-s when 2015 came out, but I can't find any documentation on it (the Help file just pulls up forum posts on it).  What makes it so much faster than command?
....


Not knowing how you're getting into Help, I don't know why that should be, but here is the on-line Help where a Search turns up an entry about it, which mentions its being faster, and says a little about what makes it faster, if the explanation is in terms that are meaningful to you.

Kent Cooper, AIA
0 Likes
Message 12 of 15

nrz13
Advisor
Advisor

Thanks for the link, Kent.  I pull the help up by entering ? at the command line.  I just did a search for command-s in the search box and that's what I was getting.  From your link, I was able to click on the c functions in the alphabetical list and then find command-s.  I can't say I understand the finer points of it, but I did understand where it says it saves a processing step.  I also saw the limitation that phanaem mentioned where each command must be broken out separately, like how I originally had it.  Anyway, it's nice to see it officially documented so I can make sure I don't misuse it.


Work:  AutoCAD 2022.1.3, Windows 10 Pro v22H2 64-bit, Intel Core i7-8700K, 32GB RAM, Samsung 960 Pro SSD, AMD Radeon Pro WX 5100, 3 Dell Monitors (3840x2160)
Home: AutoCAD 2022.1.3, Windows 10 Pro v22H2 64-bit, Intel Core i7-11700, 64GB RAM, Samsung 980 Pro SSD, NVIDIA Quadro P2200, Dell Monitor (3840x2160)
0 Likes
Message 13 of 15

nrz13
Advisor
Advisor

One other thing I've noticed with this is it fails to bring up the full Save dialog if a drawing has never been saved before; it just gives me the inline version instead (as if FILEDIA were set to 0).  Our workaround is to use CTRL+S for the first save, but accounting for it in the script would be nice if it doesn't slow it down.

Is there an easy solution to bring the full dialog up if a drawing has never been saved before but then run seamlessly in the background after that?

Thanks!  I appreciate everyone's help and input on this.  I know it's pretty basic stuff, but I just don't get into much programming.


Work:  AutoCAD 2022.1.3, Windows 10 Pro v22H2 64-bit, Intel Core i7-8700K, 32GB RAM, Samsung 960 Pro SSD, AMD Radeon Pro WX 5100, 3 Dell Monitors (3840x2160)
Home: AutoCAD 2022.1.3, Windows 10 Pro v22H2 64-bit, Intel Core i7-11700, 64GB RAM, Samsung 980 Pro SSD, NVIDIA Quadro P2200, Dell Monitor (3840x2160)
0 Likes
Message 14 of 15

Kent1Cooper
Consultant
Consultant
Accepted solution

@nrz13 wrote:

One other thing I've noticed with this is it fails to bring up the full Save dialog if a drawing has never been saved before; it just gives me the inline version instead (as if FILEDIA were set to 0). ....

Is there an easy solution to bring the full dialog up if a drawing has never been saved before but then run seamlessly in the background after that?
....


The default operation for commands that use dialog boxes, when in (command) functions, is to use the Command:-line interface instead.  If you want the dialog box for such a command, you must force it -- precede the (command) function with:

 

(initdia)

 

which stands for INITiate the DIAlog box for the immediately-following dialog-box-capable command.  I don't have AutoCAD up right now to check, but I will hope that it will merely have no effect when the drawing is already named, and when therefore QSAVE, which doesn't use a dialog box, is not converted to a command that does use one.

Kent Cooper, AIA
Message 15 of 15

nrz13
Advisor
Advisor

That worked perfectly – thank you, Kent!  I appreciate the explanation as well.  It's hard to find the time to study up on all of this at once, but learning things here and there piecemeal is helpful for me.


Work:  AutoCAD 2022.1.3, Windows 10 Pro v22H2 64-bit, Intel Core i7-8700K, 32GB RAM, Samsung 960 Pro SSD, AMD Radeon Pro WX 5100, 3 Dell Monitors (3840x2160)
Home: AutoCAD 2022.1.3, Windows 10 Pro v22H2 64-bit, Intel Core i7-11700, 64GB RAM, Samsung 980 Pro SSD, NVIDIA Quadro P2200, Dell Monitor (3840x2160)
0 Likes