ppap eroni
Mechanical
- Feb 22, 2023
- 9
When I asked AI to create a journal code that moves in the xy plane, the following code came out.
It didn't work, so I modified it a little, but it still doesn't work.
I don't know much about journals. Even if I look at the help of nx, it's not easy to learn because it's not related to practical work. So if there's someone who can modify it, please answer.
I want to study based on this.
What I want to implement is the same as doing point to point in Move Component, but discard the z point or make it 0. As a result, no matter which point you select, the part you want to move will move on the xy plane.
I'm designing a press die, and plane movement is a really necessary command.
Thank you.
--------------------------------------------------
Imports NXOpen
Module NXJournal
Sub Main ()
Dim theSession = NXOpen.Session.GetSession()
' 유틸리티 기능 객체 가져오기
Dim theUF As UFSession = UFSession.GetUFSession()
' 사용자에게 객체 선택하도록 안내
Dim workPart As WorkPart = theSession.Parts.Work
Dim selectedObjects As Selection = theSession.SelectionManager.GetSelectedObjects(True)
' 선택된 객체가 없으면 종료
If selectedObjects.Count = 0 Then
MsgBox("이동할 객체를 선택해주세요.")
Exit Sub
End If
' 이동할 거리 입력 받기
Dim xDistance As Double = CDbl(InputBox("X축 이동 거리:"))
Dim yDistance As Double = CDbl(InputBox("Y축 이동 거리:"))
' 변환 행렬 생성 (Z축 이동 무시)
Dim transformationMatrix(1 To 4, 1 To 4) As Double
' 단위 행렬로 초기화 (대각선 성분만 1)
For i As Integer = 1 To 4
For j As Integer = 1 To 4
If i = j Then
transformationMatrix(i, j) = 1
Else
transformationMatrix(i, j) = 0
End If
Next
Next
' X, Y 이동 거리 설정
transformationMatrix(1, 4) = xDistance
transformationMatrix(2, 4) = yDistance
' 선택된 각 객체에 대해 이동 적용
For Each selectedObject As NXObject In selectedObjects
Dim component As Component = TryCast(selectedObject, Component)
If component IsNot Nothing Then
theUF.Component.Move(component, transformationMatrix)
End If
Next
' 재생성
theSession.UpdateManager.DoUpdate(NXOpen.UpdateManager.UpdateOption.Regenerate)
End Sub
End Module
It didn't work, so I modified it a little, but it still doesn't work.
I don't know much about journals. Even if I look at the help of nx, it's not easy to learn because it's not related to practical work. So if there's someone who can modify it, please answer.
I want to study based on this.
What I want to implement is the same as doing point to point in Move Component, but discard the z point or make it 0. As a result, no matter which point you select, the part you want to move will move on the xy plane.
I'm designing a press die, and plane movement is a really necessary command.
Thank you.
--------------------------------------------------
Imports NXOpen
Module NXJournal
Sub Main ()
Dim theSession = NXOpen.Session.GetSession()
' 유틸리티 기능 객체 가져오기
Dim theUF As UFSession = UFSession.GetUFSession()
' 사용자에게 객체 선택하도록 안내
Dim workPart As WorkPart = theSession.Parts.Work
Dim selectedObjects As Selection = theSession.SelectionManager.GetSelectedObjects(True)
' 선택된 객체가 없으면 종료
If selectedObjects.Count = 0 Then
MsgBox("이동할 객체를 선택해주세요.")
Exit Sub
End If
' 이동할 거리 입력 받기
Dim xDistance As Double = CDbl(InputBox("X축 이동 거리:"))
Dim yDistance As Double = CDbl(InputBox("Y축 이동 거리:"))
' 변환 행렬 생성 (Z축 이동 무시)
Dim transformationMatrix(1 To 4, 1 To 4) As Double
' 단위 행렬로 초기화 (대각선 성분만 1)
For i As Integer = 1 To 4
For j As Integer = 1 To 4
If i = j Then
transformationMatrix(i, j) = 1
Else
transformationMatrix(i, j) = 0
End If
Next
Next
' X, Y 이동 거리 설정
transformationMatrix(1, 4) = xDistance
transformationMatrix(2, 4) = yDistance
' 선택된 각 객체에 대해 이동 적용
For Each selectedObject As NXObject In selectedObjects
Dim component As Component = TryCast(selectedObject, Component)
If component IsNot Nothing Then
theUF.Component.Move(component, transformationMatrix)
End If
Next
' 재생성
theSession.UpdateManager.DoUpdate(NXOpen.UpdateManager.UpdateOption.Regenerate)
End Sub
End Module