Hi everyone,
I would like to ask, how to measure the selected cylinder surface.
What I have been doing so far...
I was using the VB.NET standard Addin templete and have added a selection control in the UserPMPage.vb. This selection control was so defined, that it can only select the surfaces. Till this step the code works fine. The code for selection1:
<p>selection1 = group1.AddControl(selection1ID, controlType, "<span style="color: #e23d39;">selection</span>", leftAlign, options, "Select a cylinder.")</p>
Then I wrote a Function in SwAddin.vb, in order to measure the selected cylinder surface and return its value. Here is the codes...
<p>Public Function GetDiameter(ByVal <span style="color: #e23d39;"><span style="color: #e23d39;">selection</span> </span>As Object) As Double</p><p> Dim surfaceDiameter As Double</p><p> Dim sWMeasure As IMeasure</p><p> Dim swModel As IModelDoc2</p><p> Dim swModelDocExt As IModelDocExtension</p><p></p><p> Dim status As Boolean</p><p> Dim errors As Integer</p><p> Dim warnings As Integer</p><p> Dim fileName As String</p><p></p><p> swModel = iSwApp.ActiveDoc</p><p> swModelDocExt = swModel.Extension</p><p></p><p> status = swModelDocExt.SelectByID2("<span style="color: #e23d39;">selection</span>", "FACE", 0, 0, 0, False, 0, Nothing, 0)</p><p></p><p> sWMeasure = swModelDocExt.CreateMeasure</p><p> Debug.Print(status)</p><p> Debug.Print("Diameter: " & sWMeasure.Diameter)</p><p></p><p> Return surfaceDiameter </p><p>End Function</p>The Visual Studio Output: Debug.Print(status) gives me False. And Debug.Print("Diameter: " & sWMeasure.Diameter) gives me -1. It means nothing was selected.
My question: I have transfered the selection to the function then to the SelectByID2. What have I done wrong?
Thanks for your help!
SolidworksApi macros