-
Re: SelectionMgr.GetSelectedObjectType3() return undefined value
Artem Taturevych Oct 11, 2013 5:26 AM (in response to Manabu Yamamoto)Try the following macro which checks whether the selected object by index is sensor or not:
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swSelMgr As SldWorks.SelectionMgr
Sub main()
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swSelMgr = swModel.SelectionManager
Debug.Print IsSensor(1)
End Sub
Function IsSensor(selectionIndex As Integer)
On Error Resume Next
Dim swFeat As SldWorks.Feature
Set swFeat = swSelMgr.GetSelectedObject6(selectionIndex, -1)
If Not swFeat Is Nothing Then
IsSensor = (swFeat.GetTypeName2() = "Sensor")
Exit Function
End If
IsSensor = False
End Function
____________________________________________________
Regards,
Artem Taturevych, Application Engineer at Intercad (Australia)
translationXpert – add-in to translate SolidWorks models
myIntercad – an integrated tool for SolidWorks Professionals
-
Re: SelectionMgr.GetSelectedObjectType3() return undefined value
Jacob Corder Oct 11, 2013 7:58 AM (in response to Manabu Yamamoto)You could also check the type of the object like this.
Dim ThisSensor as Sensor
Dim SelObj as object = SelMgr.GetSelectedObject6(SelIndex,-1)
If typeof selObj is sensor then
ThisSensor = swSelMgr.GetSelectedObject6(SelIndex,-1)
End if
Or you could use Trycast as seen below
Dim ThisSensor as Sensor
ThisSensor = Trycast (SwSelMgr.GesSelectedObject6 (SelIndex,-1 ), Sensor)
If isnothing (ThisSensor) = false then
Debug.print("You got the sensor, yeah")
End if
-
Re: SelectionMgr.GetSelectedObjectType3() return undefined value
Manabu Yamamoto Oct 15, 2013 7:58 PM (in response to Manabu Yamamoto)Mr. Taturevych
Mr. Corder
My problem was solved by the method that you teached me.
Thank you.