getting each vertex of a 3d polyline

getting each vertex of a 3d polyline

My_Civil_3D
Advocate Advocate
532 Views
6 Replies
Message 1 of 7

getting each vertex of a 3d polyline

My_Civil_3D
Advocate
Advocate

hi guys i am trying to find a way to access each vertex point of a 3d polyline, i want to place a block at each vertex point. i cant seem to find real info on this

Civil 3D Certified Professional
0 Likes
Accepted solutions (1)
533 Views
6 Replies
Replies (6)
Message 2 of 7

devitg
Advisor
Advisor

@My_Civil_3D Please upload your sample dwg , include 3dpoly and block to insert

0 Likes
Message 3 of 7

hak_vz
Advisor
Advisor

If 3dpoly is not fitted(smooth) to get list of all vertexes use

 

(defun 3dPolyVertexes (eo / take pointlist3d)
	;returns vertexes of 3dpolyline
	(defun take (amount lst / ret)(repeat amount (setq ret (cons (car lst) (take (1- amount) (cdr lst))))))
	(defun pointlist3d (lst / ret) (while lst (setq	ret (cons (take 3 lst) ret) lst (cdddr lst))) (reverse ret))
	(if (not (= (type eo) 'VLA-OBJECT)) (setq eo (vlax-ename->vla-object eo)))
	(cond 
		((= (vlax-get eo 'ObjectName) "AcDb3dPolyline")
			(setq ptlist (pointlist3d (vlax-get eo 'coordinates)))
		)
	)
	ptlist
)

 

 

For smoothed 3dpolyline use

 

(vlax-curve-getpointatdist eo 20)

 

where eo is vla object created from 3dpoly entity

 

 

(defun c:get3dPolyVertexes ( / e ptlist ) 
	(setq e (car(entsel "\nSelect 3dpolyline")))
	(if (and (setq ptlist (3dPolyVertexes e)))
		ptlist
	    (progn (princ "\nSelected entity is not 3dpolyline!")(princ))
	)
)

 

 

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes
Message 4 of 7

john.uhden
Mentor
Mentor

@hak_vz ,

Nice.  That a lot more compact than what I wrote 30 years ago. 😞

John F. Uhden

0 Likes
Message 5 of 7

john.uhden
Mentor
Mentor

@hak_vz ,

Then again, somewhere in the last 20± years, I came up with a method I like...

   ;; Function to group a flat list of items into a list of
   ;; multiple lists, each of length N, e.g.
   ;; '(A B C D E F G H I) -> '((A B C)(D E F)(G H I))
   (defun @group (lst n / item new)
     (foreach element (reverse lst)
       (setq item (cons element item))
       (if (= (length item) n)
         (setq new (cons item new) item nil)
       )
     )
     new
   )

  ;; Function to return a list of polyline vertices (light, heavy, or 3D)
  (defun @plist (object / e etype coords)
    (setq e      (vlax-vla-object->ename object)
          etype  (cdr (assoc 0 (entget e)))
          coords (vlax-get object 'Coordinates)
    )
    (if (= etype "LWPOLYLINE")
      (@group coords 2)
      (@group coords 3)
    )
  )

 

John F. Uhden

0 Likes
Message 6 of 7

Kent1Cooper
Consultant
Consultant

 

Another way:

(vl-load-com)
(defun C:3DPVL (/ 3dp n); = 3D Polyline Vertices List
  (setq
    3dpVList nil ; clear previous if present [not localized so it will remain]
    3dp (car (entsel "\nSelect 3DPolyline to get a List of its Vertices: "))
  ); setq
  (if (and 3dp (member '(100 . "AcDb3dPolyline") (entget 3dp)))
    (repeat (setq n (+ (fix (vlax-curve-getEndParam 3dp)) (if (vlax-curve-isClosed 3dp) 0 1)))
      (setq 3dpVList (cons (vlax-curve-getPointAtParam 3dp (setq n (1- n))) 3dpvList))
    ); repeat
    (prompt "\nNothing selected, or not a 3D Polyline.")
  )
  3dpVList ; return to command line [also remains for further use]
)

 

Kent Cooper, AIA
Message 7 of 7

calderg1000
Mentor
Mentor
Accepted solution

Regards @My_Civil_3D 

Try this quick build code. Maybe it will help you.

;;;___
(defun c:ib (/ vlx lp v lpf)
  (setq	vlx (vlax-ename->vla-object(car (entsel "\nSelect 3DPolyline: ")))
	nb  (Getstring "\nEnter Block Name: ")
	lp  (vlax-get vlx 'Coordinates)
  )
  (repeat (/ (length lp) 3)
    (setq v (list (car lp) (cadr lp) (caddr lp))
	  lp (cdddr lp)
    )
    (command "_.insert" nb "_non" v "" "" "")
  )
)

Carlos Calderon G
EESignature
>Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.