几何尺寸与公差论坛

 找回密码
 注册
查看: 694|回复: 0

【转帖】selection boxes

[复制链接]
发表于 2009-4-12 22:21:59 | 显示全部楼层 |阅读模式
selection boxes
hello,
is there any example describing how to get selected objects from selection box inside the property page correctly? i mean the correct usage of selectionbox items list, getting marks and reassigning them. any help is greatly appreciated.
regards, basil
"and when you loose control,
you'll reap the harvest you have sown..." (c) pink floyd
solidworks 2008 x64 sp5.0 (production)
solidworks 2009 x64 sp2.0 (testing)
windows xp x64 sp2
core2quad 6600, 4gb ram, 500gb sata, ati firegl v7700 1024mb (softmodded from hd3850), 19" tft
basil,
here is a basic example that uses the pm to select components of an assembly, then set their material (may be used in future version of batchprocess, obviously a lot more sophisticated thought)...
create a module with the following code:
option explicit
public swapp as sldworks.sldworks
public part as sldworks.modeldoc2
public selmgr as sldworks.selectionmgr
public matdb as string
public mypropvals(1) as string
public pm as clspropmgr
sub main()
set swapp = application.sldworks
set part = swapp.activedoc
' check part is valid
if part is nothing then
msgbox "part or assembly must be open.", vbcritical
end
end if
set selmgr = part.selectionmanager
' setup material datebase to look in
matdb = "solidworks materials"
' setup materials list in the form: column, row
mypropvals(0) = "alloy steel"
mypropvals(1) = "cast carbon steel"
' create new instance of class
' this will call class_initialize event of the class
set pm = new clspropmgr
pm.show
end sub
then create a class with the following code:
option explicit
' required for property manager controls
' forces class to have all public procedures of propertymanagerpage2handler4
' leaving any out causes error
implements propertymanagerpage2handler4
' general objects required for propertymanagerpage
dim pm_page as propertymanagerpage2
dim pm_group as propertymanagerpagegroup
dim pm_selection as propertymanagerpageselectionbox
dim pm_label as propertymanagerpagelabel
dim pm_combo as propertymanagerpagecombobox
' each object in the page requires unique id
const groupid as integer = 1
const labelid as integer = 2
const selectionid as integer = 3
const comboid as integer = 4
dim clickedcancel as boolean
dim density as string
dim material as string
sub show()
pm_page.show
end sub
' run every time new instance created...
private sub class_initialize()
dim pagetitle as string
dim caption as string
dim tip as string
dim options as long
dim filters(0) as long
dim longerrors as long
dim controltype as integer
dim alignment as integer
' create :: propertymanagerpage
pagetitle = "set materials"
' lockedpage prevents accidental termination of the page
options = swpropertymanager_okaybutton + swpropertymanager_cancelbutton + swpropertymanageroptions_lockedpage
' handler (me [this class]) must be a class with all propertymanagerpage2handler4 procedures defined
set pm_page = swapp.createpropertymanagerpage(pagetitle, options, me, longerrors)
' make sure that it was created properly
if longerrors = swpropertymanagerpage_okay then
' fill in information for the message in pm page
' swimportantmessagebox makes it yellow
pm_page.setmessage "select all components you wish to set material. select material from list click ok.", swimportantmessagebox
' begin adding controls to the dialog...
' create :: groupbox (group materials)
caption = "materials"
options = swgroupboxoptions_visible + swgroupboxoptions_expanded
set pm_group = pm_page.addgroupbox(groupid, caption, options)
' create:: label (components to change)
controltype = swcontroltype_label
caption = "components to change"
alignment = swcontrolalign_indent
options = swcontroloptions_visible + swcontroloptions_enabled
tip = ""
set pm_label = pm_group.addcontrol(labelid, controltype, caption, alignment, options, tip)
' selectionbox (only needed for assemblies)
if part.gettype = swdocassembly then
' create: selectionbox (selected components)
controltype = swcontroltype_selectionbox
caption = ""
alignment = swcontrolalign_indent
options = swcontroloptions_visible + swcontroloptions_enabled
tip = "select components"
set pm_selection = pm_group.addcontrol(selectionid, controltype, caption, alignment, options, tip)
' setup settings for selection box
filters(0) = swselcomponents
pm_selection.singleentityonly = false
pm_selection.height = 50
pm_selection.setselectionfilters filters
pm_selection.setstandardpicturelabel swbitmaplabel_selectcomponent
end if
' create :: combobox (material selection)
controltype = swcontroltype_combobox
caption = "" ' no caption for comboboxes
alignment = swcontrolalign_indent
options = swcontroloptions_visible + swcontroloptions_enabled
tip = ""
set pm_combo = pm_group.addcontrol(comboid, controltype, caption, alignment, options, tip)
' add material array to combobox
pm_combo.additems mypropvals
else
' if propertymanagerpage not created properly
msgbox "there was an error creating the propertymanager page", vbcritical
end if
end sub
private sub propertymanagerpage2handler4_afterclose()
dim i as integer
dim component as sldworks.component2
dim part2 as sldworks.modeldoc2
if clickedcancel = true then exit sub
if part.gettype = swdocassembly then
for i = 1 to selmgr.getselectedobjectcount
set component = selmgr.getselectedobjectscomponent2(i)
set part2 = component.getmodeldoc
if part2.gettype = swdocpart then
part2.setmaterialpropertyname2 "", matdb, material
'part2.editrebuild3
end if
next i
part.editrebuild3
elseif part.gettype = swdocpart then
part.setmaterialpropertyname2 "", matdb, material
part.editrebuild3
end if
' destroy the class
set pm = nothing
end sub
private sub propertymanagerpage2handler4_onclose(byval reason as long)
if reason = swpropertymanagerpageclose_okay then
' ok was pressed
clickedcancel = false
elseif reason = swpropertymanagerpageclose_cancel then
' cancel was pressed
clickedcancel = true
end if
material = mypropvals(pm_combo.currentselection)
end sub
private function propertymanagerpage2handler4_onsubmitselection(byval id as long, byval selection as object, byval seltype as long) as boolean
' every time a selection is made, return true or false to validate and allow or disallow the selection
' good for checking whether you want the type of selected item
' allow all
propertymanagerpage2handler4_onsubmitselection = true
end function
ps in the class, you may need to define blank function calls to all of the propertypage events before it will let you build it, so just create the blanks if asked. i left them out for space saving
luke,
thank you for the example, i have seen something similar in help, but what can i do if the selection is
an edge? the manual says the method returns edge object but i can not get anything from it. i will check your code and think how can i deal with my task.
regards, basil
"and when you loose control,
you'll reap the harvest you have sown..." (c) pink floyd
solidworks 2008 x64 sp5.0 (production)
solidworks 2009 x64 sp2.0 (testing)
windows xp x64 sp2
core2quad 6600, 4gb ram, 500gb sata, ati firegl v7700 1024mb (softmodded from hd3850), 19" tft
is there any possibility how to use this selection box out of property manager page? i mean as control on user control or even better in vb6.
quick
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|Archiver|小黑屋|几何尺寸与公差论坛

GMT+8, 2024-12-23 14:48 , Processed in 0.037971 second(s), 19 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表