TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Dommy2Hotty on June 02, 2004, 06:49:36 PM

Title: Compiling multiple lisps into one larger lisp...
Post by: Dommy2Hotty on June 02, 2004, 06:49:36 PM
(http://theswamp.org/lilly.pond/Dommy2Hotty/Electrical%20Toolbar.JPG)

That is my Electrical toolbar.  I am writing a lisp for each button, but I don't want 19 seperate lisp files.  Each button inserts a block.  The lisp will put the block on it's correct layer.  I am aware I can just add the change command after the insertion macro, but I want to add a TBLSEARCH "LAYER" to each one to make sure the layer exists, and if not, then it would create it.

How would I go about arranging them within 1 lisp file, and how would the buttons call the correct lisp?  I'm guessing I make one lisp named "Electrical.lsp" with each button having it's own defun.  Something along the lines of...

Code: [Select]
Electrical.lsp
**********************
(defun c:button1 ()
          ----------
          ----------
)

(defun c:button2 ()
          ----------
          ----------
)

(defun c:button3 ()
          ----------
          ----------
)


And then each button macro would just be "^C^C_button1" "^C^C_button2"  etc....

Is all this correct??? :twisted:
Title: Re: Compiling multiple lisps into one larger lisp...
Post by: Jeff_M on June 02, 2004, 07:38:23 PM
[quote="Dommy2HottyAnd then each button macro would just be "^C^C_button1" "^C^C_button2"  etc....

Is all this correct??? :twisted:[/quote]

Yes, however I would suggest a slightly different strategy. I'm going out on a limb here and assume that you have your toolbar in it's own mnu/mns file, instead of the base acad menu. If not, I strongly suggest you do. This will make upgrades, re-installs, further customization, etc, much easier to manage.
Now, based on that, create a .mnl file that mimics the name of your menu file. Such as: your toolbars are in MyElectric.mns so create a MyElectric.mnl file. Now place all of the button defuns into this mnl file and they will always load with the menu.

edited to show the use of files having the same name, not similar names....thanks to Slim for catching that.

Just my $0.02....
Jeff    :idea:[/i]
Title: Re: Compiling multiple lisps into one larger lisp...
Post by: Slim© on June 02, 2004, 07:43:03 PM
Quote from: Jeff Mishler
MyElectric.mns so create a MeElectric.mnl file.


Both should be MyElectric.*, Right Jeff. :)  :wink:
Title: Compiling multiple lisps into one larger lisp...
Post by: Kerry on June 02, 2004, 07:55:11 PM
.. and further to that ..
Change the command names to  c:elec_button01  .. etc .. or similar to ensure the names are unique, and wont overwrite the button01 command from the next menu toolbar that you write.

Re the layer setting command : I assume that would be a stand alone library routine called from each buttonxx command. .. rather than just repeat a block of code in each routine.
Sort of like this :-
Code: [Select]

;;; Elect_tb1.mnl file
(vl-load-com)

(defun myChangeLayerCommand (LayerName / )
;;
;;
;Do Layer change stuff here ..
; < snip >
)

(defun c:Elect_tb1_01 ( / prevLayer)
;save prevLayer
(myChangeLayerCommand "ElecBlocks")

; < snip >
; < do your stuff here >

;restore prevLayer
)
Title: Compiling multiple lisps into one larger lisp...
Post by: Slim© on June 02, 2004, 07:56:18 PM
Nice stuff, Kerry :D
Title: Compiling multiple lisps into one larger lisp...
Post by: Dommy2Hotty on June 03, 2004, 11:40:58 AM
AHHH.....yes....mnl files...buh-duh....

ok...now what's up with the (vl-load-com) stuff...

a pointing to a website for the vla, vlax, ex-lax or whatever that is would be nice...have to learn it sooner or later... :twisted:
Title: Compiling multiple lisps into one larger lisp...
Post by: Kerry on June 03, 2004, 11:49:18 AM
Quote
ok...now what's up with the (vl-load-com) stuff...

a pointing to a website for the vla, vlax, ex-lax or whatever that is would be nice


RTFM will work.

.. and you're welcome.
Title: Compiling multiple lisps into one larger lisp...
Post by: MP on June 03, 2004, 11:54:25 AM
Quote from: Kerry Brown
RTFM will work.
I can verify that. :)
Title: Compiling multiple lisps into one larger lisp...
Post by: Dommy2Hotty on June 03, 2004, 12:41:02 PM
Quote from: Kerry Brown
Quote
ok...now what's up with the (vl-load-com) stuff...

a pointing to a website for the vla, vlax, ex-lax or whatever that is would be nice


RTFM will work.

.. and you're welcome.


Pardon my ignorance...but now what's RTFM :crazy:
Title: Compiling multiple lisps into one larger lisp...
Post by: Mark on June 03, 2004, 12:50:11 PM
"read the fine manual" the word "fine" can be substituted with another word of four letters.
Title: Compiling multiple lisps into one larger lisp...
Post by: Kerry on June 03, 2004, 12:53:12 PM
RTFM is a specialist technical consulting organisation for the solving of difficult problems.
Title: Compiling multiple lisps into one larger lisp...
Post by: Mark on June 03, 2004, 12:55:11 PM
Quote from: Kerry Brown
RTFM is a specialist technical consulting organisation for the solving of difficult problems.


