miggyneer
Aerospace
- May 11, 2023
- 4
Hey All, first time posting here.
I am trying to align a set of convergent bodies (.stl files imported into .prt file) to the Z-axis for internal processing purposes. The goal is to pivot all the bodies around the origin and simply "stack" them all in the same location. I've been having to do this manually, and it's quite a drag, as there are 40 objects in an arc, and I need them all to be "stacked" all on the Z axis. Think of a card dealer displaying playing cards on a table in an arc, well, I need all the cards to be centered on the Z axis following that arc.
I have tried to ask ChatGPT for help, and this is what it spat out. I am using Siemens NX 1973. I am very new to coding and journaling in general. Any help would be appreciated. I am sure there are mistakes, just looking for advice and/or corrections to save me precious time in the process I am working on.
Errors I receive:
Line 15: Value type 'Boolean' cannot be converted to '1-dimensional array of NXOpen.NXObject'
Line 19: 'GetSelectedObjects' is not a member of NXOpen.Selection'.
Line 44: 'AskBodyGeom' is not a member of 'NXOpen.UF.Mod1'.
Line 47: 'TransformFeatBody' is not a member of 'NXOpen.UF.Mod1'.
Line 50: 'RefreshView' is not a member of 'NXOpen.UF.Mod1'.
Line 59: 'Application' is not a member of 'NXOpen.UF.Mod1'.
Any help would be appreciated!
I am trying to align a set of convergent bodies (.stl files imported into .prt file) to the Z-axis for internal processing purposes. The goal is to pivot all the bodies around the origin and simply "stack" them all in the same location. I've been having to do this manually, and it's quite a drag, as there are 40 objects in an arc, and I need them all to be "stacked" all on the Z axis. Think of a card dealer displaying playing cards on a table in an arc, well, I need all the cards to be centered on the Z axis following that arc.
I have tried to ask ChatGPT for help, and this is what it spat out. I am using Siemens NX 1973. I am very new to coding and journaling in general. Any help would be appreciated. I am sure there are mistakes, just looking for advice and/or corrections to save me precious time in the process I am working on.
Code:
Option Strict Off
Imports System
Imports System.Collections
Imports NXOpen
Imports NXOpen.UF
Module Module1
Sub Main()
Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work
Dim ufs As UFSession = UFSession.GetUFSession()
' Ask user to select convergent bodies to transform
Dim sel As Selection.Response = theUI.SelectionManager.SelectObjects("Select bodies to transform", "Select bodies", Selection.SelectionScope.WorkPart, Selection.SelectionAction.ClearAndEnableSpecific, False, True)
' Check if any bodies were selected
If sel = Selection.Response.ObjectSelected Then
Dim selectedObjs() As NXOpen.TaggedObject = theUI.SelectionManager.GetSelectedObjects()
' Set the pivot point as the origin
Dim pivot(2) As Double
pivot(0) = 0.0
pivot(1) = 0.0
pivot(2) = 0.0
' Set the transformation matrix to align to Z-axis and pivot around the origin
Dim matrix(8) As Double
matrix(0) = 1.0
matrix(1) = 0.0
matrix(2) = 0.0
matrix(3) = 0.0
matrix(4) = 0.0
matrix(5) = 1.0
matrix(6) = 0.0
matrix(7) = 0.0
matrix(8) = 0.0
' Transform each selected body
For Each obj As NXOpen.TaggedObject In selectedObjs
If TypeOf obj Is NXOpen.Body Then
Dim body As NXOpen.Body = CType(obj, NXOpen.Body)
ufs.Modl.AskBodyFeatGeom(body.Tag, Nothing)
' Apply the transformation to the body
ufs.Modl.TransformFeatBody(body.Tag, pivot, matrix)
' Update the display
workPart.UpdateManager.DoUpdate(Nothing)
End If
Next
Else
' No bodies were selected, display a message box
theUI.NXMessageBox.Show("Error", NXMessageBox.DialogType.Error, "No bodies were selected.")
End If
' End the NX Open session
theSession.Application.Exit()
End Sub
Private theUI As UI = UI.GetUI()
End Module
Errors I receive:
Line 15: Value type 'Boolean' cannot be converted to '1-dimensional array of NXOpen.NXObject'
Line 19: 'GetSelectedObjects' is not a member of NXOpen.Selection'.
Line 44: 'AskBodyGeom' is not a member of 'NXOpen.UF.Mod1'.
Line 47: 'TransformFeatBody' is not a member of 'NXOpen.UF.Mod1'.
Line 50: 'RefreshView' is not a member of 'NXOpen.UF.Mod1'.
Line 59: 'Application' is not a member of 'NXOpen.UF.Mod1'.
Any help would be appreciated!