AutoRun custom command

AutoRun custom command

KuriosCowboy
Enthusiast Enthusiast
1,554 Views
6 Replies
Message 1 of 7

AutoRun custom command

KuriosCowboy
Enthusiast
Enthusiast

Im having some trouble trying to find a way to load a custom command. Im not very code-savy, and usually have to have things spelled out for me bluntly 😛

 

In our office, we have a lisp that updates a date/timestamp on our drawings. The command/lisp is DATEPLOT. I have the lisp loaded thru ACADDOC.LSP, but cannot seem to find a way to get the command to run when a drawing is opened. I have seen (thru google searches) that the code "(command "DATEPLOT")" should work, but I get an error on dwg load that the command doesnt exist, although running the command once the drawing loads completely works fine. I have also tried a basic defun code I found someone suggest to no avail as well. I have attached a snip of my ACADDOC.LSP with the defun code for reference.

0 Likes
1,555 Views
6 Replies
Replies (6)
Message 2 of 7

cadffm
Consultant
Consultant
And how do you start the command in Autocad?

If you can start the command with command:DATEPLOT

Then there is a line like
(defun c:DATEPLOT
In your DATEPLOT.lsp

In acaddoc you can run (c:DATEPLOT)

Sebastian

0 Likes
Message 3 of 7

Moshe-A
Mentor
Mentor

Hi Mr,

 

change the definition line to this:

 

(defun s::startup ()  (C:DATEPLOT))

 

a lisp command can not be called from autolisp (command) functon.

 

(s::startup) is very old, although it works i do not recommend using it.

this function can be found in any lisp (e.g acad.lsp acaddoc.lsp) and may override each other.

 

instead consider using RTEXT or FIELD or plot stamp (all of these are standard autocad tools)

 

Moshe

 

 

 

0 Likes
Message 4 of 7

john.uhden
Mentor
Mentor

I wouldn't get too paranoid by what @Moshe-A told you.

S::STARTUP is very handy to "autorun" things when a drawing opens.

It was developed when defun created a list, so that anyone could append to the function.

But somewhere (maybe R15) defun created a SUBR, to which you cannot append.

Here's the workaround.

NOTE:  The (@startup) is my own function.  Substitute whatever function you want to run.

(cond
   ((not S::STARTUP)
      (defun-q S::STARTUP ()(@startup))
   )
   ((listp S::STARTUP)
      (setq S::STARTUP (append S::STARTUP '((@startup))))
   )
   ((member (type S::STARTUP) '(SUBR USUBR))
      (eval
         (list 'defun-q 's::startup ()
            (list s::startup)        ;; NO QUOTE
           '(@startup)
         )
      )
   )
)

John F. Uhden

Message 5 of 7

roland.r71
Collaborator
Collaborator

@KuriosCowboy wrote:

Im having some trouble trying to find a way to load a custom command. Im not very code-savy, and usually have to have things spelled out for me bluntly 😛

 

In our office, we have a lisp that updates a date/timestamp on our drawings. The command/lisp is DATEPLOT. I have the lisp loaded thru ACADDOC.LSP, but cannot seem to find a way to get the command to run when a drawing is opened. I have seen (thru google searches) that the code "(command "DATEPLOT")" should work, but I get an error on dwg load that the command doesnt exist, although running the command once the drawing loads completely works fine. I have also tried a basic defun code I found someone suggest to no avail as well. I have attached a snip of my ACADDOC.LSP with the defun code for reference.


Change the line to: (defun s::startup ()  (C:DATEPLOT)), as @Moshe-A suggests,

or

Change it into: (C:DATEPLOT) as @cadffm suggests.

 

I would personally go for the later, as its all you need. (the s::startup feels like overdone to me)

You could even add that to the end of your dateplot.lsp file, to make it auto-run whenever it is loaded.

 

The first adds the function to the "startup", so it will be started on startup.

The second just starts up the function, like when you type it at the commandline. In this case this too will make sure it will be started on startup. Adding it to the lisp file, ensures it gets started on load. As it loads from acaddoc, it loads (& starts) on startup.

0 Likes
Message 6 of 7

john.uhden
Mentor
Mentor
I think Kent also pointed out that s::startup is overrated.
All I have to go by is my 2002 help...
 
"The startup LISP files (acad.lsp, acaddoc.lsp, and .mnl) all load into memory before the drawing is completely initialized. Typically, this does not pose a problem, unless you want to use the command function, which is not guaranteed to work until after a drawing is initialized. "
 
"not guaranteed" are strong enough words for me, but maybe things have changed since then.
Anyway, the s::startup function is not run until after the drawing is initialized, which may make a huge difference depending on what it tries to do.

John F. Uhden

0 Likes
Message 7 of 7

Kent1Cooper
Consultant
Consultant

@KuriosCowboy wrote:

.... I have the lisp loaded thru ACADDOC.LSP, but cannot seem to find a way to get the command to run when a drawing is opened. ... "(command "DATEPLOT")" should work, but I get an error ..., although running the command once the drawing loads completely works fine. ....


To clarify part of that, and to re-iterate some of what others have said:

The (command) function works only with native AutoCAD command names, not with custom-(defun)'d ones.  The way to run one of those from AutoLisp is in the format others have suggested, in parentheses and including the C: prefix -- (C:DATEPLOT).  Since you're loading the file with ACADDOC.lsp anyway, I wouldn't bother with S::STARTUP, but would simply add that run-it expression as another line in ACADDOC.lsp, anywhere after the loading of that file.  But you can also add it as a line inside the file itself, at the end, to run it every time it is loaded, which will have the same effect if it's being loaded by ACADDOC.lsp in every drawing you open or create.

 

But I also agree that if you're going to do this in every drawing every time, it's worth looking into the PlotStamp utility, which would mean you don't need to have or load or run any custom code.  It has a lot of options about content and format and positioning, so you may well be able to have it integrated into your drawing borders, title blocks, etc.

Kent Cooper, AIA
0 Likes