basic Autolisp

basic Autolisp

Anonymous
Not applicable
1,080 Views
6 Replies
Message 1 of 7

basic Autolisp

Anonymous
Not applicable

Hello, I am starting to learn how to work with autolisp but I'm having a really hard time. Hope you can help me because I have few questions.

1. I want to assign (don't know if this word is correct in this context) value. 

For example:

In math it is 

H=30; R=0.35H

But how do you write this in LISP language? (setq R (* 0.35 H) ?

I have an example by which I made my assignment but I still don't get it.

Here is my assignment and here is what came up with. maybe you could tell me the main things and tell where the mistakes are.

image1.JPG

 

;------------------------------------------------
 ; baseline data: p0, L, H, b, c, a, w, a1          
 ;------------------------------------------------

 ;--baseline data----------------------------
    (defun prduom ()
     (setq p0 (getpoint "\n mark base point p0:"))
     (setq L (getdist "\nWidth L <30>:"))
     (if (null L) (setq L 30)) 
     (setq H (getdist "\nHeight H <30>:"))
     (if (null H) (setq H 30))
     (setq b (* [0.35] H)
     (setq c (* [0.15] H)
     (setq a (* [0.85] H)
     (setq r (* [0.35] H)
     (setq a1 (- L a) 
     (setq W (getdist "\nPolyline width W <0.5>:"))
     (if (null w) (setq w 0.5))
     (setq m (getdist "\nScale  m <1.0>:"))
     (if (null m) (setq m 1.0))  
        )
 ;--evaluating coordinates-------------------------
    (defun skaic ()
     (setq p1 (polar p0 (/ pi 2.0) H))
     (setq p2 (polar p1 0 a1))
     (setq p3 (list (car p2) (- (cadr p2) c)))
     (setq p4 (polar p3 (* 1.75 pi) (* r (sqrt 2))))
     (setq p5 (polar p4 0 c))
     (setq p6 (polar p5 (* 1.75 pi) (* r (sqrt 2))))
     (setq p7 (list (car p6) (- (cadr p6) b)))
      )
 ;--drawing contour------------------------------
    (defun braiz ()
     (command "PLINE" p0 "w" w "" p1 p2 p3 "ARC" "ANGLE" "-90" p4 "L" p5 "ARC" "ANGLE" "90" p6 "L" p7 p0 "")
      (setq p2 (entlast))
      (command "SCALE" p2 "" p0 m )
     (setq PL2 (entlast))
     (command "hatch" "ansi31" 2 0 PL2 "")
    )    

 ;--Main Program-------------------------------------------
    (defun C:uzdv()
       (prduom)
       (skaic)
       (braiz)
       (princ)
    )

Edited by
Discussion_Admin

note please use the insert code option when post to the community

0 Likes
Accepted solutions (1)
1,081 Views
6 Replies
Replies (6)
Message 2 of 7

rkmcswain
Mentor
Mentor
donbru wrote:

In math it is 

H=30; R=0.35H

But how do you write this in LISP language? (setq R (* 0.35 H) ?

Specifically answering that question... 

 

(setq h 30.0)
(setq r (* 0.35 h))

I see you have some square brackets, those are not used. Only parenthesis.

 

 

R.K. McSwain     | CADpanacea | on twitter
Message 3 of 7

Anonymous
Not applicable

Ok, thank you. I made some corrections and I have something not quite what I need but close

.image1.JPGthis should be rotate 90 degrees to the right

I also added the corrected program

0 Likes
Message 4 of 7

Anonymous
Not applicable

Ok, the only way I get the horizontal line ( L) straight is when the line (b) is (0.15 H) or 4.5. So is the condition wrong or I made a mistake somewhere?

0 Likes
Message 5 of 7

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

Ok, the only way I get the horizontal line ( L) straight is when the line (b) is (0.15 H) or 4.5. So is the condition wrong or I made a mistake somewhere?


I think their diagram is wrong about (b).  The arcs are not quite drawn in it as full 90-degree swings, but they need to be if two (R)'s plus a (c) are going to add up to (a) at 85% of H.  [And shouldn't that (a) be a proportion of L rather than of H?  In this case they're equal, but presumably not always.]  Given quarter-circle arcs, they have two (R)'s plus (c) plus (b) making up the overall dimension in the direction parallel to H, and they add up to 110% of H.  It might be wrong in the visual implication that the side along the L dimension is perpendicular to the H side, rather than about the size of (b), but something doesn't add up.

Kent Cooper, AIA
Message 6 of 7

Anonymous
Not applicable

I just made another similar assignment. It is the same case. The L line is not horizontal. but all other dimensios are corrected. So maybe the centers of the arcs are not correct?

0 Likes
Message 7 of 7

hmsilva
Mentor
Mentor
Accepted solution

Hi donbru,

I do not see any condition in the diagram that says 'arcs must be a quarter circle'...


Fulfilling all diagram conditions, perhaps something like this will do the trick.

Just a rough draft 'demo', as a starting point...

(defun c:demo (/ A B C D F H H1 L1 OSM P0 P1 P2 P3 P4 P5 P6 P7 PF1 PF2 PMID1 PMID2 R)
  (if (and (setq p0 (getpoint "\nSpecify first point: "))
           (listp p0)
           (setq h (getdist "\nSpecify height: "))
      )
    (progn
      (setq osm (getvar 'OSMODE))
      (setvar 'OSMODE 0)
      (setq a     (* h 0.85)
            b     (* h 0.25)
            c     (* h 0.15)
            r     (* h 0.35)
            p1    (polar p0 (* pi 0.5) h)
            p2    (polar p1 0.0 c)
            p3    (polar p2 (* pi 1.5) c)
            h1    (/ (- h (+ b c)) 2.0)
            l1    (/ (- h (+ c c)) 2.0)
            p4    (list (+ (car p3) l1) (- (cadr p3) h1))
            p5    (polar p4 0.0 c)
            p6    (list (+ (car p5) l1) (- (cadr p5) h1))
            p7    (polar p6 (* pi 1.5) b)
            d     (distance p3 p4)
            f     (- r (sqrt (abs (- (* (* d 0.5) (* d 0.5)) (* r r)))))
            pmid1 (polar p3 (angle p3 p4) (* d 0.5))
            pf1   (polar pmid1 (+ (angle pmid1 p4) (* pi 0.5)) f)
            pmid2 (polar p5 (angle p5 p6) (* d 0.5))
            pf2   (polar pmid2 (+ (angle pmid2 p5) (* pi 0.5)) f)
      )
      (command "_pline" p0 p1 p2 p3 "_A" "_S" pf1 p4 "_L" p5 "_A" "_S" pf2 p6 "_L" p7 "_C")
      (setvar 'OSMODE osm)
    )
  )
  (princ)
)

 

 

Hope this helps,
Henrique

EESignature