Author Topic: Converting 3D Pline to LW Pline ...  (Read 3162 times)

0 Members and 1 Guest are viewing this topic.

Hangman

  • Swamp Rat
  • Posts: 566
Converting 3D Pline to LW Pline ...
« on: June 03, 2010, 07:10:24 PM »
Good afternoon everyone,

I am having a bit of an issue having 3D Polylines represent the linetype properly.  It simply doesn't.  So I was contemplating converting these 3D Polylines to LW Polylines.  I haven't found any posts regarding this, as most all the posts I have found are referring to making 3D Plines.  From these posts, I am going to assume it is best to trace over the 3D Pline with the LW Pline, then delete the 3D Pline ??

I have tried the following code, but it errors out with
Quote
; error: bad association list: (70 . 8 )
Code: [Select]
Command: (setq x (car (entsel)) y (entget x))

Select object: ((-1 . <Entity name: 7eb63520>) (0 . "POLYLINE") (330 . <Entity
name: 7ec31ee8>) (5 . "F264") (100 . "AcDbEntity") (67 . 0) (410 . "Model") (8
. "MAP_BUILD_EXIST_FENCE") (62 . 24) (6 . "FENCELINE3") (100 .
"AcDb3dPolyline") (66 . 1) (10 0.0 0.0 0.0) (70 . 8) (40 . 0.0) (41 . 0.0) (210
0.0 0.0 1.0) (71 . 0) (72 . 0) (73 . 0) (74 . 0) (75 . 0))

