3d Polylines to new 2d Polylines on new layer

3d Polylines to new 2d Polylines on new layer

As-Built_Sigurd
Enthusiast Enthusiast
651 Views
9 Replies
Message 1 of 10

3d Polylines to new 2d Polylines on new layer

As-Built_Sigurd
Enthusiast
Enthusiast

Hi Guys,

 

I started to learn autolisp way back, but have forgotten almost everything and want to write a small program.

Basically, I want to select all 3d polylines which are on the same layer as the one I  select, copy them all to the same position on a new layer (to be created if it doesn't exist). Then the new 3d polylines on the new layer are to be exploded & flattened, then joined to make them 2d polylines.

Is this something I could get to fairly quickly? I have access to fairly basic .lisp functions I could get ideas from.

 

Thanks

Sigurd

0 Likes
Accepted solutions (2)
652 Views
9 Replies
Replies (9)
Message 2 of 10

paullimapa
Mentor
Mentor
Accepted solution

start you off with this...see if you can figure out how to place the flattened plines into a new layer

 

; select 3dpoly to get layer
(while(not(setq en (ssget"_+.:E:S"'((0 . "POLYLINE")(100 . "AcDb3dPolyline"))))))
; get layer name
(setq lyr(cdr(assoc 8(entget (ssname en 0)))))
; select all 3dpolylines on matching layer:
(setq ss(ssget"x"(list'(0 . "POLYLINE")'(100 . "AcDb3dPolyline")(cons 8 lyr))))
; make copy selection to same location
(command"_.Copy" ss "" "@" "@") 
; now flatten original selection
(setq selected (sslength ss)) ; get total number of selected objects
(setq ss (mapcar 'vlax-ename->vla-object (mapcar 'cadr (ssnamex ss)))) ; convert selection of entities to list of vla obj
; flatten selected objects to 1e99 -1e99 which = 0 elevation 
(foreach i (list 1e99 -1e99) 
 (mapcar(function(lambda (x) (vla-move x (vlax-3d-point (list 0 0 0)) (vlax-3d-point (list 0 0 i))))) ss) 
) ; foreach
; echo how many plines flattened
(princ(strcat"\nSuccessfully Flattened [" (itoa selected) "] Plines"))

 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 3 of 10

_gile
Consultant
Consultant

Hi,

You may be inspired by this reply to a similar request at TheSwamp.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 4 of 10

Kent1Cooper
Consultant
Consultant

There are several approaches to the 3D-to-2D conversion in the Topic containing >this< offering of mine.

Kent Cooper, AIA
Message 5 of 10

As-Built_Sigurd
Enthusiast
Enthusiast

 

Hi Paul, thank you for your response.

 

I've tried to expand on your code with my extremely limited skills :P.

The only problems I have (apart from my very sloppy additions) are:

- I Can't get the new polylines to elevation 0
- Get error message at end but still works

(defun c:3DP2FLATPLBB ()

(command "-linetype" "load" "*" "E:\\Dropbox\\Dropbox\\ABD\\Linetypes\\STREAMBANK" "" "") ;Have to remove parenthesis if linetype exists in drawing
(command "_.Layer" "_Make" "ABD - A - 2d Bank Bottom" "_Color" "251" "" "LType" "STREAMBANK" "" "LWeight" "0.09" "" "")

; select 3dpoly to get layer
(while(not(setq en (ssget"_+.:E:S"'((0 . "POLYLINE")(100 . "AcDb3dPolyline"))))))
; get layer name
(setq lyr(cdr(assoc 8(entget (ssname en 0)))))
; select all 3dpolylines on matching layer:
(setq ss(ssget"x"(list'(0 . "POLYLINE")'(100 . "AcDb3dPolyline")(cons 8 lyr))))
; make copy selection to same location
(command"_.Copy" ss "" "@" "@") 

(command "_chprop" ss "" "_LA" "ABD - A - 2d Bank Bottom" "")
; I should probably setq this layer :P

; select all 3dpolylines on new layer layer:
(setq nl(ssget"x"(list'(0 . "POLYLINE")'(100 . "AcDb3dPolyline")(cons 8 "ABD - A - 2d Bank Bottom"))))

; now flatten original selection
(command "_.AeccConvert3dPolys" nl "")
; Im using Civil 3d so can use this command, but polylines end up on 1st 3dpoly point elevation


; echo how many plines flattened
(princ(strcat"\nSuccessfully Flattened [" (itoa selected) "] Plines"))
)

 

0 Likes
Message 6 of 10

As-Built_Sigurd
Enthusiast
Enthusiast

Oh another problem is that the original 3d polys are usually set to continuous lintypes, and the new 2d polys end up with the same linetypes, rather than bylayer

0 Likes
Message 7 of 10

paullimapa
Mentor
Mentor

very good additions you've made.

To test if linetype exists before loading use this code:

(if(not(tblsearch"LTYPE""STREAMBANK"))
 (command "-linetype" "load" "*" "E:\\Dropbox\\Dropbox\\ABD\\Linetypes\\STREAMBANK" "" "")
)

Since the Civil3d flatten command does not allow you to place the now 2d Polylines onto 0 elevation, used AutoCAD's built-in Change command:

(command "_.Change" ss "" "_P" "_E" "0" "")

 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 8 of 10

paullimapa
Mentor
Mentor

This linetype issue could be caused by the Civil 3D flatten command.

Perhaps try my code I provided before to flatten instead?

; now flatten original selection
(setq selected (sslength ss)) ; get total number of selected objects
(setq ss (mapcar 'vlax-ename->vla-object (mapcar 'cadr (ssnamex ss)))) ; convert selection of entities to list of vla obj
; flatten selected objects to 1e99 -1e99 which = 0 elevation 
(foreach i (list 1e99 -1e99) 
 (mapcar(function(lambda (x) (vla-move x (vlax-3d-point (list 0 0 0)) (vlax-3d-point (list 0 0 i))))) ss) 
) ; foreach

Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 9 of 10

As-Built_Sigurd
Enthusiast
Enthusiast
Accepted solution

 

Many thanks Paul. Yes putting your flattening code before the conversion to polylines did the trick. I also just added the bylayer bit too. It may look messy, but it works perfectly (as far as I have tested so far). 

 

(defun c:3DP2FLATPLBB ()

(if(not(tblsearch"LTYPE""STREAMBANK"))
 (command "-linetype" "load" "*" "E:\\Dropbox\\Dropbox\\ABD\\Linetypes\\STREAMBANK" "" "") ; To check if layer exists
)
(command "_.Layer" "_Make" "ABD - A - 2d Bank Bottom" "_Color" "251" "" "LType" "STREAMBANK" "" "LWeight" "0.09" "" "")

; select 3dpoly to get layer
(while(not(setq en (ssget"_+.:E:S"'((0 . "POLYLINE")(100 . "AcDb3dPolyline"))))))
; get layer name
(setq lyr(cdr(assoc 8(entget (ssname en 0)))))
; select all 3dpolylines on matching layer:
(setq ss(ssget"x"(list'(0 . "POLYLINE")'(100 . "AcDb3dPolyline")(cons 8 lyr))))
; make copy selection to same location
(command"_.Copy" ss "" "@" "@") 



(command "_chprop" ss "" "_LA" "ABD - A - 2d Bank Bottom" "")
(command "_chprop" ss "" "_LT" "BYLAYER" "")
; I should probably setq this layer :P


; now flatten original selection
(setq selected (sslength ss)) ; get total number of selected objects
(setq ss (mapcar 'vlax-ename->vla-object (mapcar 'cadr (ssnamex ss)))) ; convert selection of entities to list of vla obj
; flatten selected objects to 1e99 -1e99 which = 0 elevation 
(foreach i (list 1e99 -1e99) 
 (mapcar(function(lambda (x) (vla-move x (vlax-3d-point (list 0 0 0)) (vlax-3d-point (list 0 0 i))))) ss) 
) ; foreach

; select all 3dpolylines on new layer layer:
(setq nl(ssget"x"(list'(0 . "POLYLINE")'(100 . "AcDb3dPolyline")(cons 8 "ABD - A - 2d Bank Bottom"))))

; now convert 3d polys
(command "_.AeccConvert3dPolys" nl "")

; echo how many plines flattened
(princ(strcat"\nSuccessfully Flattened [" (itoa selected) "] Plines"))
)

  

0 Likes
Message 10 of 10

paullimapa
Mentor
Mentor

Glad to have helped…cheers!!!


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes