TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: venus on September 26, 2005, 06:04:06 PM

Title: Convert Polylines to lines
Post by: venus on September 26, 2005, 06:04:06 PM
Hey all,
I've got a bunch of plines in an old drawing that are "non coplanar" - I'm not able to fillet them and flattening them turns the entire drawing into a jumbled mess.  Is there a way to convert them into lines and have them be coplanar?  Any better suggestions?
Thanks
Title: Re: Convert Polylines to lines
Post by: Bob Wahr on September 26, 2005, 06:14:27 PM
what about changing the elevation property?
.CHANGE
ALL
P
E
0 (zero not o)
Title: Re: Convert Polylines to lines
Post by: venus on September 26, 2005, 06:18:28 PM
Thanks for the suggestion Bob but it didn't work - when I attempt to fillet them, they're still non coplanar.
Title: Re: Convert Polylines to lines
Post by: Bob Wahr on September 26, 2005, 06:30:16 PM
Wierd.  I thought that would work.  Any way you can email it to me to play with?
Title: Re: Convert Polylines to lines
Post by: CAB on September 26, 2005, 06:55:09 PM
Have you tried this routine to flatten the plines?
http://www.theswamp.org/forum/index.php?topic=1176.msg15206#msg15206
Title: Re: Convert Polylines to lines
Post by: venus on September 26, 2005, 07:06:07 PM
Bob:  your email is "hidden"

CAB: I've got that lisp routine and have tried it.  some of the objects flattened get turned into objects receeding to the 0,0 coordinate and the rest of them are not able to be flattened.  I think this drawing originally came from Aris CAD, if that helps.
Title: Re: Convert Polylines to lines
Post by: CAB on September 26, 2005, 07:12:00 PM
If you care to post the drawing or a copy with a few of these objects someone will check it out
to see if there is a solution.
Title: Re: Convert Polylines to lines
Post by: venus on September 26, 2005, 07:26:19 PM
You got it!
thanks
Title: Re: Convert Polylines to lines
Post by: CAB on September 26, 2005, 10:09:46 PM
The problem was the extrusion dxf 210 which needed to be 0 0 1
but simply forcing that and the elevation (dxf 38) to zero did not work.
I did find some code that would correct the vertex (dxf 10).
 
Code: [Select]
;; by . Jon Fleming
 (setq Elevation (cdr (assoc 38 elst))
        FirstVertexInWCS (trans (append (cdr (assoc 10 elst))
                                        (list Elevation)
                                )
                                (cdr (assoc 210 elst))
                                0
                         )
  )
 
  But after all that I discovered that exploding the pline to make a line
  resulted in the correct elevation, zero. So all I did was
 
 
