Welcome to the COE Discussion Forum! 

 

To participate in the discussion forum, you must be logged in to the website.  If you forget your login information, please contact COE Headquarters at coe@coe.org or (800) 263-2255.

If you are new to the COE Discussion Forum and would like to participate, please register.


Register Today
COE 2009 Annual PLM Conference & TechniFair

COE DISCUSSION FORUM
Subject: WorkObject - STComProgrammerGuide.pdf

You are not authorized to post a reply.   
Author Messages
HALE


08 Oct 2007 09:59 AM
Hello,

I've been promising myself for a while that I would make this post "when I had time."  Well I've got time today.  I've searched for the the word workobject several times and always drawn a blank.  I figure if I'm looking for it then someone else is too.

One of my biggest annoyances with the documentation lies with the STComProgrammerGuide.pdf.  Virtually every example requires you to pass in a workobject.  The examples get them from the current record when you activate a script.  Well lots of times I need to create a workobject from the results of a query and you really have to dig to find this simple and basic information.   Here is a snippet that contains a few comments and shows how to create a workobject, get data out of it, put data into it and updatedate SmarTeam with it.

Regards,
Hale

PS  Yes, I konw I cross-psoted on the Developer's Forum, but I think that this has a much wider user base.



          Dim Query As ISmQuery
          Dim QueryDef As ISmQueryDefinition
       
          Set Query = SmSession.ObjectStore.NewQuery
          Set QueryDef = Query.QueryDefinition

 
         'NOTE NOTE nClassId must changed based on what you are looking for (CATDrawings, Models, etc)


         'Note:  you would look at TDMX_CAD_IDENTIFIER = partnumber if you are
         '       checking for specific CATIA partNumber
         '       You would look at CAD_REF_FILE_NAME = CATName if you are checking
         '       for specific CATIA file names
 
 
            QueryDef.Roles.Add nClassId,"F"
            QueryDef.Select.Add "TDMX_CAD_IDENTIFIER", "F", False      'Part Number
            QueryDef.Select.Add "CAD_REF_FILE_NAME", "F", False    'CATIA CATPart, CATProduct, CATDrawing file name
            QueryDef.Select.Add "FILE_NAME", "F", False             'Vault name
            QueryDef.Select.Add "REVISION", "F", False
            QueryDef.Select.Add "CN_COMMENTS", "F", False
            QueryDef.Select.Add "OBJECT_ID", "F", False
            QueryDef.Select.Add "TDM_ID", "F", False
            QueryDef.Where.Add "","CAD_REF_FILE_NAME","=",trim(catName),False,"F"
           'QueryDef.Where.Add "","FILE_NAME","=",trim(strLine),False,"F"
           'QueryDef.Where.Add "","TDMX_CAD_IDENTIFIER","=",trim(partNumber),False,"F"
           'QueryDef.Where.Add "","REVISION","=",newRevision,False,"F"

           ' Print "Looking in database for Part Number = " + trim(partNumber)' + " and new revision = " + newRevision + " (was: " + revision + ""


             Query.Run
             count = Query.QueryResult.RecordCount
             '  Query.QueryResult.PrintToFile "C:\test.log","C:\test.log"
             '  Print "Printed Test.log of the query"
             Dim i As Integer 
             Print "Found " + cstr(Count) + " Records"


          If count = 0 Then
            '  txtout.WriteLine "NOT FOUND  Id/Rev " + partnumber+"/"+newRevision + "  " +Mid(trim(strline),40)
            '  Print "File was NOT found in Database Partnumber: "    + partnumber + " revision : " + newRevision
               txtOut.WRiteLine "NOT FOUND CATIA file name: " + catName
               kntNotFound = kntNotFound + 1
          Else
             If nClassId = 101 Then
               kntPartFnd = kntPartFnd + 1
             End If
             If nClassId = 102 Then
                kntProductfnd = kntProductFnd + 1
              End If

             If nClassId = 100 Then
                kntDrawingFnd = kntDrawingFnd + 1
             End If
             If isModel Then              'nClassId = 251 Then
                kntModelFnd = kntModelFnd + 1
             End If
             If count > 1 Then
               kntDups = kntDups + 1
               'If listDups = 6 Then
                 'txtout.WriteLine  "DUPLICATE  Id/Rev " + partnumber+"/"+newRevision + "  " +  Mid(trim(strline),40)
               '  txtout.WriteLine  "DUPLICATE count: " + cstr(count)+"  file name " + catName+ "  " +  strline
               ' End If
              End If



              If nClassId = 100 Then  ' only do this if we are looking at CATDrawings
         '      Dim i As Integer
                Dim isLinkable As Boolean
                For i = 0 To count -1
                   'cnt = cnt + 1
                   Set RecordIn = Query.QueryResult.GetRecord(i)
                     'Use the ObjectStore interface to create a new ISmObject
                    Dim SourceObject As ISmObject
                    Set SourceObject = ObjectStore.ObjectFromData(RecordIn, True)
                    On Error Resume Next



