Jump to content

How To Join Lines and Arcs Into Polyline


Bill Tillman

Recommended Posts

I have a rather simple task that I made good progress on until...

 

The task was to come up with a lisp routine that would draw a section view of various steel angles. That wasn't too hard but now I need to join all the lines and arcs into a single entity so I can copy, mirror, move, etc...with ease.

 

Now, all of you who know of my "Totally Automated" program remember that this is exactly that. Totally automated. No user input allowed. That said, here is how far I've got:

(defun DrawAngleSection ( pt l1 l2 angThk)
 (command-s "._CLAYER" "Angles")
 (setq a90 (dtr 90.) a270 (dtr 270.))
 (command-s "._LINE"
   (polar pt a270 (- angThk (- angThk 0.0625))) pt (polar pt 0 l1) (polar (polar pt 0 l1) a270 l2) (polar (polar pt 0 (- l2 (- angThk (- angThk 0.0625)))) a270 l1) "")
 (command-s "._LINE"
   (polar (polar pt 0 (- angThk 0.0625)) a270 angThk) (polar (polar pt 0 (- l1 (* angThk 2))) a270 angThk) "")
 (command-s "._LINE"    
   (polar (polar pt 0 (- l1 angThk)) a270 (* angThk 2)) (polar (polar pt 0 (- l1 angThk)) a270 (- l2 (- angThk 0.0625))) "")

 (Arc
   (polar (polar pt 0 (- angThk 0.0625)) a270 (- angThk (- angThk 0.0625)))
   (- angThk 0.0625)
   pi
   a270
   )

 (Arc
   (polar (polar pt 0 (- l2 (- angThk (- angThk 0.0625)))) a270 (- l1 (- angThk 0.0625)))
   (- angThk 0.0625)
   pi
   a270
   )

 (Arc
   (polar (polar pt 0 (- l1 (* angThk 2))) a270 (* angThk 2))
   angThk
   0
   a90
   )

 (setq x (sssetfirst nil (ssget "X" (list (cons 8 (getvar "clayer"))))))

[color=red] ;;; HERE'S WHERE I GET LOST. HOW DO I GATHER ALL THIS UP AND
;;; CREATE A SINGLE POLYLINE, OR EVEN SHOVE IT INTO A BLOCK
;;; ANY WAY SO I CAN DO THINGS WITH IT AS A SINGLE OBJECT....  [/color]

 (princ)
 ); end DrawAngleSection


(defun Arc (cen rad sAng eAng)
 (entmakex (list (cons 0 "ARC")
                 (cons 10  cen)
                 (cons 40  rad)
                 (cons 50 sAng)
                 (cons 51 eAng))))

(defun dtr ( deg ) (* pi (/ deg 180.0)))

 

BTW...I still have work on this to do as it doesn't work well with angles with unequal legs.

Link to comment
Share on other sites

  • Replies 23
  • Created
  • Last Reply

Top Posters In This Topic

  • Bill Tillman

    12

  • BIGAL

    6

  • Stefan BMR

    6

Top Posters In This Topic

Posted Images

