Jump to content

Lisp for drawing polylines


elfert

Recommended Posts

Hello Users!

 

I am in a need for a lisp that can draw a specific polyline like shown below:

 

weldline.jpg

 

The user have to give:

 

1. User point 1 and 2.

2. Length X

 

About Lisp code:

 

The program the have to figure the out how to draw the Polyline, so i think it have to calculate the y length by it self.

 

Horisontal:

 

- If the user first give the user point 1 and the Point 2 then the lisp command

have to draw the Poly line like shown in the picture 1.

- If the user first give the user point 2 and the Point 1 then the lisp command

have to draw the Poly line like shown in the picture 2.

 

Vertical:

 

- If the user first give the user point 1 and then Point 2. the lisp command

have to draw it like shown on picture 3.

- If the user first give the user point 2 and then Point 1. the lisp command

have to draw it like shown on picture 4.

 

Why i need this:

 

I use the Polylines for a welding signatures on Flatpattern drawings so the welder/Blacksmith knows were he have to weld the x lenght when he/she weld a

Flatbar on a 'Flatpattern' plate.

 

Thanx in advance.

Link to comment
Share on other sites

  • Replies 23
  • Created
  • Last Reply

Top Posters In This Topic

  • elfert

    10

  • Lee Mac

    7

  • Tharwat

    3

  • BIGAL

    2

Top Posters In This Topic

Posted Images

Here is some very simple code:

