×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Journal to create reference set

Journal to create reference set

Journal to create reference set

(OP)
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.

RE: Journal to create reference set

(OP)
The journal is gtac ecample that use
Asem.createrefset

RE: Journal to create reference set

(OP)



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 

RE: Journal to create reference set

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")
referenceSet1.SetAddComponentsAutomatically(False,False)
Dim nErrs2 As Integer
nErrs2 = theSession.UpdateManager.DoUpdate(markId4)

theSession.DeleteUndoMarksUpToMark(markId3, Nothing, False)


End Sub
End Module 

www.nxjournaling.com

RE: Journal to create reference set

(OP)
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.

RE: Journal to create reference set

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

RE: Journal to create reference set

(OP)
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 

RE: Journal to create reference set

I'm curious why you want to use ONLY the UF functions? That seems like an arbitrary and possibly very limiting constraint.

www.nxjournaling.com

RE: Journal to create reference set

(OP)
Bcause the referece help doc
Of uf is more descriptive

And not a list of methods names
And arguments types

Thank you again.

RE: Journal to create reference set

@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

RE: Journal to create reference set

@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

RE: Journal to create reference set

(OP)
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.

RE: Journal to create reference set

@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 ...
referenceSet1.RemoveObjectsFromReferenceSet(component1)
next

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

With best regards
Michael

RE: Journal to create reference set

(OP)

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.

RE: Journal to create reference set

What version of NX is this and why do you do this ?

Regards,
Tomas

RE: Journal to create reference set

(OP)
Hi Tomas and thank you.

Is nx11.
I succeeded to got it.

The journsl do a copy of an existing
Ref set.

RE: Journal to create reference set

Did you try just turning off that function Customer in Defaults?

Bob

RE: Journal to create reference set

(OP)
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.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members! Already a Member? Login


Resources


Close Box

Join Eng-Tips® Today!

Join your peers on the Internet's largest technical engineering professional community.
It's easy to join and it's free.

Here's Why Members Love Eng-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close