Jump to content

Recommended Posts

Posted

I have multiple lisp files I am trying to put into one lisp file. My goal is they will all be executed by one command. I have tried searching this site and the help menu, but I can't figure out how to accomplish this. I have tried to load Lisp#1, Lisp#2, and Lisp#3 into the drawing file and then load Lisp#4 which uses the commands of Lisp #1, #2, and #3, but that didn't work. I tried placing all the functions inside one lisp file and that didn't work. Could someone help me or tell me where to find the information in the help menu to do this?

Posted
I have tried to load Lisp#1, Lisp#2, and Lisp#3 into the drawing file and then load Lisp#4 which uses the commands of Lisp #1, #2, and #3, but that didn't work.
I tried placing all the functions inside one lisp file and that didn't work.

 

Either of those options should work, since both ensure that 'Lisp#1', 'Lisp#2', and 'Lisp#3' are defined in the active document namespace.

 

How are you currently calling 'Lisp#1', 'Lisp#2', and 'Lisp#3' from 'Lisp#4'?

Posted
How are you calling 'Lisp#1', 'Lisp#2', and 'Lisp#3'?

 

When the 3 individual lisps are loaded by themselves into the drawing file, Lisp #4 is calling them through their defined function names.

 

(defun c:Lisp#1 ()
 (princ)
 )

;;;;;;;;;;;;;;;;;;;

(defun c:Lisp#2 ()
 (princ)
 )

;;;;;;;;;;;;;;;;;;;

(defun c:Lisp#3 ()
 (princ)
 )

 

(defun c:Lisp#4 ()
 (command "Lisp#1")
 (command "Lisp#2")
 (command "Lisp#3")
 (princ)
 )

Posted (edited)

No "command" required there was a post by Lee maybe yesterday about C: LM: BIGAL: etc how to use

