Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

NX5 to NX6 issues with MACROS/JOURNALS

Status
Not open for further replies.

jkcone

Automotive
Mar 31, 2009
162
Hello
I'm switching from NX5 to NX6 & having trouble with existing macros.
The first macros I need to get working change selected face(s) to a predetermined color. I have multiple macros, one for each color.
I'm not experienced in NX code.
Generally speaking how much trouble is it to update macros to a new verion? Is there a utility to help step through this. Should I give up & try to learn Journals? Can existing macros in NX5 help generate Journals to be used in NX6?

I know the is a vague & long winded question but I hope this get the situation across.

Thanks in advance for your help.

James
 
Replies continue below

Recommended for you

While there are albeit rare situations where an older Macro may still work with a newer version of NX than the one it was originally generated in, there is no guarantee of that so it's officially NOT supported, and as such, your only alternative is to recreate them (although they can be modified using a text editor, most of the time it's more work than just doing them over). Of course, this was one of the motivations behind Journals as they are more immune to the changes in the User Interface (which is what usually kills old Macros) and therefore are easier to move from one version to the next.

As for recording a Journal while playing back a Macro, I've honestly never tried it.

John R. Baker, P.E.
Product 'Evangelist'
Product Design Solutions
Siemens PLM Software Inc.
Industry Sector
Cypress, CA

To an Engineer, the glass is twice as big as it needs to be.
 
Recording journals while replaying macros works and all commands that journals support seem to be recorded. But you would still have to modify the journal to remove "selection stickiness".

As I am trying to learn about journaling and NXOpen in general I created a simple journal that will take all preselected faces and change their color to a specified value as an exercise.


// Petter U

Code:
Option Strict Off

Imports System
Imports NXOpen

Module changeColorOfPreSelectedFaces
    Dim theSession As Session = Session.GetSession()
    Dim sel As Selection = NXOpen.UI.GetUI.SelectionManager

    Sub Main()
        '' Change this integer to any of the predefined values from the nx color space.
        Dim newColorCode As Integer = 114

        '' Array to store the preselected faces.
        Dim faceArray(-1) As DisplayableObject
        Dim faceCounter As Integer = 0

        '' Loop that iterates over all the selected items
        For i As Integer = 0 To sel.GetNumSelectedObjects()
            If TypeOf sel.GetSelectedObject(i) Is Face Then
                '' Change size of faceArray and add current selected item into array
                '' then unhiglight.
                ReDim Preserve faceArray(faceCounter)
                faceArray(faceCounter) = sel.GetSelectedObject(i)
                faceArray(faceCounter).Unhighlight()
                faceCounter += 1
            End If
        Next

        '' A display modification object is used to change to color of the faces.
        Dim changeFaceColor As DisplayModification = theSession.DisplayManager.NewDisplayModification()
        With changeFaceColor
            .ApplyToAllFaces = False
            .NewColor = newColorCode
            .Apply(faceArray)
            .Dispose()
        End With

    End Sub

    Public Function GetUnloadOption(ByVal dummy As String) As Integer

        GetUnloadOption = NXOpen.UF.UFConstants.UF_UNLOAD_IMMEDIATELY

    End Function
End Module




 
 http://www.student.ltu.se/~petulf-2/changeColorOfPreselectedFaces.vb
Thanks Peter
I copied this to a Journal file & it worked well.
It seemed to be a clean & quick file.

How difficult would it be to add the face selection process to this file?
Short of going to Itu how does one learn the Journal & NXOpen language & options?
Do you know of any tutorials or knowledge bases on the subject?

The "selection stickyness" does seem to be a constant issue when I try to create my own Journals.

Thanks again,
James
 
No problem,

Well adding the face selection process to the file could be done through a number of ways, by using the UI class like in the above example, or Block styler which is a interactive way to create a graphical user interface template. Adding a simple input box or selection dialog with the UI class could be done by appending one or two functions/sub routines to the journal. You could also try to automatically identify the faces that should have their color changed, e.g. change the color of all hole faces that have a certain radius. A more detailed description of the actions that need to be automated would help in giving advice on what method to choose.

About learning Journals and NXOpen this depends on your prior programming experience. If you have not programmed C++, Java, C# or visual basic i would recommend you to start by getting Visual Studio express and doing the basic msdn language tutorials for either C# or Visual Basic, since Siemens/UGS documentation does not cover their basic usage. I started out with NXOpen development about 1.5 months ago with no prior Visual Basic experience (thought i have used c++) and at first the API size is daunting (it still is) but you soon get the hang of how to accomplish basic operations.

The resources that i have found useful for NXOpen are,

* NXOpen programmers guide, brief guide that covers the basics of the API and how to configure the development environment (Help Library > Automation > Nxopen).
* NXOpen .NET API reference, learn to use the search and index function (Help Library > Automation > Nxopen > Open for .NET).
* Recording short journals of about 1-3 operations to see how the various classes are used.
* The NXOpen example files that you find under
NX 6.0\UGOPEN\SampleNXOpenApplications\.NET\

