;New Command: Newline
;Purpose is to set linetypes and layer upon selection of a new line
;to be drawn.
;Code in English
;Prompt User: "Select Linetype: Three Phase, Double Phase, Single Phase, Secondary, 600/347V, 120/208V
;Variable Answer = User Input
;if Answer = T (Three Phase) then
;Linetype = Three Phase
;Layer = 612
;Lwpolyline
;if Answer = D (Double Phase) then
;Linetype = Double Phase
;Layer = 612
;Lwpolyline
;if Answer = Si (Single Phase) then
;Linetype = Single Phase
;Layer = 612
;Lwpolyline
;if Answer = E (600/347V) then
;Linetype = Hidden
;Linetype Scale = 0.5
;Layer = 622
;Lwpolyline
;if Answer = F (120/208V) then
;Linetype = Custome Linetype
;Linetype Scale = 0.5
;Layer = 622
;Lwpolyline
;************************************************************
;************************************************************
;Coding
(defun c:nl (/ answer oldblip oldlayer oldplinewidth oldortho)
(initget 1 "Three Double Single seCondary E600 F208")
; Prevents the user from responding to the request by entering only ENTER
(setq answer (getkword "\nSelect Phase: Three/Double/Single/seCondary/E600/F208 <> "))
oldblip (getvar "blipmode"); set old variable to variable for call back
oldlayer (getvar "clayer"); set old variable to variable for call back
oldplinewidth (getvar "plinewid"); set old variable to variable for call back
oldortho (getvar "osmode"); set old variable to variable oldortho for call back
(cond ((= answer "seCondary") ; Secondary
(setvar "plinewid" 0.5); set polyline width to 0.5
(setvar "clayer" "622"); set layer to 622
(setvar "osmode" 0); set orthomode to off
(setvar "blipmode" 0); set blips to off
(princ answer)
)
((= answer "Three") ; Three Phase
(setvar "plinewid" 0); set polyline width to 0
(setvar "clayer" "612"); set layer to 612
(setvar "osmode" 0); set orthomode to off
(setvar "blipmode" 0); set blips to off
(princ answer)
)
((= answer "Double") ; Double Phase
(setvar "plinewid" 0); set polyline width to 0
(setvar "clayer" "612"); set layer to 612
(setvar "osmode" 0); set orthomode to off
(setvar "blipmode" 0); set blips to off
(princ answer)
)
((= answer "Single") ; Single Phase
(setvar "plinewid" 0); set polyline width to 0
(setvar "clayer" "612"); set layer to 612
(setvar "osmode" 0); set orthomode to off
(setvar "blipmode" 0); set blips to off
(princ answer)
)
((= answer "E600") ; 600/347V
(setvar "plinewid" 0); set polyline width to 0
(setvar "clayer" "622"); set layer to 622
(setvar "osmode" 0); set orthomode to off
(setvar "blipmode" 0); set blips to off
(princ answer)
)
((= answer "F208") ; 120/208V
(setvar "plinewid" 0); set polyline width to 0
(setvar "clayer" "622"); set layer to 622
(setvar "osmode" 0); set orthomode to off
(setvar "blipmode" 0); set blips to off
(princ answer)
)
)
(princ)
If you could e-mail me back at ...No way, you asked for it in public, now you're getting the comments in public, too :D
((or (= answer "Double")
(= answer "Single")
(= answer "Three")
)
(setvar 'clayer 612)
);end condition
P.S- is there any way to add attachments to this forum?
everything you are tellin me i should do and not do is complete chinese to me... I'm not understanding what you are tellin me.. Remember this is the first time i've ever written any kind of programming code... I know by your experience that you're lookin at this thing and sayin what a joke this is.. I'm lookin for some guidance and to take some small steps.. I don't want to be runnin a mile when i'm not ready for it.No need to run a mile. Take what you can now, ask questions about it and come back for more (often). I'm sure there will be plenty of comments your next time around.
- Are you sure that you want to force the user to hit escape in order to exit from the routine without doing changes? INITGET 1 is for very rare cases where input is essential for further processing. It's not for irritating the user.
I don't understand what you're tellin me with this comment
- Setting OSMODE and BLIPMODE to 0 within all conditions are unnecessary repetitions.
I understand that i've repeated this part over and over but don't understand code syntax so i don't have to re-itterate the same code over and over
Again... i know there's error traping that i will have to develop but again don't know how to develop that at this moment..
To finish this off... I don't want anyone to take it in the wrong manner.. Like i said i'm a NEWBIE to the world of programming...
I'm lookin for all the help i can get to help me learn this, As there's no places around where i live that offer courses in LISP..
... I know by your experience that you're lookin at this thing and sayin what a joke this is.. I'm lookin for some guidance and to take some small steps..
prompt use for type of line
get current variables
if line type 1 thenset these variables
check for layer and linetype
do this code
[/list:u]
or if line type 2 thenset those variables
check for layer and linetype
do this code
[/list:u]
or if line type 3 thenset those other variables
check for layer and linetype
do this code
[/list:u]
restore variables
and exit
;Code in English
;Prompt User: "Select Linetype: Three Phase, Double Phase, Single Phase, Secondary, 600/347V, 120/208V
;Variable Answer = User Input
;if Answer = T (Three Phase) then
;Linetype = Three Phase
;Layer = 612
;Lwpolyline
;if Answer = D (Double Phase) then
;Linetype = Double Phase
;Layer = 612
;Lwpolyline
;if Answer = Si (Single Phase) then
;Linetype = Single Phase
;Layer = 612
;Lwpolyline
;if Answer = E (600/347V) then
;Linetype = Hidden
;Linetype Scale = 0.5
;Layer = 622
;Lwpolyline
;if Answer = F (120/208V) then
;Linetype = Custome Linetype
;Linetype Scale = 0.5
;Layer = 622
;Lwpolyline
(defun nl (/ answer oldblip oldortho)
(initget 0 "Three Double Single seCondary E600 F208")
(setq answer (getkword "\nSelect Phase:Three/Double/Single/seCondary/E600/F208 <> "))
oldblip (getvar "blipmode)
oldortho (getvar "osmode)
(setvar "osmode" 0)
(setvar "blipmode" 0)
(cond ((= answer "seCondary") ; Secondary
(setvar "plinewid" 0.5); set polyline width to 0.5
(setvar "clayer" "622"); set layer to 622
(princ answer)
)
(defun nl (/ answer oldblip oldortho)
(initget 0 "Three Double Single seCondary E600 F208")
(setq answer (getkword "\nSelect Phase:Three/Double/Single/seCondary/E600/F208 <> "))
(setq oldblip (getvar "blipmode") ;;<- You forgot the "setq" and the closing dbl quotes.
oldortho (getvar "osmode")) ;;<- You forgot the closing dbl quotes and to
;; close the "setq" statment.
(setvar "osmode" 0)
(setvar "blipmode" 0)
;;; Pseudo code for the circle leader program ;
;;;-------------------------------------------------------------------;
;;; - Select an entity. ;
;;; - Test if block. ;
;;; - If it is, dive in. ;
;;; - Get second point. ;
;;; - Calculate polar point of circle/arc ;
;;; - Get third point (the tail) ;
;;; ~ I would calc this, but I dont want to assume the ;
;;; direction of the tail/text. ;
;;; - Prompt the user for text strings. ;
;;; ~ I could use a simple dialog box for this. ;
;;; ~ I could just start the dtext command after prgn complete. ;;
(defun c:nl (/ answer oldblip oldlayer oldplinewidth oldortho)
;;sm: Removing the "1" in INITGET allows GETKWORD to return nil, which
;;sm: means that the user simply hit enter or space (an empty input)
(initget "Three Double Single seCondary E600 F208")
;;sm: ^Therefore, we have to test if GETKWORD was given an input
;;sm: This can be done by wrapping it all into one CONDition:
(cond ((setq
answer (getkword "\nSelect Phase: Three/Double/Single/seCondary/E600/F208 <> ")
)
;;sm: OK, user gave an input that we can use.
;;sm: Now proceed. Set the environment and check the input.
;;sm: If the user hit enter, the code will not have gone
;;sm: this far and it will not be able to set his/her
;;sm: system variables (it is still inpolite to change
;;sm: them but that's another story :)
(setvar "osmode" 0)
(setvar "blipmode" 0)
(cond ((= answer "seCondary") ; Secondary
(setvar "plinewid" 0.5) ; set polyline width to 0.5
(setvar "clayer" "622") ; set layer to 622
(princ answer)
)
;;sm: Using Daron's suggestion of collecting all identical settings:
;;sm: (if you have plans of adding other statements to the conditions
;;sm: then please keep your existing structure!)
((or (= answer "Three") ; Three Phase
(= answer "Double") ; Double Phase
(= answer "Single") ; Single Phase
)
(setvar "plinewid" 0) ; set polyline width to 0
(setvar "clayer" "612") ; set layer to 612
(princ answer)
)
;;sm: Again, using Daron's suggestion:
((or (= answer "E600") ; 600/347V
(= answer "F208") ; 120/208V
)
(setvar "plinewid" 0) ; set polyline width to 0
(setvar "clayer" "622") ; set layer to 622
(princ answer)
)
)
)
)
(princ)
)
...will check all the variables that are within that function, once it finds a match you then tell the routine where to go from there...
(or
(tblsearch "layer" "0")
(tblsearch "layer" "1")
(tblsearch "layer" "2")
)
... i.e. if only layer 0 is present and layer 1 & layer 2 are NOT present it will still return TRUEActually, you wouldn't know if layer 1 and/or layer 2 are present if layer 0 is present (so it might not be a perfect test in every case) :wink:
... Actually, you wouldn't know if layer 1 and/or layer 2 are present if layer 0 is present (so it might not be a perfect test in every case) :wink::lol: I was thinking the same thing.
...
(not a b c) = too few arguements ( What does this mean? ) ...
;;;===================================================================;
;;; Layer-p ;
;;;-------------------------------------------------------------------;
;;; Determines if a layer exists in drawing. ;
;;; ;
;;; Arguments: Layer - The name of a layer.(In string format.) ;
;;; ;
;;; Returns: "T" if the layer was found, "nil" if not. ;
;;; ;
;;; Date: 10.5.03 ;
;;;===================================================================;
(defun layer-p (layer)
(and (tblsearch "LAYER" layer)))
I don't want to side track anybody or anything but wouldn't this topic be better served in the Teach Me forum ?
As you can see I set the "c" varialble to hold the value of "nil". (In other words; its "empty")
; error: too few arguments
(defun Block-Exists (x)
(and (tblsearch "Block" x))
)
(defun TxtStyle-Exists (x)
(and (tblsearch "style" x))
)
(defun DimStyle-Exists (x)
(and (tblsearch "Dimstyle" x))
)
(if
(Layer-p "612") ; <- Predicate
(setvar "clayer" "612") ; <- Consequent
(command "layer" "m" "612" "") ; <- Alternative
)
(cond
((Layer-p "612") ; <- Predicate
(setvar "clayer" "612")) ; <- Consequent
((not (Layer-p "612")) ; <- Predicate
(command "layer" "m" "612" "")) ; <- Consequent
)
(cond
((Layer-p "612")
;; If the layer "612" is present in the drawing
(setvar "clayer" "612"))
;; Then set the curent layer to "612"
((not (Layer-p "612"))
;; If the layer isnt found
(command "layer" "m" "612" ""))
;; Then create it and set it curent
);_ end conditional expression
So in this case
(defun layer-p (/ x)
(or (tblsearch "layer" "x")
(tblsearch "layer" "y")
(tblsearch "layer" "z")
)
)
x would be a passed value by user entering something when prompt to do so..
Ex. Asking the user what layer to create?
The user would enter y
y is then passed to x
tblsearch looks for a match to value of x = y
if y exists which would result in being True
then user would be prompt with " Layer already exists.
Daron, now I'm not entirely sure about this but... (Smadsen, do you know for sure?) When you create a variable name associated with the value of "nil" you are doing two things; One allocating space for a variable and two, destroying it. So as I see it, the variable 'c' is created and destroyed. By telling the interpreter that we are defining a new variable named 'c' we are telling it to allocate memory space for it, but then when we assign it to a value of 'nil' that tells the interpreter to destroy it. So the 'c' variable is nothing more then a flash in the pan.
(defun var-test ( / va vb vd vf)
(setq va "A"
vb "B"
vc "C"
vd "D"
ve "E"
vf "F")
)
Wouldn't c always = nil... not empty, not a flash in the pan, not destroyed
append Function
Takes any number of lists and appends them together as one list
(append [list ...])
Arguments
list
A list.
I see what happened... the variables after the / va vb vd vf were not assigned a value..
Variables vc ve were assigned a value..
I'm confused as to why that happened..
I was under the impression that when you used the
(setq) to give a value to a variable, the variable would then = that
value
:?
(defun local-test ( / va vb)
(setq va "A")
(setq vb "B")
(princ (strcat "\nThe value of va is " va))
(princ (strcat "\nThe value of vb is " vb))
(princ)
)
code:
--------------------------------------------------------------------------------
(defun local-test ( / va vb)
(setq va "A")
(setq vb "B")
(princ (strcat "\nThe value of va is " va))
(princ (strcat "\nThe value of vb is " vb))
(princ)
)
Now we're going to test the values of each of our variables again. Again, before you do, what result do you think you will get?
!va
!vb
Care to take a shot at why that happens the way it does?
--------------------------------------------------------------------------------
Command: (defun local-test ( / va vb)
(_> (setq va "A")
(_> (setq vb "B")
(_> (princ (strcat "\nThe value of va is " va))
(_> (princ (strcat "\nThe value of vb is " vb))
(_> (princ)
(_> )
LOCAL-TEST
Command: (setq va "Z" vb "X")
"X"
Command: !va
"Z"
Command: !vb
"X"
Command: (local-test)
The value of va is A
The value of vb is B
Command: !va
"Z"
Command: !vb
"X"
(defun local-test ( / )
(setq va "A")
(setq vb "B")
(princ (strcat "\nThe value of va is " va))
(princ (strcat "\nThe value of vb is " vb))
(princ)
)
Command: !va
"A"
Command: !vb
"B"
I get what your saying Daron. I see your point now. Your saying that when we assign 'c' to 'nil' we are creating an empty list.
That would make sense; Seeing as (setq c nil) is the same as saying (setq c '()) That's a cool lesson. Theres a lot to think about there. *huh*
I'm glad i found this forum... I've learned more in one day than i have in like weeks of reading the books that i have.
Sounds like a good idea. Wadd-ya got sofar?!
(I have almost all of the pseudo code "worked out" in my head already.)
(defun putlayer (layer)
(tblsearch "layer" "layer")
(cond ((putlayer "layer")
(setvar "clayer" "layer")
(not ((putlayer "layer"))
(command "layer" "m" "layer" ""))
)
)
(defun putlayer (x)
(tblsearch "layer" x))
;;;===================================================================;
;;; Layer-p ;
;;;-------------------------------------------------------------------;
;;; Determines if a layer exists in drawing. ;
;;; ;
;;; Arguments: Layer - The name of a layer.(In string format.) ;
;;; ;
;;; Returns: "T" if the layer was found, "nil" if not. ;
;;; ;
;;; Date: 10.5.03 ;
;;;===================================================================;
(defun layer-p (layer)
(and (tblsearch "LAYER" layer)))
(defun PutLayer (layer)
(cond
((Layer-p layer)
(setvar "clayer" layer))
((not (Layer-p layer))
(command "layer" "m" layer ""))
)
(princ)
)
Why isn't tblsearch being used this time?What does the "tblsearch" expression do?
(command "layer" "m" layer "")
Don't be sorry. I think you answered the question. Three alligators for you. So, what do you mean we're not using t(a)bl(e)search. It's embedded in the layer-p function.
There is one problem with it, though. It's missing a dot. Can you tell me where?Code: [Select](command "layer" "m" layer "")
Where's it needed?
(command ".layer" "m" layer "")
(defun layer-p (layer)
(and (tblsearch "LAYER" layer)))
(defun PutLayer (layer)
(cond
((Layer-p layer)
(setvar "clayer" layer))
((not (Layer-p layer))
(command "layer" "m" layer ""))
)
(princ)
)
O.k nothin is workin now..
I can run
(defun putlayer (layer)
(command "layer" "m" layer ""))
but as soon as i go to a conditional
i get the error message.
don't know what is goin on here.
Command: (command "layer" "m" layer "")
layer Unknown command "LAYER". Press F1 for help.
Command: m Unknown command "M". Press F1 for help.
I'm curretnly re-installing my autocad and see if this will help
Alright everyone, after the slate has been cleaned with a complete re-installment i'm back and runnin BEAUTIFULLY..
se7en,
I ran the routine you told me to run and no problems..
I couldn't do that earlier..
...
The PutLayer routine is depending on the Layer-p routine to be there.
...
That is EXACTLY the point. I not just teaching him how best to write this program, Im teaching something else entirely; Im using his program as an aid. (I'm attempting to teach him how to fish.) There is a lesson hidden in that statment. (Daron knows what im getting at here.)
Hey se7en,
I'd like to learn how to bait the hook before i go fishin...
...
The only thing that is goin through my head on how to improve it is
to make this an Autocad command, prompt the user and have that answer = a variable which would be local to that function. The conditionals would refer to that variable.
May I comment on this lesson Se7en?
O.k... question... where are we goin with this?
cause i'm startin to pull hair out of my head from frustration.
Like i've said... I don't know what i'm doin.. I don't know how to program and write code.. I'm not understanding the logic..
Feel like i've just been sacked for a 50 yard lost after throwin for 100 yards.
If i said i wrote the code i would be lying.
Someone from a newsgroup had sent me the code.
I replaced words that he had used with mine and that was it
As far as all the "INITGET" i would have never thought of that or would never known where to look for that.
I'm here to learn from the beginning..
I want to scrap my idea for the time being and learn from the start..
I wanna learn Lisp, learn how to put it all together, learn the coding and how to write it properly...
I'm a newbie to programming, please keep that in mind....
Party 1 (andre) doesn't get it. Too much information too fast.
Party 2 (the rest of us) doesn't understand how Party 1 can't see what we're talking about.
Both parties end up pulling their hair out.
Patience, young Jedi. :D
Ok, Quick Question...
How much time would you gurus say I would need to spend each night to learn Lsip? I can't spend much time during the day. I spend too much time on these forums as it is! I couldn't tell you how many times I've hit Alt-Tab when I hear footsteps!!! :)
Ok, Quick Question...
How much time would you gurus say I would need to spend each night to learn Lsip? I can't spend much time during the day. I spend too much time on these forums as it is! I couldn't tell you how many times I've hit Alt-Tab when I hear footsteps!!! :)
Here's what you should do andre.
Answer a couple of questions so we can see how much you understand what we're talking about.
1. What is a function in LISP and how do you identify a function with LISP (i.e. what command defines a function)?
2. What is a variable?
3. What's are the key differences between a local variable and a global variable?
4. How do you declare a variable as local?
5. How do you declare a variable as global?
6. How do you assign a value to a variable?
That, for a start, should give us an idea of where you are with understanding the basics.
We should be able to move on from there.
5. How do you declare a variable as global?
You assign the variable before a "/"
Quote5. How do you declare a variable as global?
You assign the variable before a "/"
No.
Everything else you got right, more or less.
The only action required to declare a variable as global is no action at all.
Putting the variable in front of the '/' will declare it as a local variable as well. But, more importantly, it will declare that variable as a 'required argument'. What, exactly, is a required argument?
(defun lisp-test (va / vb vc)
(setq vb "B")
(setq vc "C")
)
The only action required to declare a variable as global is no action at all.Heh, at least it's a comfort that the tutor got it wrong, too. I've never seen a global variable appear from no action at all. *ahem* .. a global variable appears when a symbol is assigned a value without explicit actions taken to declare it as local. "Oh what a smarta$$" (I know .. just couldn't resist) :wink:
Ahhh... the Force is strong with this one... but you are not a Jedi yet!. :D
So to test what you've learned so far try this:Code: [Select](defun lisp-test (va / vb vc)
(setq vb "B")
(setq vc "C")
)
Copy/paste that code and then run the function
(lisp-test A)
Now, being able to test the value of a variable at the command line, type the following and see what you get
!va
!vb
!vc
(defun lisp-test (va / vb vc); variables "vb" "vc" are local, "va" is a required argument.
(setq vb "B"); you're setting "B" to "vb", which is a global variable.
(setq vc "C"); you're setting "C" to "vc", which is a global variable.
)
Let me try and see what this is sayinCode: [Select](defun lisp-test (va / vb vc); variables "vb" "vc" are local, "va" is a required argument.
(setq vb "B"); you're setting "B" to "vb", which is a global variable.
(setq vc "C"); you're setting "C" to "vc", which is a global variable.
)
(setq vd "D")
Try figuring out the difference between IF and COND. Also, explain what PROGN does and why you don't need to use it in COND and why you use it in IF.
When you've explained and understand that, let's say we work on looping structures? Or is that reserved for a little further down the lesson line?
(if (= a b) ;If true...
(do something here);...Then do this if true
(do something here);...Else, do this if false
)
(if (= a b) ;If
(progn
(do something here) ;Then if true do this
(do something else here) ;if true do this too
(continue....) ;continue until progn closes
) ;end of progn
(do something here) ; Else do this if false
)
(princ "What are you doing, Dave?")
Command: (princ "What are you doing, Dave?")
What are you doing, Dave?"What are you doing, Dave?"
Command:
(print "What are you doing, Dave?")
Command: (print "What are you doing, Dave?")
"What are you doing, Dave?" "What are you doing, Dave?"
Command:
(prin1 "What are you doing, Dave?")
Command: (prin1 "What are you doing, Dave?")
"What are you doing, Dave?" "What are you doing, Dave?"
Command:
(princ [expr [file-desc]])
This function is the same as prin1, except control characters in expr are printed without expansion. In general, prin1 is designed to print expressions in a way that is compatible with load, while princ prints them in a way that is readable by functions such as read-line.
(print [expr [file-desc]])
This function is the same as prin1, except it prints a newline character before expr, and prints a space following expr.
In my experience, at least, that's pretty rare.
The way I see it, andre is just starting out and he has no programming experience at all. The basic things like what kind of values, exactly, can you assign to a variable, haven't even been touched on. Commands like getpoint haven't even been broached. In order to grasp what he'll be capable of doing with LISP in AutoCAD I thought it best to demonstrate those types of things first. Lay a little groundwork, if you will. I'm confident that, once some of these pieces start falling into place, andre will be unstoppable.
(defun calculate (a b c y / add1 add2 add3)
(setq add1 (* a y))
(setq add2 (* (expt b 2.0) y))
(setq add3 (/ (* c 4) 0.5))
(+ add1 add2 add3)
)
(defun c:formula (/ a b c y temp)
(setq a (getreal "\Value of a: "))
(setq b (getreal "\Value of b: "))
(setq c (getreal "\Value of c: "))
(setq y (getreal "\Value of y: "))
(setq temp (calculate a b c d y))
(princ "\nX = ")
(princ temp)
(princ)
)
(setq temp (calculate a b c d y))
(setq temp (calculate a b c y))
(defun calculate (a b c y / add1 add2 add3)
(setq add1 (* a y))
(setq add2 (* (expt b 2.0) y))
(setq add3 (/ (* c 4) 0.5))
(+ add1 add2 add3)
)
(defun c:formula (/ a b c y temp)
(setq a (getreal "\Value of a: "))
(setq b (getreal "\Value of b: "))
(setq c (getreal "\Value of c: "))
(setq y (getreal "\Value of y: "))
(setq temp (calculate a b c y))
(princ "\nX = ")
(princ temp)
(princ)
)
(defun c:add ()
(prompt "This will add 2 numbers together")
(setq a (getreal "\nEnter a Number: ")
b (getreal "\nEnter another Number: ")
answer (sum a b)
)
(princ "\nanswer = ")
(princ answer)
(princ)
)
Could someone give me a hand and understanding what i have to do?
Where can i find a good listing of the System Variables that i should keep in mind when i write anything and when should i start to learn about all of these? Is it to early for that yet?
Is that under Autocad 2004, I'm running AutoCAD Map5 and it doesn't have that under the express tools.
Quote from: DaronIs that under Autocad 2004, I'm running AutoCAD Map5 and it doesn't have that under the express tools.
It should. Try typing SYSVDLG on the command line and see what happens.
As far as for the polar confusion, it took me some time to fully understand it when learned it, too. Tell us what you understand about polar. My example above should give you some hints. I could add more if you like. Print in your words the arguments of the polar function though.
(defun c:square (/ pt1 pt2 pt3 pt4)
(setq pt1 (getpoint "\nSelect a point: ")
pt2 (getpoint pt1
"\Select the distance and angle of the square: "
)
pt3 (polar pt2
(+ (angle pt1 pt2) (/ pi 2))
(distance pt1 pt2)
)
pt4 (polar pt1
(+ (angle pt1 pt2) (/ pi 2))
(distance pt1 pt2)
)
)
(command ".pline" pt1 pt2 pt3 pt4 "c")
(princ)
)
So is Polar used to locate points with out drawing lines to first find them?
(defun c:square (/ pt1 pt2 pt3 pt4)
(setq pt1 (getpoint "\nSelect a point: ")
pt2 (getpoint pt1
"\Select the distance and angle of the square: "
)
pt3 (polar pt2
(+ (angle pt1 pt2) (/ pi 2))
(distance pt1 pt2)
)
pt4 (polar pt1
(+ (angle pt1 pt2) (/ pi 2))
(distance pt1 pt2)
)
)
(command ".pline" pt1 pt2 pt3 pt4 "c")
(princ)
)
(setq pt1 (getpoint "\nSelect a point: ")
pt2 (getpoint pt1
"\Select the distance and angle of the square: "
)
You're asking the user to pick a point which is then saved to PT1,
You're then asking the user to pick a distance and angle which is then saved to PT2
pt3 (polar pt2
(+ (angle pt1 pt2) (/ pi 2))
(distance pt1 pt2)
)
Did the polar notation in AutoCAD tell you something about POLAR?
Andre, do you want a proposed solution to 2.5?
Code: [Select]pt3 (polar pt2
(+ (angle pt1 pt2) (/ pi 2))
(distance pt1 pt2)
)
(polar pt2... is the base point for pt3.
(angle pt1 pt2) is just the angle between pt1 and pt2.
(+ (angle pt1 pt2) (/ pi 2)) is taking the angle of pt1 and pt2 and turning it 90 degrees counterclockwise relative to pt1 and pt2.
(distance pt1 pt2) is telling pt3 the distance it will be from pt2.
Does this make sense?
I was bangin my head tryin to figure out how to "rubberband"
Rectangular "rubberband" you would be referencing 3 points correct?
(setq pt1 (getpoint "\nPick a point: ") pt2 (getcorner pt1 "\nGet opposite corner: "))
(+ (angle pt1 pt2) (/ pi 2))
Quote from: amgirard2003Rectangular "rubberband" you would be referencing 3 points correct?
Instead of (setq pt1 (getpoint "\nblah blah:") pt2 (getpoint pt1 "\nSame"))
See what this does for you:Code: [Select](setq pt1 (getpoint "\nPick a point: ") pt2 (getcorner pt1 "\nGet opposite corner: "))
I wouldn't use it for a polar function, I just wanted to open your mind to more ideas.
Maybe i should try and go through all the functions and learn them..Sorry, there I go again, adding too much to the mind warp called lisp. You'll learn them as you ask questions and start using them. That help file will be useful, but not as useful as asking someone how to use the function. Anyway (/ pi 2)? Simply, that will give you an angle, 90 degrees from zero (east) in autocad in radians. (+ uang (/ pi 2)) is adding the user angle to 90 degrees to make the polar angle 90 degrees to the user angle. Does that help? Experiment with dividing pi by different numbers and subtracting instead of adding and multiplying instead of dividing.
QuoteMaybe i should try and go through all the functions and learn them..Sorry, there I go again, adding too much to the mind warp called lisp.You'll learn them as you ask questions and start using them.
Get center point with GETPOINT
Get radius with GETDIST
Get start angle with GETANGLE
- Used with (initget) function (flags)
Angle & Distance:- Is inputed as radians but needs to be converted to Degrees.
So i'll have to create a function to convert radians to degrees and add this to the polar function... correct??
(setq startpoint
(polar
(setq pnt1 (getpoint "\nSelect center Point: "))
(getangle "\nSelect start angle of arc: ")
(getdist "\nEnter radius of arc: ")
)
)
You could actually write the POLAR statement like this:Code: [Select]
(setq startpoint
(polar
(setq pnt1 (getpoint "\nSelect center Point: "))
(getangle "\nSelect start angle of arc: ")
(getdist "\nEnter radius of arc: ")
)
)
(defun c:arctest (/ pnt1 rad ang pnt2 cmd)
(setq pnt1 (getpoint "\nSelect Center Point: "))
(setq rad (getdist pnt1 "\nEnter Radius of arc: "))
(setq ang (getangle pnt1 "\nSelect Angle: "))
(setq pnt2 (polar pnt1 ang rad))
(setq cmd (getvar "cmdecho"))
(setvar "cmdecho" 0)
(command "arc" "c" pnt1 pnt2 pause)
(setvar "cmdecho" cmd)
(princ)
)
(defun c:REC (/ pnt1 pnt2 pnt3 pnt4 cmd)
(prompt "\nThis will create a Rectangular Pline ")
(setq pnt1 (getpoint "\nSelect Starting Point: "))
(setq pnt2 (getcorner pnt1 "\nSelect Opposite Corner: "))
(setq pnt3 (list (car pnt2) (cadr pnt1)))
(setq pnt4 (list (car pnt1) (cadr pnt2)))
(setq cmd (getvar "cmdecho"))
(setvar "cmdecho" 0)
(command "pline" pnt1 pnt4 pnt2 pnt3 "c")
(setvar "cmdecho" cmd)
(princ)
)
What do you think?
Pretty impressive i must say... i surprised myself by actually doin this.
That's good. Can you make a rectangle at any angle using two points for width and a third point or user input for length?
Quote from: amgirard2003What do you think?
Pretty impressive i must say... i surprised myself by actually doin this.
Pretty darn impressive! Ok, be honest, where did you get that code? :D
(defun c:rec ()
(Prompt "\Pline Rectangle" )
(setq len (getdist "\nEnter Length: "))
(setq wid (getdist "\nEnter Width: "))
(setq pnt1 (getpoint "\nEnter Starting Point: "))
(setq ang (getangle pnt1 "\nEnter Angle: "))
Can you make a rectangle at any angle using two points for width and a third point or user input for length?
(defun c:REC (/ pnt1 pnt2 pnt3 pnt4 cmd)
(prompt "\nThis will create a Rectangular Pline ")
(setq pnt1 (getpoint "\nSelect Starting Point: "))
(setq wid (getdist pnt1 "\nEnter Width: ")) (terpri)
(setq len (getdist pnt1 "\Enter Length: ")) (terpri)
(setq ang (getangle pnt1 "\nSelect Angle: "))
(setq pnt2 (polar pnt1 ang len)
(setq pnt3 (polar pnt2 (+(angle pnt1 pnt2) (/ pi 2)) wid))
(setq pnt4 (polar pnt3 (+(angle pnt1 pnt2) (/ pi 2)) wid))
(setq cmd (getvar "cmdecho"))
(setvar "cmdecho" 0)
(command "pline" (pnt1 pnt2 pnt3 pnt4 "c"))
(setvar "cmdecho" cmd)
(princ)
)
(defun c:REC (/ ); pnt1 pnt2 pnt3 pnt4 cmd)
(prompt "\nThis will create a Rectangular Pline ")
(setq pnt1 (getpoint "\nSelect Starting Point: "))
(setq wid (getdist pnt1 "\nEnter Width: "))
(setq len (getdist pnt1 "\nEnter Length: "))
(setq ang (getangle pnt1 "\nSelect Angle: "))
(setq pnt2 (polar pnt1 ang len))
(setq pnt3 (polar pnt2 (+ (angle pnt1 pnt2) (/ pi 2)) wid))
;;(setq pnt4 (polar pnt3 (+ (angle pnt1 pnt2) (/ pi 2)) wid))
;; ^ No good. It will just put pnt4 in the same direction
;; as pnt2-pnt3 at a distance of 2 times wid from pnt2
(setq pnt4 (polar pnt1 (+ (angle pnt1 pnt2) (/ pi 2)) wid))
;; ^ This will create the same line as pnt2-pnt3, only it will
;; place it in pnt1
(setq cmd (getvar "cmdecho"))
(setvar "cmdecho" 0)
;;(command "pline" (pnt1 pnt2 pnt3 pnt4 "c"))
;; ^ What is this? Shame on you :-)
(command "pline" pnt1 pnt2 pnt3 pnt4 "c")
(setvar "cmdecho" cmd)
(princ)
)
(command "pline" (pnt1 pnt2 pnt3 pnt4 "c"))
^ What is this? Shame on you :-)
Prompt user with the following choices:
....
(cond ((= ans "T")
(setvar "clayer" "612")
)
(setvar "ltype" "Three")
)
(cond((= ans "T")
(setvar "clayer" "612")
(setvar "ltype" Three))
)
...how do i set the linetype to become "Three"...
(cond ((= ans T)
(setvar "clayer" "1")
(setvar "celtype" "Three")
)
)
(cond ((= ans T)
(setvar "clayer" "1")
)
(T (setvar "celtype" "Three"))
)
(cond (ans
(setvar "clayer" "1")
(setvar "celtype" "Three")
)
)
Second, I don't think you mean to use the string "T" as the symbol T
(defun c:nl ()
(prompt "Run with Phil's routine only")
(terpri)
(initget 0 "T D S C E F")
(setq ans
(getkword "\nSelect Line: (T)hree/(D)ouble/(S)ingle/se(C)ondary/(E)600/(F)208: <> ")
)
(cond((= ans "T")
(setvar "clayer" "612")
(setvar "celtype" "Three"))
)
)
(defun chvars (clay lintype)
(setvar 'clayer clay)
(setvar 'celtype lintype)
(princ)
)
(cond ((= ans "T")
(chvars "612" "Three" etc.)
)
)
(defun c:nl ( / ans)
(prompt "Run with Phil's routine only")
(initget 0 "T D S C E F")
(setq ans
(getkword
"\nSelect Line: [(T)hree/(D)ouble/(S)ingle/se(C)ondary/(E)600/(F)208]: "
)
)
(cond ((= ans "T")
(setvar "clayer" "612")
(setvar "celtype" "Three")
)
)
(princ)
)
(defun c:nl ()
(prompt "Run with Phil's routine only")
(terpri)
(initget 0 "Three Double Single seCondary E E600 F F208")
(setq ans
(getkword "\nSelect Line [Three/Double/Single/seCondary/E600/F208] <>: ")
)
(cond ((= ans "T")
(setvar "clayer" "612")
(setvar "celtype" "Three")
)
)
)
when i right click it it just says : nil
it seems to be acting like the "enter" key...
i get nil after i click the right button
(defun c:nl (/ ans)
(prompt "Run with Phil's routine only")
(initget 0 "Three Double Single seCondary E E600 F F208")
(setq ans
(getkword
"\nSelect Line [Three/Double/Single/seCondary/E600/F208] : "
)
)
(cond ((= ans "T")
(setvar "clayer" "612")
(setvar "celtype" "Three")
)
((= ans "D")
(setvar "clayer" "612")
(setvar "celtype" "Double")
)
((= ans "S")
(setvar "clayer" "612")
(setvar "celtype" "Single")
)
((= ans "C")
(setvar "clayer" "622")
(setvar "celtype" "Bylayer")
(setvar "plinewid" 0.5)
)
((= ans "E")
(setvar "clayer" "622")
(setvar "celtype" "Hidden")
(setvar "ltscale" 0.5)
)
((= ans "F")
(setvar "clayer" "622")
(command "linetype" "l" "*" "conversion.lin" "")
)
)
(princ)
)
(defun c:nl (/ ans var n)
(setq var '("clayer" "celtype" "ltscale" "plinewid")
n nil
)
(foreach item var
(setq n (append n (list (cons item (getvar item)))))
)
(prompt "Run with Phil's routine only")
(initget 0 "Three Double Single seCondary E E600 F F208")
(setq ans
(getkword
"\nSelect Line [Three/Double/Single/seCondary/E600/F208] : "
)
)
(cond ((= ans "T")
(chvars "612" "Three" (cdr (nth 2 n)) (cdr (nth 3 n)))
)
((= ans "D")
(chvars "612" "Double" (cdr (nth 2 n)) (cdr (nth 3 n)))
)
((= ans "S")
(chvars "612" "Single" (cdr (nth 3 n)))
)
((= ans "C")
(chvars "622" "Bylayer" (cdr (nth 2 n)) 0.5)
)
((= ans "E")
(chvars "622" "Hidden" 0.5 (cdr (nth 3 n)))
)
((= ans "F")
(chvars "622"
(cdr (nth 1 n))
(cdr (nth 2 n))
(cdr (nth 3 n))
)
(command "linetype" "l" "*" "conversion.lin" "")
)
)
(princ n)
(princ)
)
(defun chvars (clay lintype lscale plwid)
(setvar 'clayer clay)
(setvar 'celtype lintype)
(setvar 'ltscale lscale)
(setvar 'plinewid plwid)
)
(chvars "612" "Three" (cdr (nth 2 n)) (cdr (nth 3 n)))
(defun chvars ()
(setq clay (setvar 'clayer "612")
lintype (setvar 'celtype "Three")
lscale (setvar 'ltscale (getvar 'ltscale))
plwid (setvar 'plinewid (getvar 'plinewid))
)
(setvar 'clayer clay)
(setvar ''celtype lintype)
(setvar 'ltscale lscale)
(setvar 'plinewid plwid)
)
(defun c:nl (/ ans )
(prompt "Run with Phil's routine only"); tell the user to use it with Phil's routine
(initget 0 "T D S C E F"); Capital letters of all the Linetypes
(setq ans
(getkword "\nSelect Line [Three/Double/Single/seCondary/(E)600/(F)208]: <> ")
)
(setq clay (getvar "clayer"))
(setq cltype (getvar "celtype"))
(setq pwidth (getvar "plinewid"))
(cond ((= ans "T") ; Answer to equal Three Phase
(setvar "clayer" "612") ; Set variable "Current Layer" to 612
(setvar "celtype" "Three")) ; Set variable "Current Linetype" to Three
((= ans "D") ; Answer to equal Double Phase
(setvar "clayer" "612") ; Set variable "Curren Layer" to 612
(setvar "celtype" "Double")) ; Set varaible "Current Linetype" to Double
((= ans "S") ; Answer to equal Single Phase
(setvar "clayer" "612") ; Set variable "Current Layer" to 612
(setvar "celtype" "Single")) ; Set variable "Current Linetype" to Single
((= ans "C") ; Answer to equal 120/240V
(setvar "clayer" "622") ; Set variable "Current Layer" to 622
(setvar "celtype" "Bylayer") ; Set variable "Current Linetype" to Bylayer
(setvar "plinewid" 0.5)) ; Set Polyline Width to 0.5
((= ans "E") ; Answer to equal 600/347V
(setvar "clayer" "622")
(setvar "celtype" "Hidden")
(setvar "ltscale" 0.5))
((= ans "F") ; Answer to equal 120/208V
(setvar "clayer" "622")
(command "linetype" "l" "*" "conversion.lin" "")
(setvar "celtype" ))
)
(princ)
(command "pline")
(princ)
(setvar "clayer" clay)
(setvar "celtype" cltype)
(setvar "plinewid" pwidth)
)
(defun setpick ()
(if (= (getvar "ltscale") 1)
(setvar "ltscale" 48)
)
(command ".layer" "m" "an_notes" "c" "4" "" "")
(setq lt (getvar "ltscale"))
(setvar "OSMODE" 512)
(setq a (getpoint "\nStart point of arrow: "))
(setvar "OSMODE" 0)
(setq b (getpoint a "\nDirection of arrow: "))
)
(defun ldrawing ()
(setq waro (* laro 0.6))
(setq aaro (angle a b))
(command
"PLINE"
a
"w"
"0"
waro
(polar a aaro laro)
"w"
"0"
"0"
b
) ;_ COMMAND
(setq c b)
(while (setq c (getpoint c "\nNext point: "))
(command c)
) ;_ WHILE
(command "")
)
The part of the code in reference to Stig's suggestion is the end of the last function starting with (setq c b)
(command "PLINE")
(while (> (getvar "CMDACTIVE") 0)
(command pause)
)
Andre, did you test the routine? If so, then you might notice that the pline it allows you to draw is not put on the layer and drawn with the linetype that you want. Why?
Look at the last 4-5 lines. It calls the PLINE command alright, but it is not allowed to finish before setting 3 system variables. In other words: it resets the environment before drawing any plines.
If you can solve this problem then you have written yourself a nice little routine.
Just wanted to add another, more generally purposed variant of this technique:
code:
--------------------------------------------------------------------------------
(command "PLINE")
(while (> (getvar "CMDACTIVE") 0)
(command pause)
)
--------------------------------------------------------------------------------
Can you explain what you just wrote here... i have no clue :?
(defun C:TEST ()
(setvar "CLAYER" "612")
(command "LINE")
(setvar "CLAYER" "0")
)
(defun C:TEST ()
(setvar "CLAYER" "612")
(command "LINE" pause pause)
(setvar "CLAYER" "0")
)
(defun C:TEST ()
(setvar "CLAYER" "612")
(command "LINE")
(while (> (getvar "CMDACTIVE") 0)
(command pause)
)
(setvar "CLAYER" "0")
)
(defun c:nl (/ ans clay cltype pwidth)
(prompt "Run with Phil's routine only")
; tell the user to use it with Phil's routine
(initget 0 "Three Double Single seCondary E F") ; Capital letters of all the Linetypes
(setq ans
(getkword
"\nSelect Line [Three/Double/Single/seCondary/E(600)/F(208)]: <> "
)
)
(setq cmd (getvar "cmdecho"))
(setvar "cmdecho" 0)
(setq clay (getvar "clayer"))
(setvar "clayer" "0")
(setq ltype (getvar "celtype"))
(setvar "celtype" "bylayer")
(setq scal (getvar "ltscale"))
(setvar "ltscale" 0)
(setq pwidth (getvar "plinewid"))
(setvar "plinewid" 0)
Type: Real
Saved in: Drawing
Initial value: 1.0000
Sets the global linetype scale factor. The linetype scale factor cannot equal zero.
Line 3:- Check and see if layer "612" exist
(cond ((= ans "Three")
(if (not (tblsearch "layer" "612"))
(command ".layer" "make" "612" "")
(setvar "clayer" "612")
)
(setvar "celtype" "Three"))
)
To do something with it, use it as a condition for an IF expression:
(cond ((= ans "Three")
(if (not (tblsearch "layer" "612"))
(command ".layer" "make" "612" "")
(setvar "clayer" "612")
)
(setvar "celtype" "Three"))
)
Line 1:- If ans equals "three" then do the following
Line 2:- Set layer to "612"
Line 3:- Check and see if layer "612" exist
line 4:- If it doesn't exist then create it
line 5:- Set lintype to "Three"
(defun c:nl (/ ans cmd clay ltype scal pwidth)
(prompt "Run with Phil's routine only")
; tell the user to use it with Phil's routine
(initget 0 "Three Double Single seCondary E F") ; Capital letters of all the Linetypes
(setq ans
(getkword
"\nSelect Line [Three/Double/Single/seCondary/E(600)/F(208)]: <> "
)
)
(setq cmd (getvar "cmdecho"))
(setvar "cmdecho" 0)
(setq clay (getvar "clayer"))
(setvar "clayer" "0")
(setq ltype (getvar "celtype"))
(setvar "celtype" "bylayer")
(setq scal (getvar "ltscale"))
(setvar "ltscale" 1.0)
(setq pwidth (getvar "plinewid"))
(setvar "plinewid" 0)
(cond ((= ans "Three")
(if (not (tblsearch "layer" "612"))
(command ".layer" "m" "612" "c" "6" "" "")
(setvar "clayer" "612")
)
(if (not (tblsearch "ltype" "Three"))
(command ".linetype" "l" "*" "andre (newline).lin" "")
(setvar "celtype" "Three")
)
)
((= ans "Double")
(if (not (tblsearch "layer" "612"))
(command ".layer" "m" "612" "c" "6" "" "")
(setvar "clayer" "612")
)
(if (not (tblsearch "ltype" "Double"))
(command ".linetype" "l" "*" "andre (newline).lin" "")
(setvar "celtype" "Double")
)
)
((= ans "Single")
(if (not (tblsearch "layer" "612"))
(command ".layer" "m" "612" "c" "6" "" "")
(setvar "clayer" "612")
)
(if (not (tblsearch "ltype" "Single"))
(command ".linetype" "l" "*" "andre (newline).lin" "")
(setvar "celtype" "Single")
)
)
((= ans "seCondary")
(if (not (tblsearch "layer" "622"))
(command ".layer" "m" "622" "c" "2" "" "")
(setvar "clayer" "622")
)
(setvar "celtype" "Bylayer")
(setvar "plinewid" 0.5)
)
((= ans "E")
(if (not (tblsearch "layer" "622"))
(command ".layer" "m" "622" "c" "2" "" "")
(setvar "clayer" "622")
)
(if (not (tblsearch "ltype" "Hidden"))
(command ".linetype" "l" "*" "andre (newline).lin" "")
(setvar "celtype" "Hidden")
)
(setvar "ltscale" 0.5)
)
((= ans "F")
(if (not (tblsearch "layer" "622"))
(command ".layer" "m" "622" "c" "2" "" "")
(setvar "clayer" "622")
)
(if (not (tblsearch "ltype" "OH_SECONDARY"))
(command ".linetype" "l" "*" "andre (newline).lin" "")
(setvar "celtype" "OH_SECONDARY")
)
)
)
(command "pline")
(while (> (getvar "cmdactive") 0)
(command pause)
)
(setvar "cmdecho" cmd)
(setvar "clayer" clay)
(setvar "celtype" ltype)
(setvar "ltscale" scal)
(setvar "plinewid" pwidth)
)
(setq cmd (getvar "cmdecho")
clay (getvar "clayer")
ltype (getvar "celtype")
scal (getvar "ltscale")
pwidth (getvar "plinewid")
)
(setvar "cmdecho" 0)
(setvar "clayer" "0")
(setvar "celtype" "bylayer")
(setvar "ltscale" 1.0)
(setvar "plinewid" 0)
it draws the line on the correct layer and the correct color but it draws the line on the "BYLAYER".What are you saying here? Do you want the object color to be different than the layer color? If not, it should be bylayer, if so, you need to set the color property to what you want it to be, but unless you're changing the color of a block, you normally wouldn't do that.
You learn so frickin' much when you test, play arround and inspect each expression it would be stupid not to do so.