×
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

Jobs

Add condition controlled attribute

Add condition controlled attribute

Add condition controlled attribute

(OP)
Hi

In our company when we add an image
to the non master drawing we need
to mark that by adding an attribute
to the master part.
This is needed for the release app.

Currently I have a journal that do
this in onsave part automatically.
But it's done for all parts no matter
if there is an image or not.

And now I want to add a condition
so only if there an image in the
Non master drawing the attribute
Will be written in the master part.

Thank you in advance.

RE: Add condition controlled attribute

Each part has collections for images. There are separate collections for drafting images and model images.

CODE

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

Module Module130

    Dim theSession As Session = Session.GetSession()
    Dim theUfSession As UFSession = UFSession.GetUFSession()
    Dim lw As ListingWindow = theSession.ListingWindow()

    Sub Main()

        lw.Open()

        lw.WriteLine("number of images in part: " & theSession.Parts.Work.Images.ToArray.Length.ToString)
        lw.WriteLine("number of drafting images in part: " & theSession.Parts.Work.Annotations.DraftingImages.ToArray.Length.ToString)

    End Sub

    Public Function GetUnloadOption(ByVal dummy As String) As Integer

        'Unloads the image immediately after execution within NX
        GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately

    End Function

End Module 

www.nxjournaling.com

RE: Add condition controlled attribute

(OP)
Cowski thank you very much.

That's big help for me

Please on the same issue.
If I'm in the master part how I reach
The work part of the drafting of the non master part so I can use the image collection

Thank you again.

RE: Add condition controlled attribute

In most cases, the model will be the only top level component of the drawing file. When there are multiple top level components in the drawing, you'll need to use your knowledge of your part naming scheme to determine which is the right part to use.

www.nxjournaling.com

RE: Add condition controlled attribute

(OP)

nx11 on TC

If I have the master work part

how I can get the non-master work part.


Thank you.

RE: Add condition controlled attribute

There is some code here that might help (not my code, credit to Todd Mitchell and Ian Eldred). You may need to edit the code based on your naming convention. Also, there is a slightly updated version here.

www.nxjournaling.com

RE: Add condition controlled attribute

(OP)
Cowski thank you.

In my case I use this startup for the save callback
and in this case I have p(the work part) I don't know
how to reach the top component from p.

CODE -->

'----------------------------------------------------------------------------
'                  Copyright (c) 2007 UGS Corp.
'                      All rights reserved
'-----------------------------------------------------------------------------
' 
'
'  vb_part_callbacks.vb
' 
'  Description:
'      This simple demo registers part callbacks for every available reason
'      via the Visual Basic .Net language.
'      After compiling and linking this demo program, the output library needs
'      to be placed in a folder called startup (for example c:\user_dir\startup).
'      Also the UGII_USER_DIR enviornment variable needs to point to the startup
'      directory's parent folder (for example: UGII_USER_DIR=c:\user_dir).
'      Once you have the startup directory and user dir environment variable
'      set up, start NX.  The part callbacks will be registered at startup.
'      Now anytime you create new, open, save, save as, close, modify, rename,
'      or change the workpart your part callbacks will be executed.
' 
'      To demo all of the available part callbacks at runtime - compile and link
'      execute_all_part_callbacks.c.
'      Then start NX and go to File->Execute->NX Open and select your compiled
'      execute_all_callbacks program.
' 
'----------------------------------------------------------------------------

Option Strict Off

Imports NXOpen
Imports NXOpen.UI
Imports NXOpen.Utilities

