Hello, erudite people,
I am a Japanese who has been journaling in NX for a week now. I am also a beginner in programming.
I am currently trying to build a journal that selects multiple polygon geometries within a "Fem part" and renames the selected body's custom name.
After reading your articles here, I have completed a journal that does the above within the "i.part".
Thanks to all of you.
Here is the code.
' NX 1884
' Journal created by miley on Fri Jun 2 2023 JST
' ------------------------------------------------------------------------------------
' ------------------------------------------------------------------------------------
'これはi.Prtの中でソリッドボディの名前を変更するジャーナルです。
' ------------------------------------------------------------------------------------
' ------------------------------------------------------------------------------------
Imports System
Imports NXOpen
Imports NXOpenUI
Imports NXOpen.UF
Module NXJournal
Sub Main
Dim theSession As Session = Session.GetSession()
Dim basePart As BasePart = theSession.Parts.BaseWork
Dim workPart As Part = TryCast(basePart, Part)
Dim lw As ListingWindow = theSession.ListingWindow
If workPart Is Nothing
Dim Alert as String = "i.Prtじゃないからできないよ"
Dim Title as String = "[ジャーナル]:エラー"
MsgBox(Alert, vbOKOnly + vbCritical, Title)
Exit Sub
End If
Dim KARAAGE as NXObject()
Dim RENAME As String = ""
lw.Open
lw.WriteLine("")
lw.WriteLine("")
lw.WriteLine("")
lw.WriteLine("")
lw.WriteLine("パート名を変更します.....")
RENAME = NXInputBox.GetInputString("変更したい名前を入れてください。", "パート名変更", "唐揚げ")
lw.WriteLine("パートナビゲータから、変更したいパートを選択してください。")
lw.WriteLine("")
Dim markId1 As NXOpen.Session.UndoMarkId = Nothing
markId1 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "[ジャーナル]:名前の変更")
If SelectObjects("パートを選択してください。", KARAAGE) = Selection.Response.Ok Then
For Each SeleKARA As NXObject in KARAAGE
lw.WriteLine("「 " & SeleKARA.Name & "(" & SeleKARA.Tag & ") 」 → 「 " & RENAME & " 」")
lw.WriteLine("パート名を上記の通りに変更しました。")
lw.WriteLine("")
SeleKARA.SetName(RENAME)
Next
lw.WriteLine(KARAAGE.Length & "個のパートを変更しました。")
End if
lw.Close
End Sub
Function SelectObjects(prompt As String, ByRef SeleObj as NXObject()) As Selection.Response
Dim theUI As UI = UI.GetUI
Dim typeArray() As Selection.SelectionType = {Selection.SelectionType.All}
Dim resp As Selection.Response = theUI.SelectionManager.SelectObjects(prompt, "Selection", _
Selection.SelectionScope.AnyInAssembly, False, typeArray, SeleObj)
If resp = Selection.Response.ObjectSelected Or resp = Selection.Response.ObjectSelectedByName Or _
resp = Selection.Response.OK Then
Return Selection.Response.Ok
Else
Return Selection.Response.Cancel
End If
End Function
End Module
I would like to do this within the "Fem part".
Here is the code that I have tried and failed.
' NX 1884
' Journal created by miley on Fri Jun 4 2023 JST
' ------------------------------------------------------------------------------------
' ------------------------------------------------------------------------------------
'これはFemの中でポリゴンジオメトリの名前を変更するジャーナルです。
' ------------------------------------------------------------------------------------
' ------------------------------------------------------------------------------------
Imports System
Imports NXOpen
Imports NXOpenUI
Imports NXOpen.UF
Module NXJournal
Sub Main
Dim theSession As Session = Session.GetSession()
Dim basePart As BasePart = theSession.Parts.BaseWork
Dim workFemPart As NXOpen.CAE.FemPart = TryCast(basePart, NXOpen.CAE.FemPart)
Dim lw As ListingWindow = theSession.ListingWindow
If workFemPart Is Nothing
Dim Alert as String = "Femじゃないからできないよ"
Dim Title as String = "[ジャーナル]:エラー"
MsgBox(Alert, vbOKOnly + vbCritical, Title)
Exit Sub
End If
Dim KARAAGE as NXOpen.CAE.CAEBody()
Dim RENAME As String = ""
lw.Open
lw.WriteLine("")
lw.WriteLine("")
lw.WriteLine("")
lw.WriteLine("")
lw.WriteLine("パート名を変更します.....")
RENAME = NXInputBox.GetInputString("変更したい名前を入れてください。", "パート名変更", "唐揚げ")
lw.WriteLine("パートナビゲータから、変更したいパートを選択してください。")
lw.WriteLine("")
Dim markId1 As NXOpen.Session.UndoMarkId = Nothing
markId1 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "[ジャーナル]:名前の変更")
If SelectObjects("パートを選択してください。", KARAAGE) = Selection.Response.Ok Then
For Each SeleKARA As CAE.CAEBody in KARAAGE
lw.WriteLine("「 " & SeleKARA.Name & "(" & SeleKARA.Tag & ") 」 → 「 " & RENAME & " 」")
lw.WriteLine("パート名を上記の通りに変更しました。")
lw.WriteLine("")
SeleKARA.SetName(RENAME)
Next
lw.WriteLine(KARAAGE.Length & "個のパートを変更しました。")
End if
lw.Close
End Sub
Function SelectObjects(prompt As String, ByRef SeleObj as NXOpen.CAE.CAEBody()) As Selection.Response
Dim theUI As UI = UI.GetUI
Dim typeArray() As Selection.SelectionType = {Selection.SelectionType.All}
Dim resp As Selection.Response = theUI.SelectionManager.SelectObjects(prompt, "Selection", _
Selection.SelectionScope.AnyInAssembly, False, typeArray, SeleObj)
If resp = Selection.Response.ObjectSelected Or resp = Selection.Response.ObjectSelectedByName Or _
resp = Selection.Response.OK Then
Return Selection.Response.Ok
Else
Return Selection.Response.Cancel
End If
End Function
End Module
It would be even better if the body could be selected within the "Simulation Navigator."
Can someone please help me?
Even if you don't have an answer, tips are welcome.
Please excuse my poor English.
Regards,
miley
re: multiple select FEM
Are you working in a part file that has multiple bodies or is this an assembly FEM file (each body is owned by a different component part file)?
Glad to talk to you!
Thank you very much for the reply!
I`m working in a part file that has multiple bodies.
Please help me with my ignorance ;(
miley
It seems to work, but ....
' NX 1884
' Journal created by miley on Fri Jun 16 2023 JST
' ------------------------------------------------------------------------------------
' ------------------------------------------------------------------------------------
'これはFemの中で選択したポリゴンジオメトリの名前を変更するジャーナルです。
' ------------------------------------------------------------------------------------
' ------------------------------------------------------------------------------------
Imports System
Imports NXOpen
Imports NXOpenUI
Imports NXOpen.UF
Module NXJournal
Sub Main(ByVal args() As String)
Dim theSession As Session = Session.GetSession()
Dim theUfSession As UFSession = UFSession.GetUFSession()
Dim basePart As BasePart = theSession.Parts.BaseWork
Dim workFemPart As NXOpen.CAE.FemPart = TryCast(basePart, NXOpen.CAE.FemPart)
Dim lw As ListingWindow = theSession.ListingWindow
If workFemPart Is Nothing
Dim Alert as String = "Femじゃないからできないよ"
Dim Title as String = "[ジャーナル]:エラー"
MsgBox(Alert, vbOKOnly + vbCritical, Title)
Exit Sub
End If
Dim markId1 As NXOpen.Session.UndoMarkId = Nothing
markId1 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "[ジャーナル]:名前の変更")
Dim KARAAGE as NXObject()
Dim RENAME As String = ""
lw.Open()
lw.WriteLine("")
lw.WriteLine("")
lw.WriteLine("")
lw.WriteLine("")
lw.WriteLine("")
lw.WriteLine("")
lw.WriteLine("")
lw.WriteLine("")
lw.WriteLine("---------------パート名を変更します.....---------------")
RENAME = NXInputBox.GetInputString("変更したい名前を入れてください。", "パート名変更", "唐揚げ")
lw.WriteLine("シミュレーションナビゲータから、変更したいパートを選択してください。")
lw.WriteLine("(このジャーナルでは、「すべてを選択」の使用を推奨していません。)")
lw.WriteLine("")
lw.WriteLine("")
If SelectFemObjects("ポリゴンジオメトリの選択", KARAAGE) = Selection.Response.Ok Then
For Each SeleKARA As NXObject in KARAAGE
lw.WriteLine("「 " & SeleKARA.Name & "(" & SeleKARA.Tag & ") 」 → 「 " & RENAME & " 」")
lw.WriteLine("パート名を上記の通りに変更しました。")
lw.WriteLine("")
SeleKARA.SetName(RENAME)
NEXT
lw.WriteLine("---------------" & KARAAGE.Length & "個のパートを変更しました。---------------")
End If
End Sub
Function SelectFemObjects(prompt As String, ByRef SeleFemP As NXObject()) As Selection.Response
Dim theUI As UI = UI.GetUI
Dim title As String = "ポリゴンジオメトリの選択"
Dim includeFeatures As Boolean = False
Dim keepHighlighted As Boolean = False
Dim selAction As Selection.SelectionAction = Selection.SelectionAction.ClearAndEnableSpecific
Dim scope As Selection.SelectionScope = Selection.SelectionScope.AnyInAssembly
Dim selectionMask_array(0) As Selection.MaskTriple
With selectionMask_array(0)
.Type = UFConstants.UF_caegeom_type
.Subtype = UFConstants.UF_all_subtype
End With
Dim resp As Selection.Response = theUI.SelectionManager.SelectObjects _
(prompt, title, scope, selAction, includeFeatures, keepHighlighted, selectionMask_array, SeleFemP)
If resp = Selection.Response.ObjectSelected Or resp = Selection.Response.ObjectSelectedByName Or _
resp = Selection.Response.OK Then
Return Selection.Response.Ok
Else
Return Selection.Response.Cancel
End If
End Function
End Module
It works fine, but is there anything I should be concerned about?
Thank you in advance for your help.
Please excuse my poor English.
Regards,
miley
re: multiple select FEM
As long as the selection mask limits the selection to your intended objects, it should be good. I'd suggest running it in a few different files (for example: FEM with multiple bodies, assembly FEM, even a normal part with no FEM objects) to make sure it handles those situations as you want.