Back to SDS/2 Parametric Scripts
## MemSelection.py
Version 1.04 (module macrolib.MemSelection)
## Copyright (c) 2007 Bruce Vaughan, BV
Detailing & Design, Inc.
## All rights reserved.
## NOT FOR
############################################################################
'''
Return None or return a selection set of members
Limit selection to
certain member type or types
Limit selection to
certain material type or types
Limit selection to
one member or allow multiple selections
Option to add all
members with the same piecemark to the selection set
If 'single' == False, 'all_mks' is set to False
Function: mem_select(prompt_str, member_list, material_list [, single] [, all_mks])
single defaults to True
all_mks
defaults to True
Return a list of
member objects. Valid selections are limited to the member types
in 'member_list' and
material types in 'material_list'.
Limits the selection
to W flange Beams - option to add all members with the same piecemark:
bm_list = mem_select("Select a beam", ['Beam', ], ['W flange', ])
Limits the selection
to Tube and Channel, Beams and Columns - allows multiple object selection:
col_list = mem_select("Select columns and beams", ['Beam', 'Column'],
['Tube', 'Channel'], False)
Version 1.01 (
Version 1.02 (
Version 1.03 (
Warning("You
picked a %s. You must pick a the correct member
type." % (mem1.type))
Version 1.04
(11/2/07)- Add functions memAreaSelect and memSort
'''
from macrolib.MemCnt
import member_count
from param import ClearSelection, Warning, yes_or_no,
dim_print
from param import SelectionAdd, SelectionRemove, SelectionToggle
from member import Member, MemberLocate,
MultiMemberLocate
def mem_select(prompt,
memList, mtrlList,
single=True, all_mks=True):
try:
if single ==
False:
all_mks =
False
ClearSelection()
mem_list = []
while True:
mem1 = MemberLocate(prompt)
if mem1 ==
None:
break
else:
if
mem1.type in memList:
if
'All' in mtrlList:
mem_list.append(mem1)
if
single:
break # Limit selection to one member
elif mem1.mtrl_type in mtrlList:
mem_list.append(mem1)
if
single:
break # Limit selection to one member
else:
Warning("%s
material is not supported in this script." % (mem1.mtrl_type))
else:
Warning("You
picked a %s. You must pick a the correct member
type." % (mem1.type))
if len(mem_list) == 0:
return
None
if all_mks:
chk_mem_list
= member_count(mem1)
if len(chk_mem_list) > 1:
if yes_or_no("Add all members with the same piecemark to
selection (%s members with mark %s)?" % \
(len(chk_mem_list), mem_list[0].piecemark))
== 1:
mem_list
= chk_mem_list
return mem_list
except:
ClearSelection()
return []
## End mem_select()
'''
SelectionAdd(MemberObject) - adds a member to the selection list
SelectionRemove(MemberObject) - removes a member from the selection list
SelectionToggle(MemberObject) - toggles a member from the selection list
'''
def memSort(mem1,
mem2, eps=0.001):
# sort function -
compare left location point object for sorting
x = abs(mem1.left.location.x
- mem2.left.location.x)
if x < eps:
y = abs(mem1.left.location.y
- mem2.left.location.y)
if y < eps:
return cmp(mem1.left.location.z, mem2.left.location.z)
return cmp(mem1.left.location.y, mem2.left.location.y)
return cmp(mem1.left.location.x, mem2.left.location.x)
def memAreaSelect(prompt,
memTypeList, mtrlTypeList=['All',]):
try:
ClearSelection()
memList
= []
tem_list = MultiMemberLocate(prompt)
for mem in tem_list:
if mem.type in memTypeList:
if
'All' in mtrlTypeList:
memList.append(mem)
elif mem.mtrl_type in mtrlTypeList:
memList.append(mem)
else: SelectionRemove(mem)
else: SelectionRemove(mem)
if not memList:
Warning("No
members of the correct type and material were selected.")
memList.sort(memSort)
return memList
except:
ClearSelection()
return []
if __name__ == '__main__':
'''
bm_list = mem_select("Select
a beam", ['Beam', ], ['W flange', 'Channel', 'Tube', 'Angle'])
print bm_list
col_list = mem_select("Select
a column", ['Column', ], ['W flange', 'Channel', 'Tube', 'Angle'])
print col_list
bm_list = mem_select("Select
beams", ['Beam', ], ['W flange', 'Channel', 'Tube', 'Angle'], False)
print bm_list
col_list = mem_select("Select
columns and beams", ['Beam', 'Column'], ['W flange', 'Channel', 'Tube',
'Angle'], False)
print col_list
'''
mem_list = memAreaSelect("Select
ANGLE HB and VB members by area", ['Vertical Brace', 'Horizontal Brc'], ['Angle', ])
for mem in mem_list:
# mem.highlight()
pt = mem.left.location
Warning('''Member:
%s - Type: %s - Mtrl Type: %s\nLeft
location: %s, %s, %s''' % \
(mem.piecemark,
mem.type, mem.mtrl_type, dim_print(pt.x), dim_print(pt.y), dim_print(pt.z)))
SelectionRemove(mem)
print 'Member:
%s - Type: %s - Mtrl Type: %s' % (mem.piecemark,
mem.type, mem.mtrl_type)
# mem.unhighlight()
# misc_list = mem_select("Select
misc", ['Misc', ],
['All'])
# print misc_list