Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

Journal to create reference set

Status
Not open for further replies.

Ehaviv

Computer
Jul 2, 2003
1,012
0
0
IL
Hi

When I run a journal that create
a ref set the components are added automaticaly.

Because of my session preference default.

How I can save set and restore this prefernce so the created ref set do not
Add comonents automaticaly.

Thank you.
 
Replies continue below

Recommended for you




Code:
mports System
Imports NXOpen
Imports NXOpen.UF
Imports NXOpen.UI
Imports NXOpen.Utilities

Module make_ref_set

Sub Main()

  Dim s As Session = Session.GetSession()
  Dim ufs As UFSession = UFSession.GetUFSession()

  Dim origin(2) As Double
  Dim matrix(8) As Double

  Dim ref_set_tag As NXOpen.Tag

  Dim cntr As Integer
  Dim disp_props As New NXOpen.UF.UFObj.DispProps

  ufs.Mtx3.Identity(matrix)

  Dim all_bodies() As Body = s.Parts.Work.Bodies.ToArray()

  Dim body_tags(all_bodies.Length - 1) As Tag

  For i As Integer = 0 To all_bodies.Length - 1

    ufs.Obj.AskDisplayProperties(all_bodies(i).Tag, disp_props)

    If disp_props.layer = 1 Then
      body_tags(cntr) = all_bodies(i).Tag
      cntr = cntr + 1
    End If
  
  Next

  ufs.Assem.CreateRefSet("MY_REF_SET", origin, matrix, body_tags, cntr, ref_set_tag)

  If ref_set_tag <> NXOpen.Tag.Null Then
     MsgBox("ref_set_tag: " & ref_set_tag.ToString)
  End If

End Sub

Public Function GetUnloadOption(ByVal dummy As String) As Integer

  GetUnloadOption = UFConstants.UF_UNLOAD_IMMEDIATELY

End Function

End Module
 
You can use the .SetAddComponentsAutomatically method on the reference set object to set whether components are automatically added or not.

Code:
Option Strict Off
Imports System
Imports NXOpen

Module NXJournal
Sub Main (ByVal args() As String) 

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

Dim displayPart As Part = theSession.Parts.Display


Dim markId2 As Session.UndoMarkId
markId2 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Create New Reference Set")

Dim referenceSet1 As ReferenceSet
referenceSet1 = workPart.CreateReferenceSet()

Dim markId3 As Session.UndoMarkId
markId3 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Add Components to Reference Set")

Dim markId4 As Session.UndoMarkId
markId4 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Edit Name of Reference Set")

