Cancel
Showing results for 
Search instead for 
Did you mean: 

Reflect Mesh and Increment Node and Element IDs

Creator
Creator

I have been unable to locate, either in the GUI or using the API, a way to reflect a mesh and increment the IDs of the nodes and elements. In PATRAN, I am able to reflect and then choose a number to increment nodes and also another a number to increment elements. Is there any way to accomplish this same task in Femap?

5 REPLIES

Re: Reflect Mesh and Increment Node and Element IDs

Siemens Genius Siemens Genius
Siemens Genius

DSi1042,

Please try this API.

To create reflected entities with IDs offset by the specified “ID offset”, use the "Created Entities" radio button and specify the ID Offset number. 

To create reflected entities which have the IDs of the “original entities” and have the “original entities” be offset by the “ID Offset", use the "Original Entities" radio button and specify the ID Offset number.

To simply reflect the entities and maintain the IDs in the reflected entities (i.e., NOT create a copy, but simply reflect the entities across a plane), select both "Reflect All Nodes and Elements" & "Delete Orignal Entities" check boxes and click OK in the following dialog box.

Attached is a screen capture of 4 plate elements reflected with their IDs offset to 100. 

Reflect_offset.PNG

 Please let me know if this is what you are looking for.

 

The HTML Clipboard

Dim topNode As Long
Sub Main
    Dim App As femap.model
    Set App = feFemap()

    Dim pElemSet As femap.Set
    Set pElemSet= App.feSet

    Dim pNewSet As femap.Set
    Set pNewSet = App.feSet

    Dim pAllSet As femap.Set
    Set pAllSet =App.feSet

    Dim pAllElem As femap.Set
    Set pAllElem = App.feSet

    Dim pNodeSet As femap.Set
    Set pNodeSet = App.feSet

    Dim holdSet As femap.Set
    Set holdSet = App.feSet

    Dim pTrack As femap.TrackData
    Set pTrack = App.feTrackData

    Dim nodeDlg As Boolean
    Dim elemDlg As Boolean
    Dim dBase As Variant
    Dim dNormal As Variant
    Dim dHold As Variant
    Dim nodeOffset As Long
    Dim original As Boolean
    nodeOffset = 0
    original = False
    nodeDlg = True
    elemDlg = True

    pNewSet.AddAll(FT_ELEM)
    topNode = pNewSet.Last()

    Begin Dialog UserDialog 290,154,"Reflect Options",.DlgFunc ' %GRID:10,7,1,1
        OKButton 10,126,130,21
        CancelButton 150,126,130,21
        GroupBox 10,7,270,63,"Entity ID Offset Options",.GroupBox1
        TextBox 170,49,100,14,.nodeOffset
        text 170,28,100,14,"ID Offset",.Text1
        OptionGroup .Group1
            OptionButton 20,28,130,14,"Created Entities",.OptionButton1
            OptionButton 20,49,130,14,"Original Entities",.OptionButton2
        CheckBox 30,98,180,14,"Delete Original Entities",.entDelete
        CheckBox 30,77,230,14,"Reflect All Nodes and Elements",.Entire
    End Dialog
    Dim dlg As UserDialog
    If Dialog(dlg) = 0 Then
        End
    End If
    nodeOffset = CDbl(dlg.nodeOffset)
    If dlg.group1 = 1 Then
        original = True
    End If

    If dlg.Entire = 0 Then
        If(pElemSet.Select(FT_ELEM, True, "Select Elements to reflect") <> FE_OK) Then
            End
        End If
    Else
        pElemSet.AddAll(FT_ELEM)
    End If
    pNodeSet.AddSetRule(pElemSet.ID,FGD_NODE_ONELEM)
    If App.fePlanePick("Select Plane to Reflect Across", dBase, dNormal, dHold) <> FE_OK Then
        End
    End If

    pAllSet.AddAll(FT_NODE)
    pAllElem.AddAll(FT_ELEM)

    pTrack.StartMesh()
    App.feGenerateReflect(FT_ELEM, pElemSet.ID, dBase, dNormal, 0, True)
    If dlg.entDelete Then
        App.feDeleteMesh(FT_ELEM, pElemSet.ID,True)
        pAllSet.Clear()
    End If

    pNewSet.Clear()
    pTrack.Created(FT_NODE,pNewSet.ID,True)

    pNodeSet.Reset
    pNewSet.Reset
    If original Then
        While(pNodeSet.Next)
            pNewSet.Next()
            holdSet.Add(pNodeSet.CurrentID + nodeOffset)
            If pAllSet.HasCommon(holdSet.ID) And nodeDlg Then
                App.feAppMessageBox(0,"Node ID's overlap")
                nodeDlg = False
            End If
            rc = App.feRenumber(FT_NODE,-pNodeSet.CurrentID,pNodeSet.CurrentID + nodeOffset)
            rc = App.feRenumber(FT_NODE,-pNewSet.CurrentID,pNodeSet.CurrentID)
            holdSet.Clear
        Wend
    Else
        While(pNodeSet.Next)
            pNewSet.Next()
            holdSet.Add(pNodeSet.CurrentID + nodeOffset)
            If pAllSet.HasCommon(holdSet.ID) And nodeDlg Then
                App.feAppMessageBox(0,"Node ID's overlap")
                nodeDlg = False
            End If
            rc = App.feRenumber(FT_NODE,-pNewSet.CurrentID,pNodeSet.CurrentID + nodeOffset)
            holdSet.Clear()
        Wend
    End If
    pNodeSet.Clear()
    pNodeSet.AddSet(pNewSet.ID)
    pNewSet.Clear()
     pTrack.Created(FT_ELEM, pNewSet.ID,True)

    pElemSet.Reset
    pNewSet.Reset
    If original Then
        While pElemSet.Next()
            pNewSet.Next()
            holdSet.Add(pElemSet.CurrentID + nodeOffset)
            If pAllElem.HasCommon(holdSet.ID) And elemDlg Then
                App.feAppMessageBox(0,"Element ID's overlap")
                elemDlg = False
            End If
            rc = App.feRenumber(FT_ELEM,-pElemSet.CurrentID, pElemSet.CurrentID + nodeOffset)
            rc = App.feRenumber(FT_ELEM,-pNewSet.CurrentID, pElemSet.CurrentID)
            holdSet.Clear()
        Wend
    Else
        While pElemSet.Next()
            pNewSet.Next()
            holdSet.Add(pElemSet.CurrentID + nodeOffset)
            If pAllElem.HasCommon(holdSet.ID) And elemDlg Then
                App.feAppMessageBox(0,"Element ID's overlap")
                elemDlg = False
            End If
            rc = App.feRenumber(FT_ELEM,-pNewSet.CurrentID, pElemSet.CurrentID + nodeOffset)
            holdSet.Clear()
        Wend
    End If

    App.feDeleteMesh(FT_NODE,pNodeSet.ID,True)

