AnsweredAssumed Answered

VB.NET: how to get selection from two selction controls?

Question asked by Ross John on Apr 7, 2017
Latest reply on Apr 7, 2017 by Ross John

Hi everyone,

I would like to ask how to get "values" from two selection controls in the UserPMPage. I have to say it is a very beginner's question.


What I have been doing so far...

1. I made two selection controls (selection1 and selection2) in the UserPMPage.vb file. The two selection controls were so defined, that only surfaces could be selected. It works fine till this step. Here are some of the codes....

Dim selection1 As PropertyManagerPageSelectionbox

Dim selection2 As PropertyManagerPageSelectionbox

Dim selection1ID As Integer = 51

Dim selection2ID As Integer = 52

selection1 = group1.AddControl(selection1ID, controlType, "selection1", leftAlign, options, "Select cylinder A.") 

selection2 = group1.AddControl(selection2ID, controlType, "selection2", leftAlign, options, "Select cylinder B.") 



2. Then I wrote a Function in SwAddin.vb. The two selected surfaces are inputs the outputs are the diameters of the two surfaces. Here is the struction of the Function...

Public Function GetDiameterOfSelectedSurfaces(ByVal selection1 As Object, ByVal selection2 As Object) As Double

        Dim DiameterA As Double

        Dim DiameterB As Double


        Dim swModel As ModelDoc2

        swModel = iSwApp.ActiveDoc


        Dim faces1 As IFace2 = DirectCast(selection1, IFace2)

        ' Do the job here to get DiameterA



        Dim faces2 As IFace2 = DirectCast(selection2, IFace2)

        ' Do the job here to get DiameterB



        Dim newRow(1) As String

        newRow = {DiameterA, DiameterB}

        Return newRow(1)

End Function



In the PMPHandler.vb file, I added the following codes...

   Public Function OnSubmitSelection(ByVal Id As Integer, ByVal selection1 As Object, ByVal selection2 As Object, ByVal SelType As Integer, ByRef ItemText As String) As Boolean Implements SolidWorks.Interop.swpublished.IPropertyManagerPage2Handler9.OnSubmitSelection

        axis = userAddin.GetDiameterOfSelectedSurfaces(selection1, selection2)

        Return True

    End Function



My question: I am very sure I have been going to far on the wrong way. There are so many error messages from Visual Studio. Thus I would like to have your advices to give me a correct direction. What have I done wrong?


As a beginner I could imagine to use the IDs of the two surfaces. But I dont know how.


Thank you so much!