Code: [Select]
Command: (setq ss (ssget "X" '((0 . "LWPOLYLINE,POLYLINE"))))
<Selection set: 3>

Command: explode

Select objects: p
4402 found

Select objects:


Command: Flat
Initializing...
FLATTEN version 2k.01f loaded.  Type FLATTEN to run it.
FLATTEN sets the Z coordinates of most objects to zero.
Do you want to continue <Y>:

Choose objects to FLATTEN [press return to select all objects in the drawing]
Select objects: Specify opposite corner: 11704 found

Select objects:

Working
 Done.
11704 object(s) flattened.
0 object(s) not flattened.


PS the flatten was just to make sure, I don't think it was needed.
See the attached zip file of the result in A2K
Title: Re: Convert Polylines to lines
Post by: Keith™ on September 26, 2005, 10:30:56 PM
Indeed I found that by exploding the polylines to lines, then running flatten, the result is as expected.
Title: Re: Convert Polylines to lines
Post by: venus on September 27, 2005, 02:36:20 PM
flippin' amazing.  you rock CAB.  I'll be keepin that one in my back pocket.
thanks
Title: Re: Convert Polylines to lines
Post by: deegeecees on September 27, 2005, 02:52:46 PM
I was gonna say "EXPLODE", but i digress... :roll:
Title: Re: Convert Polylines to lines
Post by: venus on September 27, 2005, 03:00:15 PM
It was all too simple, really.
Title: Re: Convert Polylines to lines
Post by: Crank on September 27, 2005, 03:19:20 PM
I was thinking of something like:
Code: [Select]
(defun C:flatpoly (/ SS cmde)
(command "_undo" "_begin")
(setq cmde (getvar "CMDECHO"))(setvar "CMDECHO" 0)
(setq SS (ssget "X" '((0 . "*POLYLINE"))))
(command "_.UCS" "W")
(command "_.move" SS "" '(0 0 1e99) "" "_.move" "_p" "" '(0 0 -1e99) "")
(command "_.UCS" "P")
(setvar "CMDECHO" cmde)
(command "_undo" "_end")
(princ)
)
This worked fine for a POLYLINE, but this was the result for a LWPOLYLINE:
Code: [Select]
Command: li
LIST 1 found

                  LWPOLYLINE  Layer: "0"
                            Space: Model space
                   Handle = e7
              Open
    Constant width     0.000
Extrusion direction relative to UCS:
                   X=   -0.614  Y=   -0.642  Z=   -0.459
              area   0.000
            length   0.000

          at point  X=-5.084E+83  Y=-1.214E+83  Z=5.392E+67
          at point  X=-5.084E+83  Y=-1.214E+83  Z=5.392E+67
          at point  X=-5.084E+83  Y=-1.214E+83  Z=5.392E+67
          at point  X=-5.084E+83  Y=-1.214E+83  Z=5.392E+67
          at point  X=-5.084E+83  Y=-1.214E+83  Z=5.392E+67
          at point  X=-5.084E+83  Y=-1.214E+83  Z=5.392E+67
          at point  X=-5.084E+83  Y=-1.214E+83  Z=5.392E+67

Command:
Every time the routine is run you get a different result. Has anyone an idea why a LWPOLYLINE behaves like this?
Title: Re: Convert Polylines to lines
Post by: MP on September 27, 2005, 04:21:30 PM
Every time the routine is run you get a different result. Has anyone an idea why a LWPOLYLINE behaves like this?

Created in a non world UCS?

Running osnap?

Perhaps --

(command "_.move" SS "" "_non" '(0 0 1e99) "" "_.move" "_p" "" "_non" '(0 0 -1e99) "")

-------------------------------------------------------------------------------------------------------------------

Just a quick note of acknowledgement -- afaik Randy Richardson was the first to publicise the use of

(command "_.move" SS "" '(0 0 1e99) "" "_.move" "_p" "" '(0 0 -1e99) "")

as a quick flattener of sorts.

-------------------------------------------------------------------------------------------------------------------

Myself I've penned many many flatteners over the years, at one point it was a major career activity. This is a very simple / less ambitious one (I have penned some that go tho whole 9 yards, de-xref, de-paperspace, remove hidden lines, retain original layering yada ...) from sometime 1999/2000:

Code: [Select]
(defun c:Splat ( / _children _splat ss i )

    (defun _children ( ename / data result )
        (if (assoc 66 (entget ename))
            (reverse
                (while
                    (/= "SEQEND"
                        (cdr
                            (assoc 0
                                (setq data
                                    (entget
                                        (setq ename   
                                            (entnext ename)
                                        )
                                    )
                                )
                            )
                        )
                    )
                    (setq result (cons ename result))
                )
            )
        )
    )
   
    (defun _splat ( ename )
        (foreach ename (cons ename (_children ename))
            (entmod
                (mapcar
                   '(lambda ( lst / key )
                        (cond
                            (   (member
                                    (setq key (car lst))
                                   '(10 11 12 13)
                                )
                                (cons
                                    (car lst)
                                    (mapcar '* '(1.0 1.0 0.0) (cdr lst))
                                )
                            )
                            (   (eq 38 key) '(38 . 0.0))
                            (   t lst  )
                        )
                    )
                    (entget ename)
                )
            )
        )
        (entupd ename)
    )   

    (if (setq ss (ssget))
        (repeat (setq i (sslength ss))
            (_splat
                (ssname ss
                    (setq i (1- i))
                )
            )
        )     
    )
   
    (princ)
   
)

Doesn't do 3dsolids, but does do attributes, polyline vertices etc., honours locked layers.
Title: Re: Convert Polylines to lines
Post by: Andrea on September 28, 2005, 09:37:06 AM
why not just use the FLATTEN command ?