Cancel
Showing results for 
Search instead for 
Did you mean: 

Create Teamcenter Datasets and import Files

Creator
Creator

Hello,

ist there any chance to create a Teamcenter dataset with relation to a item revision and import a file as named reference to it with NXOpen.

 

NXOpen.PDM.FileManagement.ImportFiles() looks right, but is limited to existing datasets.

 

Any ideas how to this with NXOpen in the current NX session?

 

Thanks in advance.

 

15 REPLIES

Re: Create Teamcenter Datasets and import Files

Experimenter
Experimenter

I found a way to do this within our Teamcenter installation. In our installation there is a pdm server call that creates a dataset. I invoked this call in NX Open, then I followed it up with the method to import the file as a named reference under the new dataset.

 

This method is dependent on the availability of the pdm server call, or one that is similar in your installation. You would need to figure that out, but this approach worked for me:

 

 

        Dim fileNumber = "1234"
        Dim fileRevision = "A"

        Dim szDatasetName = fileNumber & "_" & fileRevision & "_MyDataSet"
        Dim datasetTypeName = "MyDataSetType"
        Dim datasetRelationTypeName = "Foreign"
        Dim datasetRelation = "MyPsuedoFolderRel"
        Dim datasetRefType = "MyNamedReferenceType"
        Dim datasetFileType = "TEXT"

        Dim importDir = "D:\Users\ImportDir"

        Dim szCreateDatasetInput As String
        szCreateDatasetInput = fileNumber & "/" & fileRevision & "/" & datasetTypeName & "/" & szDatasetName & "/" & datasetRelation & "/" & datasetRefType & "/" & datasetFileType
        Dim iOutputCode As Integer = 0
        Dim szOutputString As String = Nothing
        Dim success = True
        Try
            theUfSession.Ugmgr.InvokePdmServer(210, szCreateDatasetInput, iOutputCode, szOutputString)
            If iOutputCode <> 0 Then
                MsgBox("Failed to create dataset in Teamcenter" & vbNewLine & iOutputCode & ":  " & szOutputString, MsgBoxStyle.Information, "Teamcenter push failed")
                success = False
            End If
        Catch ex As Exception
            MsgBox("Failed to create dataset in Teamcenter" & vbNewLine & ex.ToString, MsgBoxStyle.Information, "Teamcenter push failed")
            success = False
        End Try

        If success Then
            Try
                Dim pdmSession = theSession.PdmSession()
                Dim fileMgt = pdmSession.NewFileManagement()
                fileMgt.ImportFiles({fileNumber}, {fileRevision}, {szDatasetName}, {datasetTypeName}, {datasetRelationTypeName}, {importDir})
            Catch ex As Exception
                Console.WriteLine(ex)
                MsgBox("Failed to import to Teamcenter" & vbNewLine & ex.ToString, MsgBoxStyle.Information, "Teamcenter push failed")
            End Try
        End If

Re: Create Teamcenter Datasets and import Files

Experimenter
Experimenter

Hi,

how did you find out the input_code (210) to InvokePdmServer?

 

Will be grateful for any response.


@Nathaniel wrote:

theUfSession.Ugmgr.InvokePdmServer(210, szCreateDatasetInput, iOutputCode, szOutputString)

Re: Create Teamcenter Datasets and import Files

Experimenter
Experimenter

Hi,

With your method, I am able to Import files from my local computer to Teamcenter successfully. Thank you very much.

But I am struggling to export the dataset from Teamcenter to local Computer.

'The below line of code is for importing the file from local computer to Teamcenter dataset and it works perfect. Please do not get confused with the datasetnames and type name, because this is how our Teamcenter has been implemented in my organization.

pdmfilemgmt.ImportFiles({"AX465914"}, {"001"}, {"AX465914-001-dwg1"}, {"UGPART"}, {"has specification"}, {"D:\Export"})


The below line of code is for exporting the dataset from Teamcenter to local computer and it is not working. There is also no error while running the code.

Dim exportResults(0) As Integer
Dim exportDirectoryNames(0) As String

exportResults = pdmfilemgmt.ExportFiles({"D1465914"}, {"001"}, {"D1465914-001-dwg2"}, {"UGPART"}, {"has specification"}, {"testing"}, {"UGII V10-BASE"}, exportDirectoryNames)

listingwindow.WriteFullline(exportResults(0))  ' It returns zero always for me

Could you please help me on this?

Thanks & Regards,
Palani

Re: Create Teamcenter Datasets and import Files

Creator
Creator

Hi Palanisamy,

please take a look at the Siemens Example, perhaps it helps.

 

https://solutions.industrysoftware.automation.siemens.com/view.php?sort=desc&q=ExportFiles&dt=nx-api...

 

GTAC Document ID: nx_api4503

 

Here is a hint out of the example:

 

NOTE:  The methods used in this example export/import the dataset's "associated files" which is a subset of its "named reference files".  This does not include the main dataset file (.prt, .jt, etc) itself.  The files that are processed are the same set of files that would automatically be exported to a native folder when the part is opened in NX with the export associated files preference turned on:
 
