Code Red > AutoLISP (Vanilla / Visual)
Constructive Critism?
ronjonp:
Any criticism on how this is written?
--- Code: ---;Inserts barscale and prompts for scale.
(defun C:barscale (/ cmd att clay bsscale inpt)
(setq cmd (getvar "cmdecho"))
(setvar "cmdecho" 0)
(setq att (getvar "attdia"))
(setvar "attdia" 0)
(setq clay (getvar "clayer"))
(command ".-layer" "m" "M-SHEET" "" "")
(setq bsscale (getreal "\nEnter Scale: "))
(setq inpt (getpoint "\nPick barscale location"))
(command ".-INSERT"
"R:\\AEITITLE\\Barscale.dwg"
inpt
"1"
"1"
"0"
(strcat (rtos bsscale 2 0) "'")
(strcat (rtos (* bsscale 0) 2 0) "'")
(strcat (rtos (/ bsscale 2) 2 0) "'")
(strcat (rtos bsscale 2 0) "'")
(strcat (rtos (* bsscale 2) 2 0) "'")
)
(setvar "cmdecho" cmd)
(setvar "attdia" att)
(setvar "clayer" clay)
(princ)
)
--- End code ---
Thanks,
Ron :D
7 Edit: I added code tags to your post.
JohnK:
w00t! I like it. Its orginized, very nice. You get only varibles you have to change and you localized all the variables you created. Very nice.
Now if i were you i would add some checks and tests to see if the enviroment is safe before you actualy change or do anything it would be a great little program. Ill whip up a simple example that you can get an idea as to what im talking about.
JohnK:
Take a look at these lines of code:
--- Code: ---;; loop untill the test expression evals to nil
(while
;; Not will return TRUE if the test evaluates to nil; (start of test expression)
(not
;; Our getpoint function will return nil if there isnt a point
;; selected; (the root test expression)
(setq pt (getpoint))
);_ end not
);_ end while
--- End code ---
Now copy this code into your command line (or the VLIDE) and run it. Try to right click instead of actualy picking a point. what happens?
Do you see what I am doing? I am running a couple of tests to see if the end user actualy selected a point. If they didnt, then do it again, and keep asking for a point untill they get it right.
We can even make a neat little function out of this concept. Lets do that.
--- Code: ---(defun RealyGetPoint (/ pt)
(while
(not (setq pt (getpoint "\nPlease select a point: ")))
(princ "\nPlease try again..."))
pt
)
--- End code ---
This is a simple concept that you should be able to grasp and apply it to the rest of your code. -i.e. test to see if the "environment" is safe before you start to change, get, modify, or do anything. A few "if" statments, and some extra thought, should get you a very nice program with prompts to the end user if there happens to be a problem.
Think of areas in this program that could crash. (What has to be present in order for this program to run?)
ronjonp:
Thanks Se7en :D .
When I run it it works fine but it prompts this on the command line before it starts.
Command: barscale
Unknown command "BARSCALE". Press F1 for help.
Enter Scale:
Any suggestions on how to suppress this?
SMadsen:
ronjonp, remove the last return in the LAYER command:
(command ".-layer" "m" "M-SHEET" "" "")
->
(command ".-layer" "m" "M-SHEET" "")
Navigation
[0] Message Index
[#] Next page
Go to full version