solidworks二次開發-03-訪問特徵資料

來源:互聯網
上載者:User
訪問|資料 solidworks二次開發-03-訪問特徵資料
'coder arden
'filename : getchoosed.swp
'date  :2005-03-22
'used to get the simple hole infomation dep & dia
'finished lucky !!
'------------------------------------------------------------

Option Explicit
Dim swApp As SldWorks.SldWorks
Dim Model As ModelDoc2
Dim curfeature As feature
Dim boolstatus As Boolean
Dim featdata As SimpleHoleFeatureData2   '聲明一個簡單直孔對象
Dim component As Component2                
Dim dep As Double
Dim dia As Double
Dim SelMgr As SelectionMgr
Dim ncount As Integer

 

Sub getselected()

Set swApp = Application.SldWorks

Set Model = swApp.ActiveDoc

Set SelMgr = Model.SelectionManager

Set curfeature = SelMgr.GetSelectedObject5(1)  '得到當前選中的第一個特徵

    MsgBox curfeature.Name
   
Set featdata = curfeature.GetDefinition '得到特徵的定義

boolstatus = featdata.AccessSelections(Model, component) ' 可以對資料進行訪問了

ncount = featdata.GetFeatureScopeBodiesCount        

MsgBox ncount


dep = featdata.Depth    
dia = featdata.Diameter

MsgBox dia & "*" & dep

'MsgBox "error arden"    '在solidworks中可以使用swAPP.sendmsgtouser2
'featdata.ReleaseSelectionAccess
Model.Save
Model.EditRebuild
End Sub

**********************************************

上面程式運行前,假設你選擇了一個簡單直孔特徵。然後得到這個孔德一些參數。

孔深、直徑等。

solidworks的API雖然是e文的。介紹的還算詳細,並且有很多的example。大家可以多看看代碼。

要訪問一個特徵,需要經曆這樣的步驟:

定義一個特徵對象: dim....as ...

得到這個特徵 :比如使用GetSelectedObject5 還有SelectebyID等...

得到定義:GetDefinition

進行訪問:AccessSelections

上面的程式沒有if選擇的容錯機制,需要添加上。


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.