Jump to content

Break Polyline at multiple points/nodes? Modify code?


Recommended Posts

Posted

Im trying to break a polyline into smaller segments defined by multiple points at varying intervals along the polylines length. Has anyone got a lisp for this? Or able to adapt the below:

 

This is a lisp that inserts multiple points at multiple user specified lengths along a polyline or curve, is there anyway to modify it so that it also breaks the polyline and inserts the point at the same time???

 

Thanks for looking guys

 

 
(defun c:tpline (/ *error* cCurve curPt dPar dPt
enPt fPar fPt maxLen obType oldDis
oldOsn posDir rClose sFlag stPt
sumDis swMod undoLst vClose whatDo)
(vl-load-com)
(defun asmi_GetActiveSpace(/ actDoc)
(if
(= 1(vla-get-ActiveSpace
(setq actDoc
(vla-get-ActiveDocument
(vlax-get-acad-object)
); end vla-get ActiveSpace
); end setq
); end vla-get-ActiveDocument
); end =
(vla-get-ModelSpace actDoc)
(vla-get-PaperSpace actDoc)
); end if
); end of asmi_GetActiveSpace
(defun RestorePointStyle()
(if
(and xdiv:oldPm xdiv:oldPs)
(progn
(initget "Yes No")
(setq swMod
(getkword
"\nRestore point style? [Yes/No] <No>: "))
(if(null swMod)(setq swMod "No"))
(if
(= swMod "Yes")
(progn
(princ "\nPlease wait... \n")
(setvar "PDMODE" xdiv:oldPm)
(setvar "PDSIZE" xdiv:oldPs)
); end progn
); end if
); end progn
); end if
(princ)
); end of RestorePointStyle
(defun AddPointOrInsert(Mode Block Scale)
(vla-AddPoint
(asmi_GetActiveSpace)
(vlax-3d-point curPt))
); end of AddPointOrInsert
(defun AddPointOrInsert(Mode Block Scale / outObj)
(setq undoLst
(append
(list
(list
(setq outObj
(vla-AddPoint
(asmi_GetActiveSpace)
(vlax-3d-point curPt))); end setq
curPt xdiv:curDis
); end list
); end list
undoLst); end append
); end setq
outObj
); end of AddPointOrInsert
(defun *error*(msg)
(if cCurve
(progn
(vla-Highlight cCurve :vlax-false)
(setvar "OSMODE" oldOsn)
); end progn
); end if
(princ "\n*Cancel*")
(princ)
); end of *error*
(if
(member
(setq xdiv:oldPm(getvar "PDMODE"))
'(0 1)
); end member
(progn
(setq xdiv:oldPs(getvar "PDSIZE"))
(initget "Yes No")
(setq swMod
(getkword
"\nChange points style to good visible? [Yes/No] <Yes>: "))
(if(null swMod)(setq swMod "Yes"))
(if
(= swMod "Yes")
(progn
(princ "\nPlease wait... \n")
(setvar "PDMODE" 35)
(setvar "PDSIZE" -2)
); end progn
); end if
); end progn
); end if
(setq oldOsn
(getvar "OSMODE")); end setq
(if
(not xdiv:curDis)
(setq xdiv:curDis 1.0
xdiv:oldDis 1.0); end setq
); end if
(if
(setq cCurve
(entsel
"\nSelect curve > ")); end setq
(progn
(setq cCurve
(vlax-ename->vla-object
(car cCurve))); end setq
(if
(member
(setq obType
(vla-get-ObjectName cCurve))
'("AcDbLine" "AcDbPolyline" "AcDb3dPolyline"
"AcDbSpline" "AcDbArc" "AcDbCircle" "AcDbEllipse")
); end member
(progn
(vla-Highlight cCurve :vlax-true)
(setvar "OSMODE" 3071)
(setq stPt
(vlax-curve-GetStartPoint cCurve)
enPt
(vlax-curve-GetEndPoint cCurve)
fPt
(getpoint
"\nPick start markup point at curve > ")
); end setq
(if fPt
(setq fPt(trans fPt 1 0)
curPt(vla-AddPoint
(asmi_GetActiveSpace)
(vlax-3d-point fpt)); end vla-AddPoint
undoLst
(list
(list curPt 0.0 0.0)); end list
); end setq
); end if
(if
(and
fPt
(setq fPar
(vlax-curve-GetParamAtPoint cCurve fPt))
); end and
(progn
(if
(and
(not(equal fPt stPt 0.0001))
(not(equal fPt enPt 0.0001))
); end or
(progn
(setq dPt
(getpoint fPt
"\nPick point at curve to specify markup direction > "))
(if dPt
(setq dPt(trans dPt 1 0))); end if
(if
(and
dPt
(setq dPar
(vlax-curve-GetParamAtPoint cCurve dPt))
); end and
(progn
); end progn
(princ "\nEmpty input or point not at curve! ")
); end if
); end progn
); end if
); end progn
(princ "\nEmpty input or point not at curve! ")
); end if
); end progn
(princ "\nInvalid object type! ")
); end if
(setq maxLen
(-
(vlax-curve-GetDistAtPoint cCurve enPt)
(vlax-curve-GetDistAtPoint cCurve stPt)
); end -
rClose
(vlax-curve-IsClosed cCurve)
); end setq
(if(equal fPt stPt 0.0001)
(setq vClose T)
); end if
(if
(or
(equal fPt stPt 0.0001)
(and
dPar
(> dPar fPar)
); end and
); end or
(setq posDir T
sumDis
(vlax-curve-GetDistAtPoint cCurve fPt)
); end setq
(setq sumDis
(- maxLen
(- maxLen
(vlax-curve-GetDistAtPoint cCurve fPt)))
); end setq
); end if
(while(not sFlag)
(setq whatDo
(getstring
(strcat
"\nSpecify distance or [undo/Quit] <"
(if xdiv:curDis(rtos xdiv:curDis) "not defined")
">: "); end strcat
); end getstring
); end setq
(cond
((or
(= 'REAL(type(distof whatDo)))
(= "" whatDo)
); end or
(if(= "" whatDo)
(setq xdiv:curDis xdiv:oldDis)
(setq xdiv:curDis(distof whatDo))
); end if
(setq xdiv:oldDis xdiv:curDis); end setq
(cond
(posDir
(setq sumDis
(+ sumDis xdiv:curDis)
curPt
(vlax-curve-GetPointAtDist cCurve sumDis)
); end setq
(if curPt
(AddPointOrInsert nil nil nil)
(princ "\n>>> End of line <<< ")
); end if
); end condition # 1
((not posDir)
(setq sumDis
(- sumDis xdiv:curDis)
curPt
(vlax-curve-GetPointAtDist cCurve sumDis)
); end setq
(if curPt
(AddPointOrInsert nil nil nil)
(princ "\n>>> End of line <<< ")
); end if
); end condition # 1
); end cond
); end condition #1
((=(strcase whatDo) "Q")
(if
(= 1(length undoLst))
(vla-Delete(caar undoLst))
); end if
(RestorePointStyle)
(if cCurve
(progn
(vla-Highlight cCurve :vlax-false)
(setvar "OSMODE" oldOsn)
); end progn
); end if
(setq sFlag T)
)
((=(strcase whatDo) "U")
(if
(and
undoLst
(/= 1(length undoLst))
); end and
(progn
(vla-Delete(caar undoLst))
(setq undoLst(cdr undoLst)
curPt(cadar undoLst)
sumDis(- sumDis
(last
(car undoLst)))
); end setq
); end progn
(princ "\n>>> Nothing to undo <<< ")
); end if
)
); end cond
); end while
); end progn
(princ "\nEmpty selection! ")
); end if
(princ)
); end of c:xdiv 

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