;; KM:MoB 선택한 블록의 중심점 찾기
;; C:BB 선택한 블록의 기존 기준점이 아닌 블록의 중심점으로 새로운 블록 일괄 삽입
;; Access Floor 블록 기준점을 중심점으로 일괄 대체하기 위한 기능
;; 20210928 @KMLab
;; 20230817 OSNAP 초기화 추가함
;;
(defun KM:MoB ( EN / P1 P2 P3 entityname ); Find MIDPOINT of Selected a BLOCK
(setq entityname EN)
(vla-GetBoundingBox (vlax-ename->vla-object entityname) 'MinPt 'MaxPt)
(setq P1 (vlax-safearray->list MinPt)); Points of Lower Left of Selected Entity
(setq P2 (vlax-safearray->list MaxPt)); Points of Upper Right of Selected Entity
(setq P3 (mapcar '(lambda (x y) (/ (+ x y) 2)) P1 P2)); MIDPOINT between p1 and p2
;(princ P3)
;(princ)
)
(defun c:BB ( / OSNM olds old _midpoint new new_name len n dxf_block )
;; init. OSNAP;;
(setvar OSNM (getvar "osmode"))
(setvar "osmode" 0)
;;
(prompt "\nSelect Blocks: ")
(if (setq olds (ssget '((0 . "INSERT"))))
(progn
(prompt "\n...Select A target BLOCK to be replaced: ...")
(setq new (ssget ":E:S" '((0 . "INSERT"))))
(setq new_name (assoc 2 (entget (ssname new 0))))
(setq len (sslength olds))
(setq n 0)
(repeat len
(setq old (ssname olds n))
(setq _midpoint (KM:MoB old))
(setq _midpoint (list (car _midpoint) (cadr _midpoint) 0.0))
(setq dxf_block (entget old))
(setq dxf_block (subst new_name (assoc 2 dxf_block) dxf_block))
(setq dxf_block (subst (cons 10 _midpoint) (assoc 10 dxf_block) dxf_block))
(setq dxf_block (subst (cons 41 1.0) (assoc 41 dxf_block) dxf_block))
(setq dxf_block (subst (cons 42 1.0) (assoc 42 dxf_block) dxf_block))
(setq dxf_block (subst (cons 43 1.0) (assoc 43 dxf_block) dxf_block))
(setq dxf_block (subst (cons 50 0.0) (assoc 50 dxf_block) dxf_block))
(entmod dxf_block)
(setq n (1+ n))
);repeat
);progn
(princ)
);if
;; restore OSMODE
(setvar "osmode" OSNM)
::
(setq msg (strcat "\n...Changed " (itoa len) " Blocks."))
(prompt msg)
;;(close file_w)
(princ)
);defun
'autocad' 카테고리의 다른 글
중복된 블록을 제거하고 싶다면 (0) | 2021.09.30 |
---|---|
Extract BasePoints of Blocks to CSV file (0) | 2021.09.28 |
선택한 직각사각형으로 ZOOM window (0) | 2021.09.24 |
BLOCK 일괄 교체 (0) | 2021.09.23 |
객체속성 변경 (entmod chg) (0) | 2021.09.16 |