Message 1 of 6
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi, I'm in need of a lisp routine to place text inside the nearest closed polyline.
I found a lisp routine but I'm getting the following error, ; error: ActiveX Server returned the error: unknown name: Centroid. Not sure if I'm on the right track or not, but I'm guessing i need to fix GetPolylineCentroid function or am not passing the correct parameters in. I'm new to autolisp so any help would be greatly appreciated!
(defun C:MoveTextToCenter ( / ss ent pt1 plss pl centroid )
;; Function to calculate centroid of closed polyline
(defun GetPolylineCentroid (ename / obj area cx cy pt lst)
(setq obj (vlax-ename->vla-object ename)
area (vla-get-area obj)
cx (vla-get-centroid obj)
pt (vlax-variant->list cx)
)
pt
)
;; Main function
(setq ss (ssget "_:L" '((0 . "TEXT,MTEXT"))))
(if ss
(progn
(setq ent (ssname ss 0))
(setq pt1 (cdr (assoc 10 (entget ent))))
;; Select nearby closed polyline
(setq plss (ssget "_W"
(list (- (car pt1) 100) (- (cadr pt1) 100)) ; Lower-left corner
(list (+ (car pt1) 100) (+ (cadr pt1) 100)) ; Upper-right corner
'((0 . "LWPOLYLINE") (-4 . "&") (70 . 1)) ; Closed polylines only
))
;; If polyline found, get its centroid
(if plss
(progn
(setq pl (ssname plss 0))
(setq centroid (GetPolylineCentroid pl))
(command "_.move" ent "" pt1 centroid)
(princ "\nText moved to polyline centroid.")
)
(princ "\nNo closed polyline found within 100 units.")
)
)
(princ "\nNo text object selected.")
)
(princ)
)
Solved! Go to Solution.