Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

Add condition controlled attribute

Status
Not open for further replies.

Ehaviv

Computer
Jul 2, 2003
1,012
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.
 
Replies continue below

Recommended for you

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
 
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.
 
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
 

nx11 on TC

If I have the master work part

how I can get the non-master work part.


Thank you.
 
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
 

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

Thank you.
 

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.
 
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.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor