Jump to content
MS13

PLine3D->Spline->PLine3D

Recommended Posts

MS13

Hi all

I am using this routine to change 3dpoli to spline.

Quote

(defun C:Pline2Spline ;| credits to: Lee Mac |; ( / Get3DpolyVertices AddSpline e pLst spl )

(defun Get3DpolyVertices ( e / pLst )
(if (and (eq 'ENAME (type e)) (= "POLYLINE" (cdr (assoc 0 (entget e)))))
(reverse
(while (and (setq e (entnext e)) (/= "SEQEND" (cdr (assoc 0 (entget e)))))
(setq pLst (cons (cdr (assoc 10 (entget e))) pLst))
)
)
)
); defun Get3DpolyVertices

(defun AddSpline ( 3DPtLst / Spline )
(if 
(and 
(vl-consp 3DPtLst)
(vl-every (function (lambda (x) (and (vl-consp x) (= 3 (length x)) (apply 'and (mapcar 'numberp x))))) 3DPtLst)
); and
(setq Spline
(vla-AddSpline
(vlax-get (vla-get-ActiveDocument (vlax-get-acad-object))
(if (equal (getvar "CVPORT") 1) 'PaperSpace 'ModelSpace) 
)
(vlax-safearray-fill 
(vlax-make-safearray vlax-vbDouble (cons 0 (1- (length (apply 'append 3DPtLst)))))
(apply 'append 3DPtLst)
)
(vlax-3d-point '(0. 0. 0.))
(vlax-3d-point '(0. 0. 0.))
)
); setq Spline
); if 
); defun AddSpline 

(setvar 'errno 0)
(while (/= 52 (getvar 'errno))
(setq e (car (entsel "\nPick a pline <exit>: ")))
(cond
((= 7 (getvar 'errno)) (princ "\nMissed, try again.") (setvar 'errno 0))
(e
(cond
((wcmatch (cdr (assoc 0 (entget e))) "~*POLYLINE") (princ "\nInvalid object."))
((= "POLYLINE" (cdr (assoc 0 (entget e))))
(and
(setq spl (AddSpline (Get3DpolyVertices e)))
(vla-put-Closed2 spl (vla-get-Closed (vlax-ename->vla-object e)))
(setvar 'errno 52)
); and
)
((= "LWPOLYLINE" (cdr (assoc 0 (entget e))))
(and
(setq pLst (mapcar 'cdr (vl-remove-if-not (function (lambda (x) (= 10 (car x)))) (entget e))))
(if (= 2 (length (car pLst))) ; convert to 3D point list
(setq pLst (mapcar (function (lambda (x) (append x (list (cdr (assoc 38 (entget e))))))) pLst)) ; assoc 38, elevation
pLst
) 
(setq spl (AddSpline pLst))
(vla-put-Closed2 spl (vla-get-Closed (vlax-ename->vla-object e)))
(setvar 'errno 52)
); and
)
); cond
); e
); cond
); while

);| defun Spline2Pline |; (vl-load-com) (princ)

 

Is there way to amend it with few more elements:

1)Spline is drawn on the same layer as source 3d poly has

2) Spline is something what I do not need. I need this spline to be turn into another 3dpoly with precision<10>

3) Source 3dpoly is being deleted

 

I know it can be done manually and I am doing like this, but this take long long time

 

Thanks

 

Share this post


Link to post
Share on other sites
dlanorh

Post a drawing (Autocad 2010) with a short 3DPolyline showing before and after, since I don't fully understand your requirement. It sounds like you want to convert a 3DPolyline rather than replace one polyline with another.

Share this post


Link to post
Share on other sites
eldon

Perhaps PEDIT will do what you want with the original 3Dpolyline.

Share this post


Link to post
Share on other sites
dlanorh

OK, question, are they always 3DPolylines and always on layer "BANK" or is the lisp used for other polylines?

Share this post


Link to post
Share on other sites
dlanorh
Posted (edited)

OK. Try the attached. I've added a local error routine, and substituted a selection set for the entsel, so you should be able to process multiple polylines with a single selection.

 

As per the original, the spline is fitted to the polyline vertices. It now deletes the original polyline puts the spline onto the original polylines layer and converts the spline back into a polyline.

 

I've minimally tested in the drawing you supplied.

Pline2plinespline.lsp

Edited by dlanorh

Share this post


Link to post
Share on other sites
MS13

Thanks

 

Works almost perfect - spline is drawn on active layer not at the same layer as 3dpoly has

Share this post


Link to post
Share on other sites
dlanorh
6 minutes ago, MS13 said:

Thanks

 

Works almost perfect - spline is drawn on active layer not at the same layer as 3dpoly has

 

Ah!  A missing line of code in the LWPolyline condition. Try the updated attached lisp

Pline2plinespline.lsp

Share this post


Link to post
Share on other sites
MS13

Works perfect - thanks

 

I can always count on you guys

Share this post


Link to post
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
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

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