cancel
Showing results for 
Search instead for 
Did you mean: 

copy a propertyTable object in NX Open/PYTHON

Creator
Creator

I want to store the information of a CAE.PropertyTable. This seems to work in, e.g, VB:

Dim CopyPropertyTable As CAE.PropertyTable = mesh2dBuilder1.PorpertyTable

However, in python I can't figure this out because only one single instance of a CAE.PropertyTable seems to be allowed and working in NX Open:

# Mesh2dBuilder.PropertyTables from different meshBuilders reference the same object ?!?:
mb = mesh_manager.CreateMesh2dBuilder(meshes[0])
logger.debug(mb)                # <NXOpen.CAE.Mesh2dBuilder object at 0x00000000185F9C60>
logger.debug(mb.PropertyTable)  # <NXOpen.CAE.PropertyTable object at 0x00000000185F9CC0>

mb2 = mesh_manager.CreateMesh2dBuilder(NXOpen.CAE.Mesh2d.Null)
logger.debug(mb2)               # <NXOpen.CAE.Mesh2dBuilder object at 0x00000000185F9C90>
logger.debug(mb2.PropertyTable) # <NXOpen.CAE.PropertyTable object at 0x00000000185F9CC0>

ptc = NXOpen.CAE.PropertyTable() # again, the same PropertyTable object is referenced:
logger.debug(ptc)                # <NXOpen.CAE.Mesh2dBuilder object at 0x00000000185F9CC0>


# these commands actually yield different objects ...
ptc = copy.copy(mb.PropertyTable)  # <NXOpen.CAE.PropertyTable object at 0x00000000185F9DE0>
ptc = NXOpen.CAE.PropertyTable(mb.PropertyTable)  # new object, too

# ... but accesing them fails identically for both copies:
# "NXOpen.NXException: Invalid self parameter passed., Object not longer exists"

 

What can I do to solve this in python?

 

Best regards

Florian

6 REPLIES

Re: copy a propertyTable object in NX Open/PYTHON

Siemens Phenom Siemens Phenom
Siemens Phenom

The first question would be what is the bigger picture of what you are trying to do? What do you plan to do with the PropTable copy? Property tables are sub objects and cannot be assigned to other objects in whole. You can only modify individual properties in a property table.

Re: copy a propertyTable object in NX Open/PYTHON

Creator
Creator
I need to update/change all meshes in a FEM file in a certain order, due to mesh-mating conditions. Therefore, I need to store each meshe's parameters. The simplest way would be to just (deep-)copying and reassigning the PropertyTable object.
With the trial&error described above, I get all the parameters (using GetPropertyCount and GetPropertyNameByIndex) and set them to for the new mesh afterwards. But this requires a lot more source code than the copy solution.

Is it general, that subclasses' objects cannot be copied and reassigned?

Re: copy a propertyTable object in NX Open/PYTHON

Siemens Phenom Siemens Phenom
Siemens Phenom

Correct. There is no method to "set" the property table reference. You can only "get" a property table reference, then get/set individual properties on the table.

Re: copy a propertyTable object in NX Open/PYTHON

Creator
Creator
Thanks a lot for this clarification.

Re: copy a propertyTable object in NX Open/PYTHON

Creator
Creator

actually my smartest way to clone mesh properties is now

 

# copy the mesh data (assuming target/source mesh builders are available)
target_mesh_builder.ElementType.ElementDimension = \
    source_mesh_builder.ElementType.ElementDimension
target_mesh_builder.ElementType.ElementTypeName = \
    source_mesh_builder.ElementType.ElementTypeName
target_mesh_builder.ElementType.DestinationCollector.ElementContainer = \
        source_mesh_builder.ElementType.DestinationCollector.ElementContainer
target_mesh_builder.ElementType.DestinationCollector.AutomaticMode = False  # use old collector
target_mesh_builder.PropertyTable.CopyProperties(source_mesh_builder.PropertyTable)
target_mesh_builder.SelectionList.Add(source_mesh_builder.SelectionList.GetArray())  # Clear()
# note there is a bug: exportMesh will always be initialized True within a meshBuilder
# target_mesh_builder.ExportMesh = source_mesh_builder.ExportMesh
target_mesh_builder.AutoResetOption = source_mesh_builder.AutoResetOption

target_mesh_builder.SelectionList.Clear()  # remove geometries from master mesh
target_mesh_builder.SelectionList.Add(new_mesh_geometries)  # add clone geometries

copied_mesh = target_mesh_builder.CommitMesh()

# Destroy() source/target mesh builders

 

Note the use of PropertyTable.CopyProperties(PropertyTable) which copies the full property table.

 

hope this helps ...

 

Re: copy a propertyTable object in NX Open/PYTHON

Siemens Phenom Siemens Phenom
Siemens Phenom

Yes, that is using a reference from one table to set a reference on another table - the Get/Set I referred to above without any intermediate variables.