(c:lisp#1)
(C:lisp#2)
(C:lisp#3)

 

you should be able to put lisp#4 in 1 lisp also but must be after the first 3 are loaded sometimes you have to look at the way the lisp are loaded.

 

eg
all my defuns here
defun 1
defun2
now actual program starts here 
do it other way and it will error straight away as defuns not loaded.

Edited by BIGAL
forgot C:
Posted

If I load the first three lisps as a part of my CUI, they are already loaded when any drawing opens. Therefore, I should be able to reference them just like any other command right? That is what I was trying to accomplish anyway. I will try what you said though.

Posted

1- Why do you want to combine multiple lisps in one lisp. instead of loading each one separably in cui?

 

2- In case of run the 3 of them at one time (in sequance)when you run Lisp#4, Its better to convert the 3 of them to be used as subroutines

for example

 

(defun Lisp#1 ()
 (princ)
)
(defun Lisp#2 ()
 (princ)
)
(defun Lisp#3 ()
 (princ)
)

in stead of

(defun c:Lisp#1	()
 (princ)
)
(defun c:Lisp#2	()
 (princ)
)
(defun c:Lisp#3	()
 (princ)
)

 

 

And lisp#4

(defun c:Lisp#4	()
 (Lisp#1)
 (Lisp#2)
 (Lisp#3)
 (princ)
)

 

 

3- combine the codes itself

(defun Lisp#1 (a b c d e f g h i)
(progn #1)
(progn #2)
(progn #3)
(princ)
)

in stead of

(defun c:Lisp#1	(a b c)
 (progn #1)
 (princ)
)
(defun c:Lisp#2	(d e f)
 (progn #2)
 (princ)
)
(defun c:Lisp#3	(g h i)
 (progn #3)
 (princ)
)

DO NOT forget to localize variables for each lisp separately.

Posted

There are a few reasons why I did it this way:

1. I want to be able to keep my collection of lisp routines easily accessible by organizing them into individual files.

2. I want to be able to use the commands individually if needed.

3. Last but not least...I honestly don't know any better :oops:

Posted
There are a few reasons why I did it this way:

1. I want to be able to keep my collection of lisp routines easily accessible by organizing them into individual files.

2. I want to be able to use the commands individually if needed.

 

Click on the link i posted and read... read... read... :book: and read some more.

 

.... 3. Last but not least...I honestly don't know any better :oops:

 

Don't say that. we all need to start somewhere ;)

Posted

As asos2000 suggests it's better to convert your lisps into subroutines with wrapper commands. Though I'd not bother doing so for commands which do not take user input, since you can call a C:... function just like any other lisp defun (only a C:.... function is not supposed to take arguments if it's going to be used as a command).

 

Unfortunately lisp cannot call another lisp through the command function. You can do all sorts of strange stuff trying to send keystokes to acad, but none work perfectly and they're usually a lot more complex than splitting your original c:CmdName defuns into a callable function and a command wrapper.

 

E.g. (stupid example) Say you have a command which gets some text from the user and writes that to the command-line twice:

(defun c:TextTwice (/ txt)
 (if (setq txt (getstring t "Type the text: "))
   (repeat 2 (print txt)))
 (princ))

Now say you want to call that from another lisp function, but you want to pass the text to that function. Currently it's impossible, since the following:

(command "TextTwice" "Text to display twice") ;Error: Unknown command "TextTwice"
(c:TextTwice "Text to display twice") ;Error: too many arguments

Therefore you split the command into 2 portions:

(defun TextTwice (txt / )
 (if txt (repeat 2 (print txt))))

(defun c:TextTwice (/ )
 (TextTwice (getstring t "Type the text: "))
 (princ))

Now your command works perfectly fine, but also you can call the actual working defun while passing it the argument string:

(TextTwice "Text to display twice")

Posted

Re lots of lisps I would look at having a Library lisp this would hold all the common stuff your defuns that you may use in your routines some examples use autoload rather than Cui.

 

Layer missing so make it

save all existing setvars & osmode

put setvars & osmode back to what they were

maybe entmake line arc circle

 

more complex in my case a totally variable enduser layer system to draw on correct layer used in every loaded routine two lines of code in lisp Lots more in library.

Posted
There are a few reasons why I did it this way:

1. I want to be able to keep my collection of lisp routines easily accessible by organizing them into individual files.

2. I want to be able to use the commands individually if needed.

3. Last but not least...I honestly don't know any better :oops:

 

As you said you want to attach the lisps to cui. There are 2 ways

- Attach to cui directly (as see in attached pic). this way used to the lisps u use too much and there is no button for this lisp

- Load the lisp when click the button for this command for example this is line in macro of the button

^C^C(load "C:/Menu/Lisps/Lisp1");lisp1

 

be sure to replace \ with / in file path or \ with \\

001.PNG

Posted

3rd way is by making a MNL file with the same name as the CUI.

 

4th would be adding load or autoload calls inside such MNL file.

 

And if you're always going to have the LSP's in the same folder as the CUI - you don't even need to change the support paths. You could use a similar idea as per mine in the Caddons:Path function here: http://sourceforge.net/p/caddons/code/67/tree/Caddons.MNL

Posted

It looks like the others have you sorted Kyle :thumbsup:

 

Now say you want to call that from another lisp function, but you want to pass the text to that function. Currently it's impossible, since the following:
(command "TextTwice" "Text to display twice") ;Error: Unknown command "TextTwice"
(c:TextTwice "Text to display twice") ;Error: too many arguments

 

For completeness, this is actually possible, using the vlax-add-cmd function to add the function symbol to the AcEdCommandStack - though, I certainly wouldn't recommend using this method over evaluating the function through AutoLISP, unless absolutely necessary.

 

Here is an example:

 

([color=BLUE]defun[/color] test ( [color=BLUE]/[/color] str )
   ([color=BLUE]if[/color] ([color=BLUE]/=[/color] [color=MAROON]""[/color] ([color=BLUE]setq[/color] str ([color=BLUE]getstring[/color] [color=BLUE]t[/color] [color=MAROON]"\nType something: "[/color])))
       ([color=BLUE]princ[/color] ([color=BLUE]vl-list->string[/color] ([color=BLUE]reverse[/color] ([color=BLUE]vl-string->list[/color] str))))
   )
   ([color=BLUE]princ[/color])
)

([color=BLUE]defun[/color] c:cmdtest ( )
   ([color=BLUE]vlax-add-cmd[/color] [color=MAROON]"test"[/color] 'test [color=MAROON]"test"[/color] [color=BLUE]acrx_cmd_modal[/color])
   ([color=BLUE]command[/color] [color=MAROON]"test"[/color] [color=MAROON]"Lee Mac"[/color])
   ([color=BLUE]princ[/color])
)

Command: CMDTEST
test
Type something: Lee Mac caM eeL

Posted

 

I read Lee's tutorial (BTW-great job again Lee!).

 

I am familiar with the startup suite to load lisp files. But just like he said in the tutorial, I was having difficulty passing these routines on to the rest of our department when configuring their computers with the standard setup. That is why I looked into loading them through the CUI. This way, when I migrate settings, theoretically they will migrate seamlessly to the next user without the need to reload them through APPLOAD.

 

As for using the ACADDOC.lsp....I have always been leery of messing with this until I have a better understanding of what I am doing.

 

I do fear that loading all the programs into every drawing will be time consuming on start up. With that said and by what I have read in all the posts, would everyone agree that loading them only when needed through a toolbar button macro is the way to go?

Posted (edited)

With the speed of pc's & networks now now unless your loading something massive you wont even detect thats it loading a lisp, the nice thing is just give the guys a cui and its hard coded for a server location so any updates bug fixes are reflected straight away.

 

You can do a "If not then load" but while some may say dont reload every time I have never found a problem with continuously load the same lisp.

 

Now wheres that if not code

 

[My Drawing Setup]^C^C^P(cond ((null C:DWGSETUP) (load "DWGSETUP"))) DWGSETUP

Edited by BIGAL
if not now cond
Posted

The issue I have with loading direct in a button's macro is that it only loads when the macro is run. I sometimes what to call my custom commands from a script - and not be bothered to remember to load the relevant LSP file.

 

Thus I use autoload, or rather I've rolled an AutoLoad of my own. And of course you can see the one working with my CUI's path in the link in my previous post.

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