End Sub

Rem See DialogFunc help topic for more information.
Private Function DlgFunc(DlgItem$, Action%, SuppValue?) As Boolean
    Select Case Action%
    Case 1 ' Dialog box initialization
        DlgText("nodeOffset",Str$(((topNode\1000) + 1)*1000))
    Case 2 ' Value changing or button pressed
        Rem DlgFunc = True ' Prevent button press from closing the dialog box
        If DlgValue("entDelete") = 1 And DlgValue("Entire") = 1 Then
            DlgEnable("nodeOffset",False)
            DlgEnable("Group1",False)
            DlgText("nodeOffset",Str$(0))
        Else
            DlgEnable("nodeOffset",True)
            DlgEnable("Group1",True)
            'DlgText("nodeOffset",Str$(((topNode\1000) + 1)*1000))
        End If
    Case 3 ' TextBox or ComboBox text changed
        If CDbl(DlgText("nodeOffset")) <= topNode And (DlgValue("entDelete") = 0 Or DlgValue("Entire") = 0)Then
           ' MsgBox("Value must be above current highest node " + Str$(topNode))
           ' DlgText("nodeOffset",Str$(((topNode\1000) + 1)*1000))
        End If
    Case 4 ' Focus changed
    Case 5 ' Idle
                    Rem Wait .1 : DlgFunc = True ' Continue getting idle actions
    Case 6 ' Function key
    End Select
End Function

Re: Reflect Mesh and Increment Node and Element IDs

Creator
Creator

T_Giampietro,

 Awesome! This is what I was looking for. You Rock! 

 I did make a few changes just to allow me to increment both the nodes and elements by a different number.

 I very much appreciate your help on this one.

 

My modified code below:

