Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

Journal to create Associative wave links for bodies

Status
Not open for further replies.

NutAce

Mechanical
Apr 22, 2010
1,192
Hello,

I was looking for some journal where I can easily create wave linked bodies to an assembly top level.
Found below example from Cowski which is partialy fulfilling my needs.
The code is workingfine , however it only allows for one body to be selected at a time. I would like to be able to select individualy or multiple bodies at the same time.
What do I need to addapt to make that possible?

Code:
'journal to create associative wave linked body
'with an assembly as the displayed part, make one of the components the work part (this component will receive the linked body)
'run the journal, you will be prompted to select a solid body
'the selected body will be associatively linked into the current work part

Option Strict Off  
Imports System  
Imports NXOpen  
Imports NXOpen.UF  

Module Module1  

    Sub Main()  

        Dim theSession As Session = Session.GetSession()  
        Dim workPart As Part = theSession.Parts.Work  

        Dim mySolid As NXObject  
        If SelectSolid("Select a solid", mySolid) = Selection.Response.Cancel Then  
            Exit Sub  
        End If  

        Dim markId1 As Session.UndoMarkId  
        markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Start")  

        Dim nullFeatures_Feature As Features.Feature = Nothing  

        If Not workPart.Preferences.Modeling.GetHistoryMode Then  
            Throw (New Exception("Create or edit of a Feature was recorded in History Mode but playback is in History-Free Mode."))  
        End If  

        Dim waveLinkBuilder1 As Features.WaveLinkBuilder  
        waveLinkBuilder1 = workPart.BaseFeatures.CreateWaveLinkBuilder(nullFeatures_Feature)  

        Dim extractFaceBuilder1 As Features.ExtractFaceBuilder  
        extractFaceBuilder1 = waveLinkBuilder1.ExtractFaceBuilder  

        extractFaceBuilder1.FaceOption = Features.ExtractFaceBuilder.FaceOptionType.FaceChain  

        waveLinkBuilder1.Type = Features.WaveLinkBuilder.Types.BodyLink  

        extractFaceBuilder1.FaceOption = Features.ExtractFaceBuilder.FaceOptionType.FaceChain  

        waveLinkBuilder1.CopyThreads = False  

        extractFaceBuilder1.ParentPart = Features.ExtractFaceBuilder.ParentPartType.OtherPart  

        theSession.SetUndoMarkName(markId1, "WAVE Geometry Linker Dialog")  

        extractFaceBuilder1.Associative = True  

        extractFaceBuilder1.FixAtCurrentTimestamp = False  

        extractFaceBuilder1.HideOriginal = False  

        extractFaceBuilder1.InheritDisplayProperties = False  

        Dim selectObjectList1 As SelectObjectList  
        selectObjectList1 = extractFaceBuilder1.BodyToExtract  

        extractFaceBuilder1.CopyThreads = False  

        Dim added1 As Boolean  
        added1 = selectObjectList1.Add(mySolid)  

        Dim nXObject1 As NXObject  
        nXObject1 = waveLinkBuilder1.Commit()  

        theSession.SetUndoMarkName(markId1, "WAVE Geometry Linker")  

        waveLinkBuilder1.Destroy()  

    End Sub  

    Function SelectSolid(ByVal prompt As String, ByRef selObj As NXObject) As Selection.Response  

        Dim theUI As UI = UI.GetUI  
        Dim title As String = "Select a solid"  
        Dim includeFeatures As Boolean = False  
        Dim keepHighlighted As Boolean = False  
        Dim selAction As Selection.SelectionAction = Selection.SelectionAction.ClearAndEnableSpecific  
        Dim cursor As Point3d  
        Dim scope As Selection.SelectionScope = Selection.SelectionScope.AnyInAssembly  
        Dim selectionMask_array(0) As Selection.MaskTriple  

        With selectionMask_array(0)  
            .Type = UFConstants.UF_solid_type  
            .SolidBodySubtype = UFConstants.UF_UI_SEL_FEATURE_SOLID_BODY  
        End With  

        Dim resp As Selection.Response = theUI.SelectionManager.SelectObject(prompt, _  
         title, scope, selAction, _  
         includeFeatures, keepHighlighted, selectionMask_array, _  
         selobj, cursor)  
        If resp = Selection.Response.ObjectSelected OrElse resp = Selection.Response.ObjectSelectedByName Then  
            Return Selection.Response.Ok  
        Else  
            Return Selection.Response.Cancel  
        End If  

    End Function  

