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: Save additional copy of pdf to folder

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

17 Apr 2008 01:59 PM

Hi,

I'd like to save additional copy of PDF file (that one, which is created during save of CATDrawing from CATIA to SmarTeam database) to local disc or network folder.

It perhaps should be done via script hooked in right place(before check in operation which moves that PDF and CATDrawing to SmarTeam).

Can anyone can help me, because I do not know proper code to do this.

PIANNACCHIONE


17 Apr 2008 03:09 PM

You can set this feature using Applications Setup under the Editor Tools menu. In Application Setup highlight the CATIA Drawing file type. Then Click the Tools button. In the tools dialog Embedded Viewer Tab use the Modify button. This brings up the Embedded Viewer Settings. Go to the Viewer File extension textbox and enter the CATIA drawing file extension and then add a comma and the PDF file extension (i.e. .CATDrawing,.pdf) Interesting thing is this can be done for any filetype and you can also add as many extensions as you like. The catch is that the last extension is what's used by the viewer so be careful with that. Also, The PDF filename would need to exactly match the CATIA drawing filename for this to work.  Final plus, no scripting needed!!

CyFRoN

24 Apr 2008 08:16 AM

Welcome,

Thank You for reply.

But You misunderstood me.

I'd like to have second copy of PDF.

Normally when Catdrawing is saved to SmarTEam it is save with PDF file.

And those two files goes to check in vault after check-in.

But I need a second copy of that PDF file to be placed somewhere else. (for example local folder named PDF or network share).

That's why I don't know how to do this automatically during check-in operation.

If know how, please help me if you can.

CyFRoN

HALE


26 Apr 2008 12:21 AM
CryFroN,

My boss hates it when I say this, but I have that code and I'll dig it out for you tomorrow. You use the after checkin hook, and run a command that copies the catdrawing and the associesated pdf out of the vault and puts it whereever you want it (read-only). Then erase the CATdrawing, rename the pdf and you are done. As I said, I find it tomorrow.

Regards,
Hale

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


26 Apr 2008 03:13 PM

CryFron,

This is "consulting level" code, but what the heck.  I have taken working code and commented things out to make it more basic.  I haven't tested the commented version, but it should be very close to functional.  The guts to this code is the call to SessionUtil.CopyObjectFileFromVaultPermission.  Almost all of the code below is either setting up this call or setting up debugging.

This is code is being called after CATParts, CATProducts, and CATDrawings are checked in.  If you use it just for CATDrawings, it should work fine.

Hope this helps.

The PLMDatabase.bs script should already be called in the "After Check In" Hook.  I know it is in Design Express.  If it isn't there on your system you will need to create a full script and add it to the hook.  The only thing missing here from that script are the original function and the setting up of SmSession.

In PLMDatabase.bs script

STEP 1

' At the top of the script add the following "Global" variables.  Bad programming,
'  but I find it useful to be able to switch from Testing Environment to production
'  environment in the part of the script that is visible (or close it visiable) when
'  I open the script in an editor.

'NOTE - this is the path that CGR,CGM, PDF  files are copied to.  Modify as necessary
' DO NOT ADD A TRAILING SLASH

' Used for testing
Const strDest_Path As String = "C:\temp"
' You shouldn't need the extra work path.  I had to do the renaming in a separate folder
'Const strWork_Path As String = "C:\temp1"
' Used for production - comment out the previous Const and uncomment this when you

'deploy.  Obviously tailor this value to the location you want your files to go.


'  Const strDest_Path As String = "\\ProdServer\Smart_team_files\newfiles"
'  Const strWork_Path As String = "\\ProdServer\Smart_team_files\Temp"



' This constant helps me turn the debugging screen off and on.
'  Note PRINT statements will go into this window if the window is open
'  They are ignored if the window doesn't exist.   Not as neat as a debugger,
'  but better than 300 msgboxs.
Const DEBUG As String = "YES"        'One of these values "YES"  '"NO"

STEP 2.
up with the rest of the Declare lines add this one

Declare Function CopyFileFromVault(cFileName As String, SmSession As SmApplic.SmSession, FirstRec As Object ) As Integer


STEP 3.
Find the After_CheckInDocument function - the following line
Function PLMDB_AfterCheckInDocuments(ApplHndl As Long,SelectOp As String,FirstPar As Long,SecondPar As Long,ThirdPar As Long ) As Integer

Find this line
PLMDB_AfterCheckInDocuments = PLMDB.AfterCheckInDocuments (Session, RecListIn)


