Cancel
Showing results for 
Search instead for 
Did you mean: 

How to get where TxPlanningObjects are stored?

Valued Contributor
Valued Contributor

I'm trying to find a way to the path to where the TxPlanningObjects are stored.  For Engineering objects, I was able to use the TxLibraryStorage class to achieve this.  But it doesn't work for Planning objects as there is no

'StorageObject' method.

 

I tried to go through the fields for the object, but the only one that seems to be relevant is the field

"threeDRep".  However this field just returns a TxPlanningObject, so I am right back where I started.

 

14 REPLIES 14

Re: How to get where TxPlanningObjects are stored?

Genius
Genius

Hi, TGSimulation!

 

The easiest way to achieve this task is to use the eM-Planner API. The IEmpThreeDRep interface has FileName property:

Dim empContext As New EMPTYPELIBRARYLib.EmpContext With {.sessionId = TxApplication.ActiveDocument.eMSSessionId}
        Dim threeDrepWorker As New EmpThreeDRep
        Dim path As String = threeDrepWorker.FullPath(
            empContext,
            New EmpObjectKey() With
                {
                    .objectId = DirectCast(threedRep.PlatformServicesProvider, ITxEmsServicesProvider).InternalId
                })

 

Re: How to get where TxPlanningObjects are stored?

Valued Contributor
Valued Contributor

Thank you for your reply. 

 

Where are you finding EmpThreeDRep class?  I do not see that anywhere.  Is that available in 13.1  (which is what I am using) I wonder?

Re: How to get where TxPlanningObjects are stored?

Valued Contributor
Valued Contributor

Okay, I did find the EmpThreeDRepClass in the EMPMODELLib.dll in C:\Program Files\Tecnomatix_13.1\eMPower.

 

The EMPTYPELIBRARYLib.dll is in that directory, too, but also in the C:\Program Files\Tecnomatix_13.1\eMPower\DotNetCommands, which is where I was looking, because that is where I am putting custom commands.

 

Re: How to get where TxPlanningObjects are stored?

Genius
Genius

TGSimulation,

 

sorry for a delay. I would use the EMPTYPELIBRARYLib from eMPower and not from DotNetCommands. By adding the reference to this library set Embed Interop Types to False.

Re: How to get where TxPlanningObjects are stored?

Siemens Phenom Siemens Phenom
Siemens Phenom

Hi TGSimulation,

 

If you go through the fields, you need to go through "threeDRep" -> "file" -> "fileName"

You can get that using the TxEmsTraversalManager & TxEmsCacheManager.

 

Best Regards,

DianaG

Re: How to get where TxPlanningObjects are stored?

Valued Contributor
Valued Contributor

DianaG, an you please expand on this?  I tried:

 

cManager.CacheData();  --> I'm guessing that this caches objects that are loaded in this sim?  But since the sim is empty it does nothing.

 

I'm assuming the TxEmsTraversalManager is then supposed to get the information from the cache?

 

 

Re: How to get where TxPlanningObjects are stored?

Valued Contributor
Valued Contributor

I tired both techniques suggested, but I am stuck.  I think for TRY1 I am having permission issues, which is why I am getting exception. 

 

For TRY2, i am not sure the cacheManager.CacheData(); method is working or I am not entering a good index for

cacheManager[?]; because this seems like it is not returning anything.

 

Any advice would be appreciated.

