Amazingly I got part of this code to work for me but I can't seem to figure out why its bugging out.
To reproduce the error:
Draw a 300 ft meandering polyline, insert some blocks along that polyline
run the script, pick the polyline, pick the blocks. As soon as you pick the farthest block it will do weird things and error out.
;draws a perpendicular line from the insertion point of a block to another line that is offset
;prints the length for each block
(defun test(/ obj VLAobj ent1 ent2 revline inspt perppt len)
(vl-load-com)
(setq obj (entsel "\n >> Select profile >>"))
(redraw (car obj) 3) ;highlight polyline
(setq VLAobj (vlax-ename->vla-object (car obj)))
(markpt VLAobj)
(initget "Y y N n")
(setq revline (getkword "\nReverse line?"))
(cond
((or
(= revline "y")
(= revline "Y")
)
(princ "\nReverse polyline")
(command "pedit" obj "r" "")
(entdel ent1)
(entdel ent2)
(markpt VLAobj)
)
((or
(= revline "n")
(= revline "N")
)
(princ "\nKeep polyline")
(markpt VLAobj)
)
(princ "\nDone!")
);end cond
(while
(setq blk (car (entsel "\nSelect block: ")))
(setq inspt (cdr (assoc 10 (entget blk))))
(setvar "lastpoint" inspt)
(setq perpPt (osnap (cadr obj)"per"))
(setq len (vlax-curve-getdistatpoint VLAobj perppt))
(command "line" inspt perppt "")
;(command "point" perppt)
;(command "point" inspt)
(princ len)
)
(entdel ent1)
(entdel ent2)
);end defun
(defun markpt(entobj / )
(setq startpt (vlax-curve-getStartPoint entobj))
(setq mkpt (list
(cons 0 "POINT") ;entity type
(cons 10 startpt) ;coordinates
(cons 62 1) ;color
(cons 8 "0") ;layer
)
)
(setq ent1 (entmakex mkpt))
(setq mktxt (list
(cons 0 "TEXT")
(cons 10 startpt) ;coordinates
(cons 40 4.0) ;text height
(cons 1 "Start Point") ;text contents
(cons 62 1) ;color
(cons 8 "0") ;layer
)
)
(setq ent2 (entmakex mktxt))
)