cancel
Showing results for 
Search instead for 
Did you mean: 

update existing mesh with changed parameters

Creator
Creator

Hi,

 

I managed to update existing meshes to reflect design changes in the CAD part. But then, I also need to update the mesh with, e.g., a new element size (and other parameters).

 

I do find the mesh2dfree object. However it seems like this object has lost information about the face (geometry) it was created on and the mesh parameters it was created with.

 

Is there a way to change the mesh parameters of an existing mesh? Or, if I have to create a new mesh everytime via mesh2dBuilder like in the journal, how can I get the actual face the old mesh was based upon?

 

Thank you.

5 REPLIES

Re: update existing mesh with changed parameters

Valued Contributor
Valued Contributor

Hello Flo,

 

I have encountered a similar problem. Perhaps my code can help you. I wanted to edit a mesh and remove one or more bodies/faces from the mesh definition. I did not find a way to edit the mesh, so I recreated the mesh and copied the properties from the old mesh. My code only works for 2d meshes (and not for 2d mapped meshes) but can easily be extended. Below is my complete code.

 

Option Strict Off
Imports System
Imports NXOpen


Module Module1
    Public DEBUG As Boolean = False
    Public SelectedMesh As TaggedObject
    Public SelectedGeometry() As TaggedObject
    Public SelectedCollector As String


    Sub Main()

        Dim theSession As Session = Session.GetSession()
        Dim theLW As ListingWindow = theSession.ListingWindow
        theLW.Open()
        ' TODO: Add your application code here 

        GustoMSC_ExtractMesh.Main_ExtractMesh()


    End Sub

    Sub Execute()
        Dim theSession As Session = Session.GetSession()
        Dim theLW As ListingWindow = theSession.ListingWindow
        theLW.Open()
        If (DEBUG) Then theLW.WriteFullline("Start of execute")

        Dim BasePart As BasePart = theSession.Parts.BaseWork
        Dim BaseFemPart As CAE.FemPart = CType(theSession.Parts.BaseWork, CAE.FemPart)
        Dim fEModel As NXOpen.CAE.FEModel = CType(BaseFemPart.FindObject("FEModel"), NXOpen.CAE.FEModel)

        '-----------------  Step 1 -------------------------
        'Remove the selected bodies/faces from the mesh
        Dim MeshToEdit As CAE.Mesh = CType(SelectedMesh, CAE.Mesh)
        Dim meshManager1 As NXOpen.CAE.MeshManager = CType(fEModel.Find("MeshManager"), NXOpen.CAE.MeshManager)

        Dim mesh2dBuilder1 As NXOpen.CAE.Mesh2dBuilder
        mesh2dBuilder1 = meshManager1.CreateMesh2dBuilder(MeshToEdit)

        Dim cAEBody1 As NXOpen.CAE.CAEBody = CType(BaseFemPart.FindObject("CAE_Body(1)"), NXOpen.CAE.CAEBody)

        'Cast the taggedobjects from SelectedGeometry to DisplayableObject which are required as input for mesh2dBuilder1.SelectionList.RemoveArray(). 
        'Casting a complete array at once does not seem to work
        Dim objects1(SelectedGeometry.Length - 1) As NXOpen.DisplayableObject
        For ii As Integer = 0 To SelectedGeometry.Length - 1
            objects1(ii) = CType(SelectedGeometry(ii), NXOpen.DisplayableObject)
        Next

        Dim removed1 As Boolean
        removed1 = mesh2dBuilder1.SelectionList.RemoveArray(objects1)

        Dim meshes1() As NXOpen.CAE.Mesh
        meshes1 = mesh2dBuilder1.CommitMesh()

        'Copy the propertytable so it can be used in the creation of the next mesh
        Dim CopyPorpertyTable As CAE.PropertyTable = mesh2dBuilder1.PropertyTable

        '-----------------  Step 2 -------------------------
        'Create a new mesh on the selected bodies/faces

        Dim meshCollector1 As NXOpen.CAE.MeshCollector = CType(meshManager1.FindObject("MeshCollector[" & SelectedCollector & "]"), NXOpen.CAE.MeshCollector)

        Dim mesh2dBuilder2 As NXOpen.CAE.Mesh2dBuilder
        Dim NewMesh As CAE.Mesh = Nothing
        mesh2dBuilder2 = meshManager1.CreateMesh2dBuilder(NewMesh)
        mesh2dBuilder2.SelectionList.Clear()
        mesh2dBuilder2.SelectionList.Add(objects1)
        'Apply the property of the existing mesh to the new mesh
        mesh2dBuilder2.PropertyTable.CopyProperties(CopyPorpertyTable)
        mesh2dBuilder2.AutoResetOption = mesh2dBuilder1.AutoResetOption
        mesh2dBuilder2.ElementType.ElementDimension = mesh2dBuilder1.ElementType.ElementDimension
        mesh2dBuilder2.ElementType.ElementTypeName = mesh2dBuilder1.ElementType.ElementTypeName

        'mesh2dBuilder2.ElementType.DestinationCollector.ElementContainer = meshCollector1
        meshes1 = mesh2dBuilder2.CommitMesh()

        mesh2dBuilder1.Destroy()
        mesh2dBuilder2.Destroy()

        'Move the new mesh to the correct collector.
        'This is done through a new builder, since the mesh disappears from the model three if the mesh2dBuilder2 is used to get the collector... no idea why.
        Dim mesh2dBuilder3 As NXOpen.CAE.Mesh2dBuilder
        mesh2dBuilder3 = meshManager1.CreateMesh2dBuilder(meshes1(0))
        meshManager1.DragNDropMesh(meshes1(0), mesh2dBuilder3.ElementType.DestinationCollector.ElementContainer, meshCollector1)

        mesh2dBuilder3.Destroy()




    End Sub


    Public Function GetUnloadOption(ByVal dummy As String) As Integer

        'Unloads the image immediately after execution within NX
        GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately

        '----Other unload options-------
        'Unloads the image when the NX session terminates
        'GetUnloadOption = NXOpen.Session.LibraryUnloadOption.AtTermination

        'Unloads the image explicitly, via an unload dialog
        'GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Explicitly
        '-------------------------------

    End Function