End Module


Ronald van den Broek
Senior Application Engineer
Winterthur Gas & Diesel Ltd
NX9 / TC10.1.2

Building new PLM environment from Scratch using NX11 / TC11
 
Replies continue below

Recommended for you

For starters, we'll need to change the selection function to allow for multiple selections. The code below shows one way of doing that. The .SelectTaggedObjects method will return an array of objects, the code converts this to a list object (it is my personal preference to work with lists, I find them easier than arrays - though in this short example it doesn't make much difference).

Code:
Option Strict Off

Imports System
Imports System.Collections.Generic
Imports NXOpen
Imports NXOpen.UF
Imports NXOpenUI

Module Module1
    Sub Main()

        Dim theSession As Session = Session.GetSession()
        Dim workPart As Part = theSession.Parts.Work
        Dim displayPart As Part = theSession.Parts.Display
        Dim ufs As UFSession = UFSession.GetUFSession()
        Dim lw as listingwindow = thesession.listingwindow
        
        lw.open

        Dim markId3 As Session.UndoMarkId
        markId3 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Edit Object Display")

        Dim theSolids As New List(Of Body)
        If SelectSolids("Select one or more solid bodies", theSolids) = Selection.Response.Cancel Then
            Return
        End If
        
        lw.writeline(theSolids.Count.ToString & " solids were selected")


    End Sub

    Function SelectSolids(ByVal prompt As String, ByRef tempBodies As List(Of Body)) As Selection.Response

        Dim theUI As UI = UI.GetUI
        Dim title As String = "Select one or more solid bodies"
        Dim includeFeatures As Boolean = False
        Dim keepHighlighted As Boolean = False
        Dim selAction As Selection.SelectionAction = Selection.SelectionAction.ClearAndEnableSpecific
        Dim scope As Selection.SelectionScope = Selection.SelectionScope.AnyInAssembly
        Dim selectionMask_array(0) As Selection.MaskTriple
        Dim selObj() As TaggedObject

        With selectionMask_array(0)
            .Type = UFConstants.UF_solid_type
            .SolidBodySubtype = UFConstants.UF_UI_SEL_FEATURE_BODY
        End With

        Dim resp As Selection.Response = theUI.SelectionManager.SelectTaggedObjects(prompt, _
         title, scope, selAction, _
         includeFeatures, keepHighlighted, selectionMask_array, _
         selObj)
        If resp = Selection.Response.Ok Then
            For Each temp As Body In selObj
                tempBodies.Add(temp)
            Next
            Return Selection.Response.Ok
        Else
            Return Selection.Response.Cancel
        End If

    End Function

End Module

www.nxjournaling.com
 
I hit "submit" too soon. After updating the selection function, we'll need to decide how to handle the multiple bodies; when creating wave links there is an option "separate feature for each body" or "one feature for all bodies". I'm not sure which option you intend to use or how it will affect the journal code. I'd suggest recording a journal with your desired option to see what additional code (if any) is required.

www.nxjournaling.com
 
In normal case how these options "separate feature for each body" or "one feature for all bodies" will work.
And please help me how to import his journal to NX.
 
Hi Cowski,

I incorporated your examples in the original code from start of topic.
I am now getting the below error.

Journal Compile Errors said:
Line 66: Overload resolution failed because no accessible 'Add' can be called with these arguments:
'Public Function Add(inputSelectionMethod As NXOpen.SelectionMethod) As Boolean': Value of type 'System.Collections.Generic.List(Of NXOpen.Body)' cannot be converted to 'NXOpen.SelectionMethod'.
'Public Function Add(objects() As NXOpen.TaggedObject) As Boolean': Value of type 'System.Collections.Generic.List(Of NXOpen.Body)' cannot be converted to '1-dimensional array of NXOpen.TaggedObject'.
'Public Function Add(object As NXOpen.TaggedObject) As Boolean': Value of type 'System.Collections.Generic.List(Of NXOpen.Body)' cannot be converted to 'NXOpen.TaggedObject'.

For below Line in the code.

Dim added1 As Boolean
added1 = selectObjectList1.Add(mySolid)

