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!

How I can know what is my tc dummypartname

Status
Not open for further replies.

Ehaviv

Computer
Jul 2, 2003
1,012
How I can know what is my tc dummypartname ?

Code:
Hi all, NXOpen API programmers.....

Normally when using a nxopen program together with a *.dlx file (BlockStyler) - it is not possible to run and and launch such a program , withpout having an active workpart in the NX session.....
Normaly not that big problem . but in my current project, I really need to be able to fire up the dialog - even if no parts are opened in the NX session..... 
In shortness: My program will show a dialog, where end users can choose between some pre-defined load options...
Lets call these "Favorites" or "Disiciplines"..... Depended on which kind of work task in the NX environment , it is very importnant, that users are using the correct loadoptions.....
But by using this program - it is straight forward for the users, to choose the desired discipline.......
How I solved the issue to let NX fire up Block Styler in NX session without any parts open....:
The trick is, that let the program open a part temporary in background, if no parts are active, when the program is executed...
1.In the very early beginning of the program open the dummypart quite in background (if no parts a active)...
2.let the program show the dialog in the NX GUI...
3.simply close the dummypart again....
4.user can continiue "playing" with the different settings and options in the dialog....
==================================================================
Feel free to let me know your comments - and ofcourse also give it try - if needed in your projects...
br. Lars...
 
(A small vdemo ideo is attached - all names and load options showed in this video, is just concept names and settings)....
 
Demo Choose Pre-defined Load Options In Nx Session-1.m4v (2)
>

(view in My Videos)
Me too
0
Reply
3 REPLIES
Re: Sharing of a method to fire up BlockStyler in NX session without any active parts open (no workp
Yamada
  Siemens Phenom Yamada  Siemens Phenom
Siemens Phenom
I can't read your code. Can you please insert it into your post using the "Insert Code" function, as explained here.
山田
yamada
0
Reply
Re: Sharing of a method to fire up BlockStyler in NX session without any active parts open (no workp
LarsKlokmose
  Siemens Pioneer LarsKlokmose  Siemens Pioneer
Siemens Pioneer
yeahh - I will do this.....
 
Remember if you will test - then change the variabel "dummyPartNumber" to places in the code...Simply the item number of your dummy part in teamcenter....
 
 
Public Sub New()
        Try
            theSession = Session.GetSession()
            theUI = UI.GetUI()
            theDlxFileName = lkl_dialog_name
            theDialog = theUI.CreateDialog(theDlxFileName)
            theDialog.AddUpdateHandler(AddressOf update_cb)
            theDialog.AddInitializeHandler(AddressOf initialize_cb)
            theDialog.AddDialogShownHandler(AddressOf dialogShown_cb)

            '#################################################################################################################################################################
            '########################################  START SPECIAL HANDLING OF CLOSING DUMMYPART - IF OPENEND QUITE  ##################################################
            '#################################################################################################################################################################
            '
            'When we come to this line - a workpart is always active - either the active workpart opened by the user in the NX session, or the dummy workpart opened from inside this program....
            '
            'Lets start find the Tag of the dummy part - no matter if it is opened or not.....
            Dim dummyPartNumber As String = "SGRE_LoadOption_DummyPart" ' Teamcenter (item) PartNumber >> will also be used when comparing active PartNumber...
            Dim dummyPartRevision As String = "001"
            Dim dummyPartFiletype As String = "master"
            Dim dummyPartFileName As String = ""
            Dim dummyPartTag As Tag ' to be used if part shall be closed....
            ufs.Ugmgr.EncodePartFilename(dummyPartNumber, dummyPartRevision, dummyPartFiletype, "", dummyPartFileName) 'we encode the four input parameters > output can be used to ask for the part tag later on...
            dummyPartTag = ufs.Part.AskPartTag(dummyPartFileName) ' now we have the Tag of the dummy part...NIce one...

            'Lets now find the Tag of the active workpart - no matter if the part is the dummy part, or a NX part opened from the NX user....
            Dim partName As String = ""
            Dim partNumber As String = ""
            Dim partRevision As String = ""
            Dim partFileType As String = ""
            Dim partFileName As String = ""
            ufs.Part.AskPartName(workPart.Tag, partName)
            ufs.Ugmgr.DecodePartFileName(partName, partNumber, partRevision, partFileType, partFileName) 'we decode active workpart > we need the partnumber > to be used when we compare with the dummy Part number...

            'Lets then compare if active partNumber is the same as the dummyPartNumber - if so - we simply close the dummy part.....
            If partNumber = dummyPartNumber Then
                ufs.Part.Close(dummyPartTag, 0, 1)
                NX("we closed the dummy part")
            End If
            'we are done with the workaround...
            '
            '#################################################################################################################################################################
            '#########################################  END SPECIAL HANDLING OF CLOSING DUMMYPART - IF OPENEND QUITE  ###################################################
            '#################################################################################################################################################################

        Catch ex As Exception

            '---- Enter your exception handling code here -----
            Throw ex
        End Try
    End Sub
Public Shared Sub Main()
        Dim Lkl_SGRE_Set_LoadOptions_Favorit As Lkl_SGRE_Set_LoadOptions_Favorit = Nothing
        Try

            '#################################################################################################################################################################
            '#############################################  START SPECIAL HANDLING OF OPENING A DUMMYPART  QUITE ###### ##################################################
            '#################################################################################################################################################################
            '
            'When we come to "this" stage in the program, the NX System & Block Styler requires that we have an active workpart in the NX session, before the program can continue.....
            'If no active part is present, when the NX user hit the button which starts this custom tool > we simply need to let the custom tool itself, open a dummy part in backgroound temporary...
            '
            'Lets start figure out if we have an active workpart...
            Dim theTempSession As Session = Session.GetSession
            Dim theTempWorkpart As Part = theTempSession.Parts.Work
            Dim theTempUfs As UFSession = UFSession.GetUFSession

            'If  not we have an active workpart, we need to open a dummy part ( in this case we simply open the dummy part in the background > ( so users will not be "confused"...!!!!!)....
            If theTempWorkpart Is Nothing Then
                Dim dummyPartNumber As String = "SGRE_LoadOption_DummyPart" ' Teamcenter (item) PartNumber
                Dim dummyPartRevision As String = "001"
                Dim dummyPartFiletype As String = "master"
                Dim dummyPartFileName As String = ""
                Dim dummyPartTag As Tag
                Dim dummyTag1 As Tag = Tag.Null
                Dim dummyTag2 As Tag = Tag.Null
                Dim dummyLoadStatus As UFPart.LoadStatus = Nothing
                theTempUfs.Ugmgr.EncodePartFilename(dummyPartNumber, dummyPartRevision, dummyPartFiletype, "", dummyPartFileName) 'now we have a partfile format, that can be used as argument, when we will open the part...
                theTempUfs.Part.OpenQuiet(dummyPartFileName, dummyTag1, dummyLoadStatus) ' open the dummy part Quiet....
                dummyPartTag = theTempUfs.Part.AskPartTag(dummyPartFileName) ' ask for the tag of the newly opened dummypart...
                theTempUfs.Assem.SetWorkPartQuietly(dummyPartTag, dummyTag2) ' then we simply set the dummypart as workpart > but still quite, and not visible for the NX user.....
            End If
            'we are done with the workaround...so far....we also need to close dummy part again, immediately after the dialog is shown for the user in NX GUI....>> see "Public Sub New"...
            '
            '#################################################################################################################################################################
            '##############################################  END SPECIAL HANDLING OF OPENING A DUMMYPART  QUITE #########################################################
            '#################################################################################################################################################################

            Lkl_SGRE_Set_LoadOptions_Favorit = New Lkl_SGRE_Set_LoadOptions_Favorit()
            ' The following method shows the dialog immediately
            Lkl_SGRE_Set_LoadOptions_Favorit.Show()

        Catch ex As Exception

            '---- Enter your exception handling code here -----
            theUI.NXMessageBox.Show("Block Styler", NXMessageBox.DialogType.Error, ex.ToString)
        Finally
            If Lkl_SGRE_Set_LoadOptions_Favorit IsNot Nothing Then
                Lkl_SGRE_Set_LoadOptions_Favorit.Dispose()
                Lkl_SGRE_Set_LoadOptions_Favorit = Nothing
            End If
        End Try
    End Sub
 
0
Reply
Re: Sharing of a method to fire up BlockStyler in NX session without any active parts open (no workp
samwiseh
 samwiseh  Pioneer
Pioneer
I just used this in a project and it was very handy. Here's what I ended up with in my C# implimentation.
 
 
workPart = session.Parts.Work;
var dummyPartTag = Tag.Null;
try
{
  if (workPart == null)
  {
    var dummyPartNumber = "<DUMMY PART NAME>";
    var dummyPartRevision = "<DUMMY REVISION>";
    var dummyPartFiletype = "master";
    var dummyPartFileName = "";
    ufs.Ugmgr.EncodePartFilename(dummyPartNumber, dummyPartRevision, dummyPartFiletype, "", out dummyPartFileName);
    ufs.Part.OpenQuiet(dummyPartFileName, out _, out _);
    dummyPartTag = ufs.Part.AskPartTag(dummyPartFileName);
    ufs.Assem.SetWorkPartContextQuietly(dummyPartTag, out _);
  }
}
catch (Exception ex)
{
  // ---- Enter your exception handling code here -----
  ui.NXMessageBox.Show("Block Styler", NXMessageBox.DialogType.Error, ex.ToString());
}

/*******************************
/* Show Dialog
/******************************/

if (dummyPartTag != Tag.Null)
{
  ufs.Part.Close(dummyPartTag, 0, 1);
}
I check if "workPart" is null, because if it's not then I dont need to worry about loading a dummy part.
 
 
I also changed "SetWorkPartQuietly" to "SetWorkPartContextQuietly" which seems to work just the same in my project. The documentation says that SetWorkPartQuietly was deprecated in NX 5, so probably something to avoid if possible.
 
Thank you for post
 
Replies continue below

Recommended for you

Hi
This article was taken from plm forum.
And I don't know how I can get the
Dummy part name in our tc.

Any help.
Thank you.
 
Hi Ehaviv -

I did write the article on Siemens PLM forum....
Also authored the code…

You can simply create your own "dummy Part" in Tc.
Name it whatever you like....
Then in the code simply change this variabel:
Code:
Dim dummyPartNumber As String = [highlight #FCE94F]"your dummy Part"[/highlight] ' Teamcenter (item) PartNumber

That's it...

(Lars K)[highlight #FCE94F][/highlight]
lklo
 
Hi Lars and thank you very much.
Actually I was worked around this
Issue by creating new part and
Close it immediately after closing
The dialog and the app continue
Processing with the data collected
From ty dialog.

Without saying any part.

And I was thinking that an existing
Dummy part will be good.

But this only works for myself
And no for everyone.

Thank you vy much.
 
I mean if the dummy part is not
A built-in in teamcenter.
Not everyone can use my app.
 
Your trick is awesome.

If we could ensure that a dummy part
that we choose is never exists
in a teamcenter that will be great.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor