-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmodify entities.lsp
85 lines (82 loc) · 3.64 KB
/
modify entities.lsp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
;;These are commands that modify a selection
;;replacecircle will replace a single selected object (selected after the command is initiated) with a circle of equivalent size and on the same layer
;;modmirror will mirror the selected objects across the y axis from the midpoint (essentially scale x by -1)
;;modrotate will rotate a selection by 180° from the centerpoint
;;**************************************************************************************************************;;
;;replaceCircle ;;
;;Replaces the circles that are really just a bunch of lines with an actual circle ;;
;;Written CAB 2/14/18 ;;
;;**************************************************************************************************************;;
(defun c:replaceCircle ( / ent pt1 pt2 mid)
;Get the object we wish to replace
(setq ent (car (entsel)))
(setq ent (vlax-ename->vla-object ent))
;Get its bounding box
(vla-getboundingbox ent 'll 'ur)
;Turn the BB points into useable data
(setq pt1 (vlax-safearray->list ll))
(setq pt2 (vlax-safearray->list ur))
(setq ent (vlax-vla-object->ename ent))
;Get the midpoint of the object
(setq mid (list (/ (+ (car pt1) (car pt2)) 2) (/ (+ (cadr pt1) (cadr pt2)) 2)))
;Draw a circle
(entmake (list '(0 . "CIRCLE")
'(100 . "AcDbEntity")
'(100 . "AcDbCircle")
(assoc 8 (entget ent))
(cons 10 mid)
(cons 40 (/ (abs (- (car pt1) (car pt2))) 2))))
;Delete the original object
(entdel ent)
(CAB:recordCommand nil '("replaceCircle"))
(princ)
)
(princ)
;;**************************************************************************************************************;;
;;modmirror ;;
;;Finds the centerpoint of selected objects and mirrors them about the Y plane of that point ;;
;;Written CAB 3/13/18 ;;
;;**************************************************************************************************************;;
(defun c:modmirror ( / ss x xlst ylst pt ptlst os)
(setq ss (ssget))
(ssget "i")
(setq x (sslength ss))
(setq os (getvar "osmode"))
(setvar "osmode" 0)
(while (> x 0)
(setq ent (vlax-ename->vla-object (ssname ss (- x 1))))
(vla-getboundingbox ent 'll 'ur)
(setq ptlst (cons (vlax-safearray->list ll) ptlst))
(setq ptlst (cons (vlax-safearray->list ur) ptlst))
(print x)
(setq x (- x 1))
)
(setq xlst (mapcar '(lambda (x) (car x)) ptlst) ylst (mapcar '(lambda (x) (cadr x)) ptlst))
(setq pt (list (/ (+ (apply 'min xlst) (apply 'max xlst)) 2) (/ (+ (apply 'min ylst) (apply 'max ylst)) 2)))
(command ".mirror" ss "" pt (list (car pt) (+ (cadr pt) 10)) "_YES")
(setvar "osmode" os)
(princ)
)
;;**************************************************************************************************************;;
;;modrotate ;;
;;Finds the centerpoint of selected objects and rotates them 180 degrees ;;
;;Written CAB 10/1/18 ;;
;;**************************************************************************************************************;;
(defun c:modrotate ( / ss x xlst ylst pt ptlst)
(setq ss (ssget))
(ssget "i")
(setq x (sslength ss))
(while (> x 0)
(setq ent (vlax-ename->vla-object (ssname ss (- x 1))))
(vla-getboundingbox ent 'll 'ur)
(setq ptlst (cons (vlax-safearray->list ll) ptlst))
(setq ptlst (cons (vlax-safearray->list ur) ptlst))
;;; (print x)
(setq x (- x 1))
)
(setq xlst (mapcar '(lambda (x) (car x)) ptlst) ylst (mapcar '(lambda (x) (cadr x)) ptlst))
(setq pt (list (/ (+ (apply 'min xlst) (apply 'max xlst)) 2) (/ (+ (apply 'min ylst) (apply 'max ylst)) 2)))
(command ".rotate" ss "" pt 180)
(CAB:recordCommand nil '("modrotate"))
(princ)
)