Old polylines work, but new LWPoly's doesn't ??

Old polylines work, but new LWPoly's doesn't ??

Anonymous
Not applicable
1,042 Views
13 Replies
Message 1 of 14

Old polylines work, but new LWPoly's doesn't ??

Anonymous
Not applicable

I'll include my dxf with POLYLINEs and my LISP to draw 3dfaces between two polylines, but
now those polys are LWs and my old lisp doesn't work.

 

I have used this previously to draw 3Dfaces between two polylines presenting the height curves

on bilding site and then transferred the faces to my 3D-modelling software to form the actual

earth surface. 

 

Could somebody direct me to right direction, or modify my lisp to work?

 

Best regards
PCS Kouvola Oy
Matti Pitkänen FISE AA-lk.
matti.pitkanen@pcskouvola.fi

0 Likes
1,043 Views
13 Replies
Replies (13)
Message 2 of 14

marko_ribar
Advisor
Advisor

Use (c:lwpoly23dpoly) from the lisp posted here :
https://www.theswamp.org/index.php?topic=42773.msg479708#msg479708

Then when your LWPOLYLINEs are converted to 3DPOLYLINEs apply your lisp...

If previously worked, then should work and after this fix...

HTH, M.R.

Marko Ribar, d.i.a. (graduated engineer of architecture)
0 Likes
Message 3 of 14

Anonymous
Not applicable

Thanks, I'll try tomorrow.

 

BR. Matti

0 Likes
Message 4 of 14

Kent1Cooper
Consultant
Consultant

You can also just use the CONVERTPOLY command to change the LWPolylines into "Heavy" 2D Polylines [no need for a routine to make them 3D Polylines -- CONVERTPOLY is a standard AutoCAD command], and then run your routine.

 

I may take a look at editing your code to work directly with LWPolylines, so you don't need to convert them either way, but it won't be right away -- I'd need some time to figure out exactly what it's doing, since I don't know the language.

Kent Cooper, AIA
0 Likes
Message 5 of 14

marko_ribar
Advisor
Advisor

I don't see anywhere inside OP's lisp where arced segments of "LWPOLYLINE" are used in calculating resulting 3DFACEs... So it's totally irelevant weather OP is to use CONVERTPOLY command for which I agree it's simple enough and you can do it all at once (multiple conversions), or is to use lisp I suggested... Either way lisp that OP attached is written very ugly and if OP is to use it on LWPOLYLINE entities then it's probably intended exactly to perform operations with arced ones as I don't see why such request is asked... Anyway to do it with arced LWPOLYLINEs, it's better to perform segmentation of arced segments and only then use CONVERTPOLY command (current version of lisp is searching for vertices - I don't see VLISP (vlax-curve-xxx functions) - only Vanilla ALISP DXF manipulations with entity data)... So for segmentation of LWPOLYLINEs, I strongly suggest that you use PLINETOOLS posted here :

 

http://www.cadtutor.net/forum/showthread.php?67924-Draw-polyline-along-with-2-or-more-adjacent-close...

 

And beside all that you can find in archive and other useful lisps for manupulation with LWPOLYLINEs...

 

In my humble opinion I don't see weather Kent's attempt to adapt posted lisp to specific entity type (LWPOLYLINEs) is going to gain much more effect in overall results then correct using posted archive with correct setup of converted LWPOLYLINEs to HEAVY ones or 3DPOLYs and applying already operational lisp OP posted... I guess we'll have to wait and see and that waste of time is also wasting investment in solution to this request...

Marko Ribar, d.i.a. (graduated engineer of architecture)
0 Likes
Message 6 of 14

Kent1Cooper
Consultant
Consultant

@marko_ribar wrote:

... if OP is to use it on LWPOLYLINE entities then it's probably intended exactly to perform operations with arced ones as I don't see why such request is asked...


The example drawing doesn't contain any arc segments, so that may not be an issue.  It may be that they made the request simply because they drew some Polylines in the default type of Polyline, not realizing the routine wouldn't work on them when that type is LightWeight.  If that's the issue, they can just [for future use] change the PLINETYPE System Variable to 0, and then when they draw Polylines, they won't be LightWeight, and the routine should work with them.

 

