Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations KootK on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

NX 1973 Journal - Pivot All Convergent Bodies around origin to align with Z-Axis

Status
Not open for further replies.

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.

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!
 
Replies continue below

Recommended for you

Here's my understanding of your workflow:
You start with a number of convergent bodies in a circular array about the Z axis. You want to rotate each body to the +X axis and them move it to the origin.
Is this correct?

Do you want to manually select each body or do you want the journal to process each body automatically? What is your current method of determining how much to rotate and translate each body (what are you using as the "origin" point on the body)?

The posted journal is full of errors and it will probably be easier to start from scratch. If you outline your current method I'll help you translate it into working code.

www.nxjournaling.com
 
Align/move convergent sheet body objects, to the Z axis, without rotating at all.

Simply need to rotate them on the YZ plane and pivot the angle of movement on the origin point, so that they all are “stacked” on the Z-Axis.

The user should select each of the convergent sheet bodies needed to be rotated by pivoting on the origin point.

By origin point, I mean the global datum origin point. I want the journal to process the selected bodies (by the user) automatically. The convergent sheet bodies are parallel to the YZ plane. If you look at the object, the X axis is pointing towards you, and the YZ plane is parallel to the viewer.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor