Jul 30

    Save or Release a Part from CATIA

    Hale Pringle
    Hi Guys,

    I've got a small problme that has been battering my poor head for the last few days.  I need to save and checkin or release some parts from CATIA into SmarTeam.  (I need modify some properites, change the files name and get the cgr  file created.) 

    I see how to do it from SmarTeam Basic script, but that doesn't give me CATIA's magic.  VBA on the other hand gives me the CATIA stuff, but I can't see how to initiate a SmarTeam Save or Cycle Release.

    Any thoughts here?


    Douglas Snell
    [PCC Aerostructures ]
    You can add the Smarteam References to your VB/VBA Project. From the Tools Menu select references then scroll down to the Smarteam libraries and check them off. This will then give you access to SMApplic, ISMObjects, etc you are used to seeing with the Basic Scripts.

    I don't have much experience using these but that should at least get you started. As far as where the integration operations are located your best bet would be to search through the ST API Reference Guide.
    Hale Pringle

    I've been in the API Reference and lots of other places. I just don't think that using the SmarTeam COM Object references will fire off the CATIA Life Cycle sutff (in particular creating cgr files). I may be wrong, but that my gut feeling.

    Pedro Ruiz
    Well What I think.

    you can do all changes you have to do in Catia in The document.

    and generate the cgr file like here

    CATIA.DisplayFileAlerts = False
    Dim part As PartDocument
    Set part = CATIA.ActiveDocument
    part.SaveAs "C:\pdm2\Perfil_administrador\Escritorio\prueba\Part1.CATPart"
    part.ExportData "C:\pdm2\Perfil_administrador\Escritorio\prueba\Part1.CATPart.cgr", "cgr"
    CATIA.DisplayFileAlerts = True
    MsgBox CATIA.ActiveDocument.Name

    later you do one checkout of Smarteam document and attach the new file in this case the catia part and do check in (if the cgr is in the same folder) smarteam do check in of this document too,automatically.

    I thinks its easy from vba

    -Catia - changes docs , generate cgr
    -Smarteam do life cycle

    I hope this helps you.

    en una semana me voy de vacaciones!!

    Hale Pringle
    Thanks Jordi,

    I had more or less come to the same conclusion.  It bothers me some since one of the "rules" is "Let CATIA Life Cycle the CAD documents!"  I understand that rule completely when we get to the CATProduct level, I'm just not sure about at the single CATPart level.

     With thi in mind, I'll throw one further question out just in case someone has an insight.

    Dealing with a CATPart only (ignoring CATDrawing links and CATProduct links) is there a difference down the pike between a CATPart Releaded from CATIA and one Released with SmarTeam?

    The only thing I can think of is the cgr file. I know that there is a DIRTY_FLAG variable that CATIA plays with but I can't see how any of that matters until I start involving the CATPart with a CATProduct or a CATDrawing.


    Jonathan Ruffley
    [Force India F1 Team]
    Dealing with a CATPart only (ignoring CATDrawing links and CATProduct links) is there a difference down the pike between a CATPart Releaded from CATIA and one Released with SmarTeam?

    If there was an attribute linked via Catia integration which has been changed prior to or during release then release outside catia will have a consequence.

    For example if the revision field in the catia parts properties is linked to the smarteam revision. In this case your part will be dirty and so show the no entry sign in catia.

    povl petersen
    Try this

    Method 1.
    Make a vb6 project and reference to
    C:\Programmer\Dassault Systemes\B17\intel_a\code\bin\CATSmarTeamIntegTypeLib.tlb
    Method 2.
    Make a cata vba (the reference is set default)

    VBA code example making a CAI save og launch check in:
    Sub CATMain()
    Dim stiEngine As stiEngine
    Dim DBitem As StiDBItem
    Set stiEngine = CATIA.GetItem("CAIEngine")
    Set DBitem = stiEngine.GetStiDBItemFromAnyObject(CATIA.ActiveDocument)
    stiEngine.Save DBitem
    stiEngine.LifeCycleCheckIn DBitem
    End Sub

    Pedro Ruiz
    Thank you Povl!!
    This is very useful code
    Hale Pringle
    Jon and Pavl,

    Thanks for your insight.

    Jon - I don't have any links during this mass move so I think I'm Okay there.

    Pavl - I've seen this call in the manual. It seems to me (gut feeling) that this call done via VBA inside CATIA would be no different than this cass via BS or EBS inseide SmarTeam. Do you have any findings to the contrary?

    Thanks Again.
    povl petersen
    I agree. There will be no difference from VBA to BS. Mostly because the word CATIA in the line "Set stiEngine = CATIA.GetItem("CAIEngine")" is actually a CATIA object.
    Hale Pringle

    I have a real answer to the original question. Povl has rhe right solution. Any CATIA CAD file that is not saved through CATIA (either with the VBA code, Bulk Load or a normal SmarTeam Save) will not have a UUID in Smarteam. When you Check-out the file, CATIA and SmarTeam check the UUID against the database and if they are different CATIA greys out all of the the LifeCycle options except Save. You can Save the document as a new document, but you lose the link to the previous revision.

    The bottom line is that if you want links between originally imported version of a CAD document and the next version checked-out and checked-back in, you MUST have CATIA do the original Save. (The only work around I found was loading a second copy just to get the UUID and then updating those that didn't have one. This is ugly!)

    BTW This means the the SmarTeam Import tool can't be used to load originals of CATIA CAD Documents. It can be used to add information to the profile cards after the files are in SmarTeam, but Import does NOT fill in the UUID field in SmarTeam.

    BTW2 I found that CATDrawings coming from VPM have enough missing links and other issues that Bulk Load becomes useless. A variation of Povl's code was the only solution that seemed to work.

    Hale Pringle
    Povl (or others)

    You posted this code above
    Sub CATMain()
    Dim stiEngine As stiEngine
    Dim DBitem As StiDBItem
    Set stiEngine = CATIA.GetItem("CAIEngine")
    Set DBitem = stiEngine.GetStiDBItemFromAnyObject(CATIA.ActiveDocument)
    stiEngine.Save DBitem
    stiEngine.LifeCycleCheckIn DBitem
    End Sub


    I'm currious about several things
    1. Is there documentation on the stiEngine anywhere?

    2. Is there a way to update the Profile Card in SmarTeam you create with the stiEngine.Save. I see it lets you get the ObjectId and ClassID of the item you just saved, but I can't see how to update the SmarTeam profile card without a reference to the current session.

    3. Which obviously lead to the third question. Is there a way to get the current session. The object explorer in VBA says that SmApplict.SmMetaInfo.session contains the current session. SmApplic is defined, but using smMetaInfo generates a compile error.

    Eduardo Magnetto
    The idea of this has been extracted from a sample code Jos (from developers forum) gave me some time ago. I just adapted to my needs.

    Check this scenario (tested on Visual Studio 2005, Smarteam R17SP6):

    - Create e new C# project, Console application

    - Add references to

    - Code this:

    using System;
    using System.Collections.Generic;
    using System.Text;
    using SmarTeam.Std.Interop.SmarTeam.SmApplic;
    using SmarTeam.Std.Interop.SmarTeam.SmarTeam;

    namespace ConsoleApplication2
        class Program
            static void Main(string[] args)
                ISmApplication smApplic = (ISmApplication)System.Activator.CreateInstance(System.Type.GetTypeFromProgID( "SmarTeam.SmApplication" ) );
                ISmSession oSmSession = smApplic.Engine.get_Sessions(0);


    - Run Smarteam and loggin (manually)

    - on VS, run on debug mode (F11)  till you create the oSmSession object. Dont go further

    - On the Immediate window, check this:

    You should get the user logged!
    I tested and worked.

    With the session, the rest is straightforward.

    If you want on VB.NET ...

    Imports SmarTeam.Std.Interop.SmarTeam.SmarTeam
    Imports SmarTeam.Std.Interop.SmarTeam.SmApplic

    Module Module1
        Sub Main()
            Dim smApplic As ISmApplication

            smApplic = System.Activator.CreateInstance(System.Type.GetTypeFromProgID( "SmarTeam.SmApplication" ) )

            Dim oSmSession As SmSession
            oSmSession = smApplic.Engine.Sessions(0)

        End Sub
    End Module

    I don't know now if you can do something similar from VBA.
    But you can create a VB or C# DLL (COM Visible) with a class (and function) that returns the open session and call it from VBA. Or you can parse it the info you want to update (as a recordlist) and make the update from the lib.

    Please let me know if this helps!
    Hale Pringle

    Thanks for the code snippets. I've done a ton of Java work and more recently VB6 and CATIA VBA. I haven't ever needed to get into either C# or .net. I was interested in the stiEngine since it gives VBA code access to the current SmarTeam Engine. If we got the current session, we would have a good bit of what is needed to write a number of untility functions. I can access a new engine and a new session with VB, VBA, and SmarTeam Scripts. I just wanted to access the current session if possible.

    I did find in the VBA code more functionality associated with the stiEngine: I was looking up the functionality and decided to go ahead and share the methods and parameters.

    Dim stiEngine As stiEngine
    Dim myDBItem As StiDBItem
    Dim myVB As StiVB
    Dim lObjectId as Long
    Dim newFileName as String

    'Initialize the Engine (if you are connected to SmarTeam, then the stiEngine
    ' is connected)
    Set stiEngine = CATIA.GetItem("CAIEngine"
    If Err.Number 0 Then
      MsgBox "Aborting - Not stiEngine could not be created"
    End If
    'initialize the VB functionality
    Set myVB = stiEngine.GetItem("CATStiVB"

    lObjectId = 44444
    newFileName = "TestPart.CATDrawing"
    ' Copy and Item out of SmarTeam into your work folder and register it with the
    '  SMARTEAM.FileCatalog (This is a read-only open)
    myVb.FastCopyDocument "CATIA Drawing", lObjectId
    If Err.Number 0 Then
        msgbox "File could not be copied out ObjectID: " + cstr(lObjectID)
        Set drwDocument = documents1.Open("C:\AWork" + newFileName)
      ' Set the DBItem which eposes more functionality
        Set myDBitem = stiEngine.GetStiDBItemFromAnyObject(CATIA.activeDocument)
    End If
    ' Now you can check things etc.  If you had checked the item out instead of
    ' obtaining a read-only copy then you could check it back in or release it.

    Here are the methods and their parameters

    myVB.BulkLoading (no Paramaters)
    myVB.CAIOpen (FilePath as String)
    myVB.ClearListOfVisitedPoints (no Parameters)
    myVB.CompareASCIIFiles ASCIFilePath1 as String, ASCIfilePath2 as String, outTXTfilePath as String) as Boolean
    myVB.CopyFilemy(ClassName as String,  ObjectId as Long) as String  ??
    myVB.DumpDocDescriptors (FilePath as String)
    myVB.FastCopyDocument (ClassName as String, jObjectId as Long)
    myVB.FindDocument (iFileName as String, iUUID as String, iSTClassBehavior as String, iSTFileType as String,ClassID as Integer) as Long
    myVB.GenerateXMLReport(jCATIADoc as Document, XMLFilePath as String)
    myVB.GetClassName (DocumentSelected as Document) as String
    myVB.GetItem (jDName as String) as CATBaseDispatch
    myVB.GetObjectID (DocumentSelected as Document) as Long
    myVB.GetRevisionObjectID (DocumentSelected as Document, RevisionSelected as String) as Long
    myVB.GetWork (no parameters)
    myVB.GlobalRefresh (DocumentSelected as Document) as Document
    myVB.InsertComponent(jProduct as AnyObject, ClassName as String, ObjectId as Long, DialogueBox as Boolean)
    myVB.IsDocUnloadable (jdoc as Document, oAnswer as Integet, oisModified as Integer)
    myVB.LoadPropertiesFromDB (DocumentSelected as Document)
    myVB.MarkPointAsVisited (PointName as String)
    myVB.Name (name of VBA beind used. "CATIAStiVB0" for now)
    myVB.myVb.NewRelease (DocumentSelected as Document, DialogueBox as Boolean)
    myVB.OpenInReadOnly (ClassName as String, ObjectId as Long) as Document
    myVB.OpenInReadOnlyRevision(ClassName as String, DcoumentId as String, DocumentRevision as String) as Document
    myVB.Parent (no Parameters)
    myVB.PerfoDisplayAllResults (pathToFile as String)
    myVB.PerfoDisplayResults (PathtoFile as String)
    myVB.PerfoStart (no parameters)
    myVB.PerfoStop (no parameters)
    myVB.ProcessCOOTFlyList (no parameters) ...hmmmm...
    myVB.ReleaseDocument (DocumentSelected as Document, DialogueBox as Boolean)
    myVB.ReplaceWithSelectedRevision (DocumentSelected as Document, RevisionWanted as String) as Document
    myVB.SaveAs (Document as Document)
    myVB.SavePropertiesInDB (Document as Document)
    myVB.SynchronizeFileWithDB (ClassId as Integer, ObjectId as Long)
    myVB.WasPointVisited (PointName as String) as Long

    stiEngine.BuildDocDBItemFromSmarTeamID(jObjectID as Long, iClassId as Integer) as StdDbItem
    stiEngine.BuildFileDBItemFromSmarTeamID(jObjectID as Long, iClassId as Integer) as StdDbItem
    stiEngine.Connect (jUserLogin as String, iUserPassword as String)
    stiEngine.Disconnect (no Parameters)
    stiEngine.GetItem (jDName as String) as CATBaseDispatch
    stiEngine.GetSMARTEAMClassID (iStdDBItem as StiDBItem) as Integer
    stiEngine.GetSMARTEAMObjectID (iStdDBItem as StiDBItem) as Long
    stiEngine.GetStiDBItemFromAnyObject (iAnyObject as AnyObject) as StiDBItem
    stiEngine.GetStiDBItemFromCATBSTR (iFullPath as String) as StiDBItem
    stiEngine.GetTeamPDMURL (iStiDBItem as StiDBItem) as String
    stiEngine.IntegrationType (no parameters)
    stiEngine.IsConnected (no parameters)
    stiEngine.LifeCycleCheckIn (iStiDBItem as StiDBItem)
    stiEngine.LifeCycleCheckOut (iStiDBItem as StiDBItem)
    stiEngine.LifeCycleCheckOutPropagated (iStiDBItem as StiDBItem)
    stiEngine.LifeCycleNewRelease (iStiDBItem as StiDBItem)
    stiEngine.LifeCycleNewReleasePropagated (iStiDBItem as StiDBItem)
    stiEngine.LifeCycleRelease (iStiDBItem as StiDBItem)
    stiEngine.LifeCycleUndoCheckOut (iStiDBItem as StiDBItem)
    stiEngine.name (no parameters)
    stiEngine.Parent (no parameters)
    stiEngine.RefreshInfo (no parameters)
    stiEngine.Save (iStiDBItem as StiDBItem)
    myDBitem.GetItem  (iDName as String) as CATBaseDispatch
    myDBitem.IsRoot (no parameters)
    myDBitem.name (no parameters)
    myDBitem.Parent (no parameters)
    Without documentation I have to try each one to figure out what it does. For example the SavePropertiesInDB takes a Document as a Parameter. I suspect it invokes the automatic linking we set up in the Application Integration Screen, but I haven't tried it.

    I have used the FastCopyDocument.(ClassName as String, jOjbectId as Long)
    myVb.FastCopyDocument("CATIA Drawing", 4444) will copy the drawing with objectId = 4444 from SmarTeam into the work directory. It also adds the document to the SmarTeam-FileCatalog folder. I wasn't able to do this fully with SmarTeam Script code.

    I wrote a Quick and Dirty SmarTeam Script to read a list of file names, queried SmarTeam and wrote a text file of ObjectIds and CAD_REF_FILE_NAMEs (the file name written to the work folder). Then I used VBA to read this file and use the stiEngine and stiVB code to copy each file out of SmarTeam, open it, do some checking and then close the document. Its nice to do that with VBA and have CATIA closely involved in the whole process.

    I see some real possibilities for using the stiEngine and the stiVB objects for quick and dirty utility functions.

    Thanks again for you help!

    Hale Pringle

    For those who have access there is now a small manual describing the STIEngine available on the Smart Developers Forum. They asked that it stay there for now since it is prelease. Among other things they do show how to obtain the current smSession which opens most of the SmarTeam API to VBA. With the ability to do lifecylce saves, checkouts, etleases and the smSession available to do queries there are a ton of things we can do from CATIA macros that weren't possible before.

    Hale Pringle

    I figure I can share one piece that I discovered. This is a critcal piece that I had asked about and never found an answer for. The question was how to retreive the current smSession in a VBA script that is using the stiEngine module. Without the session, you can't do queries, etc.

    Here is how you find the session CATIA is using (assuming you log in using the CATIA SmarTeam Integration menu -- CONNECT.)

    Dim SmApp As ISmApplication
    Dim SmSession As ISmSession
    Dim SmEngine As ISmEngine
    Dim sessionID As String

    Set SmApp = GetObject(, "SmarTeam.Application")
    Set SmEngine = SmApp.Engine

    for i=0 to SmEngine.SessionsCount-1
    sessionID = SmEngine.Sessions(i).GlobalData.Value(“SessionID”)
    if sessionID = "StiConnection" then
    Set SmSession = SmEngine.Sessions(i)
    exit for
    end if

    Once you have the session, lots of doors open.

    BTW. One of the things I really like here is that the user must log in to SmarTeam from CATIA. The VBA script then uses that SmarTeam engine and session. This means that you do NOT have to include a username and password in your script (bad security) or force a login everytime you use the script (a pain.)

    Eduardo Magnetto
    Well, I was sure there were a cleaner and smarter way to get the session!

    COE Administrator
    [Admin Group]
    Thanks much for sharing the code! If you do find documentation on the STI API, please share, we've been looking for it for a while.

    You're right on, guys. If you try to save CATIA files without the integration, a couple of problems are typical:
    A) The UUID does not get populated in the Component Name field. This is necessary in order for the integration to recognize the file as matching the metadata. Interestingly enough, the only integration that requires this is CATIA, and back in the days of R12 Dassault kept claiming you didn't need it any more. However, I have done some testing at R16 & R17, and the integration won't work without it.

    B) Another typical issue is the creation of the SmarTeam File Catalog registration (a hidden XML file). The absence of this file, or mismatch with SmarTeam & Windows, could cause problems with save and life cycle operations.

    So, I strongly recommend to do it via the integration. Now, if you could somehow get the UUID into a text file, then SmarTeam Import would work. However, the UUID as stored internally in each CATIA file has a different ending than the UUID as stored in SmarTeam, so we haven't yet found a scripted way to get the UUID other than saving via the integration.
    Hale Pringle

    I'm trying to get them to release the documentation. It is on the SmarTeam Developer forum site, but they asked that it stay there until they get approval from somewhere. We had already figured out and posted most of the guts here. The only thing we were missing was how to get the session that was created when CATIA logged into SmarTeam and that was posted here as well.

    I ran into the same UUID problem you did Jay. One of the things I ended up doing was loading files automatically using a CATIA VBA script and the STIEngine code. I then wrote a SmarTeam script that added that UUID to each Drawing that had the same CATIA Part Number and that didn't have a UUID. (I also had to set the Dirty Flag and the Integration Type and I think the CLD). Once the UUID was in place the drawing acted use like one saved via CATIA Integration.

    RE the SmarTeam-FileCatalog. These aren't hidden. They are in a folder called SMARTEAM-FileCatalog under your work folder. I had some code that "Copied a file - with Permsissions", but it didn't register the files with CATIA. We had to open the SmarTeam File Explorer and hit the REPAIR button to get SmarTeam and CATIA to agree that they knew which file I was dealing with (this is the "registration" you mentioned.) I recently obtained some code on the PLMDatabase Forum site that is supposed to handle that automatically via SmarTeam Script but I haven't tried it yeat. I know that checking things out via the stiEngine methods does automatically register the file with the SMARTEAM -FileCatalog. It is also interesting that the stiEngine has "Open a file - readonly" methods. All of the other documentation I have read talks about CHECKING-OUT or RELEASING. "Opening - read-only" (and registering) was ignored.


    Pappa Gunnar
    [Unknown Organization]
    Hale, you wrote "I then wrote a SmarTeam script that added that UUID to each Drawing that had the same CATIA Part Number and that didn't have a UUID".

    How did you get the UUID to begin with? If i could just get the files UUID somehow (without saving it) I can get my code to run again!

    This all worked in v5r14 btw, SmarTeam just decided to remove this functionality ... great work!

    The good news is that I acctually got SmarTeam to really check in on how to solve this, hopefully i will get an answer by tomorrow.

    Hale Pringle

    I only way I know to get the UUID (and I understand that it a modified/tweaked UUID at that) was to load the file. I loaded the with a modified file name (I added an X). The bulk load type operation (actually using the stiEngine DLL) ened up with a bunch of NEW filew with no part numbers etc. I was able to find them using the date/time loaded and empty part number, use the file name to identify the part number's I wanted and move the UUID from the new files to the corresponding old files. Then I deleted the new files.

    I have looked at some length for a way to get the UUID without loading the files. For security reasons, I don't think we are ever going to get it. This is also why the UUID we get from SmarTeam is tweaked. They are trying to prevent all kinds of bad situations where a new file is substituted for an existing file "behind-the-scenes,"

    Pappa Gunnar
    [Unknown Organization]

    Thank you for your answer.

    I'm not entirely sure how you got the UUID from the new files (sorry if I'm slow)? Did you save the files to smarteam and read the UUID from the db or xml file? Or do you know how to get the UUID using Catia api's?

    I've been in contact with SmarTeam, and they suggest I use pretty much the same code you had already posted. What I want to do is quitely import files to SmarTeam with no user interatction, furthermore I want the imported files to be "the next revision" of an existing document.

    The problem with the stiEnginge.save is that it will display a profilecard, unless i have "Batch mode save" set to true (which I don't want my users have to do everytime).

    But if could just get a hold of the UUID it could manipulate the xml file and all would be good. It's ok if the file has to be opened in Catia.
    Hale Pringle

    Sorry if i wasn't clear. I had to load the files into SmarTeam, then I can find the value in the "Componant Name" field. This is the UUID according to SmarTeam.

    As far as I know there is no way to get the UUID directly from CATIA. Dassault wants to be sure that people do not fiddle with the UUID behind the scenes.

    Pappa Gunnar
    [Unknown Organization]
    Thanks Hale,

    My only problem is that I can set the useGraphicalInterface to False, but that will only prevent the "Save to Project"-box to disappear, I still have to fill out the profilecard. Unless I check the "batch mode save" in catia. There is a way to set bulk mode in the stiEngine/Stivb, but there's no way to set the "batch mode save".

    Does anyone know how to programatically set Batch Mode Save in the Catia integration?
    Hale Pringle

    I've been on the road for the last week or so. I'll see if I can find this for you as soon as my test machine recovers from the trip. I don't remember right off hand, but I think there is a way.

    Pappa Gunnar
    [Unknown Organization]
    I just got an answer from SmarTeam, they might consider this a bug. As of right now there's no apparent way of silently saving catia-documents to smarteam v5r17 without enabling batch mode save.... to bad ... They'll probably fix this at the same time pigs can fly .. or something like that.

    And they won't let me know how to read the UUID from the catia file .... Though I've heard that this is possible through some seriouse c++ coding.
    Amod Ghangurde, Project Manager
    [Geometric Limited]

    Hi All,

    I just wanted to know in which library "StiVB"  interface available.

    I found that "StiEngine" is available in library "CATSmarTeamInteg" but could not find "StiVB". Can anyone please let me know where it is available.






    All Times America/New_York

    Copyright © 2016 COE. All Rights Reserved
    800-COE-CALL - 330 N. Wabash Ave, Suite 2000 - Chicago, IL 60611 USA
    All material, files, logos and trademarks within this site are properties of their respective organizations.
    Terms of Service - Privacy Policy - Contact