solidworks二次開發(fā)-01-錄制一個宏
2024-07-21 02:16:15
供稿:網友
 
solidworks二次開發(fā)-01-錄制一個宏 
第一步:
我們需要自己錄制一個宏,然后看看程序產生了什么代碼。當初學習excel時候就是這么干的。只是,solidworks要復雜一些,直接錄制的宏不能使用,需要做一些調整。在沒有經驗的時候我們最好按照下面的建議來做。
 edit or debug solidworks macro
 
edit or debug solidworks macros using microsoft vba.   使用microsoft vba編輯或調試宏
to edit or debug a solidworks macro:
click edit macro on the macro toolbar, or click tools, macro, edit.
notes: 注意:
to automatically edit a macro after recording it, click tools, options, systems options. on the general tab, select automatically edit macro after recording and click ok. this setting is persistent across solidworks sessions.
                   此選項automatically edit macro after recording 顧名思義是在記錄宏完畢后自動打開編輯界面。
if you recently edited the macro, you can select it from the menu when you click tools, macro. this menu lists the last nine macros that you edited.
                    已經編輯了宏,菜單中會有最近的9個宏程序列表供選擇。
in the dialog box, select a macro file (.swp) and click open. 選擇一個宏swp文件
note: you can also edit .swb files, which are older-style solidworks macro files. when you run or edit a .swb file, it is automatically converted to a .swp file. 舊的宏文件后綴為swb,你也可以打開swb,那么會自動保存為swp。
 edit or debug the macro. if it is a new macro, be sure to:如果是新的宏
 delete extra lines of code: 刪除一些多余的代碼:
 the following variables are declared automatically in a solidworks macro. delete any variables not used in the macro. 這些對象的聲明是自動產生的,可以將沒用的刪除 dim swapp as object
 dim part as object
 dim boolstatus as boolean
 dim longstatus as long, longwarnings as long
 dim featuredata as object
 dim feature as object
 dim component as object
delete all lines of code that change the view. 刪除切換試圖的代碼 
譯者注:像這樣的 part.activeview().rotateaboutcenter 0.0662574, 0.0346621 無情的刪掉吧
delete all modeldocextension::selectbyid2 calls appearing immediately before modeldoc2::clearselection2 calls. however, do not delete modeldocextension::selectbyid2 calls appearing immediately after modeldoc2::clearselection2 calls.
delete all modeldoc2::clearselection2 calls appearing immediately before modeldocextension::selectbyid2.
中國最大的web開發(fā)資源網站及技術社區(qū),