'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''    THIS IS VERY IMPORTANT.  It is the workobject
''
''     Note that the query got the original record enough
''     to build the RecordIn smRecord.  This was enough
''     to build the SourceObject.  Retrieve this and you have
''     E V E R Y T H I N G!!!!
''
''      This is the WorkObject mentioned thoughout the Programmer's Guide
''      STComProgrammerGuide.pdf.  All the examples assume you get it from
''      the FirstRec.   For these utilities, you get it from the results
''      of a query.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'' ***********************************************************************
'
'
                  'Retrieve all attributs
                   SourceObject.Retrieve
        '       '  This PrintToFile has EVERYTHING.
         '         If DEBUG= "YES" Then
       '             SourceObject.Data.PrintToFile "Getting Objectid All information","c:\Assembly_recordlist.txt"
       '            End If

       '    '  Examples of gettling different Fields
'           '    Dim strD As String
'        '  strD = SourceObject.Data.Value("CN_COMMENTS"
'           On Error Resume Next
'            nObjectId = SourceObject.Data.Value("OBJECT_ID"
'            nState = SourceObject.Data.Value("STATE"
'            tdm_id = SourceObject.Data.Value("TDM_ID"
'             strDirectory = SourceObject.Data.Value("DIRECTORY"
'            cad_ref_file_name = SourceObject.Data.Value("CAD_REF_FILE_NAME"
'            TDM_FILE_ID = SourceObject.Data.Value("TDM_FILE_ID"
        '  Dim nTDM_COMPONENT_NAME As String
        '      nTDM_COMPONENT_NAME =    SourceObject.Data.Value("TDM_COMPONENT_NAME"


'
                  Dim sRevision
                  sRevision = SourceObject.Data.Value("REVISION"
                 If count > 1 And listDups = 6 Then
                  txtout.WriteLine  "DUPLICATE:   file name/Revision " + catName+ " / " + sRevision  + " " +  strline
         End If

        '     Examples of setting values
        '     SourceObject.Data.Value("TDMX_CAD_IDENTIFIER" = sPartNumber
        '     SourceObject.Data.Value("REVISION" = sRevision
                   Dim sComment As String
                   sComment = SourceObject.Data.Value("CN_COMMENTS"
                   If instr(uCase(sComment),"SPECIAL_X" ) = 0 Then
                     SourceObject.Data.Value("CN_COMMENTS" = sComment + crlf + "Special_X"
                     kntNewSpec_X = kntNewSpec_X + 1
                   End If ' the work Special_X is not already in the comment
                     kntSpec_X = kntSpec_X + 1
        '     SourceObject.Data.Value("TDM_DESCRIPTION" = sDescription
        '     SourceObject.Data.Value("TDMX_3D_CAD_IDENTIFIER" = sPartNumber
        '
                   err.clear
                   SourceObject.Update
                   If err.Number <> 0 Then
                     Print "Error updating SmarTeam"
                     msgbox "Error updating SmarTeam"
                   Else
                     Print "Drawing File Name = " + catName + " Revision: " + sRevision + "  Updated - comment now has Special_X"
                   End If
             '  strUUID = nTDM_COMPONENT_NAME
              Next I
            End If ' only do the adding of Special_X to the comments of  ' CATDrawings



 

Badencorp - CATIA/SmarTeam - Installation, Training and Support!
An hour of hard work can often save you 60 seconds on Google.
JOBY


17 Oct 2007 10:31 AM
Hi Hale,
Thanks so much for posting this.
I don't know that I've understood it completely yet, but I can tell it will be useful.
Any chance you could attach the code as a text file?
Stupid smiley faces are making it hard to read. Or maybe you know of an easy way for me to get rid of them?
When I copy and paste into notepad, they come in as "[wink]"

Thanks!
~Joe

View Joe Burch's profile on LinkedIn
HALE


21 Oct 2007 11:37 PM
Joe,

I will give a better example as soon as I can. The happy fraces are almost always just a right parenthesis. It interprets the quote right paraenthesis as a wink and then turns the wink into the [Wink]. I'll also look into what I need to do to post code in a cleaner way.

I hope the basic stuff helps you because that manual drove me completely nuts. There was great stuff in it but the workobject was required and never ever explained. In fact there is some example code for the CLEAR function that leads you down a garden path that is completely wrong.

Regards,
Hale

Badencorp - CATIA/SmarTeam - Installation, Training and Support!
An hour of hard work can often save you 60 seconds on Google.
You are not authorized to post a reply.
Forums > COE Forums > SmarTeam > WorkObject - STComProgrammerGuide.pdf



ActiveForums 3.6

    

401 North Michigan Avenue, Chicago, IL 60611-4267 | (312) 321-5153 | (800) COE-CALL (U.S.)