cancel
Showing results for 
Search instead for 
Did you mean: 

Check Element exists in a .fem/.afm from a .sim never works!

Phenom
Phenom

To all

 

I am back looking at some "old" code I neglected for a wee while and  I'd like some some help/pointer. I have established the basic code, see end of the message, to check if an element (user input) exists. However I am stuck (and have been for a few days!) when working from a .sim. The current thinking is to “switch” to the associated .fem or .afem using .SetWork, to establish the element map (defined as a public variable), check the element exits and switch back to the .sim

 

I have attached a test version of the code. I know for sure that the element exists but the code always return “Element not found”. I am attempting two tests/ways

  1. Check the FeElement exists in the Main()
  2. Pass the ElementMap to a function to check FeElement exists then return to the Main()

to test the code you will need

 any fem or .afm

 create a sim file (no need to set it up) as it is requried to test the "switch" .sim/.fem

Any help/advice would be greatly appreciated.

 

Regards

 

JXB

Option Strict Off
Imports System
Imports System.IO
Imports System.Collections

Imports NXOpen
Imports NXOpen.UF
Imports NXOpen.CAE
Imports NXOpen.Utilities
Imports NXOpen.BlockStyler

Module Module1
 
	Dim theUI As NXOpen.UI = NXOpen.UI.GetUI()
    Dim theSession As Session = Session.GetSession()
    Public Dim lw As ListingWindow = theSession.ListingWindow
	Dim theFeElement As CAE.FEElement
	Dim elementMap As CAE.FEElementLabelMap 		'= femPart.BaseFEModel.FeelementLabelMap	
	
	Public Dim theSimPart As CAE.SimPart			'the .sim file
	Public Dim theFEMCAEPart As CAE.CaePart			'the fem/afm associated with the .sim
	Public Dim theFEMPart As CAE.FemPart			'the .fem associated with .sim
	Public Dim theAssyFemPart As CAE.AssyFemPart	'the .afm associated with .sim
	
    Sub Main()
        
        lw.Open()
 
        '***************************************
        'the element ID we are interested in
		Dim lngElemID as Long = 136 '504
        '***************************************
		
		theSimPart = theSession.Parts.BaseWork
		theFEMCAEPart = theSimPart.FemPart
		
			If theFEMCAEPart.GetType is GetType(CAE.AssyFemPart) Then
				theAssyFemPart = theSimPart.FemPart
				lw.writeline("Work part is now the FEMCAE part")
				theSession.Parts.SetWork(theFEMCAEPart)
				
		'TEST 1: check if element ID exist from the Main()		
				elementMap=theAssyFemPart.BaseFEModel.FeelementLabelMap
				theFeElement = elementMap.GetElement(lngElemID)
				If (theFeElement Is Nothing) Then
					lw.WriteLine ("--Specified Element ID was not found")
				Else
					lw.WriteLine ("--Specified Element ID was found")	
				End If
				
		'TEST 2: check if element ID exist by calling a function
		'		 to test if the elementMap can be passed to a function
			'exclude lines 43-49 and remove comment mark below
			'GetOnWithIt(elementMap)
	
				theSession.Parts.SetWork(theSimPart)	
				lw.writeline("Work part is now the SIM part")
			
			Else
				lw.writeline("it's a .fem")
			End if
	
 
    End Sub
	
	'Test if the elementMap can be passed to a function
 	Sub GetOnWithIt(theElmMap as CAE.FEElementLabelMap)
	
	Dim lngElemID as Long = 136
	Dim theFeElement As CAE.FEElement
	
		If (theElmMap Is Nothing) Then
		lw.WriteLine ("Elm Map is nothing")	
		End if
	
		theFeElement = theElmMap.GetElement(lngElemID)
		If (theFeElement Is Nothing) Then
		lw.WriteLine ("--Specified Element ID was not found")
		Else
		lw.WriteLine ("--Specified Element ID was found")	
		End If	

	End Sub
End Module

 

 

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

Re: Check Element exists in a .fem/.afm from a .sim never works!

Siemens Phenom Siemens Phenom
Siemens Phenom

So many issues I don't know where to start, other than to offer my own example:

 

Option Strict Off
Imports System

Imports NXOpen

Module Module2

    Dim theUI As NXOpen.UI = NXOpen.UI.GetUI()
    Dim theSession As Session = Session.GetSession()
    Public lw As ListingWindow = theSession.ListingWindow

    Sub Main()

        Dim theSimPart As CAE.SimPart = Nothing           'the .sim file
        Dim theCAEPart As CAE.CaePart = Nothing           'the fem/afm associated with the .sim
        Dim theFEMPart As CAE.FemPart = Nothing           'the .fem associated with .sim
        Dim theAssyFemPart As CAE.AssyFemPart = Nothing   'the .afm associated with .sim

        lw.Open()

        '***************************************
        'the element ID we are interested in
        Dim lngElemID As Long = 136 '504
        '***************************************

        theSimPart = TryCast(theSession.Parts.BaseWork, CAE.SimPart)
        If theSimPart Is Nothing Then
            lw.WriteLine("Work part is not a SIM part")
            Return
        End If

        Dim theFeElement As CAE.FEElement = getElement(theSimPart, lngElemID)

        If (theFeElement Is Nothing) Then
            lw.WriteLine("--Specified Element ID was not found")
        Else
            lw.WriteLine("--Specified Element ID was found")
        End If

    End Sub

    Function getElement(ByVal caePart As CAE.CaePart, ByVal elemLabel As Integer) As CAE.FEElement

        Dim elementLabelMap As CAE.FEElementLabelMap = Nothing

        If TypeOf caePart Is CAE.FemPart Then
            Dim femPart As CAE.FemPart = CType(caePart, CAE.FemPart)
            elementLabelMap = femPart.BaseFEModel.FeelementLabelMap
        End If

        If TypeOf caePart Is CAE.AssyFemPart Then
            Dim assyFemPart As CAE.AssyFemPart = CType(caePart, CAE.AssyFemPart)
            elementLabelMap = assyFemPart.BaseFEModel.FeelementLabelMap
        End If

        If TypeOf caePart Is CAE.SimPart Then
            Dim simPart As CAE.SimPart = CType(caePart, CAE.SimPart)
            elementLabelMap = simPart.Simulation.Femodel.FeelementLabelMap
        End If

        getElement = elementLabelMap.GetElement(elemLabel)

    End Function

End Module

 

Re: Check Element exists in a .fem/.afm from a .sim never works!

Phenom
Phenom

Thanks. Will look into the kindly provided code

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