Showing results for 
Search instead for 
Do you mean 
Reply

Checking if Solution, Event and Elm ID exist - How to?

I am gathering pieced of code for a macro in NX.CAE . I am looking for a way of checking if a Solution, Event and Element ID exist in a given simulation file. The solution is a Response Simulation. So far I have isolated the following

 

 

Dim strSolutionToUse as String
Dim strEventName as String
strSolutionToUse = "aa"
strEventName= "SRSZ.803"

Dim solution1 As CAE.ResponseSimulation.Solution = CType(workSimPart.Simulation.ResponseSimulationManager.Solutions.FindObject(strSolutionToUse), CAE.ResponseSimulation.Solution)

Dim rSEvent1 As CAE.ResponseSimulation.RSEvent = CType(solution1.FindObject(strEventName), CAE.ResponseSimulation.RSEvent)

solution1.ActiveEvent = rSEvent1

 

Any help/ideas/suggestins, etc would be woelcome

 

Thanks

 

Regards

 

JXB

 

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

Re: Checking if Solution, Event and Elm ID exist - How to?

In NXOpen, if you want to iterate on objects, look for ObjectCollection.  In your example, you are looking for a specific Solution, so you should look at SolutionCollection, which is returned by the ResponseSimulationManager.Solutions method.  I would not rely on FindObject to find the solution I need because you cannot be sure the solution name is the key to find the right solution.  The string passed to FindObject must be the same as the one you would find when recording a journal and it is not guaranteed to be the solution's name.  Here is a code snippet:

 

        Dim theSession As Session = Session.GetSession()
        Dim simPart As NXOpen.CAE.SimPart = theSession.Parts.BaseWork
        Dim manager As NXOpen.CAE.ResponseSimulation.Manager = simPart.Simulation.ResponseSimulationManager

        Dim solutions As CAE.ResponseSimulation.Solution() = manager.Solutions.ToArray()
        Dim matchedSolution As CAE.ResponseSimulation.Solution
        For Each solution In solutions
            If solution.GetSolutionName = "The Solution you are looking for" Then
                matchedSolution = solution
                Exit For
            End If
        Next

        Dim matchedEvent As CAE.ResponseSimulation.RSEvent
        For Each rsEvent In matchedSolution.GetEvents()
            If rsEvent.GetEventName = "The event you are looking for" Then
                matchedEvent = rsEvent
            End If
        Next

        Dim elementIdToMatch As Integer = 1234
        Dim femPart As NXOpen.CAE.BaseFemPart = simPart.FemPart
        Dim elementMap As NXOpen.CAE.FEElementLabelMap = femPart.BaseFEModel.FeelementLabelMap
        Dim element As NXOpen.CAE.FEElement = elementMap.GetElement(elementIdToMatch)
        If (Not element Is Nothing) Then
            Dim nodes As NXOpen.CAE.FENode() = element.GetNodes()
        End If

 

You should iterate on all solutions and look for a specific name.  It would be the same idea for events.  For elements, you should use the FEElementLabelMap to check for the existence of an element.

Re: Checking if Solution, Event and Elm ID exist - How to?

Thanks a lot.

 

Once the solution has been found I can activate it after the loop

 

 If solution.GetSolutionName= strSolName Then  matchedSolution = mySolution
  theSimPart.Simulation.ActiveSolution = matchedSolution

 

Though i am not sur eif activating a solution is required to process the events in it. A bit like in an excel macro where one does not need to activate a sheet to write to it.

 

Thanks again

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

Re: Checking if Solution, Event and Elm ID exist - How to?

Hi MayaHTT_Etienne,

 

I am trying to tweak the (kindly) provided code to "fit" in my main macro but I am having trouble wi the: RespSimSolFound.GetEvents() statement. i get the erro msg about not deing defined. Below is the code

 

 

Option Strict Off
Imports System
Imports NXOpen
Imports NXUI
Imports NXOpen.UF

Module TestRespSimResults

    Dim theSession As Session = Session.GetSession()
    Dim theLW = theSession.ListingWindow()
    Dim theUI As NXOpen.UI = NXOpen.UI.GetUI()
    Dim theNXMessageBox As NXMessageBox = theUI.NXMessageBox

    Sub Main()

    theLW.Open()
	Dim basePart As BasePart = theSession.Parts.BaseWork	      
	Dim theSimPart as CAE.SimPart
    Dim theRespSimManager As NXOpen.CAE.ResponseSimulation.Manager = theSimPart.Simulation.ResponseSimulationManager
	
	Try
		theSimPart = CType(basePart, CAE.SimPart)
	Catch ex as NXException
		'part must not be a .sim part, warn user & exit journal
		msgbox("switch to a .sim part")
		return
	End Try
	 
	Dim strRSSolName as String
	Dim strRSEventName as String
	strRSSolName = "RespSim1"
	strRSEventName = "NameOfEventToFind"
		
        Dim RespSimSolFound As CAE.ResponseSimulation.Solution

	For Each myRespSimCol As CAE.ResponseSimulation.Solution In theRespSimManager.Solutions
		If myRespSimCol.GetSolutionName = strRSSolName Then
			'Set the Resp. Sim. to be used later to search for the event
			RespSimSolFound = myRespSimCol
		end if
	Next
	
    Dim matchedEvent As CAE.ResponseSimulation.RSEvent
	For each myRSEvent as RespSimSolFound.GetEvents() In theRespSimManager.Solutions
	   	theLW.WriteLine("Event Name is:" & myRSEvent.GetEventName)
		If myRSEvent.GetEventName = strRSEventName Then
              matchedEvent = rsEvent
        End If
	Next 
		
    End Sub
	
End Module

 

Thanks

 

Regards

 

JXB

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

Re: Checking if Solution, Event and Elm ID exist - How to?

Your variable RespSimSolFound is probably not set because the name you are looking for probably do not match.  Display all the solution names in your Listing Window.  Or debug your dll to see what is happening.

Re: Checking if Solution, Event and Elm ID exist - How to?

RespSimSolFound = myRespSimCol seems to the culprit and yet work! The statement
If myRespSimCol.GetSolutionName = strRSSolName Then
is taken into account but I am not sure if the allocation I staking place. The name to search definitely exist


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

Re: Checking if Solution, Event and Elm ID exist - How to?

Case sensitivity is an issue when comparing string values.

"Solution_1" <> "solution_1" <> "SoLuTiOn_1"

 

To perform a case insensitive string test, you could convert both strings to upper case (or lower case) before the test, or use the String.Compare() method with the proper value for the "case sensitive" argument.

 

"Solution_1".ToUpper = "solution_1".ToUpper = "SoLuTiOn_1".ToUpper

String.Compare("Solution_1", "solution_1", True) = 0

 

http://msdn.microsoft.com/en-us/library/zkcaxw5y%28v=vs.110%29.aspx

Re: Checking if Solution, Event and Elm ID exist - How to?

Thanks for hint. Will have to double-check this but I am pretty sure that the variable strRSSolName="RespSim1" is correctly set up because I am forcing it to that name for testing purpose. (later on it will part of a loop). Furthermore by doing something like;
if myRespSimCol.GetSolutionName = strRSSolName Then
theLW.WriteLine(" I am here")
End if

clearly shows that the test is valid as the line is "printed" in the info window
Production: NX9.0.3.4, NX10.0.2.6
Development: VB.NET (amateur level !)

Re: Checking if Solution, Event and Elm ID exist - How to?

solution appears to be

 

Dim RespSimSolFound As CAE.ResponseSimulation.Solution
Dim MatchedEvent As CAE.ResponseSimulation.RSEvent

For each myRSEvent As CAE.ResponseSimulation.RSEvent In RespSimSolFound.GetEvents
   theLW.WriteLine("  Event Name is:" & myRSEvent.GetEventName)
 If myRSEvent.GetEventName = strRSEventName Then
	MatchedEvent = myRSEvent
 End If
Next

 

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