Jump to content

convert 2d polyline to 3d polyline from contours


Guest

Recommended Posts

Hi Hippe013 is any way this lisp to support lines and polylines?

 

In this code we selecti a line and convert it to 3d polyline, I it posible to select a 2d polylione and convert it to 3d polyline

 

;Drapes a 3dpolyline over polylines along a selected line. 
(vl-load-com)
(defun c:sample-pl ( / li *ModSpc *ActDoc *Acad lobj p1 p2 ss sslen i plobj pnts n li pntli finli var)
 (setq li nil)
 (setq *ModSpc (vlax-get-property (setq *ActDoc (vlax-get-property (setq *acad (vlax-get-acad-object)) 'ActiveDocument)) 'ModelSpace))
 (setq lobj (vlax-ename->vla-object (car (entsel "\nSelect Line Object: "))))
 (setq p1 (vlax-safearray->list (vlax-variant-value (vlax-get-property lobj 'StartPoint))))
 (setq p2 (vlax-safearray->list (vlax-variant-value (vlax-get-property lobj 'EndPoint))))
 (setq ss (ssget "f" (list p1 p2) '(( 0 . "LWPOLYLINE"))))
 (setq sslen (sslength ss))
 (setq i 0)
 (repeat sslen
   (setq plobj (vlax-ename->vla-object (ssname ss i)))
   (setq el (vlax-get-property plobj 'Elevation))
   (vlax-put-property plobj 'Elevation 0)
   (setq pnts (vlax-invoke lobj 'IntersectWith plobj acExtendNone))
   (vlax-put-property plobj 'Elevation el)
   (vlax-release-object plobj)
   (setq n 0)
   (repeat (/ (length pnts) 3)
     (setq li (append li (list (nth (+ n 0) pnts))))
     (setq li (append li (list (nth (+ n 1) pnts))))
     (setq li (append li (list el)))
     (drxc (list (nth (+ n 0) pnts) (nth (+ n 1) pnts) el) 2)
     (setq n (+ n 3))
     )
   (setq i (1+ i))
   )
 (setq n 0)
 (setq pntli nil)
 (repeat (/ (length li) 3)
   (setq pntli (append pntli (list (cons (distance (list (nth (+ n 0) li) (nth (+ n 1) li)) (list (nth 0 p1) (nth 1 p1))) (list (list (nth (+ n 0) li) (nth (+ n 1) li)(nth (+ n 2) li)))))))
   (setq n (+ n 3))
   )
 (setq pntli (vl-sort pntli (function (lambda (d1 d2) (< (car d1) (car d2))))))
 (setq n 0)
 (setq finli nil)
 (repeat (length pntli)
   (setq finli (append finli (cadr (nth n pntli))))
   (setq n (1+ n))
 )
 (setq var (pl->var finli))
 (setq 3dobj2 (vlax-invoke-method *ModSpc 'Add3DPoly var))
 (vlax-put-property 3dobj2 'Color 1)
 (vlax-release-object 3dobj2)
 )


;Given Pointlist returns pointlist in variant form
(defun PL->VAR ( pl / pl ub sa var)
 (setq ub (- (length pl) 1))
 (setq sa (vlax-make-safearray vlax-vbdouble (cons 0 ub)))
 (setq var (vlax-make-variant (setq sa (vlax-safearray-fill sa pl))))
 )

;Graphically at given point and color Example (drxc '( 1 2 3) 1) draws x at x=1 y=2 z=3 in the color red 			
(defun drxc (ctr color / vs xs xs2 cor1 cor2 cor3 cor4 ctr color)
 (setq vs (getvar "viewsize"))
 (setq xs (/ vs 20))
 (setq xs2 (/ xs 2))
 (setq cor1 (polar ctr (* pi 0.25) xs2))
 (setq cor2 (polar ctr (* pi 0.75) xs2))
 (setq cor3 (polar ctr (* pi 1.25) xs2))
 (setq cor4 (polar ctr (* pi 1.75) xs2))
 (grdraw ctr cor1 color 0)
 (grdraw ctr cor2 color 0)
 (grdraw ctr cor3 color 0)
 (grdraw ctr cor4 color 0)
 )


;The following was written by LEE MAC ~ Cadtutor
;in response to my posting of the above code.
(defun c:LWPolySample ( / _dxf doc spc lobj p1 ss ev tmp lst ) (vl-load-com)
 ;; © Lee Mac 2010

 (defun _dxf ( code entity ) (cdr (assoc code (entget entity))))

 (LM:ActiveSpace 'doc 'spc)
 (COMMAND "_layer" "_m" "3d polyline" "_c" "55" "" "" "")
 (if
   (and (setq lobj (car (entsel "\nSelect Line Object:"))) (eq "LINE" (_dxf 0 lobj))
     (ssget "_F"
       (list (setq p1 (_dxf 10 lobj)) (_dxf 11 lobj)) '((0 . "LWPOLYLINE"))
     )
   )
   (progn (setq lobj (vlax-ename->vla-object lobj))
     
     (vlax-for obj (setq ss (vla-get-ActiveSelectionSet doc))

       (setq ev (vla-get-Elevation obj))
       (vla-put-Elevation obj 0.0)

       (setq lst
         (cons
           (mapcar
             (function
               (lambda ( x ) (list (car x) (cadr x) ev))
             )
             (GroupByNum (vlax-invoke obj 'IntersectWith lobj acExtendNone) 3)
           )
           lst
         )
       )
       (vla-put-Elevation obj ev)
     )
     (vla-delete ss)

     (vla-put-Color
       (vlax-invoke spc 'Add3DPoly
         (apply 'append
           (vl-sort (apply 'append lst)
            '(lambda ( a b )
               (< (distance p1 (list (car a) (cadr a))) (distance p1 (list (car b) (cadr b))))
             )
           )
         )
       )
     )
   )
 )

 (princ)
)

(defun GroupByNum ( l n / r)
 ;; © Lee Mac 2010
 (setq r (list (car l)))
 
 (if l
   (cons
     (reverse
       (repeat (1- n) (setq l (cdr l) r (cons (car l) r)))
     )
     (GroupByNum (cdr l) n)
   )
 )
)

;;--------------------=={ ActiveSpace }==---------------------;;
;;                                                            ;;
;;  Retrieves pointers to the Active Document and Space       ;;
;;------------------------------------------------------------;;
;;  Author: Lee Mac, Copyright © 2010 - www.lee-mac.com       ;;
;;------------------------------------------------------------;;
;;  Arguments:                                                ;;
;;  *doc - quoted symbol (other than *doc)                    ;;
;;  *spc - quoted symbol (other than *spc)                    ;;
;;------------------------------------------------------------;;

(defun LM:ActiveSpace ( *doc *spc )
 ;; © Lee Mac 2010
 (set *spc
   (vlax-get-property
     (set *doc
       (vla-get-ActiveDocument
         (vlax-get-acad-object)
       )
     )
     (if (= 1 (getvar 'CVPORT)) 'PaperSpace 'ModelSpace)
   )
 )
)

 

Thanks

Link to comment
Share on other sites

  • Replies 29
  • Created
  • Last Reply

Top Posters In This Topic

  • marko_ribar

    7

  • Hippe013

    7

Have you tried Lee Macs version? I believe his code supports polylines.

 

 

EDIT:

I guess it doesn't.

 

I suppose it is possible. I am wondering how and why you would use it along a polyline.

Link to comment
Share on other sites

Hippe013 I delete this line

(eq "LINE" (_dxf 0 lobj))

but nothing happend. When i select a LWPOLYLINE the only thing is to create a layer 3d polyline with nothing on it .... :?

Link to comment
Share on other sites

prodromosm,

 

I didn't tell you to delete that line of code. I was pointing out which part of the code was the filter for a line. It has become clear that you are not understanding what the code is doing. In order to have it where you could select a polyline rather than a line the code would have to be rewritten. The original intent of the code was to drape a LINE onto various 2d polylines set at various elevations resulting in a 3dpolyline.

 

regards,

 

hippe013

Link to comment
Share on other sites

Yes Hippe013 but i ask if it posible to select a 2d polylione and convert it to 3d polyline ,and you tell me that

Have you tried Lee Macs version? I believe his code supports polylines.

 

How Lee Macs version supports polylines ?

Link to comment
Share on other sites

Neither one supports polylines as the draping object. Only lines. The code would have to be rewritten in order to support polylines as the drape object.

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...