referenceSet1.SetName("test1")
[highlight #FCE94F]referenceSet1.SetAddComponentsAutomatically(False,False)[/highlight]
Dim nErrs2 As Integer
nErrs2 = theSession.UpdateManager.DoUpdate(markId4)

theSession.DeleteUndoMarksUpToMark(markId3, Nothing, False)


End Sub
End Module

www.nxjournaling.com
 
Cowski thank you.

But in ghe gtac example their is not yet
a refset exsist and the new created
Refset grab all components.

If I want to usse uf functions only
Is it passible.?

Thank you again.
 
If you want to use the .CreateRefSet method, you can turn off the components option after it is created.

Code:
Imports System
Imports NXOpen
Imports NXOpen.UF
Imports NXOpen.UI
Imports NXOpen.Utilities

Module Module118

    Sub Main()

        Dim s As Session = Session.GetSession()
        Dim ufs As UFSession = UFSession.GetUFSession()

        Dim markId2 As Session.UndoMarkId
        markId2 = s.SetUndoMark(Session.MarkVisibility.Visible, "Create New Reference Set")

        Dim origin(2) As Double
        Dim matrix(8) As Double

        Dim ref_set_tag As NXOpen.Tag

        Dim cntr As Integer
        Dim disp_props As New NXOpen.UF.UFObj.DispProps

        ufs.Mtx3.Identity(matrix)

        Dim all_bodies() As Body = s.Parts.Work.Bodies.ToArray()

        Dim body_tags(all_bodies.Length - 1) As Tag

        For i As Integer = 0 To all_bodies.Length - 1

            ufs.Obj.AskDisplayProperties(all_bodies(i).Tag, disp_props)

            If disp_props.layer = 1 Then
                body_tags(cntr) = all_bodies(i).Tag
                cntr = cntr + 1
            End If

        Next

        ufs.Assem.CreateRefSet("MY_REF_SET", origin, matrix, body_tags, cntr, ref_set_tag)
        Dim myNewRefSet As ReferenceSet = Nothing

        If ref_set_tag <> NXOpen.Tag.Null Then
            MsgBox("ref_set_tag: " & ref_set_tag.ToString)
            myNewRefSet = Utilities.NXObjectManager.Get(ref_set_tag)
            myNewRefSet.SetAddComponentsAutomatically(False, False)
        End If


    End Sub

    Public Function GetUnloadOption(ByVal dummy As String) As Integer

        GetUnloadOption = UFConstants.UF_UNLOAD_IMMEDIATELY

    End Function

End Module

www.nxjournaling.com
 
Cowski thank you very much.

You helped me to make it pure UF functions.


Code:
Imports System
Imports NXOpen
Imports NXOpen.UF
Imports NXOpen.UI
Imports NXOpen.Utilities

Module create_ref_set_of_all_solid_bodies_on_layer_one

    Sub Main()

        Dim s As Session = Session.GetSession()
        Dim ufs As UFSession = UFSession.GetUFSession()

        Dim markId2 As Session.UndoMarkId
        markId2 = s.SetUndoMark(Session.MarkVisibility.Visible, "Create New Reference Set")

        Dim origin(2) As Double
        Dim matrix(8) As Double

        Dim ref_set_tag As NXOpen.Tag

        Dim cntr As Integer
        Dim disp_props As New NXOpen.UF.UFObj.DispProps

        ufs.Mtx3.Identity(matrix)

        Dim all_bodies() As Body = s.Parts.Work.Bodies.ToArray()

        Dim body_tags(all_bodies.Length - 1) As Tag

        For i As Integer = 0 To all_bodies.Length - 1

            ufs.Obj.AskDisplayProperties(all_bodies(i).Tag, disp_props)

            If disp_props.layer = 1 Then
                body_tags(cntr) = all_bodies(i).Tag
                cntr = cntr + 1
            End If

        Next

        ufs.Assem.CreateRefSet("MY_REF_SET", origin, matrix, body_tags, cntr, ref_set_tag)
        If ref_set_tag <> NXOpen.Tag.Null Then
            MsgBox("ref_set_tag: " & ref_set_tag.ToString)
            ufs.Assem.SetAutoAddNewComps(ref_set_tag, False)
        End If

    End Sub

    Public Function GetUnloadOption(ByVal dummy As String) As Integer

        GetUnloadOption = UFConstants.UF_UNLOAD_IMMEDIATELY

    End Function

End Module
 
Bcause the referece help doc
Of uf is more descriptive

And not a list of methods names
And arguments types

Thank you again.
 
@Cowski, NX automaticall add components to referenceset even if You add line:

Code:
referenceSet1.SetAddComponentsAutomatically(False,False)

there must be line:

Code:
referenceSet1.RemoveObjectsFromReferenceSet(components1)

and some kind of loop to deselect all components in created reference set.

With best regards
Michael
 
@niedzviedz,
Good point. If the option to add all components automatically was turned on at the time of ref set creation, it will contain the components. These will need to be removed if this is not desirable. There is an option in customer defaults that will disable the 'add components automatically' option for new reference sets. Personally, I like to disable the 'auto add' option as it gives me more control of what is added and when. If you turn on the option later, it will ask you if you want the components added; however, if you turn off the option after creation, it will not ask you to remove the components.

www.nxjournaling.com
 
Cowski I'm very thsnk you.

I'm turned of this preference aldo.

I tested the journal above
And its run ok withoud adding
Components.

But in other journal that merge two refsets
But it works only on objects that are not
A components.
To do the merge I use the ask members
And add members.

So I do not understabd what is the
Problem with refsets and componentd.

 
@Cowski,
I only use 3 type of reference set: True, false and sometimes DWG for drawings, so I have this option on. For False I have journal to select which body I wanna add. For all 3 I have modified my template.
I think of some kind of loop:

Code:
For each component1 As NXOpen.Assemblies.Component in ...
[indent]referenceSet1.RemoveObjectsFromReferenceSet(component1) [/indent]
next

But what to put after in? I tried few options, but all generate an error.

With best regards
Michael
 

Cowski you are right. When the customer defaul auto add comps is set to on

NX automaticall add components to referenceset even if You add line:

So I added a remove object
And thst works ok.

Thank you.
 
I don't do that for two redions

1 its our company ddfault.
2 I want my journal to work in that
Option off or on.

Thank you.
 
Status
Not open for further replies.
Back
Top