2 Replies Latest reply on May 6, 2014 9:01 AM by Jacob Corder

    API MacroFeature Security Function. Cannot Get MacroFeatureData Object.

    Jacob Corder

      I am writing an application using macrofeatures that is using a COM Server, not a vba macro. everything works great until i try to get the MacroFeatureData object in the security function. Once i call IFeature.GetDefinition, it recursiveley calls itself forever. whats the deal with that. according to the API Help, the security function can get the IMacrofeatureData Object from the supplied Feature Object.

       

      I am assuming i have to tell it not to check for security all of the time but i have to set security based on some values stored in the MacroFeatureData Object.

       

      i have this code in the function to allow temporary disabling of the feature but i really don't like it.

       

      I am just checking the type of MacroFeature that i have defined, then i am seing if it is required as stored in the Parameters.

      if it is required then i am returning swMacroFeatureSecurityOptions_e.swMacroFeatureSecurityCannotBeDeleted

       

       

      '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

      Dim DisableSecurity as boolean = false    

      Dim SecurityCheck as integer = 0

       

      Public Function Security(ByVal app As Object, ByVal modelDoc As Object, ByVal feature As Object) As Object Implements SolidWorks.Interop.swpublished.ISwComFeature.Security

              Security = swMacroFeatureSecurityOptions_e.swMacroFeatureSecurityByDefault

              If SecurityCheck > 1 And DisableSecurity = False Then

                  DisableSecurity = True

              End If

              If DisableSecurity = False Then

                  DisableSecurity = True

                  Dim MacFeatData As MacroFeatureData = feature.GetDefinition

                  DisableSecurity = False

                  SecurityCheck = 0

                  If IsNothing(MacFeatData) = False Then

                      Dim Req As String = "FALSE"

                      Dim FeatType As Integer

                      MacFeatData.GetIntegerByName(JEMFeatures.CFeatureType, FeatType)

                      If FeatType = JEMEnum.MacroFeatureType_e.Child Then

                          MacFeatData.GetStringByName(JEMFeatures.ChildRequired, Req)

                          If UCase(Trim(Req)) = "TRUE" Then

                              Return swMacroFeatureSecurityOptions_e.swMacroFeatureSecurityCannotBeDeleted

                          End If

                      End If

                  End If

              Else

                  SecurityCheck = SecurityCheck + 1

              End If

          End Function

      '''''''''''''''''''''''''''''''

      Any ideas on a better way would be great.

        • Re: API MacroFeature Security Function. Cannot Get MacroFeatureData Object.
          Jacob Corder

          Does anyone have any ideas or recommendation for me on this?

            • Re: API MacroFeature Security Function. Cannot Get MacroFeatureData Object.
              Jacob Corder

              Ok so what i have done is in the COMServer that implements SwComFeature i have added a trigger to allow bypass of retrieval of the MacroFeatureData object

              I have a boolean value in my MacroFeatureData object that is named "Required"

              i have a local Variable Called DisableSecurityCheck this is what i set to true or false

              I have a Local Variable Called RegenCalling and EditCalling which are set to true once the Edit function is called and when the Regen Function is called. they are returned to false once those functions are done.

               

              During Normal Operation the security function will get called from Solidworks. beforei try to get the MacroFeatureData object, i set DisableSecurity to True. Once i get the macroFeatureData object i set it to False.

               

              what this does is it stops solidworks from calling the Security Function Over and over indefinately.

              This then allows me to set the feature as a non deleteable feature.

               

              All of my MacroFeatures have a parent unless it is the parent feature. i check for this with Feature.GetownerFeature

               

              Public Function Security(ByVal app As Object, ByVal modelDoc As Object, ByVal feature As Object) As Object Implements SolidWorks.Interop.swpublished.ISwComFeature.Security

                      Security = swMacroFeatureSecurityOptions_e.swMacroFeatureSecurityByDefault

                      If RegenCalling = False And EditCalling = False Then

                          If SecurityCheck > 2 Then

                              DisableSecurity = False

                              SecurityCheck = 0

                          End If

                          If DisableSecurity = True Then

                              SecurityCheck = SecurityCheck + 1

                              DisableSecurity = False

                          ElseIf DisableSecurity = False Then

                              Try

                                  Dim Req As String = "False"

                                  Dim FeatType As Integer = 0

                                  'Set The Feature Obeject to Type of Feature

                                  With TryCast(feature, Feature)

                                       'Check to see if it is a child Feature

                                      If IsNothing(.GetOwnerFeature) = False Then

                                         'Disable Security to allow for getting the MacroFeatureData Object

                                          DisableSecurity = True

                                          'Get the MacroFeatureDataObject

                                          With TryCast(.GetDefinition, MacroFeatureData)

                                             'Get The FeatureType which is a stored value that i have added to the MacroFeatureData Object

                                              .GetIntegerByName("COM Feature Type", FeatType)

                                              'I have many MacroFeatureTypes

                                              Select Case FeatType

                                                  Case MacroFeatureType_e.Child

                                                      'Check to see if it is Required

                                                      .GetStringByName("Required, Req)

                                                  Case MacroFeatureType_e.Appearance, MacroFeatureType_e.WaxFill

                                                      'These Features are always Required

                                                      Req = "TRUE"

                                              End Select

                                          End With

                                      End If

                                  End With

                                  If UCase(Trim(Req)) = "TRUE" Then

                                      'Set The Security to Non Deleteable

                                      Security = swMacroFeatureSecurityOptions_e.swMacroFeatureSecurityCannotBeDeleted

                                  End If

                             Catch Ex as Exception

                              Finally

                             'Ensure that the Security is set to False

                                  DisableSecurity = False

                                  SecurityCheck = 0

                              End Try

                          End If

                      End If

                      Return Security

                  End Function