8 Replies Latest reply on Apr 6, 2017 4:46 PM by Amen Allah Jlili

    VB.NET: measure the selected cylinder surface?

    Ross John

      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:

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

       

       

      Then I wrote a Function in SwAddin.vb, in order to measure the selected cylinder surface and return its value. Here is the codes...

       

      Public Function GetDiameter(ByVal selection As Object) As Double
           Dim surfaceDiameter As Double
           Dim sWMeasure As IMeasure
           Dim swModel As IModelDoc2
           Dim swModelDocExt As IModelDocExtension
      
           Dim status As Boolean
           Dim errors As Integer
           Dim warnings As Integer
           Dim fileName As String
      
           swModel = iSwApp.ActiveDoc
           swModelDocExt = swModel.Extension
      
           status = swModelDocExt.SelectByID2("selection", "FACE", 0, 0, 0, False, 0, Nothing, 0)
      
           sWMeasure = swModelDocExt.CreateMeasure
           Debug.Print(status)
           Debug.Print("Diameter: " & sWMeasure.Diameter)
      
           Return surfaceDiameter 
      End Function
      

       

      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!