End Module

The variables SelectedMesh, SelectedGeometry and SelectedCollector are populated into this code from the

GUI.

 

Hope this is of some help to you.

 

Regards,

Frederik

Re: update existing mesh with changed parameters

Siemens Phenom Siemens Phenom
Siemens Phenom

If you instantiate a builder with no reference to an existing object, the builder will create a new object. If you provide a reference to an existing object when instantiating the builder, you will be editing that existing object.

 

Instantiating a mesh builder with a reference to an existing mesh object is analagous to editing the mesh in the UI.

Re: update existing mesh with changed parameters

Valued Contributor
Valued Contributor

Hello Jim,

 

Thank you for your reply. In my case I wanted indeed a new mesh.

 

I have created a functionality similar to the existing "extract", but which does not lock up the mesh. In the first step, I remove bodies selected by the user from the mesh selected by the user. In the second step, I create a new mesh, on the previously selected bodies (which have been removed from the mesh definition) with the same properties as the previously selected mesh, apart from the mesh collector, which is also user selected.

 

This way, we can mesh our complete geometry in one operation (which gives the nicest meshes) We can then use our custom extract mesh to change the thickness for bodies, while keeping associativity.

I have added a short video showing the functionality.

(view in My Videos)

Regards,

Frederik

Re: update existing mesh with changed parameters

Creator
Creator
Hi Frederik,
thank you for your quick reply and sharing your code. Albeit I use NXOpen/python, it made the solution and the underlying structure very clear. It think adding/removing bodies will be one of my next tasks.
Regards Florian

Re: update existing mesh with changed parameters

Creator
Creator

Hi Jim,

thank you for sharing this key information. I just found the according section in the documentation.

Regards