Quantcast
Channel: NX Journaling - Journaling / NXOpen API
Viewing all articles
Browse latest Browse all 787

Multiple selection of polygon geometry in a Fem

$
0
0

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


Viewing all articles
Browse latest Browse all 787

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>