After that line add this.  Obviously I'm not using the tmpString for anything right now.
  Dim ok1 As Integer
  Dim tmpString As String
  ok1 =   CopyFileFromVault(tmpString, Session, RecListIn)

 ' Your choice on how you hanlde debugging/ error messages
   ' if ok1 <> Err_None then
   '  msgbox "Copy File From Vault failed"
   ' end if

STEP 4.  Insert this code at the bottom of the PLM_Database.bs file
Function CopyFileFromVault(cFileName As String, SmSession As SmApplic.SmSession, FirstRec As Object ) As Integer
' NOTE  cFileName is not being used right now
  Dim FirstPar As Long
  Dim SecondRec As Object
  Dim ThirdRec As Object
  Dim FirstWorkObject As SmApplic.ISmObject
  Dim SecondWorkObject As SmApplic.ISmObject
  Dim Vault As SmApplic.ISmObject ' vault as object
  'Dim Vault As Object ' vault as object
  Dim VaultType As Integer ' type of vault
  Dim SourceVault As Long ' source vault object id
  Dim SourceDirectory As String 'source directory in vault
  Dim SourceFileName As String 'source file name
  Dim DestinationDirectory As String 'destination directory in vault
  Dim DestinationFileName As String 'destination file name
  Dim SessionUtil As SmUtil.SmSessionUtil 'main SMARTEAM service object
  Dim Result As Long ' object id for refresh
  Dim FileMode As Integer 'file mode in destination directory
  Dim finalFile As String
  '  Set the Function value.  If everything runs okay, set it back to err_none
  CopyFileFromVault = Err_Gen


  ' DEBUG was set globally
  If DEBUG = "YES" Then
    ViewPort.Open "Debug window",3000,3000,500,500
    ViewPort.Clear   ' Comment this line out if you have several things that run
                      ' one right after the other.  The view window then contains the
                      ' message from all of the runs.
    ' now put Print statements whereever you want
    Print "Starting Program  = After Check-in"
    ' I like to see what is actually in the FirstRec.  Sometimes I'm surprised
    ' either by what is there or what is NOT there.
    FirstRec.PrintToFile "In PLMDB Check In", "C:\rec_checkin_copy2vault.txt"
  End If


  Set FirstWorkObject = SmSession.ObjectStore.ObjectFromData(FirstRec.GetRecord(0),true)
  Set SessionUtil = SmSession.GetService("SmUtil.SmSessionUtil"
  ' Vault type
  VaultType = VltInWork    ' Checked In vault.  There is a different value for the
                           ' Released vault
 ' Get Vault for WorkObject according to specific vault type

  Set Vault = SessionUtil.GetVaultForObject(VaultType, FirstWorkObject)
         
' Get Vault object id - for local vault NULL object id
  If Vault Is Nothing Then
      SourceVault = NULL_OBJ_ID
'      msgbox "Aborint Copy file failed - Could not get Vault ID"
'      exit function
  Else
      SourceVault = Vault.ObjectId
  End If
' Set all parameters
    SourceDirectory = FirstWorkObject.Data.ValueAsString(NM_DIRECTORY)
 '  DestinationDirectory = SecondWorkObject.Data.ValueAsString(NM_DIRECTORY)
  ' NOTE:  The following variable Is Set As a Global variable so that it can be modified
  ' at the top of the script

'   DestinationDirectory = strWork_Path
    DestinationDirectory = strDest_Path
'     On Error Resume Next
'     mkdir DestinationDirectory
'     On Error GoTo 0
   Print "Destination Directory: " + DestinationDirectory

   SourceFileName = FirstWorkObject.Data.ValueAsString(NM_FILE_NAME)
   Dim strId As String
   strId = FirstWorkObject.Data.ValueAsString("TDM_ID"
   Print "TDM_ID = " + strId

   Print "Source File Name: " + SourceFileName
  ' msgbox "SourceFileName = " + SourceFileName
   DestinationFileName = SourceFileName
   FileMode = modReadWrite 'file mode in destination directory

' You don't need this.  It allowed renaming to file to include the user who checked
'  the CATDrawing in
'  Dim User As String
'  On Error Resume Next
'  Set CATIA = GetObject(,"CATIA.Application"

'User = CATIA.SystemService.Environ("LOGNAME"
'  If (User = "" Then
'    User = CATIA.SystemService.Environ("USERNAME"
'  End If
'Print "User set to " + User


' HERE is the guts of the function
  err.clear
SessionUtil.CopyObjectFileFromVaultPermission FirstWorkObject,   DestinationFileName, DestinationDirectory, FileMode
  If err.number <> 0 Then
    msgbox "Copy of PDF file " + DestinationFileName + " to " + DestinationDirectory + " failed!"
    Print "Copy of PDF file " + DestinationFileName + " to " + DestinationDirectory + " failed!"
  End If

'  Dim strRev As String
'  strRev = FirstWorkObject.Data.ValueAsString("REVISION"
'  Dim StrCmt As String
'  Dim StrCadId As String
'  Dim nameLen As Integer
'  nameLen = inStr(DestinationFileName,"_"
 
'  StrCmt = FirstWorkObject.Data.ValueAsString("CN_COMMENTS"
'    If inStr(uCase(DestinationFileName),".CATPART" > 0 Then'
'    strCmt = FindComment(strId, "CATIA Part" ' ;As String
'       strCadId = FindCadId(strId, "CATIA Part" ' ;As String
'    End If
'    If inStr(uCase(DestinationFileName), ".CATPRODUCT" > 0 Then
'       strCmt = FindComment(strId, "CATIA Product" ' ;As String
'       strCadId = FindCadId(strId, "CATIA Product" ' ;As String
'    End If
'    If inStr(uCase(DestinationFileName), ".CATDRAWING" > 0 Then
'      strCmt = FindComment(strId, "CATIA Drawing" ' ;As String
'      strCadId = FindCadId(strId, "CATIA Drawing" ' ;As String
'    End If
'     Print "Comment = " + strCmt
'     Print "CAD ID = " + strCadId
'     If ucase(strCadId) = "MISSING" Then
'       strCadId = "Error: " +Mid(DestinationFileName,1,nameLen)
'     End If

'    Print "Revision: " + strRev
    Dim strFile As String
    Dim strFileOut As String
    ' This is the CAD folder and file name we just copied out of the vault
    strFile =DestinationDirectory + "\" + DestinationFileName
    If inStr(uCase(DestinationFileName),".CATPART" > 0 Or inStr(uCase(DestinationFileName), ".CATPRODUCT" > 0 Then
      Print "CATPart/CATProduct Delete extra file: " + strFile
      ' This erases the CATPart or CATProduct itself
      kill strFile

      'GHP Note: set this to your desired file Name
      ' You can comment more of this out if the vault name is okay as the finale name
      ' by default it will contain the vault name which has the part number and
      ' and objectId number and an objectType number separated by underscores.
       strFileOut = DestinationFileName + ".cgr"  'strCadId+"_"+strRev+"_"+User + ".cgr"


'      finalFile = strDest_Path + "\" + strFileOut
'      strFileOut =DestinationDirectory + "\" + strFileOut
       strFile = strFile + ".cgr"
'      Print    "Rename " + strFile + " to " + strFileOut
       Name strFile As strFileOut
'      FileCopy strFileOut, finalFile
'      kill strFileOut
   Else
      If inStr(uCase(DestinationfileName),".CATDRAWING" > 0 Then
 
        Print "CATDrawing Delete extra file: " + strFile
        ' Kill the CATDrawing file
        kill strFile
        Print "CATDrawing file deleted"
        ' NOTE: Set this to your desired name
        strFileOut = DestinationFileName + ".pdf"  'strCadId+"_"+strRev+"_"+User + ".pdf"
'        finalFile = strDest_Path + "\" + strFileOut
'        strFileOut =DestinationDirectory + "\" + strFileOut
        strFile = strFile + ".pdf"
        Print    "Rename " + strFile + " to " + strFileOut
        If fileExists(strFile) Then
          Name strFile As strFileOut
          Print "File renamed"
'          FileCopy strFileOut, finalFile
'          kill strFileOut

        Else
           Print "File did not exist and was not renamed"
           msgbox "Source File missing.  File NOT written to PLM " + strFileOut

        End If


     Else
       ' This would not be a CATPart, CATProduct or CATDrawing - nothing done
     End If
  End If
  Print    "Finished okay"

  CopyFileFromVault = Err_None

End Function

Regards,
Hale

 


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


26 Apr 2008 03:19 PM
One of these days, I'm going to take the time to figure out the COE editor. The happy faces are just closing parentheses.

Regards,
Hale

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


09 Jun 2008 02:50 PM
Although I'm not quite ready for it, I think this will come in very handy soon...
And now it's you who's saved me hours of work instead of Google...
Thanks very much.
~Joe

View Joe Burch's profile on LinkedIn
You are not authorized to post a reply.
Forums > COE Forums > SmarTeam > Save additional copy of pdf to folder



ActiveForums 3.6

    

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