Command: (entmod (if (setq e (assoc 70 (entget x)))
((_> (subst (cons 70 0)(assoc 70 e) e)
((_> (entupd (cdr (assoc -1 y)))
((_> ))
Code: [Select]
Command: (entmod (if (setq e (assoc 70 (entget x)))
((_> (subst (cons 70 0)(assoc 70 e) e)
((_> (entupd (cdr (assoc -1 e)))
((_> ))
Code: [Select]
Command: (entmod (if (setq e (assoc 70 (entget x)))
((_> (subst (cons 70 0)(assoc 70 e) e)
((_> (append e (list (cons 70 0)))
((_> ))

I was hoping it would be easy enough to change this from a 3DPolyline (DXF 70 . 8 ) to an LWPolyline (DXF 70 . 0) but alas, it is not.
I could just explode the 3DPLines into plain old lines, but I'd prefer LWPolylines and I really don't want to get chewed out by those reading this thought.  I know it's worse than a badly trained draftsman to this so, what suggestions do you have in regards to converting 3D Polylines to LW Polylines ??

Thanks guys.
Hangman  8)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Drafting Board, Mechanical Arm, KOH-I-NOOR 0.7mm
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Converting 3D Pline to LW Pline ...
« Reply #1 on: June 03, 2010, 09:53:29 PM »
If you decide to 'convert' them to LWPolylines, just entnext through the 3DPolyline and extract the 10 code from each vertex, then with some additional extracted data (color, layer, linetype, ltscale, etc.), you can easily 'convert' them all.

This should get you started. It will step through a 3DPolyline and extract each 10 code (vertex) and put it in the form needed to entmake and LWPolyline.

Code: [Select]
(defun foo (e / orig lst)
  (setq orig e)
  (while (setq e (entnext e))
    ((lambda (ent)
       (if (and (eq "VERTEX" (cdr (assoc 0 ent)))
                (eq orig (cdr (assoc 330 ent)))
           )
         (setq lst (cons (reverse (cdr (reverse (assoc 10 ent)))) lst))
       )
     )
      (entget e)
    )
  )
  (reverse lst)
)

eg.
Code: [Select]
Command: (foo (car (entsel)))
Select object: ((10 -369.785 58.9001) (10 -342.373 97.9905) (10 -331.342
65.9164) (10 -306.604 99.9951) (10 -291.227 54.8909) (10 -264.149 112.691) (10
-244.76 72.5985) (10 -225.371 114.028) (10 -211.331 71.262))

Once you have this, the rest is pretty easy...
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Re: Converting 3D Pline to LW Pline ...
« Reply #2 on: June 03, 2010, 10:23:08 PM »
One way to do this....using ActiveX. If you feed the AddPolyline method the Coordinates from the 3dpoly it ignores the Z values, so you end up with a 2d poly at 0.00 elevation. If you still want the LWPoly, use the convertpoly command on it. Or, strip the Z values yourself using one of the 3d to 2d list functions you can find on the Swamp. Then use the AddLightweightPolyline method.

Quick example of the first case, taken from the Offset3dpoly routine I posted somewhere back in 2005...
Code: [Select]
(vl-load-com)
(setq doc (vla-get-activedocument (vlax-get-acad-object))
space (if (= (getvar "cvport") 1)
(vla-get-paperspace doc)
(vla-get-modelspace doc)
)
)
(setq ss (ssget ":S" '((0 . "POLYLINE")(-4 . "&=")(70 . 8))))
(setq obj (vlax-ename->vla-object (ssname ss 0))
         coords (vlax-get obj 'coordinates)
  )
(setq tmp (vlax-invoke space 'addpolyline coords))
;;at this point set the new pline to have the same layer, linetype, etc, as the original, then delete the original.

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Converting 3D Pline to LW Pline ...
« Reply #3 on: June 03, 2010, 10:32:03 PM »
I thought about ActiveX, but it seemed like it would be less legwork to use entmake and just remove the pairs you need and put them into the entmake of the LWPolyline.

Jeff, what does this mean? (-4 . "&=")
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Converting 3D Pline to LW Pline ...
« Reply #4 on: June 03, 2010, 10:41:08 PM »
-4 indicates that a test is required on the next statement. ie on (70 . 8 )
"&="  test both bits match.

kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Converting 3D Pline to LW Pline ...
« Reply #5 on: June 04, 2010, 06:00:54 AM »
& is a Bitwise AND

&= is a Bitwise Masked Equals

The difference being this behaviour:

Code: [Select]
&:

(/= 0 (logand bit filter))

Code: [Select]
&= :

(= filter (logand bit filter))

« Last Edit: June 04, 2010, 06:04:25 AM by Lee Mac »

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Converting 3D Pline to LW Pline ...
« Reply #6 on: June 04, 2010, 06:33:47 AM »
Another method for getting at Polyline Vertices  :wink:

Code: [Select]
(defun foo ( ent / p )
  (if (and (setq ent (entnext ent)) (setq p (cdr (assoc 10 (entget ent)))))
    (cons p (foo ent))
  )
)

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Converting 3D Pline to LW Pline ...
« Reply #7 on: June 04, 2010, 07:15:39 AM »
I thought I'd have a stab at it myself - I actually found it harder than I first anticipated, perhaps I have followed the wrong path  :oops:

Code: [Select]
(defun 3D->LW ( ent / Verts )
  ;; © Lee Mac  ~  04.06.10
  (setq Verts
    (mapcar
      (function
        (lambda ( x )
          (if (= 10 (car x)) (list 10 (cadr x) (caddr x)) x)
        )
      )
      (apply 'append (foo ent))
    )
  )

  (if
    (entmake
      (append '( (0 . "LWPOLYLINE") (100 . "AcDbEntity") (100 . "AcDbPolyline") )
        (list
          (cons 90 (/ (length Verts) 4))
          (cons 70 (logand 129 (cdr (assoc 70 (entget ent)))))
        )
        (RemovePairs '(0 10 40 41 66 70 71 72 73 74 75 100) (entget ent))
        Verts
      )
    )
    (entdel e)
  )
)

(defun foo ( ent / p )
  ;; © Lee Mac  ~  04.06.10
  (if (and (setq ent (entnext ent)) (setq p (assoc 10 (entget ent))))   
    (if (= 16 (logand 16 (cdr (assoc 70 (entget ent)))))     
      (foo ent)     
      (cons
        (reverse
          (member (assoc 42 (entget ent))
            (reverse
              (member p (entget ent))
            )
          )
        )     
        (foo ent)
      )
    )
  )
)

(defun RemovePairs ( pairs lst )
  ;; © Lee Mac  ~  04.06.10
  (vl-remove-if
    (function
      (lambda ( pair )
        (vl-position (car pair) pairs)
      )
    )
    lst
  )
)


(defun c:test ( / e )
  (if (setq e (car (entsel))) (3D->LW e))
  (princ)
)

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Converting 3D Pline to LW Pline ...
« Reply #8 on: June 06, 2010, 08:42:07 AM »
Did my program work for you Hangman?

Krushert

  • Seagull
  • Posts: 13679
  • FREE BEER Tomorrow!!
Re: Converting 3D Pline to LW Pline ...
« Reply #9 on: November 29, 2010, 10:31:12 AM »
It worked for me.  Though selecting 1235 3d polylines one by one was a bit tedious.  :evil: :roll:

Actually what I did was explode all and then join them all back to regular polylines, because the file will eventually end up in Google SketchUp.  So I have to break it down in pieces/categories to separate files then flatten and dumb those files down.   :ugly:  Apparently to Google SketchUp cannot handle a 3d topo Autocad file.  :roll: That is according to my architect/boss.   :-D
I + XI = X is true ...  ... if you change your perspective.

I no longer CAD or Model, I just hang out here picking up the empties beer cans

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Converting 3D Pline to LW Pline ...
« Reply #10 on: November 29, 2010, 11:41:22 AM »
It worked for me.  Though selecting 1235 3d polylines one by one was a bit tedious.  :evil: :roll:

Good to hear  :lol: