cancel
Showing results for 
Search instead for 
Did you mean: 

Question about EndModeling method on the ITxComponent

Siemens Pioneer Siemens Pioneer
Siemens Pioneer

Question:

 

From the API view I have a EndModeling method on the ITxComponent Interface but with a path parameter.
From where should I know the path of the component, when before opening into a modeling state it was in the library and I want have it back on the same place in the lib?

 

Answer:

 

You can use the following code to get the filePath:

 

TxObjectList children = TxApplication.ActiveSelection.GetItems();

 

if (children.Count > 0)

{

       ITxComponent obj = children[0] as ITxComponent;

       if (obj != null && !obj.IsOpenForModeling)

       {

              string value = string.Empty;

 

               ITxStorable storableObject = obj as ITxStorable;

               TxStorage storage = storableObject.StorageObject;

 

                if (storage is TxLibraryStorage)

                {

                      string filePath  = (storage as TxLibraryStorage).FullPath;

                      obj.SetModelingScope();

 

                      //do your changes

 

                      obj.EndModeling(filePath);

                  }                  

              }

}

 

5 REPLIES

Re: Question about EndModeling method on the ITxComponent

Siemens Phenom Siemens Phenom
Siemens Phenom

How could I do end-modelling on Teamcenter?

 

Re: Question about EndModeling method on the ITxComponent

Siemens Legend Siemens Legend
Siemens Legend

Currently there is no API available method for End Modeling on Teamcenter platform.

The ITxComponent.EndModeling method can be called only in Process Simulate on eMServer or Process Simulate Standalone.

Re: Question about EndModeling method on the ITxComponent

Experimenter
Experimenter

I have a problem with the EndModeling method however:

 

Sometimes, it is necessary to store the cojt at a different path than we have loaded it from. But, when I try to save the cojt, it always stores the component at the original location.

 

Here is the code I have so far:

 

public override void Execute(object cmdParams)
{
// get the selection
TxObjectList selection = TxApplication.ActiveSelection.GetItems();
if (selection.Count < 1) return;
ITxComponent component = selection.First() as ITxComponent;

if (component == null || !component.IsOpenForModeling) return;

// get the name of the component
string componentName = component.Name;

// init file dialog
SaveFileDialog sfd = new SaveFileDialog
{
FileName = componentName + ".cojt",
Filter = "Component files (*.cojt)|*.cojt|All files (*.*)|*.*",
InitialDirectory = TxApplication.SystemRootDirectoryNormalized + "LIB_ROOT"
};

// show file dialog
DialogResult dialogResult = sfd.ShowDialog();
if (dialogResult != DialogResult.OK) return;

// concat jt path and name
string cojtPath = sfd.FileName;
if (!Directory.Exists(cojtPath)) Directory.CreateDirectory(cojtPath);
string jtPath = cojtPath + "\\" + cojtPath.Split('\\').LastOrDefault()?.Replace(".cojt", string.Empty);

if (string.IsNullOrEmpty(jtPath)) return;
try
{
Debug.WriteLine(jtPath, "saving component " + componentName + " to");

// this should save the component to the new path
// but the component is saved at the original location
component.EndModeling(jtPath);
}
catch (TxComponentSaveAsFailedException ex)
{
Debug.WriteLine("Couldn't save modeling changes.");
Debug.WriteLine(ex.FailureComponent);
Debug.WriteLine(ex.Source);
Debug.WriteLine(ex.Message);
Debug.WriteLine(ex.StackTrace);
throw;
}
catch (Exception ex)
{
Debug.WriteLine(ex);
throw;
}
}

 

Everything works as expect, except for the wrong path. It even saves the component, but at the original location. The path parameter given to the EndModeling method would be something like:

 

C:\TESTENVIRONMENT\LIB_ROOT\TESTKOMPONENTEN\testcomp_123.cojt\testcomp_123

 

Some additional information:

  • We are using Process Simulate 13.0 Hotfix 18
  • We try to save a component that is either loaded in a study or its prototype is dragged from the library into the cell.
  • The component is set to modeling scope by the usual Process Simulate command (not via API)
  • Only one component is set to modeling scope

 

I'd be very grateful if someone could help me out here. Thanks.

 

Re: Question about EndModeling method on the ITxComponent

Valued Contributor
Valued Contributor

Hi Zefrank,

 

you can copy the component to local storage using the function CopyToLocal in TxLibraryStorage class and than save JT using SaveToLibrary function:

'create temporary folder

Dim workPath As String = IO.Path.Combine(TxApplication.SystemRootDirectory, "Temp")

If Not IO.Directory.Exists(workPath) Then

IO.Directory.CreateDirectory(workPath)

End If

'save the object in the temporary folder

Dim libraryData As TxLibraryData = New TxLibraryData(workPath, cojtFileName)

Dim localStorage As TxLocalStorage = Nothing

If TypeOf obj.StorageObject Is TxLibraryStorage Then

localStorage = DirectCast(obj.StorageObject, TxLibraryStorage).CopyToLocal()

Else

localStorage = DirectCast(obj.StorageObject, TxLocalStorage)

End If

 

localStorage.SaveToLibrary(libraryData)

 

Re: Question about EndModeling method on the ITxComponent

Siemens Legend Siemens Legend
Siemens Legend

Hi zafank,

 

A-S-E gave you a good example. EndModeling updates the existing cojt and does not make a copy of it. In order to make a copy, you need to use the SaveToLibrary method of TxLocalStorage class. You can use the SaveComponent method to save the modeling changes localy only as a jt file.

 

Here is the example in C#:

            ITxStorable selectedComponent = TxApplication.ActiveSelection.GetItems()[0] as ITxStorable;

            TxLibraryData libraryData = new TxLibraryData(path, "test.cojt");

            TxLocalStorage storage;
            if (selectedComponent.StorageObject is TxLibraryStorage)
            {
                storage = (selectedComponent.StorageObject as TxLibraryStorage).CopyToLocal();
            }
            else
            {
                storage = selectedComponent.StorageObject as TxLocalStorage;
            }

            storage.SaveToLibrary(libraryData);

 

 

Best Regards,

DianaG