'------------------------------------------------------------
'
'  Module MyProject
'
'      Demo class used to register all available part callbacks
'------------------------------------------------------------
Module vb_part_callbacks_called_when_part_saved

    '-----------------------------------------------------
    ' Used to tell us if we've already registered our callbacks
    '-----------------------------------------------------
    Dim registered As Integer = 0

    '-----------------------------------------------------
    ' The ids of the registered callbacks are used if
    ' you ever want to unregister a callback.
    ' If you plan to register the callback once for
    ' the enitre session, and don't intend to remove them,
    ' (recommended) tracking the id may not be necessary.
    '-----------------------------------------------------
    Dim idPartCreated1 As Integer = 0
    Dim idPartOpened1 As Integer = 0
    Dim idPartSaved1 As Integer = 0
    Dim idPartSavedAs1 As Integer = 0
    Dim idPartClosed1 As Integer = 0
    Dim idPartModified1 As Integer = 0
    Dim idPartRenamed1 As Integer = 0
    Dim idWorkPartChanged1 As Integer = 0
    Dim theSession As Session = Session.GetSession()
    Dim lw As ListingWindow = theSession.ListingWindow

    '-----------------------------------
    ' Called when a new part is created
    ' Prints the name of the created part
    ' to the listing window
    '-----------------------------------
    'Sub PartCreated1(ByVal p As BasePart)
        'lw.Open()
        'lw.WriteLine("    VB created: " & p.FullPath)
        'MsgBox("created1: " & p.FullPath, MsgBoxStyle.OkOnly)
    'End Sub

    '-----------------------------------
    ' Called when a part is opened
    ' Prints the name of the opened part
    ' to the listing window
    '-----------------------------------
    'Sub PartOpened1(ByVal p As BasePart)
        'lw.Open()
        'lw.WriteLine("    VB opened: " & p.FullPath)
    'End Sub

    '-----------------------------------
    ' Called when a part is saved
    ' Prints the name of the saved part
    ' to the listing window
    '-----------------------------------
    Sub PartSaved1(ByVal p As BasePart)
        lw.Open()
        lw.WriteLine("    VB saved: " & p.FullPath)
    End Sub

    '-----------------------------------
    ' Called when a part is saved as
    ' Prints the name of the saved as part
    ' to the listing window
    '-----------------------------------
    'Sub PartSavedAs1(ByVal p As BasePart)
        'lw.Open()
        'lw.WriteLine("    VB saved as: " & p.FullPath)
    'End Sub

    '-----------------------------------
    ' Called when a part is closed
    ' Prints the name of the closed part
    ' to the listing window
    '-----------------------------------
    'Sub PartClosed1(ByVal p As BasePart)
        'lw.Open()
        'lw.WriteLine("    VB closed: " & p.FullPath)
    'End Sub

    '-----------------------------------
    ' Called when a part is modified
    ' (for the first time)
    ' Prints the name of the modified part
    ' to the listing window
    '-----------------------------------
    'Sub PartModified1(ByVal p As BasePart)
        'lw.Open()
        'lw.WriteLine("    VB modified: " & p.FullPath)
    'End Sub

    '-----------------------------------
    ' Called when a part is renamed
    ' Prints the name of the renamed part
    ' to the listing window
    '-----------------------------------
    'Sub PartRenamed1(ByVal p As BasePart)
        'lw.Open()
        'lw.WriteLine("    VB renamed: " & p.FullPath)
    'End Sub

    '-----------------------------------
    ' Called when the workpart changes
    ' Prints the name of old workpart and
    ' new workpart to the listing window
    '-----------------------------------
    'Sub WorkPartChanged1(ByVal p As BasePart)
        'lw.Open()
        'lw.WriteLine("    VB work part changed")

        'If p Is Nothing Then
            'lw.WriteLine("        Old Work Part: NULL")
        'Else
            'lw.WriteLine("        Old Work Part: " & p.FullPath)
        'End If
        'If theSession.Parts.Work Is Nothing Then
            'lw.WriteLine("        New Work Part: NULL")
        'Else
            'lw.WriteLine("        New Work Part: " & theSession.Parts.Work.FullPath)
        'End If

    'End Sub

    '-----------------------------------------------------
    ' Called when NX starts up
    ' registers the part callbacks with NX
    '-----------------------------------------------------
    Public Function Startup() As Integer
        Dim theUI As UI = UI.GetUI()

        If registered = 0 Then
            'MsgBox("Registering callbacks", MsgBoxStyle.OkOnly)
            'idPartCreated1 = theSession.Parts.AddPartCreatedHandler(AddressOf PartCreated1)
            'idPartOpened1 = theSession.Parts.AddPartOpenedHandler(AddressOf PartOpened1)
            idPartSaved1 = theSession.Parts.AddPartSavedHandler(AddressOf PartSaved1)
            'idPartSavedAs1 = theSession.Parts.AddPartSavedAsHandler(AddressOf PartSavedAs1)
            'idPartClosed1 = theSession.Parts.AddPartClosedHandler(AddressOf PartClosed1)
            'idPartModified1 = theSession.Parts.AddPartModifiedHandler(AddressOf PartModified1)
            'idPartRenamed1 = theSession.Parts.AddPartRenamedHandler(AddressOf PartRenamed1)
            'idWorkPartChanged1 = theSession.Parts.AddWorkPartChangedHandler(AddressOf WorkPartChanged1)

            registered = 1
        End If

        Startup = 0

    End Function ' Startup ends

    '------------------------------------------------------------
    '
    '  Main()
    '
    '      Called manually from File->Execute->NX Open
    '
    '------------------------------------------------------------
    'Sub Main()

        'Add your code here
        'If registered = 0 Then
            'MsgBox("Registering VB callbacks", MsgBoxStyle.OkOnly)
            'Startup()
        'End If

    'End Sub

    '------------------------------------------------------------
    '
    '  GetUnloadOption()
    '
    '     Used to tell NX when to unload this library
    '
    '     Available options include:
    '       Session.LibraryUnloadOption.Immediately
    '       Session.LibraryUnloadOption.Explicitly
    '       Session.LibraryUnloadOption.AtTermination
    '
    '     Any programs that register callbacks must use 
    '     AtTermination as the unload option.
    '------------------------------------------------------------
    Public Function GetUnloadOption(ByVal dummy As String) As Integer
        GetUnloadOption = Session.LibraryUnloadOption.AtTermination
    End Function
