Showing results for 
Search instead for 
Do you mean 
Reply
Solved! Go to solution

'Is Nothing' Operator

Hi,

Is there a specific command to write correctly :

If resultAccess.AskNodalResult(nodeIndex) Is Nothing Then
[do something]
End If

Indeed, I would like to do some actions if 'resultAccess.AskNodalResult(nodeIndex)' is accessible (it may or may not exist for some groups in my model), and otherwise to do nothing.

Written like that, an error message says that the 'Is operator' does not work with a Double type.

Thanks for your help,

Best Regards,

Baptiste ALLAFORT

7 REPLIES

Re: 'Is Nothing' Operator

 

That method returns a double, so try it like this:

 

If resultAccess.AskNodalResult(nodeIndex).Equals(0) Then
[do something]
End If

Re: 'Is Nothing' Operator

Hi,

Unfortunately, I tried that, and it doesn't work ..

Re: 'Is Nothing' Operator

The error message says that  : "data are not defined for all entities"

Solution
Solution
Accepted by topic author ballafort
‎03-03-2016 07:46 AM

Re: 'Is Nothing' Operator

[ Edited ]

Can the check be included in a Try...Catch Loop? if it fails to get the nodal result it most likely due to the fact that there is no data in the AccessResults for that node. If so can display a message and skip to the next node. Might not be "pretty" and goes against "proper" coding but I used this approach when dealing with similar issue (albeit with element), see below

 

Try
	theAccessedResult.AskElementNodalResult(elmIndex, elmNodeIdxs, elementValues)
Catch ex As Exception
	theLW.WriteLine ("-WARNING - Element " & iFEElmLabel.ToString & " does not exist in the accessed result - Ignored")
	ListElmNoResult.Add(iFEElmLabel.ToString)
	GoTo ProcessNextFEElm:
End Try	

 

Production: NX9.0.3.4, NX10.0.2.6
Development: VB.NET (amateur level !)

Re: 'Is Nothing' Operator

Yes it works perfectly ! This is exactly what I wanted ! Thanks a lot !

Re: 'Is Nothing' Operator

The "correct" way to do this is to use NXOpen.CAE.ResultAccess.IsResultDefined() to verify that a result exists on the node or element before you try to get the result.

 

        If resultAccess.IsResultDefined({elmIndex})(0) Then
            theAccessedResult.AskElementNodalResult(elmIndex, elmNodeIdxs, elementValues)
        End If

 

Note that the input is a list of indicies and the output is an array of booleans indicating wether each index has results.

Re: 'Is Nothing' Operator

Thanks for that JimB. Certainly looks "neater". Looks like I am getting close to "amateur level +"Smiley Wink

 

Will have a look at my code and may change it (most likely will change it!)

 

If the input is an array can you then passed an entire array of CAE.FEElement to .IsResultDefined? I currently have a loop

 

For Each theFEElm As CAE.FEElement In arrFEElmInGroupTarget
  
    Dim elmIndex As Integer = theresults.AskElementIndex(theFEElm.Label)
   ' do something

Next
Production: NX9.0.3.4, NX10.0.2.6
Development: VB.NET (amateur level !)