2 Replies Latest reply on Aug 6, 2015 3:26 PM by Danny Bradford

    How to access a created property manager features?

    Danny Bradford

      Greetings all,

      I have created a property manager that has 2 selection boxes and a button. The selection boxes are limited to only edges and single selections each selection box.

       

      My work is in VB.net.

       

      FYI that combo box PIN 1 and PIN 2 is just there for a future use and does not participate with the code in question.

       

      I have played extensively with variations of the following within the "Add Pins" Button subroutine:

       

              Dim swApp As SldWorks

              Dim swModel As ModelDoc2

              Dim swSelMgr As SelectionMgr

              Dim swFeat As Feature

              Dim the_edge As Edge

              Dim instance As IModelDocExtension

              Dim Append As Boolean = False

              Dim Mark As Integer = 0

              Dim Callout As Callout = Nothing

              Dim SelectOption As Integer = 0

              Dim value As Boolean

       

                  swApp = GetObject("", "SldWorks.Application")

                  swModel = swApp.ActiveDoc

                  swSelMgr = swModel.SelectionManager

                  instance = swModel.Extension

       

       

                  pm_Selection.SetSelectionFocus()

                  pm_Selection.SetSelectedItem(0, True)

                  'Dim test As Integer = pm_Selection.SelectionIndex(0)

       

                  swFeat = CType(pm_Selection.GetSelectedItems(0), Feature)

                  value = swFeat.Select2(False, 0)

       

                  MsgBox(value)

       

                  pm_Selection.GetSelectedItems()

       

                  swFeat = swSelMgr.GetSelectedObject6(0, -1)

       

                  MsgBox(swFeat.GetID.ToString)

       

       

      Please dont read too much in the code as it has changed a million times and I am not sure if what you see above even works in its current state.

       

      I have tried to utilize the property manager selection boxes to select the edges in Solidworks and then grabbing them there but I am at a complete loss.

       

      Simply put, how do I programmatically utilize each of the items in the selection boxes to perform other functions like measuring them, create planes, points etc?

       

      Your help is greatly appreciated!

       

      Danny B

        • Re: How to access a created property manager features?
          Danny Bradford

          Greetings again,

          I have moved forward with the knowledge I have gained that there may not be a way to directly do what I need to do. I have built the measurement subroutine against the selected item in the assembly. This works great!

           

          The last piece to this puzzle is to have the Property manager select the lines. I have built something but this does not highlight each line as anticipated.

           

          Any guidance is greatly appreciated.

           

          Public Sub OnButtonPress(ByVal Id As Integer) Implements SolidWorks.Interop.swpublished.IPropertyManagerPage2Handler9.OnButtonPress

                  Dim swEnt As Entity

                  Dim swSelComp As Component2

                  Dim swSelObj As Object

                  Dim swApp As SldWorks

                  Dim swModel As ModelDoc2

                  Dim swSelMgr As SelectionMgr

                  Dim the_edge As Edge

           

                  Try

                      'measure long line

                      pm_Selection.SetSelectionFocus()

                      pm_Selection.SetSelectedItem(0, False) 'I hoped this would select the 3D Edge to then measure but it does not.

           

                      swApp = GetObject("", "SldWorks.Application")

           

                      swModel = swApp.ActiveDoc

                      swSelMgr = swModel.SelectionManager

                      swEnt = swSelMgr.GetSelectedObject5(1)

                      swSelObj = swSelMgr.GetSelectedObject5(1)

                      swSelComp = swSelMgr.GetSelectedObjectsComponent2(1)

           

                      the_edge = swSelObj

                      measure_line(the_edge) 'subroutine to measure the edge.

           

                      'measure short line

                      pm_Selection2.SetSelectionFocus()

                      pm_Selection2.SetSelectedItem(0, False) 'I hoped this would select the 3D Edge to then measure but it does not.

           

                      swApp = GetObject("", "SldWorks.Application")

           

                      swModel = swApp.ActiveDoc

                      swSelMgr = swModel.SelectionManager

                      swEnt = swSelMgr.GetSelectedObject5(1)

                      swSelObj = swSelMgr.GetSelectedObject5(1)

                      swSelComp = swSelMgr.GetSelectedObjectsComponent2(1)

           

                      the_edge = swSelObj

                      measure_line(the_edge) 'subroutine to measure the edge.

           

                  Catch ex As Exception

                      MsgBox(ex.ToString)

                  End Try

              End Sub

          • Re: How to access a created property manager features?
            Danny Bradford

            I got it. At least I have something that works. Instead of extracting the selected items after the selection is made from the selection box the only way I have found is to capture it within the handler for change:

             

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

             

                    OnSubmitSelection = True

             

                    edge_grp(Id) = Selection

             

                End Function

             

            In this instance edge_grp() is an array of edges and I am using the ID of the selection box to define which item in the array to pull as required in later functions.

             

            This is an incredibly limited way to do this, but in my case its OK because I only expect and allow one selection per selection box. This could be used for more but again it feels fragile and indirect.

             

            Why oh Why can I not just pull the items in the list directly?! It seems so obvious but who am I.

             

            If anyone can provide better insight on how to do this it would be much appreciated.