([color=BLUE]defun[/color] c:zigzag ( [color=BLUE]/[/color] a d i l p q x y )
   
   ([color=BLUE]defun[/color] l ( a b )
       ([color=BLUE]entmake[/color] ([color=BLUE]list[/color] '(0 . [color=MAROON]"LINE"[/color]) ([color=BLUE]cons[/color] 10 a) ([color=BLUE]cons[/color] 11 b)))
   )
   ([color=BLUE]setq[/color] x 10.0
         y 10.0
   )
   ([color=BLUE]if[/color] ([color=BLUE]and[/color]
           ([color=BLUE]setq[/color] p ([color=BLUE]getpoint[/color] [color=MAROON]"\n1st Point: "[/color]))
           ([color=BLUE]setq[/color] q ([color=BLUE]getpoint[/color] [color=MAROON]"\n2nd Point: "[/color] p))
       )
       ([color=BLUE]progn[/color]
           ([color=BLUE]setq[/color] p ([color=BLUE]trans[/color] p 1 0)
                 q ([color=BLUE]trans[/color] q 1 0)
                 a ([color=BLUE]angle[/color] p q)
                 d ([color=BLUE]distance[/color] p q)
                 i ([color=BLUE]/[/color] [color=BLUE]pi[/color] 2.0)
           )
           ([color=BLUE]repeat[/color] ([color=BLUE]fix[/color] ([color=BLUE]/[/color] d x))
               (l p ([color=BLUE]setq[/color] p ([color=BLUE]polar[/color] p a x)))
               (l p ([color=BLUE]setq[/color] p ([color=BLUE]polar[/color] p ([color=BLUE]+[/color] a ([color=BLUE]setq[/color] i ([color=BLUE]-[/color] i))) y)))
           )
           ([color=BLUE]if[/color] ([color=BLUE]not[/color] ([color=BLUE]equal[/color] 0.0 ([color=BLUE]rem[/color] d x) 1e-)
               (l p ([color=BLUE]polar[/color] p a ([color=BLUE]rem[/color] d x)))
           )
       )
   )
   ([color=BLUE]princ[/color])
)

Edited by Lee Mac
Link to comment
Share on other sites

You can do all sorts of pline stuff including arcs I wrote a number of batting routines zig-zag wavy curves etc they work the way you want start-end width, I can not post code copyrited but more than happy to help how to do.

 

Search here for batting there are some examples

 

batter.jpg

Link to comment
Share on other sites

Another with Polyline entity .

Hope you like it . :)

 

(defun c:PolyZag (/ a ang d l p1 p2 p3 p4)
;;; Author: Tharwat Al Shoufi     ;;;
;;; Codes to make zig zag polyline     ;;;
 (vl-load-com)
 (setq x (if x
           *x*
           1.0
         )
 )
 (setq y (if y
           *y*
           1.0
         )
 )
 (if
   (and (setq *x* (cond ((getdist (strcat "\n Specify X segment < "
                                          (rtos x 2 2)
                                          " > :"
                                  )
                         )
                        )
                        (t x)
                  )
        )
        (setq *y* (cond ((getdist (strcat "\n Specify Y segment < "
                                          (rtos y 2 2)
                                          " > :"
                                  )
                         )
                        )
                        (t y)
                  )
        )
        (setq p1 (getpoint "\n Specify start point :"))
        (setq p2 (getpoint "\n Specify next point :" p1))
        (if (< (setq d (distance p1 p2)) *x*)
          (progn
            (alert
              " Distance between points must be bigger than X segment "
            )
            nil
          )
          t
        )
   )
    (progn (setq ang (angle p1 p2)
                 a   '-
                 x   *x*
                 y   *y*
           )
           (setq l (cons p1 l))
           (repeat (fix (/ d *x*))
             (setq l (cons (setq p3 (polar p1 ang *x*)) l))
             (setq l (cons (setq p4 (polar p3
                                           ((if (eq a '-)
                                              (eval (setq a '+))
                                              (eval (setq a '-))
                                            )
                                             ang
                                             (* pi 0.5)
                                           )
                                           *y*
                                    )
                           )
                           l
                     )
             )
             (setq p1 p4)
           )
           (cond ((eq (rem d *x*) 0.0) (setq l (vl-remove (car l) l)))
                 ((not (equal (/ d *x*) 0.0))
                  (setq l (cons (polar p1 ang (rem d *x*)) l))
                 )
           )
           (entmakex
             (append
               (list '(0 . "LWPOLYLINE")
                     '(100 . "AcDbEntity")
                     '(100 . "AcDbPolyline")
                     '(70 . 0)
                     (cons 90 (length l))
               )
               (mapcar '(lambda (x) (cons 10 (list (car x) (cadr x)))) l)
             )
           )
    )
    (princ)
 )
 (princ "\n Written by Tharwat Al Shoufi")
 (princ)
)

Edited by Tharwat
Link to comment
Share on other sites

Nice Replys to all the replys in this thread ! Many thanks...

 

Tha****:

 

- can you do some 'explanation what the code does. Then i could better understand the code and maybe change it.

- if you see my picture you will notice that the y is the horizontal line segment between the x line segments maybe i should have called it X1 one instead then there wasn't a misunderstanding there my fault... But any way the lisp code have to calculate the y line segment by itself.

- The code is asking for the y coordinates from the start point but in the pictures it says it always have to be 20mm.

- The first x line segment and the last x line segment have to have the same y-coordiantes like shown on the picture.

- The way that the poly turns direction depending on witch way the user gives the start and end point seams working..thanks!

 

Thanx forum members....

Link to comment
Share on other sites

Here's a fun one for you to play with:

 

[color=GREEN];; Dynamic Zig-Zag  -  Lee Mac[/color]

([color=BLUE]defun[/color] c:zz ( [color=BLUE]/[/color] a d g i l p q r x y )
   ([color=BLUE]setq[/color] x 10.0
         y 10.0
         i ([color=BLUE]/[/color] [color=BLUE]pi[/color] 2.0)
   )
   ([color=BLUE]if[/color] ([color=BLUE]setq[/color] p ([color=BLUE]getpoint[/color] [color=MAROON]"\nSpecify 1st Point: "[/color]))
       ([color=BLUE]progn[/color]
           ([color=BLUE]princ[/color] [color=MAROON]"\nSpecify 2nd Point [+/-] <Exit>: "[/color])
           ([color=BLUE]while[/color]
               ([color=BLUE]progn[/color]
                   ([color=BLUE]setq[/color] g ([color=BLUE]grread[/color] [color=BLUE]t[/color] 15 0)
                         q ([color=BLUE]cadr[/color] g)
                         g ([color=BLUE]car[/color]  g)
                   )
                   ([color=BLUE]cond[/color]
                       (   ([color=BLUE]member[/color] g '(3 5))
                           ([color=BLUE]redraw[/color])
                           ([color=BLUE]setq[/color] a ([color=BLUE]angle[/color] p q)
                                 d ([color=BLUE]distance[/color] p q)
                                 i ([color=BLUE]abs[/color] i)
                                 r p
                           )
                           ([color=BLUE]repeat[/color] ([color=BLUE]fix[/color] ([color=BLUE]/[/color] d x))
                               ([color=BLUE]grdraw[/color] r ([color=BLUE]setq[/color] r ([color=BLUE]polar[/color] r a x)) 1 1)
                               ([color=BLUE]grdraw[/color] r ([color=BLUE]setq[/color] r ([color=BLUE]polar[/color] r ([color=BLUE]+[/color] a ([color=BLUE]setq[/color] i ([color=BLUE]-[/color] i))) y)) 1 1)
                           )
                           ([color=BLUE]if[/color] ([color=BLUE]not[/color] ([color=BLUE]equal[/color] 0.0 ([color=BLUE]rem[/color] d x) 1e-)
                               ([color=BLUE]grdraw[/color] r ([color=BLUE]polar[/color] r a ([color=BLUE]rem[/color] d x)) 1 1)
                           )
                           ([color=BLUE]=[/color] 5 g)
                       )
                       (   ([color=BLUE]=[/color] 2 g)
                           ([color=BLUE]cond[/color]
                               (   ([color=BLUE]member[/color] q '(43 61))
                                   ([color=BLUE]setq[/color] x ([color=BLUE]1+[/color] x))
                               )
                               (   ([color=BLUE]member[/color] q '(45 95))
                                   ([color=BLUE]setq[/color] x ([color=BLUE]max[/color] ([color=BLUE]1-[/color] x) 1))
                               )
                           )
                       )
                   )
               )
           )
           ([color=BLUE]if[/color] ([color=BLUE]=[/color] 3 g)
               ([color=BLUE]progn[/color]
                   ([color=BLUE]setq[/color] i ([color=BLUE]abs[/color] i)
                         p ([color=BLUE]trans[/color] p 1 0)
                         q ([color=BLUE]trans[/color] q 1 0)
                         a ([color=BLUE]angle[/color] p q)
                   )
                   ([color=BLUE]repeat[/color] ([color=BLUE]fix[/color] ([color=BLUE]/[/color] d x))
                       ([color=BLUE]setq[/color] l ([color=BLUE]cons[/color] ([color=BLUE]cons[/color] 10 p) l)
                             l ([color=BLUE]cons[/color] ([color=BLUE]cons[/color] 10 ([color=BLUE]setq[/color] p ([color=BLUE]polar[/color] p a x))) l)
                             l ([color=BLUE]cons[/color] ([color=BLUE]cons[/color] 10 ([color=BLUE]setq[/color] p ([color=BLUE]polar[/color] p ([color=BLUE]+[/color] a ([color=BLUE]setq[/color] i ([color=BLUE]-[/color] i))) y))) l)
                       )
                   )
                   ([color=BLUE]if[/color] ([color=BLUE]not[/color] ([color=BLUE]equal[/color] 0.0 ([color=BLUE]rem[/color] d x) 1e-)
                       ([color=BLUE]setq[/color] l ([color=BLUE]cons[/color] ([color=BLUE]cons[/color] 10 ([color=BLUE]polar[/color] p a ([color=BLUE]rem[/color] d x))) l))
                   )
                   ([color=BLUE]entmake[/color]
                       ([color=BLUE]append[/color]
                           ([color=BLUE]list[/color]
                              '(000 . [color=MAROON]"LWPOLYLINE"[/color])
                              '(100 . [color=MAROON]"AcDbEntity"[/color])
                              '(100 . [color=MAROON]"AcDbPolyline"[/color])
                               ([color=BLUE]cons[/color] 90 ([color=BLUE]length[/color] l))
                              '(70 . 0)
                           )
                           ([color=BLUE]reverse[/color] l)
                       )
                   )
               )
           )
           ([color=BLUE]redraw[/color])
       )
   )
   ([color=BLUE]princ[/color])
)

 

Example:

 

ZigZag.gif

Link to comment
Share on other sites

Thanks Lee Mac ...but...it was not spot on.

 

I will try to explain again:

 

New weldline with colors.jpg

 

The User have to give the following:

 

- length of one of the horizontal x line segment. (Marked red)

- start point. (Marked red)

- end point. (Marked red)

 

1. The code have calculate the horizontal y line segments when the user have given start and end point. It not important how long y is. (Marked green)

2. At the start point it has to be a X line segment and just before endpoint there has to be a Horizontal X line segment.

3. The distance between X line segment and Y line segment is vertical always 20mm.

4. The poly line have to change direction according to the first post i write in this thread.

 

Thx in advance...Lee Mac.

Edited by elfert
failure
Link to comment
Share on other sites

Great codes Lee . :thumbsup:

 

elfert , why do not you give yourself a favor and try to learn from the plenty examples in this post ?

 

LEE MAC i am sorry if i did't 'a one step to far' in the last post. I wasn't a bad code you made there but i wasn't what am i seeking. I would try to fool around / change it. But i would be more easy task if the was a. ;;Explanation to every line what i does. :oops:

 

And to Tharwat:

 

Actually You code wasn't far of what i am seeking...and i could try to fool around/ change it but i would be more easy if the there was an ;;Explanation to every line what i does. I asked about this see page 1:

 

Tha****:

 

- can you do some 'explanation what the code does. Then i could better understand the code and maybe change it.

I also know this is not a free lisp code forum ... every body have to learn and work to make it function.

It would be a hard job to decipher every line of code to novice user like me.

 

Sorry guys :oops:

Link to comment
Share on other sites

Start learning by brushing up on the polar command this works out the next point along the pline.

 

newpt = (Polar pt angle distance)

 

Some more hints take pt1 pt2 get the "distance" between them divide by the horizontal step length this is how many times you need to "repeat" horizontal line, your line type is made of 4 steps right, up, right, down and a last step the remainder line.

 

Then your proceedure becomes pt1 pt2 height width right up right down right up right down and so on you start the pline command and do a repeat for as many as required.

 

Lee as usual has taken the project to a top level and enhanced it by allowing drag.

Link to comment
Share on other sites

1. The code have calculate the horizontal y line segments when the user have given start and end point. It not important how long y is. (Marked green)

 

Unless there is a specified number of 'x' segments of a given length, the calculated 'y' segments will be simply the division of the remainder of the distance between the two picked points divided by the length of the 'x' segments, by the number of 'x' segments minus one - this will be a small distance indeed.

 

Great codes Lee . :thumbsup:

 

Many thanks Tharwat :)

Link to comment
Share on other sites

Unless there is a specified number of 'x' segments of a given length, the calculated 'y' segments will be simply the division of the remainder of the distance between the two picked points divided by the length of the 'x' segments, by the number of 'x' segments minus one - this will be a small distance indeed.

 

To demonstrate this point:

 

([color=BLUE]defun[/color] c:zigzag ( [color=BLUE]/[/color] a d h i l n p q x y )
   ([color=BLUE]setq[/color] x 10.0
         h 20.0
   )
   ([color=BLUE]if[/color] ([color=BLUE]and[/color]
           ([color=BLUE]setq[/color] p ([color=BLUE]getpoint[/color] [color=MAROON]"\n1st Point: "[/color]))
           ([color=BLUE]setq[/color] q ([color=BLUE]getpoint[/color] [color=MAROON]"\n2nd Point: "[/color] p))
           ([color=BLUE]setq[/color] p ([color=BLUE]trans[/color] p 1 0)
                 q ([color=BLUE]trans[/color] q 1 0)
                 a ([color=BLUE]angle[/color] p q)
                 d ([color=BLUE]distance[/color] p q)
                 i ([color=BLUE]/[/color] [color=BLUE]pi[/color] 2.0)
                 n ([color=BLUE]fix[/color] ([color=BLUE]/[/color] d x))
           )
       )
       ([color=BLUE]if[/color] ([color=BLUE]<[/color] 1 n)
           ([color=BLUE]progn[/color]
               ([color=BLUE]setq[/color] y ([color=BLUE]/[/color] ([color=BLUE]rem[/color] d x) ([color=BLUE]1-[/color] n)))
               ([color=BLUE]repeat[/color] ([color=BLUE]1-[/color] n)
                   ([color=BLUE]setq[/color] l ([color=BLUE]cons[/color] ([color=BLUE]cons[/color] 10 p) l)
                         l ([color=BLUE]cons[/color] ([color=BLUE]cons[/color] 10 ([color=BLUE]setq[/color] p ([color=BLUE]polar[/color] p a x))) l)
                         l ([color=BLUE]cons[/color] ([color=BLUE]cons[/color] 10 ([color=BLUE]setq[/color] p ([color=BLUE]polar[/color] p ([color=BLUE]-[/color] a i) h))) l)
                         l ([color=BLUE]cons[/color] ([color=BLUE]cons[/color] 10 ([color=BLUE]setq[/color] p ([color=BLUE]polar[/color] p a y))) l)
                         l ([color=BLUE]cons[/color] ([color=BLUE]cons[/color] 10 ([color=BLUE]setq[/color] p ([color=BLUE]polar[/color] p ([color=BLUE]+[/color] a i) h))) l)
                   )
               )
               ([color=BLUE]entmake[/color]
                   ([color=BLUE]append[/color]
                       ([color=BLUE]list[/color]
                          '(000 . [color=MAROON]"LWPOLYLINE"[/color])
                          '(100 . [color=MAROON]"AcDbEntity"[/color])
                          '(100 . [color=MAROON]"AcDbPolyline"[/color])
                           ([color=BLUE]cons[/color] 90 ([color=BLUE]1+[/color] ([color=BLUE]length[/color] l)))
                          '(70 . 0)
                       )
                       ([color=BLUE]reverse[/color] ([color=BLUE]cons[/color] ([color=BLUE]cons[/color] 10 ([color=BLUE]polar[/color] p a x)) l))
                   )
               )
           )
           ([color=BLUE]princ[/color] [color=MAROON]"\nDistance too small."[/color])
       )
   )
   ([color=BLUE]princ[/color])
)

 

[ rather messy code ]

Link to comment
Share on other sites

Thanks Lee Mac that's a great code you made there..i took the liberty to change some of it that part of it that i have little knowledge to change.

 

(defun c:zigzag ( / a d h i l n p q x y )
   (setq h 20.0)
   (if (and
           (setq x (getreal "\nWeld legnth: "))
           (setq p (getpoint "\n1st Point: "))
           (setq q (getpoint "\n2nd Point: " p))
           (setq p (trans p 1 0)
                 q (trans q 1 0)
                 a (angle p q)
                 d (distance p q)
                 i (/ pi 2.0)
                 n (fix (/ d x))
              )
       )
       (if (< 1 n)
           (progn
               (setq y (/ (rem d x) (1- n)))
               (repeat (1- n)
                   (setq l (cons (cons 10 p) l)
                         l (cons (cons 10 (setq p (polar p a x))) l)
                         l (cons (cons 10 (setq p (polar p (- a i) h))) l)
                         l (cons (cons 10 (setq p (polar p a y))) l)
                         l (cons (cons 10 (setq p (polar p (+ a i) h))) l)
                   )
               )
               (entmake
                   (append
                       (list
                          '(000 . "LWPOLYLINE")
                          '(100 . "AcDbEntity")
                          '(100 . "AcDbPolyline")
                           (cons 90 (1+ (length l)))
                          '(70 . 0)
                       )
                       (reverse (cons (cons 10 (polar p a x)) l))
                   )
               )
           )
           (princ "\nDistance too small.")
       )
   )
   (princ)
)

You right about that the y line segment is very small. But i need the to change the code so the y line segment is calculate like in this example:

 

Let we say that the distance between the 1 point and 2 point is 160mm.

The weld length is 25mm. (X line segment)

Then code should calculate the y line segment to be 20mm.

 

Hope this help!

 

I have read...and...read...but i simple can't find the place to change the code please....please....help.

Link to comment
Share on other sites

Let we say that the distance between the 1 point and 2 point is 160mm.

The weld length is 25mm. (X line segment)

Then code should calculate the y line segment to be 20mm.

 

Unless I'm overlooking something obvious, by what relationship are you calculating the length of Y to be 20mm?

 

80% of X?

 

160/25 = 6.4, 6x25 = 150, 160-150 = 10, 10x2 = 20?

Link to comment
Share on other sites

Unless I'm overlooking something obvious, by what relationship are you calculating the length of Y to be 20mm?

 

80% of X?

 

160/25 = 6.4, 6x25 = 150, 160-150 = 10, 10x2 = 20?

 

First i need to find out how many X line segments i need between the 2 points:

 

160/2 = 80 , 80/25 = 3.2 , (3+1) = 4 line segments.

 

Second i need to out how many Y line segments i need between the 2 points:

 

160/25 = 6,4 this i round off to 6, (6+1) - 4 line segments = 3 line segments.

 

This means that the length of y line segment is.

 

160-(4x25)=60 , 60/3=20mm.

 

Check if i am correct: (4*25)+(3*20) = 160mm. yes it fits.

 

I hope this helps....Thx lee mac.

Link to comment
Share on other sites

Simplifying your calculations, try this quick mod:

 

([color=BLUE]defun[/color] c:zigzag ( [color=BLUE]/[/color] a d h i l n p q x y )
   ([color=BLUE]setq[/color] h 20.0)
   ([color=BLUE]if[/color] ([color=BLUE]and[/color]
           ([color=BLUE]setq[/color] x ([color=BLUE]getdist[/color] [color=MAROON]"\nWeld Length: "[/color]))
           ([color=BLUE]setq[/color] p ([color=BLUE]getpoint[/color] [color=MAROON]"\n1st Point: "[/color]))
           ([color=BLUE]setq[/color] q ([color=BLUE]getpoint[/color] [color=MAROON]"\n2nd Point: "[/color] p))
           ([color=BLUE]setq[/color] p ([color=BLUE]trans[/color] p 1 0)
                 q ([color=BLUE]trans[/color] q 1 0)
                 a ([color=BLUE]angle[/color] p q)
                 d ([color=BLUE]distance[/color] p q)
                 i ([color=BLUE]/[/color] [color=BLUE]pi[/color] 2.0)
                 n ([color=BLUE]fix[/color] ([color=BLUE]/[/color] d x 2.0))
           )
       )
       ([color=BLUE]if[/color] ([color=BLUE]<[/color] 0 n)
           ([color=BLUE]progn[/color]
               ([color=BLUE]setq[/color] y ([color=BLUE]/[/color] ([color=BLUE]-[/color] d ([color=BLUE]*[/color] x ([color=BLUE]1+[/color] n))) n))
               ([color=BLUE]repeat[/color] n
                   ([color=BLUE]setq[/color] l ([color=BLUE]cons[/color] ([color=BLUE]cons[/color] 10 p) l)
                         l ([color=BLUE]cons[/color] ([color=BLUE]cons[/color] 10 ([color=BLUE]setq[/color] p ([color=BLUE]polar[/color] p a x))) l)
                         l ([color=BLUE]cons[/color] ([color=BLUE]cons[/color] 10 ([color=BLUE]setq[/color] p ([color=BLUE]polar[/color] p ([color=BLUE]-[/color] a i) h))) l)
                         l ([color=BLUE]cons[/color] ([color=BLUE]cons[/color] 10 ([color=BLUE]setq[/color] p ([color=BLUE]polar[/color] p a y))) l)
                         l ([color=BLUE]cons[/color] ([color=BLUE]cons[/color] 10 ([color=BLUE]setq[/color] p ([color=BLUE]polar[/color] p ([color=BLUE]+[/color] a i) h))) l)
                   )
               )
               ([color=BLUE]entmake[/color]
                   ([color=BLUE]append[/color]
                       ([color=BLUE]list[/color]
                          '(000 . [color=MAROON]"LWPOLYLINE"[/color])
                          '(100 . [color=MAROON]"AcDbEntity"[/color])
                          '(100 . [color=MAROON]"AcDbPolyline"[/color])
                           ([color=BLUE]cons[/color] 90 ([color=BLUE]1+[/color] ([color=BLUE]length[/color] l)))
                          '(70 . 0)
                       )
                       ([color=BLUE]reverse[/color] ([color=BLUE]cons[/color] ([color=BLUE]cons[/color] 10 ([color=BLUE]polar[/color] p a x)) l))
                   )
               )
           )
           ([color=BLUE]princ[/color] [color=MAROON]"\nDistance too small."[/color])
       )
   )
   ([color=BLUE]princ[/color])
)

Link to comment
Share on other sites

Thanks lee mac for the last code that is was seeking in last week. (Great)

 

But to my surprise on Thursday i have to make another routine where the user guess a length between x line segment. I called this line segment y1. Then the code have to calculate the y line segment and add this to the y1 line segment to give the the space between the x line segments.

 

An example:

 

User input:

Distance between 1 st. point and 2.nd is 135mm.

Weld length x is 25mm.

A guess weld length y1 is 20mm

 

Lisp routine:

- Then the code should calculate the y line segment to 10mm and draw the polyline.

 

I have tried to make some change to code but no luck:

 

(defun c:wzz ( / a d h i l n p q x y y1)
   (setq h 20.0)
   (if (and
           (setq x  (getdist "\nWeld Length: "))
           (setq y1 (getreal "\nGuess a Weld length space: "))
           (setq p (getpoint "\n1st Point: "))
           (setq q (getpoint "\n2nd Point: " p))
           (setq p (trans p 1 0)
                 q (trans q 1 0)
                 a (angle p q)
                 d (distance p q)
                 i (/ pi 2.0)
                 n (fix (/ d (x+y1)))
           )
       )
       (if (< 0 n)
           (progn
               (setq y (/ (- d (* x (1+ n))) n))
               (repeat n
                   (setq l (cons (cons 10 p) l)
                         l (cons (cons 10 (setq p (polar p a x))) l)
                         l (cons (cons 10 (setq p (polar p (- a i) h))) l)
                         l (cons (cons 10 (setq p (polar p a y))) l)
                         l (cons (cons 10 (setq p (polar p (+ a i) h))) l)
                   )
               )
               (entmake
                   (append
                       (list
                          '(000 . "LWPOLYLINE")
                          '(100 . "AcDbEntity")
                          '(100 . "AcDbPolyline")
                           (cons 90 (1+ (length l)))
                          '(70 . 0)
                       )
                       (reverse (cons (cons 10 (polar p a x)) l))
                   )
               )
           )
           (princ "\nDistance too small.")
       )
   )
   (princ)
)

I pretty sure that math is something like this:

 

n=d/x+y1+y

y=((d-x)/n)-(x+y1)

 

This means from

 

d=135mm x=25mm y1=20mm

 

n=135/25+20+10=2,4545 = 2.

y=((135-25)/2)-(25+20)=10mm.

 

Please help!

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...