lmao 2 points for Kerry. :D
Title: Compiling multiple lisps into one larger lisp...
Post by: Kerry on June 03, 2004, 12:57:43 PM
:D  They will also do peoples homework, If asked properly.
Title: Compiling multiple lisps into one larger lisp...
Post by: Anonymous on June 03, 2004, 01:02:52 PM
RTFM is a powerful tool that every competent developer continually uses, and surprisingly, the very thing that frequently prevents casual coders from evolving. No attitude here, just statin' facts.
Title: Compiling multiple lisps into one larger lisp...
Post by: Kerry on June 03, 2004, 01:08:50 PM
Quote
.. No attitude here, just statin' facts.


Even if it was attitude, I wouldn't apologise. ... attitude is what keeps me at this game.


:)
Title: Compiling multiple lisps into one larger lisp...
Post by: MP on June 03, 2004, 01:09:12 PM
Quote from: Anonymous
RTFM is a powerful tool that every competent developer continually uses, and surprisingly, the very thing that frequently prevents casual coders from evolving. No attitude here, just statin' facts.
Oops. Sorry, thought I was logged in; my bad.

= All your lisp are belong to us =
Title: Compiling multiple lisps into one larger lisp...
Post by: Dommy2Hotty on June 03, 2004, 01:15:09 PM
Quote from: MPuckett

= All your lisp are belong to us =


lol...that's funny stuff....

I don't take offense to anything said...it's understandable...just be warned that if it happens again, I'll have to punchasize your face :twisted:






just kidding....
Title: Compiling multiple lisps into one larger lisp...
Post by: Kerry on June 03, 2004, 01:18:13 PM
Quote
I don't take offense to anything said


.. you're no fun at all !!
Title: Compiling multiple lisps into one larger lisp...
Post by: MP on June 03, 2004, 01:24:50 PM
Quote from: Dommy2Hotty

... I'll have to punchasize your face ...
A wise person once said:

"You can do anything you wish ... you only have to pay the consequences."
Title: Compiling multiple lisps into one larger lisp...
Post by: Dommy2Hotty on June 03, 2004, 01:36:35 PM
Quote from: Kerry Brown
Quote
I don't take offense to anything said


.. you're no fun at all !!


well, I know I'm a n00b at this stuff...so I expect to be made fun of for stupid questions...
Title: Compiling multiple lisps into one larger lisp...
Post by: Dommy2Hotty on June 07, 2004, 04:39:50 PM
Okay...got it all compiled, works perfectly (to the best of my knowledge).  Just one more question:  Does having the LISP's in a .mnl file take up memory like loading a LISP file thru the acad2004.lsp's Autoload section?  Or does it only load each LISP when it's called by the button?  Just wondering :twisted:
Title: Compiling multiple lisps into one larger lisp...
Post by: Mark on June 07, 2004, 04:48:19 PM
It all depends on how you set it up in the .mnl file. But if it were me I wouldn't worry about it that much with todays computers and the amount of ram thay have.
Title: Compiling multiple lisps into one larger lisp...
Post by: Dommy2Hotty on June 07, 2004, 05:18:22 PM
Quote from: Mark Thomas
It all depends on how you set it up in the .mnl file.


Just like as follows, but with 19 total defun's for the 19 buttons on the toolbar.  Only difference between them is the defun name, block name, one different insert option on some, and one is on a different layer than the rest.

Code: [Select]

;;; Electrical.mnl file
;;; Dominic Cesare
;;; Last update: Fri June 4, 2004

;Duplex Outlet
(defun c:Duplex_Outlet (/ oldsnaps oldecho oldlayer block)
  ;error trapping
  (setq temperr *error*)
  (setq *error* trap1)
  ;storing current variables
  (setq oldlayer (getvar "clayer")
oldsnaps (getvar "osmode")
oldecho (getvar "cmdecho")
)
  ;turning snaps and echo off
  (setvar "osmode" 0)
  (setvar "cmdecho" 0)
  ;prompts user to select insertion point and rotation
  (prompt "\nSelect Insertion Point and Rotation.....")
  ;inserting block
  (command "-insert" "r1001" "nea" pause "" "" pause)
  ;setting the inserted block to "block"
  (setq block (entlast))
  ;creating PL-ELEC-FIXTURE layer if not present
  (if (not (tblsearch "layer" "PL-ELEC-FIXTURE"))
    (command ".layer" "m" "PL-ELEC-FIXTURE" "C" "3" "" "")
    )
  ;changing inserted block to the PL-ELEC-FIXTURE layer
  (command "change" block "" "p" "la" "PL-ELEC-FIXTURE" "")
  ;resetting system variables
  (setvar "clayer" oldlayer)
  (setvar "osmode" oldsnaps)
  (setvar "cmdecho" oldecho)
  ;error trapping
  (setq *error* temperr)
  ;ending silently
  (princ)
  )
;error trapping
(defun trap1 (errmsg)
  (command "u")
  (setvar "clayer" oldlayer)
  (setvar "osmode" oldsnaps)
  (setvar "cmdecho" oldecho)
  (setq *error* temperr)
  (prompt "Resetting System Variables.....")
  (princ)
  )
Title: Compiling multiple lisps into one larger lisp...
Post by: Mark on June 07, 2004, 06:18:54 PM
Sorry, my mistake. I did not understand what you were doing.  :oops:

IMO, the way you have it setup is fine, all the defun's in the .mnl file will be ready to use everytime you open a dwg. i.e. their are all loaded at once. My custom .mnl file is much the same way, except I have more than 19 in mine!! The programs I use on ocassion say once a day I load as needed, like so;
Code: [Select]

(defun c:program () (if (not c:program)(load "program")))

that way it's not loaded until I need it.