SolidWorks Two APIs used to access the characteristics
To learn two APIs:
SELECTBYID2 and GetSelectedObject5. These two functions, the first one by giving the NAME selection object of the object. The second is to get an object by the index that has been selected before the program is enabled.
Look at the following procedure:
Option expedition
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 characteristics called "Tensile 1"
BoolStatus = Model.extension.Selectbyid2 ("Stretch 1", "Bodyfeature", 0, 0, 0, False, 0, Nothing, SWSELECTOTIONDEFAULT)
'Mainly this sentence, the last parameter of the function after writing Option Explicit SwselectOptionDefault can use 0 instead
'Ness the selection was successful, "EXTRUDE1" WAS
'SELECTED AND IS A "Bodyfeature", Then Get That Feature; OtherWise,
'Indicate Failure
If BoolStatus = True Then 'If there is a "stretch 1" this feature below the code
DIM SELMGR AS SelectionMgr
SET SELMGR = Model.SelectionManager
Set feature = sleelmgr.getSelectedObject5 (1) 'Use an index here to get features
Debug.print feature.name
Else
Debug.print "Error"
END IF
End Sub
Finally, the VB syntax of these two functions is listed:
ModelDocExtension :: SelectByID2 DescriptionThis method selects the specified entity. Syntax (OLE Automation) retval = ModelDocExtension.SelectByID2 (Name, Type, X, Y, Z, Append, Mark, Callout. SelectOption)
Input: (BSTR) NameName of object to select or an empty stringInput: (BSTR) TypeType of object (uppercase) as defined in swSelectType_e or an empty stringInput: (double) XX selection location or 0Input: (double) YY selection location or 0Input : (Double) ZZ Selection Location or 0Input: (variant_bool) append
If ... And if entity is ... Then ... TRUENot already selected The entity is appended to the current selection listAlready selectedThe entity is removed from the current selection listFALSENot already selectedThe current selection list is cleared, and then the entity is put on the listAlready selectedThe current selection list remains the same Input: (long) MarkValue that you want to use as a mark; this value is used by other functions that require ordered selectionInput: (LPCALLOUT) CalloutPointer to the associated calloutInput: (long) SelectOptionSelection option as defined in swSelectOption_e (see Remarks) Output:. (VARIANT_BOOL) retvalTRUE if item was successfully selected, FALSE if notSelectionMgr :: GetSelectedObject5 DescriptionThis method gets the selected object Syntax (OLE Automation) retval = SelectionMgr.GetSelectedObject5 (AtIndex)
Input: (long) AtIndexIndex position within the current list of selected items, where AtIndex ranges from to 1 SelectionMgr :: GetSelectedObjectCountOutput: (LPDISPATCH) retvalPointer to the Dispatch object as defined in swSelType_e; NULL may be returned if type is not supported or if Nothing is success
You can also use the VC to use the VC.