Dim topNode As Long
Dim topElem As Long
Sub Main
    Dim App As femap.model
    Set App = feFemap()

    Dim pElemSet As femap.Set
    Set pElemSet= App.feSet

    Dim pNewSet As femap.Set
    Set pNewSet = App.feSet

    Dim pAllSet As femap.Set
    Set pAllSet =App.feSet

    Dim pAllElem As femap.Set
    Set pAllElem = App.feSet

    Dim pNodeSet As femap.Set
    Set pNodeSet = App.feSet

    Dim holdSet As femap.Set
    Set holdSet = App.feSet

    Dim pTrack As femap.TrackData
    Set pTrack = App.feTrackData

    Dim nodeDlg As Boolean
    Dim elemDlg As Boolean
    Dim dBase As Variant
    Dim dNormal As Variant
    Dim dHold As Variant
    Dim nodeOffset As Long
    Dim elemOffset As Long
    Dim original As Boolean
    nodeOffset = 0
    elemOffset = 0
    original = False
    nodeDlg = True
    elemDlg = True

    pNewSet.AddAll(FT_NODE)
    topNode = pNewSet.Last()
    pNewSet.Clear()
    pNewSet.AddAll(FT_ELEM)
    topElem = pNewSet.Last()

	Begin Dialog UserDialog 400,154,"Reflect Options",.DlgFunc ' %GRID:10,7,1,1
		OKButton 70,126,130,21
		CancelButton 210,126,130,21
		GroupBox 10,7,380,63,"Entity ID Offset Options",.GroupBox1
		TextBox 160,49,100,14,.nodeOffset
		TextBox 280,49,100,14,.elemOffset
		text 160,28,100,14,"Node ID Offset",.Text1
		text 280,28,100,14,"Elem ID Offset",.Text2
		OptionGroup .Group1
			OptionButton 20,28,130,14,"Created Entities",.OptionButton1
			OptionButton 20,49,130,14,"Original Entities",.OptionButton2
		CheckBox 30,98,180,14,"Delete Original Entities",.entDelete
		CheckBox 30,77,230,14,"Reflect All Nodes and Elements",.Entire
	End Dialog
    Dim dlg As UserDialog
    If Dialog(dlg) = 0 Then
        End
    End If
    nodeOffset = CDbl(dlg.nodeOffset)
    elemOffset = CDbl(dlg.elemOffset)
    If dlg.group1 = 1 Then
        original = True
    End If

    If dlg.Entire = 0 Then
        If(pElemSet.Select(FT_ELEM, True, "Select Elements to reflect") <> FE_OK) Then
            End
        End If
    Else
        pElemSet.AddAll(FT_ELEM)
    End If
    pNodeSet.AddSetRule(pElemSet.ID,FGD_NODE_ONELEM)
    If App.fePlanePick("Select Plane to Reflect Across", dBase, dNormal, dHold) <> FE_OK Then
        End
    End If

    pAllSet.AddAll(FT_NODE)
    pAllElem.AddAll(FT_ELEM)

    pTrack.StartMesh()
    App.feGenerateReflect(FT_ELEM, pElemSet.ID, dBase, dNormal, 0, True)
    If dlg.entDelete Then
        App.feDeleteMesh(FT_ELEM, pElemSet.ID,True)
        pAllSet.Clear()
    End If

    pNewSet.Clear()
    pTrack.Created(FT_NODE,pNewSet.ID,True)

    pNodeSet.Reset
    pNewSet.Reset
    If original Then
        While(pNodeSet.Next)
            pNewSet.Next()
            holdSet.Add(pNodeSet.CurrentID + nodeOffset)
            If pAllSet.HasCommon(holdSet.ID) And nodeDlg Then
                App.feAppMessageBox(0,"Node ID's overlap")
                nodeDlg = False
            End If
            rc = App.feRenumber(FT_NODE,-pNodeSet.CurrentID,pNodeSet.CurrentID + nodeOffset)
            rc = App.feRenumber(FT_NODE,-pNewSet.CurrentID,pNodeSet.CurrentID)
            holdSet.Clear
        Wend
    Else
        While(pNodeSet.Next)
            pNewSet.Next()
            holdSet.Add(pNodeSet.CurrentID + nodeOffset)
            If pAllSet.HasCommon(holdSet.ID) And nodeDlg Then
                App.feAppMessageBox(0,"Node ID's overlap")
                nodeDlg = False
            End If
            rc = App.feRenumber(FT_NODE,-pNewSet.CurrentID,pNodeSet.CurrentID + nodeOffset)
            holdSet.Clear()
        Wend
    End If
    pNodeSet.Clear()
    pNodeSet.AddSet(pNewSet.ID)
    pNewSet.Clear()
     pTrack.Created(FT_ELEM, pNewSet.ID,True)

    pElemSet.Reset
    pNewSet.Reset
    If original Then
        While pElemSet.Next()
            pNewSet.Next()
            holdSet.Add(pElemSet.CurrentID + elemOffset)
            If pAllElem.HasCommon(holdSet.ID) And elemDlg Then
                App.feAppMessageBox(0,"Element ID's overlap")
                elemDlg = False
            End If
            rc = App.feRenumber(FT_ELEM,-pElemSet.CurrentID, pElemSet.CurrentID + elemOffset)
            rc = App.feRenumber(FT_ELEM,-pNewSet.CurrentID, pElemSet.CurrentID)
            holdSet.Clear()
        Wend
    Else
        While pElemSet.Next()
            pNewSet.Next()
            holdSet.Add(pElemSet.CurrentID + elemOffset)
            If pAllElem.HasCommon(holdSet.ID) And elemDlg Then
                App.feAppMessageBox(0,"Element ID's overlap")
                elemDlg = False
            End If
            rc = App.feRenumber(FT_ELEM,-pNewSet.CurrentID, pElemSet.CurrentID + elemOffset)
            holdSet.Clear()
        Wend
    End If

    App.feDeleteMesh(FT_NODE,pNodeSet.ID,True)