End Module 

RE: Add condition controlled attribute

(OP)

Do you know if there is a function to get the parrent part of the workpart.

Thank you.

RE: Add condition controlled attribute

(OP)

To make things simple I think
how to do it from the non master part.

In the non master I have one comment
Only the master part.

The problem is how to set the attribute
From the non master to the master part.
Without the user see that.

Thank you.

RE: Add condition controlled attribute

(OP)
By trying I found that calling
Getuserattributeasstring(db_part_no
Getuserattributeasstring(db_part_rev
On the non master part give me the
db_part_no and db_part_rev
Of the master part.

So using askparttag I got the part tag
of the master part.

And that leads me to the solution.

Of course the key is
If theSession.Parts.Work.Annotations.DraftingImages.ToArray.Length > 0
Of Cowski help

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

eBook - Manufacturing the Cars of Tomorrow
In this ebook, we'll explore how additive manufacturing is going to transform the way cars are made. This includes commentary from thought leaders such as Ford's CTO, Ken Washington, Customer case studies of ways 3D printing is being used today, and a variety of part examples where 3D printing is already impacting how automobiles are made. Download Now
White Paper - Smart Manufacturing for Semiconductor
New technologies and approaches present great opportunities for semiconductor manufacturers to achieve high levels of innovation, yield and improvement. This white paper explores some of these cutting-edge technologies and how they can be applied effectively in the semiconductor industry. Read about how Smart Manufacturing is transforming the semiconductor industry. Download Now
White Paper - Analysis and Simulation in Aircraft Structure Certification
Organizations using simulation and analysis tools effectively see the benefits in their ability to achieve certification faster and with drastically less total cost than those who do not maximize these tools. Read this White Paper to learn about how digital tools such as analysis and simulation help in aircraft structure certification. Download Now

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