TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started 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...
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:
-
[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]
-
MyElectric.mns so create a MeElectric.mnl file.
Both should be MyElectric.*, Right Jeff. :) :wink:
-
.. 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 :-
;;; 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
)
-
Nice stuff, Kerry :D
-
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:
-
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.
-
RTFM will work.
I can verify that. :)
-
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:
-
"read the fine manual" the word "fine" can be substituted with another word of four letters.
-
RTFM is a specialist technical consulting organisation for the solving of difficult problems.
-
RTFM is a specialist technical consulting organisation for the solving of difficult problems.
lmao 2 points for Kerry. :D
-
:D They will also do peoples homework, If asked properly.
-
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.
-
.. No attitude here, just statin' facts.
Even if it was attitude, I wouldn't apologise. ... attitude is what keeps me at this game.
:)
-
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 =
-
= 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....
-
I don't take offense to anything said
.. you're no fun at all !!
-
... 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."
-
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...
-
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:
-
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.
-
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.
;;; 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)
)
-
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;
(defun c:program () (if (not c:program)(load "program")))
that way it's not loaded until I need it.