I have this alternative that avoids copying the original, but assumes that the mid point of the block is the mid point of the line. I have changed the the routine name to BPER2
so you will need to type this instead of TEST on the command line.
It is tested and seems to do exactly the same as the previous one, and should be faster.
(defun rh:gbbc (obj / ll ur lst c_pt)
(if (and obj (= (type obj) 'ENAME)) (setq obj (vlax-ename->vla-object obj)))
(cond (obj
(vlax-invoke-method obj 'getboundingbox 'll 'ur)
(setq lst (mapcar 'vlax-safearray->list (list ll ur))
c_pt (mapcar '(lambda (x y) (/ (+ x y) 2.0)) (car lst) (cadr lst))
);end_setq
)
);end_cond
c_pt
);end_defun
(defun rh:sammlung_n (o_lst grp / tmp n_lst)
(setq n_lst nil)
(cond ( (and o_lst (= (rem (length o_lst) grp) 0))
(while o_lst
(repeat grp (setq tmp (cons (car o_lst) tmp) o_lst (cdr o_lst)))
(setq n_lst (cons (reverse tmp) n_lst) tmp nil)
);end_while
)
);end_cond
(if n_lst (reverse n_lst))
);end_defun
(vl-load-com)
(defun c:bper2 ( / *error* c_doc c_spc l_obj ent e_lst ss cnt obj s_pt m_pt e_pt x_obj x_pts s_d d_lst x_pt)
(defun *error* ( msg )
(if (not (wcmatch (strcase msg) "*BREAK*,*CANCEL*,*EXIT*")) (princ (strcat "\nOops an Error occurred : " msg)))
(princ)
);end_defun *error*
(setq c_doc (vla-get-activedocument (vlax-get-acad-object))
c_spc (vlax-get-property c_doc (if (= 1 (getvar 'cvport)) 'paperspace 'modelspace))
);end_setq
(while (not l_obj)
(setq ent (car (entsel "\nSelect Line : "))
e_lst (entget ent)
);end_setq
(if (vl-position (cdr (assoc 0 e_lst)) (list "ARC" "LINE" "LWPOLYLINE" "RAY" "SPLINE" "XLINE")) (setq l_obj (vlax-ename->vla-object ent)))
);end_while
(if (and (princ "\nSelect Bars : ")(setq ss (ssget ":L" '((0 . "INSERT")(2 . "`*U*")))))
(repeat (setq cnt (sslength ss))
(setq obj (vlax-ename->vla-object (ssname ss (setq cnt (1- cnt))))
s_pt (vlax-get obj 'insertionpoint)
m_pt (rh:gbbc obj)
e_pt (polar s_pt (angle s_pt m_pt) (* (distance s_pt m_pt) 2.0))
x_obj (vlax-invoke c_spc 'addxline s_pt e_pt)
x_pts (rh:sammlung_n (vlax-invoke x_obj 'intersectwith l_obj acextendnone) 3)
s_d 1.0e200
d_lst nil
);end_setq
(vla-delete x_obj)
(foreach x_pt x_pts
(if (< (setq d (distance x_pt s_pt)) s_d) (setq s_d d d_lst (list s_pt x_pt)))
(if (< (setq d (distance x_pt e_pt)) s_d) (setq s_d d d_lst (list e_pt x_pt)))
);end_foreach
(vlax-invoke obj 'move (car d_lst) (cadr d_lst))
);end_repeat
);end_if
(princ)
);end_defun