Author Topic: Arcs along a LWPolyline  (Read 3686 times)

0 Members and 1 Guest are viewing this topic.

S.Langhammer

  • Guest
Arcs along a LWPolyline
« on: March 19, 2013, 09:03:25 AM »
Hello again!
I'm in quite a mess with my script to read Information from .dwg files to a custom file, considering LWPolylines and arcs.
I got great help from Lee Mac (thanks again) about the conversion of two points and the bulge between them to arc values i can actually work with.
First i tried to transscript the Lisp code to Delphi, but then I decided to edit Lee Macs function a teency bit and do the conversion within Lisp.

Now here's my Problem: when I let my code runs through (the necessary lines following), the last two following points get my "emergency replacement" instead of the actual values of an arc. Also it seams, that the first converted arc isn't added to the list of arcs I create. Might anyone see my Problem?

Code - Auto/Visual Lisp: [Select]
  1.         (setq tmpPntBlgPntLst(list))
  2.         (foreach a entity
  3.                 (if(= (car a) 10)
  4.                         (setq tmpPntBlgPntLst(append tmpPntBlgPntLst(list (cadr a) (caddr a))))
  5.                 )
  6.                 (if(= (car a) 42)
  7.                         (setq tmpPntBlgPntLst(append tmpPntBlgPntLst(list (cdr a))))
  8.                 )
  9.         )
  10.  
  11.         (while (nth 4 tmpPntBlgPntLst)
  12.                 (setq tmpBlg(caddr tmpPntBlgPntLst))
  13.                 (setq tmpPt1(list (car    tmpPntBlgPntLst) (cadr  tmpPntBlgPntLst)))
  14.                 (setq tmpPt2(list (cadddr tmpPntBlgPntLst) (nth 4 tmpPntBlgPntLst)))
  15.                 (if (/= 0 tmpBlg)
  16.                         (setq tmpArcLst (append  tmpArcLst(list(LM:Bulge->Arc tmpPt1 tmpPt2 tmpBlg))))
  17.                         (setq tmpArcLst (append  tmpArcLst(list '(0.0 0.0 0.0 0.0 0.0))))
  18.                 )
  19.                 (setq tmpPntBlgPntLst (cddddr tmpPntBlgPntLst))
  20.         )
  21.        
  22.         (foreach a entity
  23.                 (setq nStr "")
  24.                 (if(= (car a) 10)
  25.                         (progn
  26.                                 (setq nStr(strcat "\n" (rtos(cadr a)2 4)spcr(rtos(caddr a)2 4)))
  27.                         )
  28.                 )
  29.                 (if(= (car a) 42)
  30.                         (progn
  31.                                 (setq nStr(strcat nStr spcr (rtos(cdr a)2 4) spcr))
  32.                                 (if (= nil (atom tmpArcLst))
  33.                                         (progn
  34.                                                 (setq tmpArc (car tmpArcLst))
  35.                                                 (setq tmpX              (rtos (car              tmpArc)2 4))
  36.                                                 (setq tmpY              (rtos (cadr             tmpArc)2 4))
  37.                                                 (setq tmpSAng   (rtos (caddr    tmpArc)2 4))
  38.                                                 (setq tmpEAng   (rtos (cadddr   tmpArc)2 4))
  39.                                                 (setq tmpRad    (rtos (nth 4    tmpArc)2 4))
  40.                                                 (setq nStr(strcat nStr tmpX spcr tmpY spcr tmpSAng spcr tmpEAng spcr tmpRad))
  41.                                                 (setq tmpArcLst (cdr tmpArcLst))
  42.                                         )
  43.                                         (progn
  44.                                                 (setq nStr(strcat nStr "0" spcr "0" spcr "0" spcr "0" spcr "0" spcr "provisional"))
  45.                                         )
  46.                                 )
  47.                         )
  48.                 )
  49.                 (setq pointList(append pointList(list nStr)))
  50.         )
  51.        
  52. ;;; max list index 8
  53. ;; Bulge to Arc - Lee Mac 2012
  54. ;; p1 - start vertex
  55. ;; p2 - end vertex
  56. ;; b  - bulge
  57. ;; Returns: (<centre X> <centre Y> <start angle> <end angle> <radius>) (EDIT)
  58. (defun LM:Bulge->Arc (p1 p2 b / a r c)
  59.         (setq a (* 2 (atan b))
  60.                   r (/ (distance p1 p2) 2 (sin a))
  61.                   c (polar p1 (+ (- (/ pi 2) a) (angle p1 p2)) r)
  62.         )
  63.         (if (minusp b)
  64.                 (list (car c) (cadr c) (angle c p2) (angle c p1) (abs r))       ;;; EDIT: c as floats instead of list
  65.                 (list (car c) (cadr c) (angle c p1) (angle c p2) (abs r))       ;;; EDIT: c as floats instead of list
  66.         )
  67. )
  68.  

For example one of the LWPolylines I tested with gave a result like this:

LWPOLYLINE,0,0,0,1,0,
-1147.9919,-46.9602,0,0,0,0,0,0
-935.5212,-196.4767,0.6809,344.1897,25510.9497,4.6968,4.6912,25515.9977
-720.4273,-54.8295,-1.9278,-21989.396,188.4877,6.2773,6.2582,21994.3349
-361.0632,-209.5922,4.5555,241.0924,402.1413,5.054,4.3984,590.7769
58.6321,-159.7533,-6.047,0,0,0,0,0,provisional
438.9809,-154.5071,-0.2075,0,0,0,0,0,provisional

That the last point gives provisional is not actually a Problem yet, that's an issue to fix later, considering the fact, that I would need the values of the first point again, my focus now is to get the snippet workling correctly, that should make a list of all temporary arcs.

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Arcs along a LWPolyline
« Reply #1 on: March 19, 2013, 09:23:41 AM »
This program may help you: Polyline Information

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Arcs along a LWPolyline
« Reply #2 on: March 19, 2013, 09:33:51 AM »
Two obvious things:

1.
Considering the tmpPntBlgPntLst variable has this format:
(Xcoord Ycoord Bulge Xcoord Ycoord Bulge ...)
On line 19 you should not use cddddr but cdddr

2.
The setq on line 23:
(setq nStr "")
is unnecessary.

S.Langhammer

  • Guest
Re: Arcs along a LWPolyline
« Reply #3 on: March 19, 2013, 09:40:46 AM »
Typpical case of staring at the Point until it turns invisible...
Also Lee Mac, I need to donate to you as soon as I have some spare money!

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Arcs along a LWPolyline
« Reply #4 on: March 19, 2013, 09:49:39 AM »
Also Lee Mac, I need to donate to you as soon as I have some spare money!

You are too kind Steven  :-)

S.Langhammer

  • Guest
Re: Arcs along a LWPolyline
« Reply #5 on: March 19, 2013, 10:00:31 AM »
@Lee Mac:
Don't mention it, you've seriously helped me a lot!
@roy:
the (setq nStr "") becomes necessary, once the handling for closed LWPolylines is implemented or you get this junk for a reasult:

LWPOLYLINE,0,0,0,1,1,NILNILNILNILNILNILNILNILNILNILNILNILNIL
-1147.9919,-46.9602
-1147.9919,-46.9602
-1147.9919,-46.9602
-1147.9919,-46.9602,0,0,0,0,0,0,0
-935.5212,-196.4767
-935.5212,-196.4767
-935.5212,-196.4767
-935.5212,-196.4767,0.6809,-855.8716,-83.2904,4.0992,0.2071,-3.8921,138.4022
-720.4273,-54.8295
-720.4273,-54.8295
-720.4273,-54.8295
-720.4273,-54.8295,-1.9278,-486.2267,-5.6169,5.2628,3.3487,-1.9141,239.3153
-361.0632,-209.5922
-361.0632,-209.5922
-361.0632,-209.5922
-361.0632,-209.5922,4.5555,-97.1909,-639.6171,2.1212,1.2568,-0.8644,504.5295
58.6321,-159.7533
58.6321,-159.7533
58.6321,-159.7533
58.6321,-159.7533,-6.047,241.0924,402.1413,5.054,4.3984,-0.6555,590.7769
438.9809,-154.5071
438.9809,-154.5071
438.9809,-154.5071
438.9809,-154.5071,-0.2075,-230.5228,1728.7663,4.2355,5.054,0.8185,1998.7382
438.9809,-154.5071,-0.2075,-230.5228,1728.7663,4.2355,5.054,0.8185,1998.7382