To all
Could someone explain something to me? This is more vb specific but with NX keywords (and reflect my very limited knowledge of programming). I am looking at the ‘SimSimulation’ Class which has a property called ‘Solutions’ which returns the CAE Solution collection belonging to this sim part. The doc for this property gives
Public ReadOnly Property Solutions As SimSolutionCollection
Get
The questions are
1. How does one use the keyword? Something like that?
Dim basePart As BasePart = theSession.Parts.BaseWork
Dim simPart As CAE.SimPart = CType(basePart, CAE.SimPart)
Dim simulation As CAE.SimSimulation = simPart.Simulation()
Dim AllSolutions As CAE.SimSolution = simulation.Solutions()
2. What is 'AllSolutions' and what does it contains? An array? Digging further in the doc under the ‘SimSolutionCollection’ one can read ToArray() which returns an array of CAE.SimSolution objects.
The reason I am asking is that I want to be able to
1. get all the solutions defined in a simulation
2. for each solution found, compare its name to a user defined name
3. if the solution name = user name then do something
Any clarifications and/or explanations are welcome
Thanks
Regards
JXB
re: classes, objects, properties, and methods
Covering Object Oriented Programming (OOP) concepts is a tall order for a simple forum post, I'll try to give an abbreviated overview. Before OOP became all the rage, there was (and still is) procedural programming. With procedural programming you would write a bunch of functions to act on data that you have. The data and the functions to work with that data were separate entities. OOP changes that by combining the data and the code. The data can be contained in the class as properties; and the code can be exposed as methods (there is some overlap between properties and methods). There are several advantages to be had with OOP, among them are:
For an example, let's look at NXOpen's Line object:
The NX 8.5 Line object has 19 properties, among these are:
Line objects don't live in isolation, each line is owned by a part object. In fact, a part object may have multiple lines. When we examine the Part class in the NXOpen API reference, we see that the Part has a property called "Lines" which is defined as a LineCollection, or container that holds references to multiple line objects (a collection is similar to an array, but easier to use). We can use a "For Each" loop to examine/process each item in the collection. So if we want to change the color of every line in a given file, we could do something like the following (assume myPart is a valid reference to the part file we are interested in):
For each tempLine as Line in myPart.Lines
tempLine.Color = 82
tempLine.RedisplayObject
Next
The for each construct will automatically loop through all the items in the collection, no need to query the number in the collection to initialize the loop. Each time through the loop, the "tempLine" variable will be set to reference the current line object. We can now use the object's properties and methods to query or alter the line object as we desire.
Similarly, we can loop through the solutions in a CAE part (.sim file). The code below isn't tested (yet).
Dim basePart As BasePart = theSession.Parts.BaseWork
Dim theSimPart as CAE.SimPart
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 and rerun the journal")
return
End Try
dim resultDir as string
dim resultFileName as string
For Each mySolution as CAE.SimSolution in theSimPart.Simulation.Solutions
lw.writeline("name: " & mySolution.Name)
lw.writeline("analysis type: " & mySolution.AnalysisType)
lw.writeline("group count: " & mySolution.GetGroupCount.ToString)
mySolution.GetResultFile(resultDir, resultFileName)
lw.writeline("results directory: " & resultDir)
lw.writeline("results file: " & resultFileName)
lw.writeline("")
Next
If the code above works, you can add a test to check the solution name against the name of interest and take the appropriate actions.
re: classes, objects, properties, and methods
thanks a lot for that. Much appreciated. at the moment I am wrestling with understanding all these class, etc and making sense of the NXOpen do which is very poor. I have more than exhausted my very limited vb programming skills. The example code provided works and return information that could indeed be very useful. Yesterday I managed to test the following.
Dim simPart As CAE.SimPart = CType(basePart, CAE.SimPart)
Dim simulation As CAE.SimSimulation = simPart.Simulation()
Dim colAllSolutions As CAE.SimSolutionCollection = simulation.Solutions()
'Search the Collection 'colAllSolutions' for the user specified Solution Name
For Each collectionItem As Object In colAllSolutions
theLW.WriteLine("--Solution name found is: " + collectionItem.Name)
Next collectionItem
Questions.
1. usings 'collectionItem.ToString returns: SimSolution 63296. What is the number returns?
2. Once I have confirmed that a user specified solution name exists in the simulaitn I tried to active it like so
simulation.ActiveSolution = strSolName
but sure enough it failed!
3. to extend/modify the code to handle Response Simulation does one just replace CAE.SimSolution by CAE.ResponseSimulation?
Thanks
Regards
JXB
Thanks
Regards
re: classes questions
This tells us that the ActiveSolution property is a SimSolution object. We can change the active solution by passing in a SimSolution object of our choice; passing in a name of an existing solution is not adequate.
One way to do this is shown below:
Dim resultDir As String
Dim resultFileName As String
Dim targetSolution As CAE.SimSolution
For Each mySolution As CAE.SimSolution In theSimPart.Simulation.Solutions
lw.writeline("name: " & mySolution.Name)
lw.writeline("analysis type: " & mySolution.AnalysisType)
lw.writeline("group count: " & mySolution.GetGroupCount.ToString)
mySolution.GetResultFile(resultDir, resultFileName)
lw.writeline("results directory: " & resultDir)
lw.writeline("results file: " & resultFileName)
lw.WriteLine("")
If mySolution.Name = "widget" Then
targetSolution = mySolution
End If
Next
theSimPart.Simulation.ActiveSolution = targetSolution
'code to work with solution "widget"
For Each mySolution As CAE.ResponseSimulation.Solution In theSimPart.Simulation.ResponseSimulationManager.Solutions
lw.WriteLine("name: " & mySolution.Name)
lw.WriteLine("solution name: " & mySolution.GetSolutionName)
lw.WriteLine("result file name: " & mySolution.GetResultFileName)
lw.WriteLine("")
Next
Use of ResponseSimulation & RSEVent Class
Hi NX Journaling
I am trying to modify the provided sample code to deal with .ResponseSimulation & .RSEnent but I have failed miserably. The NXOpen documentation is terribly poor! I am attempting to loop through each Response Simulation defined in the Simulation and each events defined in each Response Simulation.
For Each myRespSim as CAE.ResponseSimulation.Solution in theSimPart.Simulation.Solutions
theLW.writeline("name: " & myRespSim.Name)
theLW.writeline("")
Next
Thanks
Regards
JXB
Thanks
Regards