国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > 綜合 > 正文

solidworks二次開發-04-修改數據

2024-07-21 02:16:14
字體:
來源:轉載
供稿:網友
solidworks二次開發-04-修改數據
上次已經可以訪問特征的各參數了,今天我們來修改它:

要修改前面的步驟不能少,當我們已經可以讀取一些特征時,我們就可以給他設定一些值。當然有時需要調用特定的參數。solidworks是ole和com的,所以要習慣這樣。

在修改完特征后需要調用函數modifydefinition()來實現變化。

我們給一個例子,這個例子比前面的都要全面,它有很好的容錯引導機制,可以直接拿來成為一個穩定的宏程序。

this example doubles the length of the base extrude.這個例子將拉伸凸臺的長度增加一倍



 



dim swapp as sldworks.sldworks



dim model as modeldoc2



dim component as component2



dim curfeature as feature



dim isgood as boolean



' will become an extrudefeaturedata object



dim featdata as object



dim depth as double



dim selmgr as selectionmgr



 



 



sub doublebe()



}}-->    }}-->set swapp = createobject("sldworks.application")



}}-->    }}-->set model = swapp.activedoc



}}-->    }}-->' make sure that the active document is a part



}}-->    }}-->if model.gettype <> swdocpart and model.gettype <> swdocassembly then

‘這里的swdocpart 、swdocassembly 我的環境沒有通過。我使用msgbox model.gettype  的笨辦法得到整數為1和2 



}}-->        }}-->msg = "only allowed on parts or assemblies" ' define message



}}-->        }}-->style = vbokonly ' ok button only



}}-->        }}-->title = "error" ' define title



}}-->        }}-->call msgbox(msg, style, title) ' display error message



}}-->        }}-->exit sub ' exit this program



}}-->    }}-->end if



}}-->    

}}-->

}}-->    }}-->' get the selection manager



}}-->    }}-->set selmgr = model.selectionmanager



}}-->    

}}-->

}}-->    }}-->' get the selected object (first in the group if there are more than one)



}}-->    }}-->' note that at this point curfeature is just a feature object



}}-->    }}-->set curfeature = selmgr.getselectedobject3(1)



}}-->    }}-->if curfeature is nothing then



}}-->        }}-->' tell the user that nothing is selected



}}-->        }}-->swapp.sendmsgtouser2 "please select the base-extrude", swmbwarning, swmbok



}}-->        }}-->exit sub



}}-->    }}-->end if



 



}}-->    }}-->' check the feature's type name



}}-->    }}-->' make sure it is an extrusion



}}-->    }}-->if not curfeature.gettypename = swtnextrusion then  

’在這里使用swtnextrusion我的環境沒有通過,我改成了extrusion才ok

}}-->        }}-->swapp.sendmsgtouser2 "please select the base-extrude", swmbwarning, swmbok



}}-->        }}-->exit sub



}}-->    }}-->end if



 



}}-->    }}-->' get the extrusion's feature data



}}-->    }}-->set featdata = curfeature.getdefinition



}}-->           

}}-->

}}-->   }}-->' get the access selections for the feature data



}}-->   }}-->' note that component is null when accessing the selections of a standalone part. }}--> }}-->if we were calling accessselections from within an assembly, then model would refer to the top-level document in the assembly and component would refer to the actual part.



}}-->    }}-->isgood = featdata.accessselections(model, component)



}}-->            

}}-->

}}-->    }}-->' inform the user of an error



}}-->    }}-->if not isgood then



}}-->        }}-->swapp.sendmsgtouser2 "unable to obtain access selections", swmbwarning, swmbok



}}-->        }}-->exit sub



}}-->    }}-->end if



}}-->    

}}-->

}}-->    }}-->' make sure the user has selected the base extrude



}}-->    }}-->if not featdata.isbaseextrude then



}}-->        }}-->swapp.sendmsgtouser2 "please select the base-extrude", swmbwarning, swmbok



}}-->        }}-->featdata.releaseselectionaccess



}}-->        }}-->exit sub



}}-->    }}-->end if



}}-->            

}}-->

}}-->    }}-->' change the depth of this extrusion to double its previous depth



}}-->    }}-->depth = featdata.getdepth(true)



}}-->    }}-->featdata.setdepth true, depth * 2



}}-->            

}}-->

}}-->    }}-->' implement the changes to the feature



}}-->    }}-->isgood = curfeature.modifydefinition(featdata, model, component)



}}-->            

}}-->

}}-->    }}-->' if the modify definition failed



}}-->    }}-->if not isgood then



}}-->        }}-->swapp.sendmsgtouser2 "unable to modify feature data", swmbwarning, swmbok



}}-->        }}-->' release the accessselections



}}-->        }}-->featdata.releaseselectionaccess



}}-->    }}-->end if



}}--> 

}}-->

end sub

 

如果出現特征出現“退回”狀態,我現在還沒有找到問題的原因,只能在代碼執行到最后調用

    model.save
    model.rebuild

這兩個函數來自動更新。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 长垣县| 洪江市| 岱山县| 黑河市| 廊坊市| 通渭县| 耿马| 宁安市| 丰原市| 石城县| 郸城县| 泸溪县| 安义县| 萍乡市| 玛纳斯县| 武清区| 仁布县| 吴堡县| 增城市| 城市| 德钦县| 铜鼓县| 本溪| 广水市| 潞城市| 扶沟县| 会同县| 玉树县| 德惠市| 黄山市| 兴宁市| 建瓯市| 浦北县| 徐州市| 通城县| 广西| 泉州市| 稻城县| 嘉荫县| 惠安县| 上饶市|