public override void Execute(object cmdParams)
        {
            selection = TxApplication.ActiveSelection;           

            //objList = selection.GetItems();  // gets all loaded objects
            objList = selection.GetAllItems();  // gets all objects selected (loaded and unloaded)

            foreach (ITxObject obj in objList)
            {
                switch (obj.GetType().ToString())
                {
                    // Other cases //
                    case TX_PLANNING.PLANNING_TOOL_PROTOTYPE: //"Tecnomatix.Planning.TxPlanningObject"
                        
                        /////////////////////////////////////// TRY1 /////////////////////////////////////////////

                        EmpContext empContext = new EmpContext();  // in EMPTYPELIBRARYLib.dll
                        empContext.sessionId = TxApplication.ActiveDocument.eMSSessionId;

                        EmpObjectKey key = new EmpObjectKey(); // in EMPTYPELIBRARYLib.dll
                        key.objectId = ((ITxEmsServicesProvider)((TxPlanningObject)obj).PlatformServicesProvider).InternalId;

                        EmpThreeDRep threeDRep = new EmpThreeDRep();  // in EMPMODELLib.dll
                        
                        try
                        {
                            //string path = threeDRep.get_FullPath(ref empContext, ref key);  // Throws System.Runtime.InteropServices.COMException.  Permission issue???
                        }
                        catch (Exception e)
                        {
                            MessageBox.Show(e.GetType().ToString());
                            //MessageBox.Show(e.HResult.ToString());
                        }
                        //Process.Start((@path));
                           
                        /////////////////////////////////////// TRY2 /////////////////////////////////////////////

                        OutputForm tempForm = new OutputForm();
                        tempForm.Show();
                                                
                        TxEmsCacheManager cacheManager = new TxEmsCacheManager();
                        cacheManager.CacheData();  // Not sure if this actually works???

                        // Not sure what to put for item index cacheManager[?] //
                        //TxEmsTraversalData tData = cacheManager[obj.Name];  // Throws error
                        TxEmsTraversalData tData = cacheManager[((ITxPlanningObject)obj).ProcessModelId.ExternalId];
                        //TxEmsTraversalData tData = cacheManager[key.objectId];  
                        /////////////////////////////////////////////////////////
                        
                        string[] pathList = tData.PathsList;
                        string[] attrList = tData.AttributesList;
                        TxObjectList objList = tData.RootObjects;

                        tempForm.ListBox_Add(pathList.Length.ToString());   // returns 0 for both cases above
                        tempForm.ListBox_Add(attrList.Length.ToString());   // returns 0 for both cases above
                        tempForm.ListBox_Add(objList.Count.ToString());     // returns 0 for both cases above

                        break;
                }
            }
        }

 

Re: How to get where TxPlanningObjects are stored?

Genius
Genius

Hi!

 

You have retrieve the key of ThreeDRep before you try to get the path:

 ''' <summary>
    ''' Gets the path of ThreeDRep of the tool prototype.
    ''' </summary>
    ''' <remarks>
    ''' Required references:
    ''' EMPCORElib
    ''' EMPMODELLib
    ''' EMPTYPELIBRARYLib
    ''' 
    ''' In the Compile of the project must be set right target: x64 for x64 PS installation.
    ''' </remarks>
    ''' <param name="prototype">The <see cref="ITxPlanningObject"/> that represents the tool prototype.</param>
    ''' <returns>The full path of the three dimentional representation of the tool prototype.</returns>
    Private Function GetThreeDrepPath(prototype As ITxPlanningObject) As String
        'Use current eMServer session:
        Dim context As New EmpContext() With {.sessionId = TxApplication.ActiveDocument.eMSSessionId}

        'Get the key of the tool prototype:
        Dim prototypeKey As New EmpObjectKey() With {.objectId = DirectCast(prototype.PlatformServicesProvider, ITxEmsServicesProvider).InternalId}

        'Obtain and verify the key of ThreeDRep
        Dim empToolPrototype As New EmpToolPrototype
        If Not empToolPrototype.IsKindOf(context, prototypeKey, "ToolPrototype") Then Throw New ArgumentException("Specified object is not a tool prototype.", NameOf(prototype))
        Dim threedRepKey As EmpObjectKey = empToolPrototype.GetThreeDRep(context, prototypeKey)
        If threedRepKey.objectId = 0 Then Throw New InvalidOperationException("No ThreeDRep found.")

        'Get the path of ThreeDRep
        Dim empThreeDRep As New EmpThreeDRep

        'The first approach is to get the FullPath property. But in many cases I get here double backslashes after the SysRoot path:
        'Return empThreeDRep.FullPath(context, threedRepKey)

        'Therefore build it self:
        Dim relativePath As String = empThreeDRep.Filename(context, threedRepKey)

        'I have not seen any ThreeDRep, that was not placed under SysRoot, but I have seen the attachments, that are registered with absolute path.
        'To be sure, that we get really right path check if the path starts with the SysRoot placeholder:
        If relativePath.StartsWith("#\") Then
            Return IO.Path.Combine(TxApplication.SystemRootDirectory, relativePath.Substring(2))
        Else
            Return relativePath
        End If
    End Function

Re: How to get where TxPlanningObjects are stored?

Valued Contributor
Valued Contributor

So there are 2 keys?  I did not get that from the orignal code -> the prototypeKey is used to get the threeDRepKey. 

 

My translation of this from VB to C# works, so I will mark this as solution.  Thanks!