But looking at the example drawing does raise other questions in my mind.  If the routine is stepping along vertex locations to find corners for 3DFaces it's going to draw, shouldn't the Polylines have the same number of vertices, to get the 3DFaces to fill up all the way along both edges of a space between Polylines?  The ones in the example drawing have different numbers of vertices.  What happens at the trailing end?  [I couldn't really try it and see what happens, not knowing what the prompts were asking for.]  And if it's supposed to do what I would imagine, I wonder what happens along the "sides" of that big bulge to the right -- do some 3DFaces cut across each other, or something?

Kent Cooper, AIA
0 Likes
Message 7 of 14

Anonymous
Not applicable

Hello All, who bothered to try to help me ;>)

 

First of all, I must apologize not beeing exact enough to explane the case.

The solution is so old, that on that time Polylines were only object of their kind, so there

were no LWPOLYs or younger objects at all.

 

This is written to take two old style polylines; first and second,

ask the amount of dividents to be used to divide both of them to same amount of points and:

draw 3dfaces between the lines described with those division points,

do some Layer On/OFF in between the process.

 

I'll translate my lisp from Finnish to English so you can better understand it.

 

And for bulge I though the same, but it can be solved dividing those polylines for smaller

pieces and let the program do rest.

 

I also received one advice to have PLINETYPE = zero and result is also attached.

 

BR Matti

0 Likes
Message 8 of 14

marko_ribar
Advisor
Advisor

Here, I've adapted your code and make cosmetic and some other refinements...

 

;; Korkeuskäyrien väliin tehdään 3dface-pinnat
                                        ; 21.11.2000 Matti Pitkänen
                                        ; Ohjelmalle nimeksi 3dpinta
                                        ; 10.1.2001 muutetttu niin, että tekee pintaa avaruudessa
                                        ; olevien 3dpoly objektien väliin eikä ole rajoitettu pelkästään
                                        ; vaakatasossa ( UCS oli vaakataso ) olevien käyrien välisen pinnan
                                        ; piirtämiseen
                                        ;
                                        ; translated 2016 02 25
                                        ; modified to be applicable and for LWPOLYLINE entities by M.R.

(defun C:3dfp (/      a      pl     e1     e2     e3     pt1    pllist1
               lenpl1 osa1   ind    osa    pllist2       etp1   etp2
               etp3   etp4   et1    et2    et3    et4    te1    te2
               lenpl2 osa2   jakolkm       dl1    dl2    fptl1  pta
               ptl    dx     dy     dz     osia   dxx    dyy    dzz
               ux     uy     uz     fptl2  3df    vast
              )

  (print "Give me #1 POLYLINE")
  (setq a (ssget '((0 . "*POLYLINE"))))  ; otetaan polyline
  (setq pl (entget (ssname a 0)))
  (if (eq (cdr (assoc 0 pl)) "POLYLINE")
    (progn
      (setq e1 (cdr (assoc -1 pl)))
      (setq e2 (entnext e1))
      (setq e3 (entget e2))
      (setq pt1 (cdr (assoc 10 e3)))
      (setq pllist1 (cons pt1 pllist1))
      (while pt1
        (setq e2 (entnext e2))
        (setq e3 (entget e2))
        (setq pt1 (cdr (assoc 10 e3)))
        (setq pllist1 (cons pt1 pllist1))
      )                                     ;end while
      (setq pllist1 (cdr pllist1))          ; remove nil from list
    )
    (setq pllist1 (reverse (mapcar '(lambda ( p ) (trans p (ssname a 0) 0)) (mapcar '(lambda ( p ) (list (car p) (cadr p) (cdr (assoc 38 pl)))) (mapcar 'cdr (vl-remove-if-not '(lambda ( x ) (eq (car x) 10)) pl))))))
  )
                                        ; count the lenght of pline
  (setq lenpl1 0.0)
  (setq ind 0)
  (repeat (1- (length pllist1))
    (setq osa (distance (nth ind pllist1) (nth (1+ ind) pllist1)))
    (setq osa1 (cons osa osa1))
    (setq lenpl1 (+ osa lenpl1))
    (setq ind (1+ ind))
  )                                     ; end repeat
  (setq osa1 (reverse osa1))


                                        ; sama toiselle polylinelle
                                        ; same for #2
  (print "and #2 POLYLINE")
  (setq a (ssget '((0 . "*POLYLINE")))) ; otetaan polyline
  (setq pl (entget (ssname a 0)))
  (if (eq (cdr (assoc 0 pl)) "POLYLINE")
    (progn
      (setq e1 (cdr (assoc -1 pl)))
      (setq e2 (entnext e1))
      (setq e3 (entget e2))
      (setq pt1 (cdr (assoc 10 e3)))
      (setq pllist2 (cons pt1 pllist2))
      (while pt1
        (setq e2 (entnext e2))
        (setq e3 (entget e2))
        (setq pt1 (cdr (assoc 10 e3)))
        (setq pllist2 (cons pt1 pllist2))
      )                                     ;end while
      (setq pllist2 (cdr pllist2))          ; remove nil from list
    )
    (setq pllist2 (reverse (mapcar '(lambda ( p ) (trans p (ssname a 0) 0)) (mapcar '(lambda ( p ) (list (car p) (cadr p) (cdr (assoc 38 pl)))) (mapcar 'cdr (vl-remove-if-not '(lambda ( x ) (eq (car x) 10)) pl))))))
  )

                                        ; tarkistetaan, että listat eivät mene ristiin
                                        ; lasketaan päätepisteiden etäisyydet ja pienempi asento
                                        ; otaksutaan oikeaksi
                                        ;
                                        ; check that polys do not cross
                                        ; count distances from endpoint and
                                        ; smaller distance will be selected as the right choise
                                        ;
  (setq etp1 (car pllist1))
  (setq etp2 (last pllist1))
  (setq etp3 (car pllist2))
  (setq etp4 (last pllist2))
  (setq et1 (distance etp1 etp4))
  (setq et2 (distance etp2 etp3))
  (setq et3 (distance etp1 etp3))
  (setq et4 (distance etp2 etp4))
  (setq te1 (+ et1 et2))
  (setq te2 (+ et3 et4))

  (if (< te1 te2)
    (progn
      (setq pllist1 (reverse pllist1))
      (setq osa1 (reverse osa1))
    )
  )




                                        ; count the lenght of pline
  (setq lenpl2 0.0)
  (setq ind 0)
  (repeat (1- (length pllist2))
    (setq osa (distance (nth ind pllist2) (nth (1+ ind) pllist2)))
    (setq osa2 (cons osa osa2))
    (setq lenpl2 (+ osa lenpl2))
    (setq ind (1+ ind))
  )                                     ; end repeat
  (setq osa2 (reverse osa2))



                                        ; jatketaan laskentaa

  (print " The #1 had ")
  (princ (length osa1))
  (princ " segments")
  (print " and #2 had ")
  (princ (length osa2))
  (princ " segments ")
  (print)
  (textscr)
  (while (not (eq nil (getkword "\nENTER TO CONTINUE ... "))))
  (initget 7)
  (setq jakolkm (getint "\nGive the number of dividends ? : "))
  (setq dl1 (/ lenpl1 jakolkm))
  (setq dl2 (/ lenpl2 jakolkm))
  (setq ind 0)                          ;counter
  (setq fptl1 nil)                      ; list for points
                                        ; repeated for all 
  (repeat (length osa1)
    (setq pta (nth ind pllist1))        ; startpoint coord
    (setq ptl (nth (1+ ind) pllist1))   ; endpoint coord
    (setq dx (- (car ptl) (car pta)))   ; dx
    (setq dy (- (cadr ptl) (cadr pta))) ;  dy-
    (setq dz (- (last ptl) (last pta))) ;  dz-
    (setq osa (nth ind osa1))           ; lenght of 
                                        ; here I check if divident is bigger than .....
    (if (< osa dl1)                     ; jos osan pituus < kuin koko polylinen
                                        ; pituudelta laskettu osan pituus
      (progn
        (setq fptl1 (cons pta fptl1))
      )                                 ; otetaan osa sellaisenan

      (progn                            ; muuten aletaan tehdä hommia
        (setq osia (fix (/ osa dl1)))   ; montako osaa saadaan sopimaan
                                        ; osaan
        (setq dxx (/ dx osia))          ; osan jako-osien koordinaattierot
        (setq dyy (/ dy osia))          ; y-
        (setq dzz (/ dz osia))          ; z-

        (setq fptl1 (cons pta fptl1))
        (repeat (1- osia)
          (setq ux (+ (car pta) dxx))
          (setq uy (+ (cadr pta) dyy))
          (setq uz (+ (last pta) dzz))
          (setq pta (list ux uy uz))
          (setq fptl1 (cons pta fptl1))
        )                               ; end repeat
      )                                 ;endprogn
    )                                   ;endif
    (setq ind (1+ ind))
  )                                     ; end repeat
  (setq fptl1 (cons ptl fptl1))




  (setq ind 0)
  (setq fptl2 nil)
  (repeat (length osa2)
    (setq pta (nth ind pllist2))
    (setq ptl (nth (1+ ind) pllist2))
    (setq dx (- (car ptl) (car pta)))   ; osan päiden koordinaattierot
    (setq dy (- (cadr ptl) (cadr pta))) ;  y-
    (setq dz (- (last ptl) (last pta))) ;  z-
    (setq osa (nth ind osa2))

    (if (< osa dl2)
      (progn
        (setq fptl2 (cons pta fptl2))
      )
      (progn
        (setq osia (fix (/ osa dl2)))
                                        ; osaan
        (setq dxx (/ dx osia))          ; osan jako-osien koordinaattierot
        (setq dyy (/ dy osia))          ; y-
        (setq dzz (/ dz osia))          ; z-
        (setq fptl2 (cons pta fptl2))
        (repeat (1- osia)
          (setq ux (+ (car pta) dxx))
          (setq uy (+ (cadr pta) dyy))
          (setq uz (+ (last pta) dzz))
          (setq pta (list ux uy uz))
          (setq fptl2 (cons pta fptl2))
        )                               ; end repeat
      )
    )                                   ;endif

    (setq ind (1+ ind))
  )                                     ; end repeat
  (setq fptl2 (cons ptl fptl2))



                                        ; sitten tehdään lista, josta tulee 3dface pinnan piirto
                                        ; list for drawing actual 3Dfaces

  (setq 3df (cons (nth 0 fptl1) 3df))
  (setq 3df (cons (nth 1 fptl1) 3df))
  (setq 3df (cons (nth 0 fptl2) 3df))
  (setq 3df (cons (nth 0 fptl2) 3df))
  (setq 3df (cons (nth 1 fptl2) 3df))

  (setq ind 1)
  (repeat jakolkm
    (setq 3df (cons (nth ind fptl1) 3df))
    (setq 3df (cons (nth (1+ ind) fptl1) 3df))
    (setq 3df (cons (nth ind fptl2) 3df))
    (setq 3df (cons (nth (1+ ind) fptl2) 3df))
    (setq ind (1+ ind))
  )                                     ; end repeat

  (setq 3df (cons (nth ind fptl1) 3df))
  (setq 3df (reverse 3df))
  (command "_.layer" "_make" "earthsurface" "")

  (command "_.3dface" (foreach nimi 3df (command nimi)))

  (command "_.layer" "_make" "Curves" "")

                                        ;  käyttäjä näkee, mitä tuli
                                        ; user info, if it looks OK
  (initget 1 "Yes No")
  (setq vast
         (getkword
           "\nDoes it look OK [Yes/No], if not press [No] and layer will turn off ? : "
         )
  )

  (if (= vast "No")
    (command "_.layer" "_off" "earthsurface" "")
  )                                     ;endif

  (princ)

)                                       ;end 3dfp

 

Regards, M.R.

Marko Ribar, d.i.a. (graduated engineer of architecture)
0 Likes
Message 9 of 14

Anonymous
Not applicable

Hello Marko and thank you, your solutions works.  ;>)

 

I found although that this is not perfect yet, because it cannot follow the polylines edges

accurately and seems to end premature without reaching the endpoints ;>(

 

I ( or someone else ) could improve it for better results. 

 

BR Matti

 

PS. I received this email, but cannot find what they ask anywhere, although I have a feeling, that I have seen it ????

Topic: Old polylines work, but new LWPoly's doesn't ??
Date: 02-24-2016 08:00 AM

Did it solve your problem?

Click here to view the replies and mark one as an Accepted Solution.

This helps others find helpful answers in the community too!

Thanks for being a Autodesk Community member.

Your Autodesk Community Team

Autodesk Community sent this message to matti.pitkanen@pcskouvola.fi.

 

0 Likes
Message 10 of 14

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

... this is not perfect yet, because it cannot follow the polylines edges

accurately and seems to end premature without reaching the endpoints ;>(

.... 


The original doesn't reach all endpoints either [in the sample drawing attached to Post 7, as well as in my own trial].  I haven't dug really deeply into the operation of that or @marko_ribar's LWPolyline variant, but I'm guessing it has to do with too great a difference in the numbers of segments in different Polylines.

 

Obviously, if the number of subdivisions you ask for is greater than the number of segments in the Polylines, both routines are adding 3DFace corners inside some Polyline segments.  That seems to be the cause of 3DFaces that overlap each other, at least when the number of Polyline segments differs, within limits.  What should happen if you ask for fewer subdivisions than the number of segments in one or both Polylines?  It seems the 3DFaces are supposed to meet all Polyline vertices, but what if I ask for 10 divisions but a Polyline has 15 segments?  Would that ever be the case?  If so, should some of the 3DFace edges span across open space and not lie along such a Polyline in some places?

 

I suspect this could be done much more concisely using (vla-curve...) functions, which I may take a shot at -- for one thing, it should be doable in a way that wouldn't care whether the Polylines are lightweight or heavy, or in the case of heavy ones, 2D or 3D.

Kent Cooper, AIA
0 Likes
Message 11 of 14

Anonymous
Not applicable

Hello,

 

In my last note, I ment my original solution. As can be seen from the code it has been written at 2000 

when I had need to form a steep slope for amusement park water slide foundations.

It can be seen at www.tykkimaki.fi, also in English. Sorry but there seems to be no fotos.

 

BR Matti

 

 

0 Likes
Message 12 of 14

Anonymous
Not applicable

I'll tell what was my intention ;>)

 

When divident is given by user, by dividing the total lenght of polyline by given amount of divedents,

we have a unit distance ( naturally for both polylines will have their own ).

If some part of that polyline is smaller than this unit, this part should be taken as one step alone and

longer parts should be divided accordinly but I haven't succeed to accomplish that not even closely ;>(

 

But in any case I managed to do quite a close representation of the surface between these two polylines.

 

I think that I'll tackle this again some day. ( Or if we can find a ready made solution, then I'll pass. )

 

BR Matti

0 Likes
Message 13 of 14

Kent1Cooper
Consultant
Consultant

You may be interested in my DivPLVerts.lsp routine with its DPV command, available here.  It takes a Polyline and forces it to have the specified number of vertices, adding some to the longer segments as necessary.  It obviously requires the specified number to be more than what it already has, but it looks like that's your typical situation, anyway.  When that's the situation, you could apply DPV to your Polylines, and then run 3DFaces using every vertex of the DPV'd Polylines directly, without the overlapping situations.

Kent Cooper, AIA
0 Likes
Message 14 of 14

Anonymous
Not applicable

Hello Marko and Kent,

 

I tried your programs, first xxx from Kent and then Markos version of my original lsp

using my original polylines. Markos version took polylines to elevation zero, which 

has to be changed to their original heights to achieve the final result: the image 

of the earhsurface at that location, but all together with same number in both

programs, the result is good. Much better than my original.

 

Thank you for your efforts

Matti

 

 

 

0 Likes