End Sub

Rem See DialogFunc help topic for more information.
Private Function DlgFunc(DlgItem$, Action%, SuppValue?) As Boolean
    Select Case Action%
    Case 1 ' Dialog box initialization
        DlgText("nodeOffset",Str$(((topNode\1000) + 1)*1000))
        DlgText("elemOffset",Str$(((topElem\1000) + 1)*1000))
    Case 2 ' Value changing or button pressed
        Rem DlgFunc = True ' Prevent button press from closing the dialog box
        If DlgValue("entDelete") = 1 And DlgValue("Entire") = 1 Then
            DlgEnable("nodeOffset",False)
            DlgEnable("elemOffset",False)
            DlgEnable("Group1",False)
            DlgText("nodeOffset",Str$(0))
            DlgText("elemOffset",Str$(0))
        Else
            DlgEnable("nodeOffset",True)
            DlgEnable("elemOffset",True)
            DlgEnable("Group1",True)
            'DlgText("nodeOffset",Str$(((topNode\1000) + 1)*1000))
        End If
    Case 3 ' TextBox or ComboBox text changed
        If CDbl(DlgText("nodeOffset")) <= topNode And (DlgValue("entDelete") = 0 Or DlgValue("Entire") = 0)Then
           ' MsgBox("Value must be above current highest node " + Str$(topNode))
           ' DlgText("nodeOffset",Str$(((topNode\1000) + 1)*1000))
        End If
    Case 4 ' Focus changed
    Case 5 ' Idle
                    Rem Wait .1 : DlgFunc = True ' Continue getting idle actions
    Case 6 ' Function key
    End Select
End Function

 

Re: Reflect Mesh and Increment Node and Element IDs

Creator
Creator

Ok, so I've found some oddity.

I'm running v11.3.2. When I ran the script, the nodal output coordinate system was changed. I had several coordinate systems that I had previously created. All the original nodes had the default 0 basic coordinate system.

I created just a dummy script that only reflected elements using the feGenerateReflect command. I tried it on a portion of another model. Same deal, a different output coordinate system was assigned. I used the Femap Mesh--> Reflect--> Element command and did not observe the change in nodal output coordinate system.

I'm wondering if there is a bug in the feGenerateReflect function. Are you seeing anything similar?

Re: Reflect Mesh and Increment Node and Element IDs

Siemens Genius Siemens Genius
Siemens Genius

Yes I am seeing the same thing. The last argument in App.feGenerateReflect(...) "If True, then loads and constrains on the original entities are copied to newly created entities. If False, only the select entities are duplicated." 

 

When this is True it is duplicating the Csys and setting the output coordinate system on the duplicate entities to the newly created Csys. If it is set to False, the duplicated entities' output coordinate system remain the same as the originals. 

 

If you use Mesh > Reflect > Element and check "Loads, Constraints, Regions..." then a new coordinates system will be created and the duplicate entities will use that as the output coordinate system. This will act the same as when the API command is set to True.

 

 

Re: Reflect Mesh and Increment Node and Element IDs

Creator
Creator
Interesting. Ok. I may add a checkbox to allow both options. I supposed I didn't really think about it creating a new coordinate system for the nodes. In my instance I am mirroring about the XZ plane and my new Csys that is created is rotated 180 degrees about the X. We use grid point force data both through Femap freebody functions as well as through some of the printed output.
Thanks again!