11 Replies Latest reply on Nov 23, 2016 2:22 AM by Alexandre Gragnano

    Macro Feature, SetSelections2 won't update the MacroFeatureData object

    Jacob Corder

      Hi. I'm having issues with replacing a selected face in my macro feature. I have a face that is selected and defines a features selected face similar to editing a 2d sketch's plane.

       

      My code calls macrofeature.accessselections

      Getselectedobjects

      Replace the current face's selected object index with with the new face.

      Setselectedobjects2

      Macrofeature.modifydefinition

       

      But it just doesnt work. I keeps the old selected face.

      I can set selections to nothing and that updates but replacing that selectedobjects index fails.

      Ill attach the code in the morning.

      Thanks

        • Re: Macro Feature, SetSelections2 won't update the MacroFeatureData object
          Jacob Corder

          Ok. I was able to figure it out. The only reason why it wasnt working is that if i call MacrofeatureData.SetSelections2(SelObj,SelMarks,SelDrViews) it fails. But if I Call MacroFeatureData.SetSelections(SelObj,SelMarks) it works. so for some reason SetSelections2 does not work but SetSelections() does work.

           

          so im just going to use the obsoleted api SetSelections()

            • Re: Macro Feature, SetSelections2 won't update the MacroFeatureData object
              Mohammed Elkalakhi

              Hell Jacob,

               

              I have the same problem, but even MacroFeatureData.SetSelections(SelObj,SelMarks) doesn't work for me,

              Could you pass me a sample of your code to see how you resolve it.

               

              Thank you in advance.

                • Re: Macro Feature, SetSelections2 won't update the MacroFeatureData object
                  Jacob Corder

                  Basically all i am doing is looking for the current item, and replaceing it with  a new item. The thing that bothers me the most is that the objects must be an array of a specific type like Face2() or body2() i have tried using objects() but it also failed. so luckily i was only needing to use faces.

                                                

                           Dim SelDrawingViews As Object = Nothing

                                                          Dim SelMarks As Object = Nothing

                                                          Dim SelObj As Object = Nothing

                                                          Dim SelTypes As Object = Nothing

                                                          Dim SelReplaced As Boolean = False

                                                          ParFeatData.GetSelections3(SelObj, SelTypes, SelMarks, SelDrawingViews, Nothing)

                                                          If IsNothing(SelObj) = False And IsNothing(SelTypes) = False Then

                                                              For i = LBound(SelTypes) To UBound(SelTypes)

                                                                  Select Case CType(SelTypes(i), swSelectType_e)

                                                                      Case swSelectType_e.swSelFACES

                                                                          If CurrentFeatureFace.IsSame(SelObj(i)) = True Then

                                                                              SelObj(i) = NewFeatureFace

                                                                              SelReplaced = True

                                                                          End If

                                                                  End Select

                                                              Next

                                                              If SelReplaced = True Then

                                                                  Dim SelFaceObj() As Face2 = Nothing

                                                                  Dim SelMarkInt() As Integer = Nothing

                                                                  For i = LBound(SelObj) To UBound(SelObj)

                                                                      If SelTypes(i) = swSelectType_e.swSelFACES Then

                  'This just calls a function that adds a face to an array of faces.

                                                                          JEMArrays.AddFaceToFaceArray(SelFaceObj, TryCast(SelObj(i), Face2), True)

                                                                          JEMArrays.AddIntegerToIntegerArray(SelMarkInt, CInt(SelMarks(i)), True)

                                                                      End If

                                                                  Next

                  'HERE IS THE ONLY WAY IT WORKS for me.

                  SelFaceobj is an array of faces

                                                                  ParFeatData.SetSelections(SelFaceObj, SelMarkInt)

                                                              End If

                                                          End If

              • Re: Macro Feature, SetSelections2 won't update the MacroFeatureData object
                Mohammed Elkalakhi

                Hello,

                 

                This is my code :

                 

                Public Sub EditMacroFeature()
                
                        ...
                
                        Dim newSel As Object
                        Dim mark As Integer
                
                        Dim selObj, selTypes, selMarks As Object
                
                        Dim newSelObj() As DispatchWrapper
                        Dim newSelMarks() As Integer
                        Dim drViews() As View
                
                        Try
                
                            ...
                
                            swFeatData.GetSelections3(selObj, selTypes, selMarks, Nothing, Nothing)
                
                            If newSel Is selObj(0) Then Exit Sub
                
                            selObj(0) = newSel
                            selMarks(0) = mark
                
                            ReDim Preserve newSelObj(0)
                            ReDim Preserve newSelMarks(0)
                            ReDim Preserve drViews(0)
                
                            newSelObj(0) = New DispatchWrapper(selObj(0))
                            newSelMarks(0) = selMarks(0)
                            drViews(0) = Nothing
                
                            swFeatData.SetSelections2(newSelObj, newSelMarks, drViews)
                
                            ' I also tried this swFeatData.SetSelections(newSelObj, newSelMarks)
                
                            swFeature.ModifyDefinition(swFeatData, swDoc, swComponent)
                
                        Catch ex As Exception
                            Throw ex
                        End Try
                
                    End Sub
                

                 

                I dont see why this does not work ?

                 

                Please help me!

                  • Re: Macro Feature, SetSelections2 won't update the MacroFeatureData object
                    Jacob Corder

                    I dont think its working because your not chaning the selected objects. Your just passing the same parameters back. Try to send it a new selection. I think solidworks checks to see if the current objects are the same.

                    • Re: Macro Feature, SetSelections2 won't update the MacroFeatureData object
                      Jacob Corder

                      I was able to use the DispatchWrapper successfully this morning. however, it does not work with SetSelections2. It only works with SetSelections(). Thanks to Artem, i can now have many different selection types.

                       

                      'If The Feature Face has changed then process it as follows.

                                                      If IsNothing(NewFeatureFace) = False Then

                                                          If ParFeatData.AccessSelections(ModDoc, Nothing) = True Then

                                                              ModDoc.ClearSelection2(True)

                                                              Dim SelDrawingViews As Object = Nothing

                                                              Dim SelMarks As Object = Nothing

                                                              Dim SelObj As Object = Nothing

                                                              Dim SelTypes As Object = Nothing

                                                              Dim SelReplaced As Boolean = False

                                                              ParFeatData.GetSelections3(SelObj, SelTypes, SelMarks, SelDrawingViews, Nothing)

                                                              If IsNothing(SelObj) = False And IsNothing(SelTypes) = False Then

                                                                  For i = LBound(SelTypes) To UBound(SelTypes)

                                                                      Select Case CType(SelTypes(i), swSelectType_e)

                                                                          Case swSelectType_e.swSelFACES

                                                                              If CurrentFeatureFace.IsSame(SelObj(i)) = True Then

                                                                                  SelObj(i) = NewFeatureFace

                                                                                  SelReplaced = True

                                                                              End If

                                                                      End Select

                                                                  Next

                                                                  If SelReplaced = True Then

                                                                      Dim SelFaceObj(UBound(SelObj)) As DispatchWrapper

                                                                      For i = LBound(SelObj) To UBound(SelObj)

                                                                          SelFaceObj(i) = New DispatchWrapper(SelObj(i))

                                                                      Next

                                                                      ParFeatData.SetSelections(SelFaceObj, SelMarks)

                                                                  End If

                                                              End If

                                                          End If

                                                      End If

                    • Re: Macro Feature, SetSelections2 won't update the MacroFeatureData object
                      Mohammed Elkalakhi

                      Now its work for me

                       

                      I only need to add this line code :

                       

                      swFeatData.AccessSelections(swDoc, swComponent)

                       

                      before calling GetSelections3 method.

                       

                      Thank you for your help

                      • Re: Macro Feature, SetSelections2 won't update the MacroFeatureData object
                        Alexandre Gragnano

                        Be careful to pass typed array to the method SetSelections2:

                        Take a look at Re: MacroFeature & PMPSelectionbox