solidworks二次开发-02-用来访问特征的两个API 来学习两个api:SelectByID2和GetSelectedObject5。">
aspx">solidworks二次开发-02-用来访问特征的两个api
selectbyid2与getselectedobject5.这两个函数,第一个通过给出对象的name选择对象.第二个通过启用程序前已经选择的索引得到对象. 【程序编程相关:[原创]C#实现Window管道技术 】
来学习两个api: 【推荐阅读:如何使用vb6.0来实现中文实名搜索 】
option explicit 【扩展信息:昨日关注:C-omega vs ADO.】
看下面程序:
dim swapp as sldworks.sldworks
dim model as modeldoc2
dim feature as feature
dim boolstatus as variant
sub main()
set swapp = application.sldworks
set model = swapp.activedoc
选择叫"拉伸1"的特征
boolstatus = model.extension.selectbyid2("拉伸1", "bodyfeature", 0, 0, 0, false, 0, nothing, swselectoptiondefault)
主要就是这一句话,在写option explicit后函数的最后一个参数swselectoptiondefault可以使用0来代替
if the selection was successful, that is, "extrude1" was
selected and it is a "bodyfeature", then get that feature; otherwise,
indicate failure
if boolstatus = true then 如果有“拉伸1”这个特征下面的代码将其选中
dim selmgr as selectionmgr
set selmgr = model.selectionmanager
set feature = selmgr.getselectedobject5(1) 此处使用一个索引来得到特征
debug.print feature.name
else
debug.print "error"
... 下一页