SolidWorks Two development -02-two APIs for accessing features

Source: Internet
Author: User
Tags empty ole
Visit | Visit SolidWorks Two development -02-two APIs for accessing features
To learn two APIs:

SelectByID2 and GetSelectedObject5. The first of these functions is to select the object by giving the name of the object. The second gets the object by the index that was selected before the program was enabled.

Look at the following program:

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



' Select the feature called ' Stretch 1 '

Boolstatus = Model.Extension.SelectByID2 ("Stretching 1", "Bodyfeature", 0, 0, 0, False, 0, nothing, swselectoptiondefault)



' Mainly this sentence, after writing Option explicit the last parameter of the function Swselectoptiondefault can use 0来 instead

' If ' selection was successful, which is, ' Extrude1 ' was

' Selected and it is a ' bodyfeature ', then to that feature; Otherwise,

' Indicate failure

If boolstatus = True Then ' If there is a feature of Stretch 1, the following code selects it

Dim Selmgr as Selectionmgr

Set selmgr = Model.selectionmanager

Set feature = SELMGR.GETSELECTEDOBJECT5 (1) ' Use a cable here to get the feature

Debug.Print feature. Name

Else

Debug.Print "Error"

End If

End Sub

Finally, the VB syntax for these two functions is listed:

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 a empty string



Input:



(BSTR) Type



Type of object (uppercase) as defined in Swselecttype_e or a 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 are 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 the functions that require ordered selection



Input:



(lpcallout) Callout



Pointer to the associated callout



Input:



(long) Selectoption



Selection option as defined in swselectoption_e (= remarks)



Output:



(VARIANT_BOOL) retval



TRUE If Item is 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::getselectedobjectco Unt



Output:



(lpdispatch) retval



Pointer to the Dispatch object as defined in Swseltype_e; NULL may being returned if type is not supported or if it is selected




You can also use VC to access through COM.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.