You can also find many examples via the UGSolutions search, by searching for "NXOpen Sample" and adding appropriate keywords like face, or selection.


//Petter U


 
Created a simple Block Styler example just for fun. It allows the user to enter a color code and select which faces to apply this new color to.

facecolor.png


To use the example unzip the file into either
* ../NX 6.0/UGII/ directory
* $UGII_USER_DIR/application
* Or add a the path to the directory where you unzipped the files into $UGII_ROOT_DIR\menus\custom_dirs.dat

Then run the faceColor.vb file as any other journal.

// Petter U
 
Petter
I down loaded the zip file & ran it like you said. It ran well, no problems.
I changed the selection filter to Single Faces after running it a few times. It remembered this setting the next time it ran. I'm assuming this is because it uses a .dlx file. Very cool.

I'm trying to alter your previous "ChangeColorOfPreselecedFaces.vb" to add the single face selection to it where it will start off automatically in that selection mode & not require the .dlx file. But all I'm doing is going around in circles & throughly confusing myself. Do you know & can you tell me what to add to "ChangeColorOfPreselecedFaces.vb" to accomplish this? It would be greatly appreciated!

Thanks,
James
 
James

Below you will find a modified version that uses the UI class to select the faces, it is not as slick as the dlx based one. The actual selectFaces() subroutine that does the face selection is from a GTAC: UGsolutions example.

// Petter U

Code:
Option Strict Off

Imports System
Imports NXOpen
Imports NXOpen.UF
Imports NXOpenUI


Module changeColorOfPreSelectedFaces_v2
    Dim theSession As Session = Session.GetSession()
    Dim sel As Selection = NXOpen.UI.GetUI.SelectionManager

    Sub Main()
        '' Integer variable to store color code in.
        Dim newColorCode As Integer = 114

        '' While loop to ensure that color code is Integer value
        While 1
            newColorCode = Convert.ToInt32(NXInputBox.GetInputNumber("Color code:", "Enter New Face Color Code", 1))
            If newColorCode > 0 And newColorCode < 217 Then
                Exit While
            End If
            MsgBox("Code must be Integer between 1 and 216")
        End While


        '' The selectFaces method takes an NXobject array by reference 
        Dim selectedObjectsArray() As NXObject
        SelectFaces(selectedObjectsArray)

        '' Need to recast the face NXObjects to Displayable objects
        Dim faceArray(selectedObjectsArray.Length - 1) As DisplayableObject
        For i As Integer = 0 To selectedObjectsArray.Length - 1
            faceArray(i) = CType(selectedObjectsArray(i), DisplayableObject)
        Next

        '' A display modification object is used to change to color of the faces.
        Dim changeFaceColor As DisplayModification = theSession.DisplayManager.NewDisplayModification()
        With changeFaceColor
            .ApplyToAllFaces = False
            .NewColor = newColorCode
            .Apply(faceArray)
            .Dispose()
        End With

    End Sub


    '' The following routine is from GTAC

    ' ----------------------------------------------
    '   sub to select faces
    ' ----------------------------------------------

    Sub SelectFaces(ByRef selectedObjects As NXObject())

        Dim ui As UI = NXOpen.UI.GetUI

        Dim message As String = "Select Faces"
        Dim title As String = "Selection"

        Dim scope As Selection.SelectionScope = Selection.SelectionScope.WorkPart
        Dim keepHighlighted As Boolean = False
        Dim includeFeatures As Boolean = False
        Dim response As Selection.Response

        Dim selectionAction As Selection.SelectionAction = Selection.SelectionAction.ClearAndEnableSpecific

        Dim selectionMask_array(1) As Selection.MaskTriple
        With selectionMask_array(0)
            .Type = UFConstants.UF_solid_type
            .Subtype = 0
            .SolidBodySubtype = UFConstants.UF_UI_SEL_FEATURE_ANY_FACE
        End With

        response = ui.SelectionManager.SelectObjects(message, title, scope, _
                                         selectionAction, includeFeatures, _
                                     keepHighlighted, selectionMask_array, _
                                                      selectedObjects)

        If response = Selection.Response.Cancel Or response = Selection.Response.Back Then
            Return
        End If

    End Sub

    Public Function GetUnloadOption(ByVal dummy As String) As Integer

        GetUnloadOption = NXOpen.UF.UFConstants.UF_UNLOAD_IMMEDIATELY

    End Function
End Module
 
 http://www.student.ltu.se/~petulf-2/changeColorOfPreselectedFaces_v2.vb
This is nice Petter. Thanks very much!
I like this better without the dlx. I think it's cleaner & quicker. It worked great.

It's apparent I need to do a lot of reading & get up to speed.
I wonder if there's a "UG Code For Dummies".

Thanks again,
James
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor