Professional Documents
Culture Documents
Autocad VBA Selection Sets - Frfly
Autocad VBA Selection Sets - Frfly
Autocad VBA Selection Sets - Frfly
Us ng Move, Copy w th
AcadSelect onSet
Posted on February 10, 2018 by frfly
Select on Sets n Autocad VBA do not conta n methods to Move, Copy, Rotate, Scale, M rror
etc. The programmer has to make a For-Each loop to terate through the Select on Set and
apply the method to each nd v dual ent ty one at a t me. There are qu te a few steps between
mak ng the select on set, populat ng t, then loop ng through ts members and actually do ng
someth ng to them. Break ng down these steps nto small re-usable sub-procedures s the way
to go.
Other than how to use them, Select on Sets have pretty good documentat on not too hard to
understand. The f rst sub-procedure makes a new clean Select on Set n the draw ng. If t
already ex sts t deletes t. Its called w th a parameter name.
In a recent program I made two k nds of select on, ALL and W ndow, so I made two funct on
procedures to handle th s task and return an AcadSelect onSet object. These funct ons call
addss above. The way these work are documented and eas ly found w th VBA
ACADSelect onSets. Th nk of th s as the second layer of abstract on, a funct on to make and
return a set accord ng to your select on method.
n tpt s a l ttle helper I made. You don’t need the ByRef keyword, I put t n there to rem nd that
arrays always pass by reference. It would not work otherw se.
Now we have, when properly called, a select on set of our choos ng. We want to make sub-
procedures for MOVE, COPY, ROTATE, MIRROR and SCALE wh ch accept a select on set as
an argument and whatever other bas c parameters requ red, such as a d splacement for
MOVE. Th s s the th rd level of abstract on. We are call ng these methods w th a select on set
prev ously selected by whatever method.
now f nally here s the code to MOVE a select on set us ng a loop to go thru the set for each
tem. It takes the set tself as argument and the d splacement n x and y. You can select tems
w th e ther of the subs above by w ndow or all or your program w th Cross ng or F lters. Delet ng
the select on set at the end of the rout ne s opt onal and may not always be des red, say f you
wanted to move and rotate.
At th s po nt these sub-procedures st ll do not change per program requ rements. They are
bas c tools.
https://frfly.wordpress.com/category/autocad-vba-select on-sets/ 2/4
21.05.2018 Autocad VBA Select on Sets | frfly
Here are m rror and scale (I have not needed COPY yet).
Now to some extent, we have h dden the loops, we don’t have to dupl cate them, and we can
call them w th s mple programs. Here are some upper level call ng programs. You w ll need to
wr te your own accord ng to the method and select on you want to use.
1 Sub erase_all()
2 Dim sset As AcadSelectionSet
3 Set sset = sset_all
4 Call erase_ss(sset)
5 End Sub
6
7 Sub move_all(x1 As Double, y1 As Dou
8 Dim sset As AcadSelectionSet
9 Set sset = sset_all
10 Call move_ss(sset, x1, y1)
11 End Sub
12
13 Sub scale_w(x1 As Double, y1 As Doub
14 'scales from pt 0,0
15 Dim sset As AcadSelectionSet
16 Set sset = sset_win(x1, y1, x2,
17 Call scale_ss(sset, 0, 0, sc)
18 End Sub
19
https://frfly.wordpress.com/category/autocad-vba-select on-sets/ 3/4
21.05.2018 Autocad VBA Select on Sets | frfly
20 Sub mirror_all(pt1() As Double, pt2(
21 Dim sset As AcadSelectionSet
22 Set sset = sset_all
23 Call mirror_ss(sset, pt1, pt2)
24 End Sub
those get called rather s mply by your top level, where you can see what you are do ng w thout
hav ng to d ve n to the deta ls.
1 Call erase_all
2 Call move_all (0,20)
3 Call scale_w(-1, -1, 12, 9.5, sc)
4 Call mirror_all(vt1, vt4)
when you draw w th xy data start ng at the or g n, th s s how you move and pos t on the p ece
onto your draw ng assembly or border.