现在的位置: 首页 > 综合 > 正文

solidworks二次开发-02-用来访问特征的两个API

2013年08月13日 ⁄ 综合 ⁄ 共 2306字 ⁄ 字号 评论关闭

solidworks二次开发-02-用来访问特征的两个API

来学习两个api:

SelectByID2和GetSelectedObject5。这两个函数,第一个通过给出对象的name选择对象。第二个通过启用程序前已经选择的索引得到对象。

看下面程序:

Option Explicit

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"

End If

 End Sub

最后列出这两个函数的VB语法:

ModelDocExtension::SelectByID2

 

Description

This method selects the specified entity.

 

Syntax (OLE Automation)

retval = ModelDocExtension.SelectByID2 ( Name, Type, X, Y, Z, Append, Mark, Callout. SelectOption )

Input:

(BSTR) Name

Name of object to select or an empty string

Input:

(BSTR) Type

Type of object (uppercase) as defined in swSelectType_e or an empty string

Input:

(double) X

X selection location or 0

Input:

(double) Y

Y selection location or 0

Input:

(double) Z

Z selection location or 0

Input:

(VARIANT_BOOL) Append

If...

And if entity is...

Then...

TRUE

Not already selected

 

The entity is appended to the current selection list

Already selected

The entity is removed from the current selection list

FALSE

Not already selected

The current selection list is cleared, and then the entity is put on the list

Already selected

The current selection list remains the same

 

Input:

(long) Mark

Value that you want to use as a mark; this value is used by other functions that require ordered selection

Input:

(LPCALLOUT) Callout

Pointer to the associated callout

Input:

(long) SelectOption

Selection option as defined in swSelectOption_e (see Remarks)

Output:

(VARIANT_BOOL) retval

TRUE if item was successfully selected, FALSE if not

SelectionMgr::GetSelectedObject5

  

Description

This method gets the selected object.

 

Syntax (OLE Automation)

retval = SelectionMgr.GetSelectedObject5 ( AtIndex )

Input:

(long) AtIndex

Index position within the current list of selected items, where AtIndex ranges from 1 to SelectionMgr::GetSelectedObjectCount

Output:

(LPDISPATCH) retval

Pointer to the Dispatch object as defined in swSelType_e; NULL may be returned if type is not supported or if nothing is selected

也可以通过COM使用vc来访问。

抱歉!评论已关闭.