cancel
Showing results for 
Search instead for 
Did you mean: 

Checking if a property is "associated" with a Mesh Collector

Phenom
Phenom

To all,

 

I am trying to add a check before executing a small piece of code but I cannot seems to find the way of checking the "status" of a variable. Consider the following case: In NX.CAE create a 2D Mesh collector and DO not associate a property to it

 

The following get the property table "associated" with the Mesh collector

 

Dim propTable As CAE.PropertyTable = theMeshCollector.ElementPropertyTable

 

 

If there is no property associated with the 2D collector I expected 'propTable' to be (empty /Nothing) but this does not seem to be case: propTable.GetPropertyCount = 1

 

A quick test, see below, seems to always return a GetPropertyType = "NamedPropertyTable"

 

Dim spropName2 As String = propTable.GetPropertyNameByIndex(0)
theLW.WriteLine(" GetPropertyType is " & propTable.GetPropertyType(spropName2).ToString)

 

 

Any idea how I could do this test?

 

Dim propTable As CAE.PropertyTable = theMeshCollector.ElementPropertyTable

If (propTable Is Nothing) Then Goto ProcessNextMeshcollector

 

 

Thanks

Regards

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

Re: Checking if a property is "associated" with a Mesh Collector

Siemens Phenom Siemens Phenom
Siemens Phenom

You need to actually try to get the NamedPropertyTable. If one is not assigned, the Get will fail. Use Try/Catch to handle this.

 

        Dim femPart As CAE.FemPart = CType(theSession.Parts.BaseWork, CAE.FemPart)

        theLw.Open()

        For Each collector As CAE.MeshCollector In femPart.BaseFEModel.MeshManager.GetMeshCollectors

            theLw.WriteLine("Collector: " + collector.Name)

            Dim elemPropTable As CAE.PropertyTable = collector.ElementPropertyTable

            For i As Integer = 0 To elemPropTable.GetPropertyCount - 1

                Dim propName As String = elemPropTable.GetPropertyNameByIndex(i)
                Dim propType As CAE.PropertyTable.PropertyType = elemPropTable.GetPropertyType(propName)
                theLw.WriteLine(String.Format("  Property Name: {0}    Type: {1}", propName, propType.ToString))

                If propType = CAE.PropertyTable.PropertyType.NamedPropertyTable Then

                    Try

                        Dim pshellTable As CAE.NamedPropertyTable = elemPropTable.GetNamedPropertyTablePropertyValue("Shell Property")
                        theLw.WriteLine("    Shell Property name: " + pshellTable.Name)

                    Catch ex As Exception

                        theLw.WriteLine("    No Shell Property assigned to this collector")

                    End Try

                End If

            Next i

            theLw.WriteLine(vbNewLine)

        Next collector

Re: Checking if a property is "associated" with a Mesh Collector

Phenom
Phenom

Thanks JimB. Wanted to avoid a Try... Loop as I expected /naively thought that "Nothing" would be returned. Amended code as per your suggestion. Seems to work

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