Delete vertexes on 3D polylines with 0 elevation

Delete vertexes on 3D polylines with 0 elevation

Anonymous
Not applicable
2,402 Views
12 Replies
Message 1 of 13

Delete vertexes on 3D polylines with 0 elevation

Anonymous
Not applicable

Hi,

I have just start with the lisp edition. So I'm not very good editor.

I work actually on the project with many 3D polylines. On this polylines I have many vertexes with 0 elevation.  My question have you a lisp  to delete all vertexes with 0 in elevation. Or if we have a fonction autocad to make the same thing ?

 

Many thanks in advance.

0 Likes
Accepted solutions (1)
2,403 Views
12 Replies
Replies (12)
Message 2 of 13

Kent1Cooper
Consultant
Consultant

Can you post a sample drawing with one or two of them?  I'm wondering about the kind of geometry that would not be "ruined" in some way by removing vertices just for their elevation, rather than for [as an example] being too many too close together.

Kent Cooper, AIA
0 Likes
Message 3 of 13

Anonymous
Not applicable

Hi,

For this project the good geometry for polylines is when the vertexes have an elevation. The vertexes with 0 in elevation was not good. (They were generated by the customer, for another project.

I have attached an example.

0 Likes
Message 4 of 13

Moshe-A
Mentor
Mentor

@Anonymous  hi,

 

i view your file in 3d and it looks like 50% of the points are in zero elevation, removing all these point will change the polyline geometry in 3d dramatically - is this what you want?!

 

moshe

 

0 Likes
Message 5 of 13

Kent1Cooper
Consultant
Consultant
Accepted solution

Try this [lightly tested]:

(vl-load-com)
(defun C:NoZ0 (/ plobj coordslist noZ0list) (setq plobj (vlax-ename->vla-object (car (entsel "\n3DPolyline to remove Z=0 vertices from: ")))) (setq coordslist (vlax-get plobj 'coordinates)) (while coordslist (if (/= (caddr coordslist) 0.0); this vertex at other-than-0 elevation? (setq noZ0list (append noZ0list (list (car coordslist) (cadr coordslist) (caddr coordslist)))) ; then -- put it into fixed list ); if (setq coordslist (cdddr coordslist)); remove that vertex from list ); while (vlax-put plobj 'Coordinates noZ0list); impose fixed coordinates list (princ) ); defun
Kent Cooper, AIA
Message 6 of 13

Anonymous
Not applicable

Many thanks, it works.

Thanks to you I will save a lot of time

0 Likes
Message 7 of 13

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

Many thanks, it works.

Thanks to you I will save a lot of time


You're welcome.  When I first thought about how to go about it, I expected it would take a lot more lines of code to do it.

 

It does occur to me that, since your example 3DPolylines extend both above and below the Z=0 level, there's a possibility that a vertex you would want kept will be removed.  It would need to land at exactly 0.0000, which at first I didn't think would be very likely very often [the first one I looked at went from about 0.0330 to -0.0430 as it crossed that level].  But I notice this over-straightening in the results, where there must have been a series of "correct" vertices that were at Z=0:

NoZ0.PNG

I'm not sure how to think about preventing that, since it's hard to picture how the routine could determine which are the desirable ones at Z=0 and which are the undesirable ones.  In some places there are two  extra vertices at Z=0 between each adjacent pair at elevations to keep, but in other places only one, so it couldn't be just a matter of something like checking every other one.  Do you have any definable criteria?

Kent Cooper, AIA
0 Likes
Message 8 of 13

Anonymous
Not applicable

Hi,

I haven't definable criteria the evalation goes from 35m to -20m.

You are right some "good" vertexes can be deleted beacause they are 0 in elevation. I forgot this when 

Maybe I have the solution for get around the problem. I can ask the customers to change the elevation 0 to 100 so the elevation of wrong vertexes are out of the project elevation. If it possible.

But for the lisp is it to possible to choose which elevation we can delete ? not only 0

 

0 Likes
Message 9 of 13

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

.... I can ask the customers to change the elevation 0 to 100 so the elevation of wrong vertexes are out of the project elevation. .... is it to possible to choose which elevation we can delete ? not only 0


 

Yes, something like this [untested]:

(vl-load-com)
(defun C:NoZU (/ UZ plobj coordslist noZUlist)
  (setq
    UZ (getreal "\nUser-Z Coordinate of vertices to be removed: ")
    plobj (vlax-ename->vla-object (car (entsel "\n3DPolyline to remove User-Z vertices from: ")))
    coordslist (vlax-get plobj 'coordinates)
  ); setq
  (while coordslist
    (if (/= (caddr coordslist) UZ); this vertex at other-than-User-Z elevation?
      (setq noZUlist (append noZUlist (list (car coordslist) (cadr coordslist) (caddr coordslist))))
        ; then -- put it into fixed list
    ); if
    (setq coordslist (cdddr coordslist)); remove that vertex from list
  ); while
  (vlax-put plobj 'Coordinates noZUlist); impose fixed coordinates list
  (princ)
); defun

 

It could also be made to ask for the User to pick a point [one of the vertices at that elevation] to set that, rather than type in a number.  And other improvements are possible -- verify that you picked something, and the right kind of thing, remember the chosen elevation and offer it as default on subsequent use, Undo begin-end wrapping, error handling, multiple path selection at one run, etc.

Kent Cooper, AIA
0 Likes
Message 10 of 13

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

... for the lisp is it to possible to choose which elevation we can delete ? not only 0


 

Or, if you always want the same  elevation used [i.e. if it's viable to ask the source to always use a particular elevation that you know will always be outside the vertical range of the end results], you can simply replace the 0.0 in the code with that particular elevation.  Then you won't need to answer a prompt for the elevation every time you use it.

Kent Cooper, AIA
0 Likes
Message 11 of 13

Anonymous
Not applicable

Thank you for your work.

I try your lisp and you are right for last if the elevation is the same.

 

Thank again for your help.

0 Likes
Message 12 of 13

braudpat
Mentor
Mentor

Hello Kent

1) Thks for all your beautiful routines !

2) Please may I ask your for a "better" version ?

3) 2 questions :
Altitude less or equal than ? Default = 0
Altitude greater or equal than ? Default = 1000

So the routine will keep 3D vertex only between !

Of course, il will be possible to select N 3DPlines ?

Do your see what I mean ?

Thanks in avance, Regards, Patrice



Patrice ( Supporting Troops ) - Autodesk Expert Elite
If you are happy with my answer please mark "Accept as Solution" and if very happy please give me a Kudos (Felicitations) - Thanks

Patrice BRAUD

EESignature


0 Likes
Message 13 of 13

kamalgaramja556
Enthusiast
Enthusiast

This is perfect and works fine! but here I have a little bit modified it. Previously the process was one by one but using this modification you can do multiple selection or windows selection:

 

(vl-load-com)
(defun C:NoZ0 (/ ss index plobj coordslist noZ0list objType)
  (setq ss (ssget)) ; Select any objects
  
  (if ss ; Check if anything was selected
    (progn
      (setq index 0) ; Initialize index for selection set
      
      (while (< index (sslength ss))
        (setq plobj (vlax-ename->vla-object (ssname ss index)))
        (setq objType (vla-get-ObjectName plobj))
        
        (if (eq objType "AcDb3dPolyline") ; Check if the object is a 3D polyline
          (progn
            (setq coordslist (vlax-get plobj 'coordinates))
            (setq noZ0list nil) ; Reset the list for each polyline
            
            (while coordslist
              (if (/= (caddr coordslist) 0.0) ; Check if Z-coordinate is not 0
                (setq noZ0list (append noZ0list (list (car coordslist) (cadr coordslist) (caddr coordslist))))
              )
              (setq coordslist (cdddr coordslist)) ; Move to the next vertex
            )
            
            (vlax-put plobj 'Coordinates noZ0list) ; Update coordinates of the polyline
          )
        )
        
        (setq index (1+ index)) ; Move to the next object in the selection set
      )
      
      (princ "\nZ=0 vertices removed from selected 3D polylines.")
    )
    (princ "\nNo objects selected.")
  )
  (princ)
)
0 Likes