Jump to content

3d polyline to 2d polyline


daiharv

Recommended Posts

Hello,

 

I have a lisp programme which converts 3D polylines to 2D polylines.

 

Unfortunately it disgards the elevation/height data.

 

The 3D lines I have are a constant height (they are contours).

 

Does anyone know if its possible to amend the lisp below to retain the height data?

 

;; CVPOLY.LSP Copyright 1996, 1997 Tony Tanzillo all rights reserved

;; ;; Converts 3D polylines to 2D polylines that lie on

;; the XY plane of the current UCS.

(setq filter:3dpoly '( (-4 . " (-4 . "AND>") ) )

(defun get (key alist) (cdr (assoc key alist)) )

(defun UCSZdir ()

(trans '(0 0 1) 0 1)

)

(defun UCSPoint2D (wcspoint)

( (lambda (p) (list (car p) (cadr p) 0.0) ) (trans wcspoint 0 1) )

)

(defun mapvertex (e function / e d rslt)

(while (/= "SEQEND" (get 0 (setq d (entget (setq e (entnext e)) '("*"))))

)

(setq rslt (cons ( (lambda (function data / e d rslt) (apply function (list data)) ) function d ) rslt ) ) ) (reverse rslt) )

(defun cvpoly (pline / data ucs)

(setq data (entget pline '("*"))) (entmake (subst (cons 70 (logand (get 70 data) (~ 8)))

(assoc 70 data) (subst (cons 210 (setq ucs (ucszdir))) (assoc 210 data) (subst '(100 . "AcDb2dPolyline") '(100 . "AcDb3dPolyline") data ) ) )

)

(mapvertex pline '(lambda (data) (if (zerop (logand (get 70 data) 9))

(entmake (list '(0 . "VERTEX") '(100 . "AcDbEntity") (assoc 8 data) '(100 . "AcDbVertex") '(100 . "AcDb2dVertex")

(cons 10 (UCSPoint2d (get 10 data))) (cons 70 (logand (get 70 data) (~ 32))) ) ) ) ))

(entmake '((0 . "SEQEND"))) (entdel pline)

)

(defun C:CVPOLY ( / ss i)

(cond

( (not (setq ss (ssget filter:3dpoly))) (princ "\nNo 3D Polylines selected."))

(t (setvar "CMDECHO" 0) (command "._UNDO" "_Begin") (repeat (setq i (sslength ss)) (cvpoly (ssname ss (setq i (1- i)))) ) (command "._UNDO" "_En") ) ) (princ)

)

(princ "\nCVPOLY.LSP Copyright 1997 Tony Tanzillo") (princ "\nCVPOLY command loaded.")

(princ)

;; END CVPOLY.LSP

 

 

I'm using AutoCAD 2006.

Link to comment
Share on other sites

Do you need to process 3DPolylines only, or you have simple lines too?

I can't fix your lisp but may be I can write a VBA code to convert 3DPolylines to 2DPolylines, taking for elevation the Z-coordinate of the first vertice of each 3DPolyline.

Link to comment
Share on other sites

Try this one. After running the macro you are promptrd to select all the 3dPolylines you want to be turned to 2dPolylines. After the transformation all the newly created objects are being highlighted.Old 3dPolylines are deleted...

 

 

 

Sub Convert3To2DPolylinesWithElevation()

Dim objEnt As AcadEntity

Dim SS As AcadSelectionSet

Dim objSS As AcadSelectionSet

 

For Each SS In ThisDrawing.SelectionSets

If SS.Name = "MySS" Then

ThisDrawing.SelectionSets("MySS").Delete

Exit For

End If

Next

 

ThisDrawing.SelectionSets.Add ("MySS")

Set objSS = ThisDrawing.SelectionSets("MySS")

objSS.SelectOnScreen

 

If objSS.Count = 0 Then

MsgBox "Nothing selected!"

Exit Sub

End If

 

 

Dim Coords As Variant

Dim objPol As AcadPolyline

Dim Cn As Double

Cn = 0

 

For Each objEnt In objSS

If objEnt.ObjectName = "AcDb3dPolyline" Then

 

Coords = objEnt.Coordinates

For i = 1 To ((UBound(Coords) + 1) / 3) - 1

Coords(3 * i + 2) = 0

Next

Set objPol = ThisDrawing.ModelSpace.AddPolyline(Coords)

objPol.Elevation = Coords(2)

objEnt.Delete

Cn = Cn + 1

objPol.Update

objPol.Highlight True

End If

Next

MsgBox Cn & " 3dPolyline(s) converted to 2dPolyline(s)"

 

 

End Sub

Link to comment
Share on other sites

Hi daiharv,

 

I'll have to analyze more deeply the code you posted to answer your question...however at first glance I could say that you have to modify

the function UCSPoint2D.

You should try to consider the Z value too ...which is missing in the original syntax:

 

try to substitute the old function with the new "UCSPoint3D"

 

(defun UCSPoint3D ()

( (lambda (p) (list (car p) (cadr p) 0.0) ) (caddr p) )

)

 

I haven't yet tested it inside Autocad, try yourself and let me know...if you like.

 

ciao!

 

ARKLisp

http://webspace.omniway.sm/fbattistini/

 

p.s. I made "SPOLYLINER2005" plug-in for ARKLisp TNT

(autolisp/vlisp extension for AutoCAD)... a collection of optimized tools

to solve this kind of problems.

Link to comment
Share on other sites

Hi guys,

 

This is probably a really simple question, but how do I load a marco?

 

ARKLisp- have tried insert you text to the lisp but without any luck.

 

 

Apologies for not being great with routines, any help you can offer will be greatfully accepted.

 

Tahnks,

 

Daiharv.

Link to comment
Share on other sites

Don't worry, I can help you...

loading autolisp/vlisp macros is very simple, first of all you have to launch

Autocad, then you can type at the prompt line the command "_APPLOAD", finally you browse your directories and select the macro to load, you push load button and then 'close'.

 

Modification of autolisp macro requires a minumum knowledge of this language... autolisp is very simple but not "stupid".

 

hear you soon, bye!

8)

 

ARKLisp

Link to comment
Share on other sites

Well, follow these steps to to be able to use the VBA macro I sent to you:

 

1.Open Autocad (no matter new drawing or not)

2.Tools-->Makro-->VisualBasicEditor - Visual Basic window is opened

3.From the menus: Insert-->Module

4.Copy the macro "Convert3To2DPolylinesWithElevation" from CadTutor window and Paste it in the newly created module (the blank area to the right in the VisualBasic window)

5.File-->Save (browse for a place to save your new project ). Visual Basic proposes you should save it with the name "Project", but it's up to you to choose any name (may be smth more associative like "3dTo2d")

 

 

Now your new project is loaded. But each time you open a drawing you must load it. You must do it in the AutoCad drawing choosing Tools-->LoadApplication ...Find the already created project and press Load. If you want to have this project automatically loaded each time press "Contents" button and add the prject there too. Close the dialog box

 

To run the macro in Autocad choose Tools-->Macro-->Macros

if you have no other projects loaded you will have only one macro there - "Convert3To2DPolylinesWithElevation". Otherwise you have to find it among the others, select it and press Run. If everything is done properly you will be prompted from the CommandLine to select objects onscreen so that the 3dPolylines will be processed

 

Every time you want to use the macro start it from Tools-->Macro-->Macros ... Run

 

 

Regards: Joro

Link to comment
Share on other sites

Just to show another way to skin the cat, this short, non-elegant lisp will convert a 3dpolyline to 2dpolyline:

 

(defun c:3d2d()

(command "_explode" pause "")

(command "_pedit" "_m" "_p" "" "_y" "_j" "" "")

(princ)

)

Link to comment
Share on other sites

CarlB

Please let me to put a finger on that code:

(defun c:3d2d() 
(command "_explode" pause "") 
(command "_pedit" "_m" "_p" "")
(if (= 0 (getvar "peditaccept")) (command  "_y"))
(command  "_j" "" "") 
(princ) 
)

Now it works whatever is the value of PEDITACCEPT. I assume that people are using AutoCAD 2k4 or newer because PEDITACCEPT vas introduced in that relase only.

It could be tested the ACADVER to see if the version is prior to 2k4 but I don't think that it worth the effort.

  • Like 1
Link to comment
Share on other sites

  • 2 years later...

hello to all

would you pleae modify the lisp to convert 3dpolylines to lwpolyline instead of 2dpolyline because i have lisp to draw banks that use lwpolyline can't recognize 2dpolyline

thanks in advanced

Link to comment
Share on other sites

motee-z

 

Look into the CONVERTPOLY command.

 

Lee,

 

Heavy 2D PLOYLINEs still exist. I think that there is a setting to force their creation in lieu of LWPOLYLINEs. -David

Link to comment
Share on other sites

i don't know how to draw 2dpolyline

but the lisp given in this thread give 2dpolyline

now you can see the diference if you see the list of each one

okay they are flatten both but diferent entity

thanks

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...