几何尺寸与公差论坛

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

【转帖】rename in feature manager tree

[复制链接]
发表于 2009-4-12 19:26:20 | 显示全部楼层 |阅读模式
rename in feature manager tree
the macro below(macro 1) works fine. the object of the macro is to extrude a surface and rename the feature in the feature manager tree accordingly.the pre-condition should be that a line has to be selected before running the macro.
macro2 works pretty much the same as macro1.
the problem arises when macro 2 is run accidently without selecting a sketch.macro 2 renames the sketch of the previous surface to "electrode surface".i require both these macros to work only if a sketch line is selected.
macro1
dim swapp as object
dim part as object
dim selmgr as object
dim boolstatus as boolean
dim longstatus as long, longwarnings as long
dim feature as object
sub main()
set swapp = application.sldworks
set part = swapp.activedoc
set selmgr = part.selectionmanager
boolstatus = part.extension.selectbyid2("line4", "sketchsegment", -0.01345668175817, 0.03285693360425, 0, false, 0, nothing, 0)
part.clearselection2 true
boolstatus = part.extension.selectbyid2("line4", "sketchsegment", -0.01345668175817, 0.03285693360425, 0, false, 0, nothing, 0)
part.featureextrurefsurface2 true, false, false, 0, 0, 0.005, 0.0025, false, false, false, false, 0.02617993877992, 0.02617993877992, false, false, false, false
part.selectionmanager.enablecontourselection = 0
part.featurebypositionreverse(0).name = "wire surface"
end sub
macro2
dim swapp as object
dim part as object
dim selmgr as object
dim boolstatus as boolean
dim longstatus as long, longwarnings as long
dim feature as object
sub main()
set swapp = application.sldworks
set part = swapp.activedoc
set selmgr = part.selectionmanager
boolstatus = part.extension.selectbyid2("line1", "sketchsegment", 0.02949422013878, 0.01517958600207, -0.0225, false, 0, nothing, 0)
part.clearselection2 true
boolstatus = part.extension.selectbyid2("line1", "sketchsegment", 0.02949422013878, 0.01517958600207, -0.0225, false, 0, nothing, 0)
part.featureextrurefsurface2 true, false, true, 0, 0, 0.005, 0.005, false, false, false, false, 0.02617993877992, 0.02617993877992, false, false, false, false
part.selectionmanager.enablecontourselection = 0
part.featurebypositionreverse(0).name = "surefirst surface"
end sub
feroz mahomed
windows xp professional sp2
sworks 2009 sp2
nvidia quadro fx1500
hi,
what you have forces the selection of a specific line regardless of pre-selection.
you want to test for pre-selection before trying to extrude the surface.
you could also validate the selection to see if it is what is needed.
------sample macro------
dim swapp as sldworks.sldworks
dim part as object
dim selmgr as sldworks.selectionmgr
dim boolstatus as boolean
dim longstatus as long, longwarnings as long
dim feature as object
sub main()
set swapp = application.sldworks
set part = swapp.activedoc
set selmgr = part.selectionmanager
if selmgr.getselectedobjectcount = 0 then
msgbox "nothing is selected."
exit sub
end if
part.featureextrurefsurface2 true, false, false, 0, 0, 0.00254, 0.00254, false, false, false, false, 0.01745329251994, 0.01745329251994, false, false, false, false
part.selectionmanager.enablecontourselection = 0
part.selectedfeatureproperties 0, 0, 0, 0, 0, 0, 0, 1, 0, "new name of feature here"
part.clearselection2 true
end sub
hi scott,
the macro works fine now. thank you for the speedy response.
i have another macro that is used to rename a sketch in the feature manager tree.is it possible to have the user select a new name from a form/drop down or listbox?i currently have 8 macros to rename 8 different sketches.
feroz mahomed
windows xp professional sp2
sworks 2009 sp2
nvidia quadro fx1500
quick
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-12-23 03:57 , Processed in 0.034363 second(s), 19 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2023 Discuz! Team.

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