already making modifications
Some of the polylines used are open, come are closed. I would also like a block to be at the beginning of an "open" polyline, but doing so for a closed polyline would create a "double" block at the start (=end) point of the polyline.
Reading the lisp manual I stumbled upon "vlax-curve-isClosed", which checks if a given entity is closed. The code now looks like this (also changed layernames and mStep to my specific needs):
Code:
;; CAB 05.22.07
;; Divide a dividable object based on segment length
;; and max dist between blocks to be inserted
;; -=< NO ERROR CHECKING >=-
(defun c:DivideSegments () (c:DS))
(defun c:DS (/ CNT DIST ENDPAR ENT IDX LEN MSTEP START STEP clay)
(vl-load-com)
(setq clay (getvar "clayer"))
(if (and (setq ent (entsel "\nSelect object to divide."))
(not (vl-catch-all-error-p
(setq start (vl-catch-all-apply
'vlax-curve-getpointatparam
(list (car ent) 0.0))))))
(progn
(command "._Undo" "_begin")
(setvar "clayer" "staalkabel") ; Block Layer
(setq ent (car ent))
(setq mStep 8000)
(setq endpar (vlax-curve-getendparam ent))
(setq idx 0)
(while (<= (setq idx (1+ idx)) endpar)
(setq len (- (vlax-curve-getdistatparam ent idx)
(vlax-curve-getdistatparam ent (1- idx))))
(setq step (/ len (fix (+ (/ len mstep) 0.99))))
(setq cnt (fix (+ (/ len step) 0.99)))
(setq dist (+ step (vlax-curve-getdistatparam ent (1- idx))))
; avoid double blocks on closed polylines
(if (vlax-curve-isClosed ent) ; check if polyline is closed
() ;if polyline is closed, do nothing
(command "-insert" "paal" "_non" (vlax-curve-getpointatdist ent 0) "1" "" "") ;if polyline is open, insert block at beginning of polyline
) ;end if
(repeat cnt
(command "-insert" "paal" "_non" (vlax-curve-getpointatdist ent dist) "1" "" "")
(setq dist (+ dist step))
) ;end repeat
) ; end while
(setvar "clayer" clay)
(command "._Undo" "_end")
)
(prompt "\n*** ERROR - Can not divide that object. ***")
) ; end if
(princ)
)
<edit: typo's>