Jump to content

Lisp program is not completing the pose


Tharwat

Recommended Posts

Hello,

I made this simple Autolisp program, but it's not completing the pose.

Maybe due to wrong angle degree (72). or Length of that line (125.873).

Note: After implementing the program notice that start and end points are not connected .... why?

(defun c:ax (/ p1 p2 p3 p4 p5  oldsnap oldortho newortho)
(setq small 38)
(setq pcs1 (getdist"\nLength of First peice: "))
(setq p1 (getpoint"\nSpecify the start point of peice:"))
(setq p2 (polar p1 (DTR 270) 120)) 
(setq p3 (polar p2 (DTR 0)(- pcs1 small))) 
(setq p4 (polar p3 (DTR [color="red"]72[/color]) [color="Red"]125.873[/color])) 
(setq p5 (polar p4 (DTR 180) pcs1))
 (setq oldsnap (getvar "osmode"))
 (setq oldortho (getvar "orthomode"))
 (setq newsnap (setvar "osmode" 0))
 (setq newortho (setvar "orthomode" 0))
 (command "_pline" p1 "_w" 0 0 p2 p3 p4 p5 "")   
 (setvar "osmode" oldsnap)
 (setvar "orthomode" oldortho)
 (princ "Made by Tharwat")
 (princ))
;++++++++++++ degree to radians ++++++++++++
(defun DTR (ang)(* pi (/ ang 180.0)))

Your help would be highly appreciated ...

Thanks,

 

Tharwat

Link to comment
Share on other sites

I can only comment on your trigonometry, not the lisp.

 

Your angle of 72 is not exact, and anyway should be (72 + 180).

 

Why do you not start the lisp drawing from the right hand end of the lower line? Then the lisp would draw the 600 line, the 120 line and then the 638 line. THEN finish the polyline off with the 'c' option to close. You do not have to work out the awkward angle in this case.

Link to comment
Share on other sites

I have made some corrections to your code - always try to calculate your values instead built-in it to increase precision.

 

 
(defun c:ax( / p1 p2 p3 p4 p5 small height SlopeLength SlopeAngle oldsnap )
(setq small  38.0
      height 120.0)
(setq pcs1 (getdist"\nLength of First piece: "))
(setq p1 (getpoint"\nSpecify the start point of piece:"))
(setq p2 (polar p1 (DTR 270) height)) 
(setq p3 (polar p2 0.0       (- pcs1 small))) 
(setq SlopeLength (sqrt (+ (expt small 2) (expt height 2)))
      SlopeAngle  (atan (/ height small)))
(setq p4 (polar p3 SlopeAngle SlopeLength))
(setq p5 (polar p4 pi pcs1))
(setq oldsnap (getvar "osmode"))
(setvar "osmode" 0)
(command "_pline" p1 "_w" 0 0 p2 p3 p4 p5 "")   
(setvar "osmode" oldsnap)
(princ "Made by Tharwat")
(princ)
)
;++++++++++++ degree to radians ++++++++++++
(defun DTR (ang)(* pi (/ ang 180.0)))

 

Regards,

Link to comment
Share on other sites

Thank you so much msasu that was wonderful.

 

You did recalculate the angle value and gave a value to height although that, I calculated them manually and inserted the value only as you might have noticed that in the code.

 

So why did not Autocad understand or performed correctly since that values were correct too as well .... ?

 

I hope you explain it to me.

 

great thanks to you.

Tharwat

Link to comment
Share on other sites

You're welcome!

 

That gap is because you don't get enough precision using manually calculated/rounded values: for example your slope part's angle is 72.42874... degrees instead of 72.

 

Regards,

Link to comment
Share on other sites

I can only comment on your trigonometry, not the lisp.

 

Your angle of 72 is not exact, and anyway should be (72 + 180).

 

Why do you not start the lisp drawing from the right hand end of the lower line? Then the lisp would draw the 600 line, the 120 line and then the 638 line. THEN finish the polyline off with the 'c' option to close. You do not have to work out the awkward angle in this case.

 

First of all Thanks for your reply.

 

In regard to your question. That way of dealing with Autolisp is completely wrong and it is a very advanced way but backwards not forwards.

 

So that's why.

Tharwat

Link to comment
Share on other sites

In regard to your question. That way of dealing with Autolisp is completely wrong and it is a very advanced way but backwards not forwards.

 

So that's why.

Tharwat

 

In fact, I was suggesting that you could calculate p4, by going 600 from p1 at a bearing of 0. Having evaluated p1, p2, p3 & p4, you do not need p5, which should have been the same as p1 anyway. Then the drawing of the Polyline is completely separate command and does not have to start with p1, it can start with p4, and then when you get to p3, close the line with the 'c' option.

 

Then you would not have needed to calculate p4 with a dodgy length and a dodgy direction and your p5 was wrong because it was derived from p4. I am not sure what is wrong in my logic, but perhaps you do not understand me :cry: I know enough about Autolisp to understand some simple wrong calculating.

 

Anyway you have something that works, which is what this is all about.

Link to comment
Share on other sites

In regard to your question. That way of dealing with Autolisp is completely wrong and it is a very advanced way but backwards not forwards.

 

I completely disagree - Eldon's method is much easier:

 

(defun c:test ( / delt hgt l pt p1 )

 (setq delt 38. hgt 120.)

 (if (and (setq l  (getdist "\nSpecify Length: "))
          (setq pt (getpoint "\nPick Insertion: ")))
       
   (LWPoly (list (polar pt 0 l) pt (setq p1 (polar pt (/ pi 2.) hgt))
                 (polar p1 0 (+ l delt))) 1)
 )
 (princ)
)

(defun LWPoly ( lst cls )
 (entmakex (append (list (cons 0 "LWPOLYLINE")
                         (cons 100 "AcDbEntity")
                         (cons 100 "AcDbPolyline")
                         (cons 90 (length lst))
                         (cons 70 cls))
                   (mapcar (function (lambda ( p ) (cons 10 p))) lst))))

Link to comment
Share on other sites

Hi Eldon.

Thank you for your second reply and doing your best to help.

 

Your point was not wrong, but it can not be developed that much. And I got what you meant from the first time you wrote to me, Because these codes that I have written in the beginning were a part of a big Lisp program.

 

So your idea is really smart way, but for sole tool or one simple pose.

 

I did really liked your kind technique of giving the idea ... honestly.

 

My best regards,

 

Tharwat

Link to comment
Share on other sites

I completely disagree - Eldon's method is much easier:=

If I considered that Autolisp only to get it works, I would agree with you.

But if I wanted to go deeply in science of codes and getting more advanced techniques with it to the far most, I would probably say that you will agree with me, Don't you ... ?

 

In this regards, I would like you to give me your advises of how to become a very good Autolisp composer :D . Beside that, I do like this Programming Language a lot, and at least I could write lots of helpful programs.

 

Waiting for a reply.

 

Tharwat

Link to comment
Share on other sites

In my opinion the simplest way to do something is usually the most efficient and a better way to apprach the solution.

 

Notice that in my code, I only have to calculate three points and let the group 70 DXF code close the polyline for me, hence eliminating the need to perhaps introduce errors when calculating the slope.

 

I'm not sure quite what you are referring to, but the method is definitely not "wrong". The method I use, as suggested by Eldon is to merely calculate the points in a different order to ease the calculations and decrease the amount of code needed.

 

Notice that I use entmake to make creation of the polyline both quicker and more reliable.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...