14 Replies Latest reply on Jun 19, 2018 11:19 AM by Aleksandras Korolkovas

    Get5 (CustomPropertyManager) returns value, which by description is not possible

    Aleksandras Korolkovas

      Hi,

      For me this issue is very hard to solve and is nessesary to solve.

      In my code I have such line:

       

      STatusInt = custPropMgr.Get5("Aiva", False, Value, resolvedValue, isResolvedValue)

       

      and if I understood get5 function description right

      2017 SOLIDWORKS API Help - Get5 Method (ICustomPropertyManager)

      then isResolvedValue cant be false.

       

      Possibly function took longer to spit out value, but isResolvedValue value must be true.

      On my PC where is visual studio installed it is always true, but on all other computers usually it always false.

      I have checked this on my pc in debug mode and as solidworks addin command (logging to txt file). On other  computers only with logging to file.

       

      Someone can tell me what can be wrong?

        • Re: Get5 (CustomPropertyManager) returns value, which by description is not possible
          Jim Sculley

          Create a small, complete example that exhibits the problem.  Then post it here. 

          • Re: Get5 (CustomPropertyManager) returns value, which by description is not possible
            Alex Burnett

            It is difficult to tell what exactly is going on from the description you have given. I'll try to explain what the purpose of the isResolvedValue.

             

            Suppose you have the following custom property table:

             

            If you use Get5 then the following should apply for Material.

             

            isResolvedValue is true          result: Alloy Steel

            isResolvedValue is false          result: SW-Material@76320.sldprt

             

            I hope that makes sense. Good luck!

            • Re: Get5 (CustomPropertyManager) returns value, which by description is not possible
              Aleksandras Korolkovas

              a bit more explanation

               

              this is how api help describes function

              Dim instance As ICustomPropertyManager

              Dim FieldName As System.String

              Dim UseCached As System.Boolean

              Dim ValOut As System.String

              Dim ResolvedValOut As System.String

              Dim WasResolved As System.Boolean

              Dim value As System.Integer

              value = instance.Get5(FieldName, UseCached, ValOut, ResolvedValOut, WasResolved)

               

              this is how function return values acording to UseCashed

               

               

              If UseCached is set to...

              And the configuration has already been activated...

               

               

              Then...

              True

              Yes

              Up-to-date data is returned and WasResolved = true

              True

              No

              Cached data is returned and WasResolved = false

              False

              Yes

              Up-to-date data is returned and WasResolved = true

              False

              No

              Up-to-date data is returned and WasResolved = true

              So, as I understood, if put false, then it will always resolve value and WasResolved returns True.

              But...

              code lines:

              STatusInt = custPropMgr.Get5("Aiva", False, Value, resolvedValue, isResolvedValue)

              AddInLoger(String.Format("StatusInt ={0}; isResolved = {1}; Parameter value: {2}", STatusInt.ToString, isResolvedValue.ToString, resolvedValue.ToString)) 'it is special function to write txt log file and see where error is on other pc

              on my pc second line wrtes to txt:

              >>> StatusInt =2 ; isResolved = True; Parameter value:  Stainless pipe 42.4x2 polished AISI 316

              on any other pc where this ADDIN command is used:

              >>> StatusInt =2; isResolved = False; Parameter value: 

               

              Solidworks by itself showing resolved values on all computers, just api calls returns diferent values.

               

              tested on the same solidworks assembly and the same part. With Get5 I geting values from weldmember bodies in cut list.

              Jim, is no sense to put here example if only one code line act diferently on other pc and I want know why.

              Alex, I knew this, but it is from another opera.

                • Re: Get5 (CustomPropertyManager) returns value, which by description is not possible
                  Artem Taturevych

                  Alex, isResolved is ByRef parameter, not ByVal (so it is returned from the function, not expected by the function as an input). The expression and the resolved value is returned in the valOut and resValOut parameters respectively.

                   

                  I think what isResolved tells you is if you can truly 'trust' the value returned. Let me explain what I mean.

                   

                  For some performance improvements SOLIDWORKS is not caching the values within the configurations. So when property is accessed there is an option to specify if you want that to return from cache (i.e. instant) or that should resolve the configuration. You can do a test and purge the cache from the configuration so you can see minus instead of green check against the configuration name. Now when you specify False as cached parameter of Get5 you will see that SW will activate all configurations while getting the property so it would take some time. Otherwise it will return an instant value from the cache. I assume there may be the case when cached value won't be equal to the actual value (not updated) so the returned property is invalid.

                   

                  Aleksandras, I have tried to do some tests to prove my theory above, but for me the isResolved is inconsistent even within my machine. I have tried different options (e.g. changing the property within the document manager, pdm, purging the data, linking to dimension etc) but that always returned the valid resolved value while isResolved keep changing both when I use cached and not cached option. So seems like a bug to me (or maybe invalid documentation). I would recommend to use the 'cached = false' and ignore the isResolved option as you will get up-to-date value anyway. Or you might contact API Support for clarification.

                   

                  Thanks,

                  Artem

                    • Re: Get5 (CustomPropertyManager) returns value, which by description is not possible
                      Aleksandras Korolkovas

                      Artem, thanks for answer.

                       

                      In any case i use 'cached = false', but not only "isResolved' returns 'False'. In my biger explanation you can see 'resolvedValue' can return empty string when in Solidworks I see value which is resolved and not empty. This log making function shows that on other PC isResolved always false but 'resolvedValue' not always empty. Anyway, i cant trust this value, because later it goes to ERP program.

                       

                      On other PC's with ADDIN dll file in same directory placed other library dll files. This files is required to make ADDIN work. I dont see diference in version of dll libraries on my PC and other PC's, but probably they can be... Can it be that they are cause of this issue?

                      • Re: Get5 (CustomPropertyManager) returns value, which by description is not possible
                        Alex Burnett

                        Artem, you are correct. I was going a bit by memory and it turns out the SolidDNA API that I am using wrapped the Get5 method with a more intuitive function. That function takes an input of whether you want the resolved value or not.

                         

                        The function that calls Get5 actually has UseCached set to false for all calls. So in agreement with your answer, I would set UseCached to false so that you force SolidWorks to evaluate the data so it will always be up to date. If you're forcing it to evaluate every time, the wasResolved output should theoretically always be true.

                         

                        The only scenario I can see the wasResolved value being needed is if UseCached is set to true and there may or may not already be a value in the cache. This way you could see if it is evaluated when called rather than pulled from the cache.

                    • Re: Get5 (CustomPropertyManager) returns value, which by description is not possible
                      Ivana Kolin

                      are you getting properties from your active doc (main assembly or part) or from one of the components. Is it by chance possible that user has components in lightweight mode?

                        • Re: Get5 (CustomPropertyManager) returns value, which by description is not possible
                          Aleksandras Korolkovas

                          I always resolving whole assembly before the all other code. From lightweigt components most values is not trustable or posible error "object cant be set to instance". It means, lightweigt component have chances be kind of invisiblity to API calls.

                          I resolve it with api call in beginning of code. So user doesn't have chances to miss resolve of all components.

                            • Re: Get5 (CustomPropertyManager) returns value, which by description is not possible
                              Ivana Kolin

                              this is why Jim asked for complete example. Now we can only guess what you do.

                                • Re: Get5 (CustomPropertyManager) returns value, which by description is not possible
                                  Aleksandras Korolkovas

                                  You think there is sence to show sample of thousand lines?  Less is no sence for me, because it will not show more than this single line. Main question why one line of code gives diferent values on diferent computers but with same assembly model.

                                    • Re: Get5 (CustomPropertyManager) returns value, which by description is not possible
                                      Alex Burnett

                                      We don't need to see your full code or anything. Like Jim said above, if you could create a small example part along with a short API that is calls the Get5 method and exhibits the issue you're describing then that would help immensely. From there, we may be able to debug or track down a scenario that causes your issue.

                                        • Re: Get5 (CustomPropertyManager) returns value, which by description is not possible
                                          Aleksandras Korolkovas

                                             Before this is checked that this part is single body and this body is weldmember (pipe, bar,.. any profile).

                                          Part is component of assembly.

                                          Part usualy have only one configuration.

                                          Assembly is fully resolved.

                                           

                                          Function getSingleBodyWeldmentparameterValues(ByRef SingleBodyWeldmentModel As ModelDoc2, ByVal RefConfigName As String) As Tuple(Of String, String)

                                                  Dim AiVaKodas As String

                                                  Dim AivaApr As String

                                                  Dim swSubFeat As Feature

                                                  Dim swFeat As Feature

                                                  Dim cutFolder As BodyFolder

                                                  Dim custPropMgr As CustomPropertyManager

                                                  Dim CutListBody As Body2

                                                  Dim CutListBodies As Object

                                                  Dim propNames As Object

                                                  Dim vName As Object

                                                  Dim propName As String

                                                  Dim Value As String

                                                  Dim resolvedValue As String

                                                  Dim ITM_N As Integer

                                                  Dim isResolvedValue As Boolean

                                                  Dim STatusInt As Integer

                                                 

                                                  SingleBodyWeldmentModel.ShowConfiguration2(RefConfigName)

                                                  Dim modelName As String = Path.GetFileNameWithoutExtension(SingleBodyWeldmentModel.GetPathName)

                                                  swFeat = CType(SingleBodyWeldmentModel.FirstFeature, Feature)

                                                  ITM_N = 0

                                                  Do While Not swFeat Is Nothing

                                                      swSubFeat = CType(swFeat.GetFirstSubFeature, Feature)

                                                      Do While Not swSubFeat Is Nothing

                                                          cutFolder = Nothing

                                                          If swSubFeat.GetTypeName = "CutListFolder" Then

                                                              If swSubFeat.ExcludeFromCutList = False Then

                                                                  cutFolder = CType(swSubFeat.GetSpecificFeature2, BodyFolder)

                                                              End If

                                                          End If

                                                          If Not cutFolder Is Nothing Then

                                                              If cutFolder.GetBodyCount > 0 Then

                                                                  CutListBodies = cutFolder.GetBodies

                                                                  CutListBody = CType(CutListBodies(0), Body2)

                                                                  ITM_N = ITM_N + 1

                                                                  If CutListBody.IsSheetMetal = False Then

                                                                      custPropMgr = swSubFeat.CustomPropertyManager

                                                                      If Not custPropMgr Is Nothing Then

                                                                          propNames = custPropMgr.GetNames

                                                                          If Not IsNothing(propNames) Then

                                                                              For Each vName In CType(propNames, IEnumerable)

                                                                                  propName = CStr(vName)

                                                                                 If propName = "LENGTH" Then

                                                                                       Try

                                                                                          STatusInt = custPropMgr.Get5("Aiva", False, Value, resolvedValue, isResolvedValue)  '<-- This line gives diferent values depending on PC

                                          'line below write formatted string to text file

                                                                                         AddInLoger(String.Format("StatusInt ={0}; isResolved = {1}; Parameter value: {2}", _

                                          STatusInt.ToString, isResolvedValue.ToString, resolvedValue.ToString))

                                                                                          If STatusInt <> 2 Or isResolvedValue = False Or resolvedValue = "" Then

                                                                                              AivaApr = ""

                                          'line below write formatted string to text file

                                                                                              AddInLoger(String.Format("value is not trustable: {0}", AivaApr))

                                                                                          Else

                                                                                              AivaApr = resolvedValue

                                          'line below write formatted string to text file

                                                                                              AddInLoger(String.Format("Parameter value is ok: {0}", AivaApr))

                                                                                          End If

                                                                                      Catch ex As Exception

                                                                                          AivaApr = ""

                                          'line below write formatted string to text file

                                                                                          AddInLoger(String.Format("exception {1} --------while try to get parameter value: {0}", AivaApr, ex.Message))

                                                                                      End Try 'never got exception

                                           

                                          'another property

                                                                                      Try

                                                                                          STatusInt = custPropMgr.Get5("AivaKodas", False, Value, resolvedValue, isResolvedValue)

                                                                                          AddInLoger(String.Format("StatusInt ={0}; isResolved = {1}; Parameter value: {2}", _

                                          STatusInt.ToString, isResolvedValue.ToString, resolvedValue.ToString))

                                                                                          If STatusInt <> 2 Or isResolvedValue = False Or resolvedValue = "" Then

                                                                                              AiVaKodas = ""

                                                                                              AddInLoger(String.Format("value is not trustable: {0}", AiVaKodas))

                                                                                          Else

                                                                                              AiVaKodas = resolvedValue

                                                                                              AddInLoger(String.Format("Parameter value is ok: {0}", AiVaKodas))

                                                                                          End If

                                           

                                                                                      Catch ex As Exception

                                                                                          AiVaKodas = ""

                                                                                          AddInLoger(String.Format(" exception {1} --------while try to get parameter value: {0}", AiVaKodas, ex.Message))

                                                                                      End Try

                                                                                  End If

                                                                             Next vName

                                                                          End If

                                                                      End If

                                                                  End If

                                                              End If

                                                          End If

                                                          swSubFeat = CType(swSubFeat.GetNextSubFeature, Feature)

                                                      Loop

                                                      swFeat = CType(swFeat.GetNextFeature, Feature)

                                                  Loop

                                                  Dim RetTuple As New Tuple(Of String, String)(AivaApr, AiVaKodas)

                                                  AddInLoger(String.Format("Function returns: {0};  {1}", AivaApr, AiVaKodas))

                                                  Return RetTuple

                                              End Function