File-> Utitilies-> Customer Defaults
   Teamcenter Integration for NX-> General
       Export Associated Files

The subset of files that are exported/imported are controlled by Roles.  Each role has a set of file extensions (types) that are exported from the database when the role is specified.  Please see the documentation for additional information:
  Teamcenter Integration for NX > Introduction to Teamcenter Integration for NX > Teamcenter Integration Roles 

I'm not sure about the copyright, so I just link the example.

Re: Create Teamcenter Datasets and import Files

Experimenter
Experimenter

Hi,

 

Thanks for your reply.

 

Actually, based on the example on the link which you have provided only, I was trying to export. I already know this example (someone has put this example on the internet somewhere and I referred to it).

 

My ultimate goal is to download all the datasets associated to the Item revision (especially PDF Drawing Dataset, .prt file and text file if they exist) to local computer. Please note that, I do not want to generate the PDF drawing file using some other methods in NXOPEN, because it will take more time to freshly create PDF files every time. Instead, i want to download already existing PDF dataset in Teamcenter.

 

So, I have tried with the example on the link which you have provided. It is a very nice example and pretty straight forward. But, unfortunatley this code works for Import even for .prt file data set.

 

But this code doesn't work for export option.

 

Now I want to know

 

 

what is wrong in my code?

Is there any special settings that I have to do in NX or teamcenter applications?

 

(Or)

 

Is it never all possible to download the .prt, pdf and text datasets? If so, what is the best way to achieve downloading named references of the data sets?

 

If you like, I can send you my full code in the next post.

 

 

Thanks & Regards,

Palani

 

 

 

Re: Create Teamcenter Datasets and import Files

Creator
Creator

Hi Palanisamy,

I've tried to export a PDF Dataset from our Database, but it also didn't worked. This function semms to be limited or needs some special input parameters.

 

Perhaps anyone else have an idea or just contact Siemens via GTAC, they are usually very helpful.

Re: Create Teamcenter Datasets and import Files

Valued Contributor
Valued Contributor

Hi All,

I was looking for ways to import file & create dataset in Teamcenter from NX Manager. And then I found this in NXOpen programming tools document.

 

int [] NXOpen.PDM.FileManagement.ImportFilesAndCreateDatasets ( string[] itemIds,
string[] itemRevisionIds,
string[] datasetNames,
string[] datasetTypeNames,
string[] datasetRelationTypeNames,
string[] datasetToolNames,
bool[] fileType,
string[] namedReferenceNames,
string[] importFileNames,
string[] importFileDirectoryNames
)

 

Should work in versions, starting from NX11.0.1. I tried this in NX 12 and it worked perfect.

Hope this is useful for many people!

Thanks,
Anbu

Teamcenter Architect & PLM/CAD Administrator,
Teamcenter 11.4 | Active Workspace 3.4 | NX 12

Re: Create Teamcenter Datasets and import Files

Valued Contributor
Valued Contributor

Hello Anbu,

 

I tried using this API but am getting an error. The details are mentioned below. Any idea what could be the problem here.

 

static void CreateDataset(string ItemID, string revesion, string outputPath, string inputFileName )
{
FileManagement fileManagement = Session.GetSession().PdmSession.NewFileManagement();

string[] itemIds = new string[1];
string[] itemRevisionIds = new string[1];
string[] datasetNames = new string[1];
string[] datasetTypeNames = new string[1];
string[] datasetRelationTypeNames = new string[1];
string[] datasetToolNames = new string[1];
bool[] fileType = new bool[1];
string[] namedReferenceNames = new string[1];
string[] importFileNames = new string[1];
string[] importFileDirectoryNames = new string[1];


itemIds[0] = ItemID;
itemRevisionIds[0] = revesion;

datasetNames[0] = ItemID + "_" + revesion + "_" + "3D";

datasetToolNames[0] = "PDF_Tool";

datasetTypeNames[0] = "PDF";

datasetRelationTypeNames[0] = "IMAN_manifestation";

fileType[0] = true; // binary

namedReferenceNames[0] = "PDF_Reference";

importFileNames[0] = inputFileName;

importFileDirectoryNames[0] = outputPath;

int[] importResults = fileManagement.ImportFilesAndCreateDatasets(itemIds, itemRevisionIds, datasetNames, datasetTypeNames, datasetRelationTypeNames, datasetToolNames, fileType,
namedReferenceNames, importFileNames, importFileDirectoryNames);

foreach (int i in importResults)
{
if (i == 0)
{
Console.WriteLine("Successfully imported dataset");
}

else
{
Console.WriteLine("Import failed");
}
}
}datasetError.JPG

I have create an executable an am executing it with the required input parameters in the TC command promt.

Any idea or suggestion what could be the problem here?

Re: Create Teamcenter Datasets and import Files

Experimenter
Experimenter

I asked my organization's Teamcenter administrators for a list of available PDM server calls and found this in the list.