Code:
'journal to create associative wave linked body
'with an assembly as the displayed part, make one of the components the work part (this component will receive the linked body)
'run the journal, you will be prompted to select a solid body
'the selected body will be associatively linked into the current work part

Option Strict Off  
Imports System
Imports System.Collections.Generic
Imports NXOpen
Imports NXOpen.UF
Imports NXOpenUI 

Module Module1  

    Sub Main()  

        Dim theSession As Session = Session.GetSession()  
        Dim workPart As Part = theSession.Parts.Work  

        Dim mySolid As New List(Of Body)
        If SelectSolids("Select one or more solid bodies", mySolid) = Selection.Response.Cancel Then
            Return
        End If

        Dim markId1 As Session.UndoMarkId  
        markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Start")  

        Dim nullFeatures_Feature As Features.Feature = Nothing  

        If Not workPart.Preferences.Modeling.GetHistoryMode Then  
            Throw (New Exception("Create or edit of a Feature was recorded in History Mode but playback is in History-Free Mode."))  
        End If  

        Dim waveLinkBuilder1 As Features.WaveLinkBuilder  
        waveLinkBuilder1 = workPart.BaseFeatures.CreateWaveLinkBuilder(nullFeatures_Feature)  

        Dim extractFaceBuilder1 As Features.ExtractFaceBuilder  
        extractFaceBuilder1 = waveLinkBuilder1.ExtractFaceBuilder  

        extractFaceBuilder1.FaceOption = Features.ExtractFaceBuilder.FaceOptionType.FaceChain  

        waveLinkBuilder1.Type = Features.WaveLinkBuilder.Types.BodyLink  

        extractFaceBuilder1.FaceOption = Features.ExtractFaceBuilder.FaceOptionType.FaceChain  

        waveLinkBuilder1.CopyThreads = False  

        extractFaceBuilder1.ParentPart = Features.ExtractFaceBuilder.ParentPartType.OtherPart  

        theSession.SetUndoMarkName(markId1, "WAVE Geometry Linker Dialog")  

        extractFaceBuilder1.Associative = True  

        extractFaceBuilder1.FixAtCurrentTimestamp = False  

        extractFaceBuilder1.HideOriginal = False  

        extractFaceBuilder1.InheritDisplayProperties = False  

        Dim selectObjectList1 As SelectObjectList  
        selectObjectList1 = extractFaceBuilder1.BodyToExtract  

        extractFaceBuilder1.CopyThreads = False  

        Dim added1 As Boolean  
        added1 = selectObjectList1.Add(mySolid)  

        Dim nXObject1 As NXObject  
        nXObject1 = waveLinkBuilder1.Commit()  

        theSession.SetUndoMarkName(markId1, "WAVE Geometry Linker")  

        waveLinkBuilder1.Destroy()  

    End Sub  

    Function SelectSolids(ByVal prompt As String, ByRef tempBodies As List(Of Body)) As Selection.Response

        Dim theUI As UI = UI.GetUI
        Dim title As String = "Select one or more solid bodies"
        Dim includeFeatures As Boolean = False
        Dim keepHighlighted As Boolean = False
        Dim selAction As Selection.SelectionAction = Selection.SelectionAction.ClearAndEnableSpecific
        Dim scope As Selection.SelectionScope = Selection.SelectionScope.AnyInAssembly
        Dim selectionMask_array(0) As Selection.MaskTriple
        Dim selObj() As TaggedObject

        With selectionMask_array(0)
            .Type = UFConstants.UF_solid_type
            .SolidBodySubtype = UFConstants.UF_UI_SEL_FEATURE_BODY
        End With

        Dim resp As Selection.Response = theUI.SelectionManager.SelectTaggedObjects(prompt, _
         title, scope, selAction, _
         includeFeatures, keepHighlighted, selectionMask_array, _
         selObj)
        If resp = Selection.Response.Ok Then
            For Each temp As Body In selObj
                tempBodies.Add(temp)
            Next
            Return Selection.Response.Ok
        Else
            Return Selection.Response.Cancel
        End If

    End Function  

End Module

Ronald van den Broek
Senior Application Engineer
Winterthur Gas & Diesel Ltd
NX9 / TC10.1.2

Building new PLM environment from Scratch using NX11 / TC11
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor