Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations GregLocock on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

An Autolisp Lesson part 3 2

Status
Not open for further replies.

shadow

Computer
Mar 1, 2001
321
Wow just relized how many posts was in An Autolisp Lesson part 2's thread

any way
a recap
(setq linelength (rtos linelength 4 8))
RTOS converts length into text string thats what it does

Then we learned about getting the drawing name and path using the following

setq MYPATH (getvar "dwgprefix"))

I do not recall if it comes with a slash or without.
If slash missing, add it thus:
(setq MYPATH (strcat MYPATH "/"))
try on command line till it works right - "/" or "\\" or else.
Then attach dwgname to this path.
(setq MYPATH (strcat MYPATH (getvar "dwgname")))

and how to use the prin(t)(c)(1) functions

(princ ", " f) ;puts a comma and a space on the same line
(princ "\n, " f) ;the same on a new line - never needed I suppose but to illustrate the use of \n

(print ", " f) ; the same on a new line but with quotations

(prin1 ", " f) ; used to do something - I forgot.


then we leearned about how to remove the extention from the drawing name to use as a name for a txt file using the following

(setq DWGNAME (getvar "DWGNAME"))
(setq NAME (substr DWGNAME 1 (- (strlen DWGNAME) 4)))

& we learned that possibly lisp cannot read the clipboard


now another ???

Conditional Rotation
back to the linelength.lsp
how do you go about telling the lisp to get the rotation angle of the line and if it is an angle between0-45 degrees then textangle should be at an angle opposit of that angle so inother words if the line comes out 45d then the text should be -45d or 315d
i would assume the latter would end up a variable that would be placed in the area where the followig is


(COMMAND "_.text" "_j" "mc"midpoint angledegree linelength)

with the variable txtang being the rotation angle for the text to be inserted right

So i guess the best place to start would be explaining what is being done on the following lines

;10 get the inclination
(setq angleradian (angle starting ending))
(setq angledegree (/ (* angleradian 180. 7. ) 22.))

i understand the first its getting the angle between the starting and ending poins collected in the selection set but what does the other do
if everyone helps everybody the world will be a better place
 
Replies continue below

Recommended for you

No doubt, I am still wondering why the function fails to operate on his system....
 

I can answer that, Striker

(rtos linelength 4 4)

gives units in feet and inch to the precision of 4.
but if feedback says - ahhm uhhm why do I get decimals,
it has simply not been tested at all, or result not observed after running.

The expected feedback was this:
ahhm, I looked up the syntax of command (rtos ... and now I know how to change the precision as I wish or the units system from arch to eng etc.


Any other feedback is direct corollary of Murphy's laws:

Any simple problem can be made unsolvable if enough conferences are held to discuss it ( Law of Committeelogy)

Better solve a problem with a crude approximation than demand an exact solution and get confused

Whenever a system becomes completely defined someone discovers something that either abolishes the system or expands it beyond recognition (BROKE)
 
tigrek you have a good point
this thread is getting to long im starting another called part 4 the legend continues
if everyone helps everybody the world will be a better place
 
*Clearly a novice, and I know nothing about lisps,
and I know you've ended this topic, but would this work?*


;10 get the inclination
(setq angleradian (angle starting ending))
(setq angledegree (* PI ( / angleradian 180))


As STRIKER says, PI is a built in function so no need to approximate, if so, PI should inherently be numeric and fit directly in to the command?

(Go easy please, jus' tryin'a help!)
 
I acknowledge the point about answering the question, but in fact the post was
"cause in the line where it actually uses rtos to set the text useing the string info it drops the 0" if it has it but why does it do this "

The response originally was I cannot answer why the 0" would be dropped without seeing the code. After looking at the code, I made a recommendation to adjust the angle conversion routine, outside of that, if you read my original post, and subsequent posts, I said the routine works flawlessly on my system, in fact I have tested the posted code in all versions of AutoCAD from R12 to A2002. Still since there is nothing wrong with the code to produce the stated problem, the only recommendation I could see to improve the code would be to make the angles accurate. Now for the accuracy point.

You stated:
"22/7 or 3.14 as radian of 180 degrees was good enough for this purpose. It still is."

perhaps it is, however, why would you purposely make a program to do inaccurate calculations? I can see you are interested only in the "look" of the drawing and not accuracy.

also:
"22/7 was kind of cute and original because it is not used in any of lisp examples under Support."

Simply because it was inaccurate. Would you create a piece of millwork or architectural design and purposly skew the lines? What happens when someone else uses your drawings,it makes you look incompetent.

What if your work processor arbitrarily placed capital and lower case letters whenever you typed. Hey the word is still spelled the same, who cares about capitalization anyway. I would think it would make grammar professionals cringe. Which is exactly how inaccuracy make me feel in drafting.

enough said on this subject, but keep in mind that any programmer who is a programmer will not purposely make the program do inaccurate work, and 22/7 is in no way, shape, form, or fashion "PI".
 
To put the text about a text size from the line was the big approximation I did.

After that very grob assumption, to go for a tenth of a degree is ridiculous.

And, to replace 22/7 with the system parameter PI ought to not take so much of discussion. All were free to replace the text whereever and however they liked. This was expressed in the comment in the starting source code.

The ensuing mess defeated the purpose.

Not my idea of useful tutorial.

 
Sorry folks, I was wrong in using 22/7 for 3.14 or PI.

As compensation, here some selecetions from Arthur Bloch's Murphy's Law on Doctors - Malpractice makes Perfect:

---
Murphy's Law

for economy in Research
1. I Deny the last established truth on the list
2. Add mine
3. Pass the list

Research is the process of going up alleys to see if they are blind.
When I do not know what i am doing, I do it neatly.
Teamwork is essential - allows me to blame someone else
If I have the right data, I have the wrong problem.
One man's error is another man's data.
Those who can, do. Those who cannot, improve.
No one is listening until you make a mistake.

The two rules for ultimate success:
1. never tell everything you know.

 
Maybe I'm missing something in the conversation because I only skimmed through it, but if you are trying to find a way to convert radians to degrees simply use "RTD"
for example:
(setq a1 (rtd (ANGLE P1 P2)))
in which I'm finding the angle between point1 and point2 and converting it to degrees.
 
So CDH are you saying in our case we should use this

(setq angledegree (rtd (ANGLE Starting Ending)))

Instead of this

(setq angledegree (distof (angtos angleradian)))

if everyone helps everybody the world will be a better place
 
keep in mind that RTD is an externally defined function and is not on every installation of AutoCAD. If you do not have it, let me know
 
It should work. I have used this in some of my programs and it works, although I did not realize it is not in every installation.
Also, I am by no means a lisp expert, so my method may not be the best, I guess it depends on the situation. In my case I was manually picking two points along a line, so this seemed the best method. :)
 
Striker where and what situations have u run into that RTD is not there due to a specific install i would like to know if everyone helps everybody the world will be a better place
 
On some installations, the user has select to not install all of the support lisps and examples. If this is the case, the RTD function will not be installed. To check if you have it, you can type !RTD at the command line. If you have it, it will show up as either a list (pre A2k) or as an external function in A2k and AutoCAD 2002.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor