Submitted by JXB on Mon, 09/29/2014 - 07:24
Forums:
To all,
I am looking at a loop to go through each mesh in a .fem. so far it seems to work! I now want to check if a mesh collector is empty/blank. Looking at the doc I found
IsBlanked(): Returns the blank status of this object. I do not know what a blank status is but I do not believe this is what I am looking for. Does anyone have any idea how to check if mesh (collector) is empty ?
For Each mesh In meshes
counter = counter + 1
mesh.SetName(MCol.Name & "(" & counter & ")")
'check if mesh collector is empty
if IsEmpty(mesh)=True then
'do something
end if
Next
Thanks
Regards
JXB
re: blank
The show/hide command used to be called blank/unblank. The UI was updated to make it more obvious what the command was used for (also, it really didn't translate well into non-english languages). The API commands still have the old name of the function, it helps maintain compatibility with older code.
RE: blank
Thanks for the explanation. There are no other properties in the Mesh Class as I can see which could be used to check the "content" of the mesh collector
Thanks
Regards
RE: Blank & LockStatus
I am carrying on investigating different keywords to test things I will need for a macro. I am now locking at 'LockStatus()' for a mesh.
Returns or sets the lock status for this mesh.
Public Property LockStatus As Boolean
Get
Set
So I tried expanding my basic code as follows;
For Each mesh In meshes
counter = counter + 1
InfoWindow.WriteLine ("Renaming Mesh Container:" & mesh.Name & " To: " & MCol.Name & "(" & counter & ")")
mesh.SetName(MCol.Name & "(" & counter & ")")
mesh.LockStatus=True
Next
but the lockstatus is not taken/working. But NX does not return a "failed" msg either!
Regards
JXB
Thanks
Regards
RE: Blank & LockStatus
looks like 'mesh.LockStatus=True' does work. I was testing the code in an fem created from an import action rather than a "proper" NX created fem
Thanks
Regards
re: meshes
Try the following code:
Option Strict Off
Imports System
Imports NXOpen
Module Module1
Sub Main()
Dim theSession As Session = Session.GetSession()
Dim lw As ListingWindow = theSession.ListingWindow
lw.Open()
Dim femPart As CAE.FemPart
Try
femPart = CType(theSession.Parts.BaseWork, CAE.FemPart)
Catch ex As Exception
MsgBox("Not a FEM part")
Return
End Try
Const undoMarkName As String = "report meshes"
Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, undoMarkName)
lw.WriteLine("Mesh Collectors:")
For Each theMeshCollector As CAE.MeshCollector In femPart.BaseFEModel.MeshManager.GetMeshCollectors
lw.WriteLine(" name: " & theMeshCollector.Name)
lw.WriteLine(" type: " & theMeshCollector.CollectorType)
lw.WriteLine(" contains meshes:")
For Each theMesh As CAE.Mesh In theMeshCollector.GetMeshes
lw.WriteLine(" name: " & theMesh.Name)
lw.WriteLine(" type: " & theMesh.GetType.ToString)
lw.WriteLine(" descriptor name: " & theMesh.ElementPropertyTable.DescriptorSpecificName)
lw.WriteLine(" property count: " & theMesh.ElementPropertyTable.GetPropertyCount.ToString)
lw.WriteLine("")
Next
Next
lw.Close()
End Sub
End Module
Correction (October 1, 2014): changed Try Catch block to catch Exception rather than NXException.
RE: Empty mesh collector
Thanks NXJournaling. I am learning every day! The example code works and if 'theMesh' is empty (2nd For .. Next loop) then nothing is returned. One should be able to test if 'theMesh' is Empty/Nothing and then tale action (i.e. delete the mesh). As soon as I have found the key word to delete a mesh !
Thanks
Regards
JXB
Thanks
Regards
I am having trouble with the:
I am having trouble with the: RespSimSolFound.GetEvents() statement. I get the error msg about not being defined. Below is the code. 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
'--------------------------------------
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
re: loop events
I think your For Each loop has some issues. Try the following:
For Each myRsEvent As CAE.ResponseSimulation.RSEvent In RespSimSolFound.GetEvents
'your code here
Next
re: loop events
Thanks a lot. Works as intended. Moving on to deal with result for each event!
'-------------------
For Each myRespSimCol As CAE.ResponseSimulation.Solution In theRespSimManager.Solutions
theLW.WriteLine("Resp Sim Name is:" & myRespSimCol.GetSolutionName)
If myRespSimCol.GetSolutionName = strRSSolName Then
'Set the Resp. Sim. to be used later to search for the event
RespSimSolFound = myRespSimCol
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
End If
Next
Thanks
Regards