Add this line after (setq x (ssgetfirst ....

(command-s "_pedit" "_m" (cadr x) "" "_y" "_j" "" "")

To fix your unequal angles, the last point in the second line should be

(polar (polar (polar pt 0 l1) a270 l2) 0.0 -0.0625)

and the center point of the second arc should be

(polar (polar (polar (polar pt 0 l1) a270 l2) 0.0 -0.0625) a90 (- angThk 0.0625))

Of course, you can always take the entmake route

(defun DrawAngleSection ( pt l1 l2 angThk)
 (entmakex
   (list
     '(  0 . "LWPOLYLINE")
     '(  8 . "Angles")
     '(100 . "AcDbEntity")
     '(100 . "AcDbPolyline")
     '( 90 . 9)
     '( 70 . 1)
     (list 10 0.0 0.0)
     (list 10 0.0 (* -0.4 angThk))
     (cons 42 (- (sqrt 2.0) 1))
     (list 10 (* 0.6 angThk) (- angThk))
     (list 10 (- l1 (* 2.2 angThk)) (- angThk))
     (cons 42 (- 1 (sqrt 2.0)))
     (list 10 (- l1 angThk) (* -2.2 angThk))
     (list 10 (- l1 angThk) (- (* 0.6 angThk) l2))
     (cons 42 (- (sqrt 2.0) 1))
     (list 10 (- l1 (* 0.4 angThk)) (- l2))
     (list 10 l1 (- l2))
     (list 10 l1 0.0)
     )
   )
 (command-s "_move" (entlast) "" "_non" '(0 0 0) "_non" pt)
 (sssetfirst nil (ssadd (entlast) (ssadd)))
 )

Edited by Stefan BMR
Link to comment
Share on other sites

Thanks Stefan, I actually fixed my problem with the shape with unequal legs slightly different. But when I tried out the entmakex function, I'm home. This is a once in a blue moon need. We typically use a real steel shape LISP for this stuff but being totally automated I don't have that luxury. The entmakex routine works fine.

Edited by Bill Tillman
Link to comment
Share on other sites

Thanks Stefan, I actually fixed my problem with the shape with unequal legs slightly different. But when I tried out the entmakex function, I home. This is a once in a blue moon need. We typically use a real steel shape LISP for this stuff but being totally automated I don't have that luxury. The entmakex routine works fine.

I'm glad to hear that. Anyway, my Pedit sample was wrong... I will update my firs replay.

Link to comment
Share on other sites

Maybe a different way make 1st object a pline then as you add your lines and arcs use this (setq objs (cons (entlast) objs)) this make a list of the object names and you can use Pedit to join them up.

Link to comment
Share on other sites

Hey BigAl, thanks for chiming in. That's one of the cool things about AutoCAD is there's always more than one way of doing things. But while I'm here let me ask for a quick explanation on the entmakex method which Stefan BMR posted. I went through it one line at a time and understand most of it. But what I only kind of understand is the bulge parts...I'm going to be reading up on that more in the morning. Or in your part of the planet, night...!

Link to comment
Share on other sites

Okay, now that I look at it more, I see that having some of the vertices in a list will make it easy to draw another object that's going to be fit right in the profile. What I'd be after is vertices #3, #4, #5 and #6.

Link to comment
Share on other sites

Some pline code

 

; 90 mm 25 arc's with straights
(command "pLINE"  p2 "w" 0.0 0.0)
(setq m 0)
(while (< m N)
 (setq p3 (polar p2 ang1 d2))
 (setq p4 (polar p3 ang1 d2))
 (setq p5 (polar (polar p3 ang1 20)(+ ang1 4.71239) d3))
 (setq p6 (polar p5 ang1 d2 ))
 (setq p7 (polar p6 ang1 d2))
 (setq p8 (polar p4  ang1 d4))
(command "a" "ce" p3 "a" "-180" "l" p5 "a" "ce" p6 p7 "l" p8)
; parallel lines now drawn
 (setq m (+ 1 m))
 (setq p2 p8)
)
 (command "")   
; ends pline

Link to comment
Share on other sites

Hey BigAl, thanks for chiming in. That's one of the cool things about AutoCAD is there's always more than one way of doing things. But while I'm here let me ask for a quick explanation on the entmakex method which Stefan BMR posted. I went through it one line at a time and understand most of it. But what I only kind of understand is the bulge parts...I'm going to be reading up on that more in the morning. Or in your part of the planet, night...!

Hi Bill.

From autocad reference

The bulge is the tangent of 1/4 of the included angle for the arc between the selected vertex and the next vertex in the polyline's vertex list. A negative bulge value indicates that the arc goes clockwise from the selected vertex to the next vertex.
In your case, the angle is a = 90 deg, a/4 = 22.5, tan(22.5) = sqrt(2)-1.

For the clockwise arc, the bulge value is negative, so - (sqrt(2) - 1) = 1-sqrt(2).

Link to comment
Share on other sites

I ended up capturing the points I needed like this:

(setq temp (vlax-get (vlax-ename->vla-object (entlast)) 'Coordinates)
   sp1 (list (nth 8 temp) (nth 9 temp))
   sp2 (list (nth 6 temp) (nth 7 temp))
   )

Link to comment
Share on other sites

  • 4 weeks later...

The method that Stefan MBR posted for drawing the angle worked really slick so I'm trying to use it for another object I need drawn. The other object is the plan view of an angle with radiused corners. Here is the code I've got so far:

(defun DrawPlanofAngle (l thk w)
 (entmakex
   (list
     '(0 . "LWPOLYLINE")
     '(8 . "0")
     '(100 . "AcDbEntity")
     '(100 . "AcDbPolyline")
     '(90 . 6)
     '(70 . 1)
     (list 10 0.0 0.0)
     (list 10 (- w 0.25) 0.0)
     (cons 42 (- 1 (sqrt 2.0)))
     (list 10 w -0.25)
     (list 10 w (* (- l thk) -1))
     (cons 42 (- 1 (sqrt 2.0)))
     (list 10 (- w 0.25) (* l -1))
     (list 10 0.0 (* l -1))      
   )
 )
 ); end DrawPlanofAngle

Works pretty good but I'm stumped with a few last things. I need to include another line that will represent the thickness of the leg that you will see in the plan view of this angle. And the code also draws the thing at '(0.0 0.0) and then moves the completed polyline to the desired point. I was hoping to get this thing to draw it at the desired point from the get-go, and I think I can get that done. But how I could include the other line is where I'm lost. I can of course draw it but then if I move it I loose it. So I was trying to make that line part of the same polyline but again, that starts to become inefficient, IMHO. Here are some sketches which should explain my point.

PlanofAngle.jpg

Link to comment
Share on other sites

Okay, figured out the problem with the location but still working this morning on getting that second line into the mix. I guess I could draw the line and then make a group of the two items. But I'm thinking that I could just overlap a short line segment and create it all as one polyline. More to come.

(defun DrawPlanofAngle (pt l thk w)
 (entmakex
   (list
     '(0 . "LWPOLYLINE")
     '(8 . "0")
     '(100 . "AcDbEntity")
     '(100 . "AcDbPolyline")
     '(90 . 
     '(70 . 1)
     (list 10 (car pt) (cadr pt))
     (list 10 (- (+ (car pt) w) 0.25) (cadr pt))
     (cons 42 (- 1 (sqrt 2.0)))
     (list 10 (+ (car pt) w) (- (cadr pt) 0.25))
     (list 10 (+ (car pt) w) (- (cadr pt) l -0.25))
     (cons 42 (- 1 (sqrt 2.0)))
     (list 10 (- (+ (car pt) w) 0.25) (- (cadr pt) l))
     (list 10 (car pt) (- (cadr pt) l))
   )
 )
 ); end DrawPlanofAngle

Link to comment
Share on other sites

I would go the overlap easier to work out and edit than a region. A very complicated pline could be drawn so to not have a overlap.

 

Puzzle of the day draw a 3x3 grid of circles connect all nine circles with 1 pline of 4 segments, pen and paper is a bit easier do not lift pen till 4 lines.

Link to comment
Share on other sites

Hey BIGAL, good morning to you down under from the USA. By George, I think I have it...and in LISP.

(defun c:BIGAL ()
 (setq origin '(0.0 0.0 0.0)
  a90 (dtr 90.)
  a270 (dtr 270.)
  )
 (setvar 'CECOLOR "Yellow")
 (command-s "._CIRCLE" origin 0.25 "")
 (command-s "._ARRAYRECT" (entlast) "" "COL" 3 3 "R" 3 1.5 "" "")

 (setvar 'CECOLOR "Red")
 (command-s ".PLINE"
   (polar origin 0 3)
   (polar origin a90 3)
   (polar (polar origin a90 3) 0 4.5)
   (polar origin a270 1.5)
   (polar origin a90 3) "")

 (setvar 'CECOLOR "ByLayer")  
 (command-s "._ZOOM" "E")
 (princ)
 ); end bal
 
(defun dtr (deg) (* pi (/ deg 180.)))

I just have one question about this. I wanted the centers of the circles to be 1.5 on center but to achieve this I had to set the distance between the columns of the array at 3 not 1.5 ??? Anyway, here's my solution. As always it will be cool to see how others would do it.

Link to comment
Share on other sites

(defun c:rebigal ( / i)      
 (setq i 0)
 (repeat 9
   (entmake (list '(0 . "CIRCLE") '(62 . 3) (list 10 (rem i 3) (/ i 3)) '(40 . 0.1)))
   (setq i (1+ i))
 )
 (entmake
  '(
     (0 . "LWPOLYLINE") (100 . "AcDbEntity") (100 . "AcDbPolyline")
     (62 . 1) (90 . 5) (70 . 0)
     (10 0 1) (10 0 3) (10 3 0) (10 0 0) (10 2 2)
   )
 )
 (command "_zoom" '(-1 -1) '(4 4))
 (princ)
)

Link to comment
Share on other sites

  • 1 month later...

Having to revisit this one. Just when I thought I had it all figured out I keep running into a "Bad DXF Code" error. I'm trying to draw the shape in the enclosed drawing. It will vary depending on some input parameters but for now I'm just hard coding everything in order to get it working. The LISP code I've got so far is like so:

(vl-load-com)

(defun dtr ( deg ) (* pi (/ deg 180.0)))

(defun C:DrawIt ()
 
 (setq a90 (dtr 90.)
         a270 (dtr 270.)    
         pt1 '(0.0 0.0 0.0)
         pt2 (polar pt1 0 62)
   )

  (DrawShape pt1 pt2)  

  (princ)
 ); end DrawIt

(defun DrawShape (pt01 pt02)
 (entmakex
   (list
     '(0 . "LWPOLYLINE")
     '(8 . "0")
     '(100 . "AcDbEntity")
     '(100 . "AcDbPolyline")
     '(90 . 16)
     '(70 . 1)

     ;;; 1
     (list 10 (- 8 (car pt01)) (+ 2.29 (cadr pt01)))
     ;;; 2
     (list 10 (- 8 (car pt01)) (+ 2.29 (cadr pt01)))
     ;;; 3
     (list 10 (+ 1.375 (car pt01)) (cadr pt01))
     ;;; 3
     (list 10 (+ 1.375 (car pt01)) (+ 0.3125) (cadr pt01))

     (cons 42 (- 1 (sqrt 2.0)))
     
     ;;; 5
     (list 10 (+ 1.625 (car pt01)) (+ 0.5625 (cadr pt01)))
     ;;; 6
     (list 10 (+ 4.375 (car pt01)) (+ 0.5625 (cadr pt01)))

     (cons 42 (- 1 (sqrt 2.0)))

     ;;; 7
     (list 10 (+ 4.625 (car pt01)) (+ 0.3125 (cadr pt01)))
     ;;; 8
     (list 10 (+ 4.625 (car pt01)) (cadr pt01))
     ;;; 9
     (list 10 (- (car pt02) 4.625) (cadr pt02))
     ;;; 10
     (list 10 (- (car pt02) 4.625) (+ (cadr pt02) 0.3125))

     (cons 42 (- 1 (sqrt 2.0)))
     
     ;;; 11
     (list 10 (- (car pt02) 4.375) (+ (cadr pt02) 0.5625))
     ;;; 12
     (list 10 (- (car pt02) 1.625) (+ (cadr pt02) 0.5625))

     (cons 42 (- 1 (sqrt 2.0)))
     
     ;;; 13
     (list 10 (- (car pt02) 1.375) (+ (cadr pt02) 0.3125))
     ;;; 14
     (list 10 (- (car pt02) 1.375) (cadr pt02))
     ;;; 15
     (list 10 (+ (car pt02)  (cadr pt02))
     ;;; 16
     (list 10 (+ (car pt02)  (+ (cadr pt02) 2.29))
     )
   )

 ); end DrawShape

Shape01.dwg

Link to comment
Share on other sites

1st Did you have a look at "Alssteelmill" its steel sections with lisps etc.

 

2nd have you had a look at "Dynamic blocks" 1 angle and use a look up for all the relevant details which alters to correct size. Same with plan views etc

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