Getting error for ImportedComponents.CreateDataExchangeDefinition

Getting error for ImportedComponents.CreateDataExchangeDefinition

sneha.sadaphal
Advocate Advocate
530 Views
5 Replies
Message 1 of 6

Getting error for ImportedComponents.CreateDataExchangeDefinition

sneha.sadaphal
Advocate
Advocate

Hi 

I am trying to import the online data in part environment in inventor 2024

but getting the error for 

ImportedComponentDefinition oImportCompDef = oPartCompDef.ReferenceComponents.ImportedComponents.CreateDataExchangeDefinition(exchangeFileUrn, options);

 this api 

Please help me out this if I am doing anything wrong.


here is the code for this issue

 

image (1).png

PartDocument pDoc = _document as PartDocument;
PartComponentDefinition oPartCompDef = pDoc.ComponentDefinition;
if (pDoc != null)
{
//Add new Occurance
var options = InventorApp.TransientObjects.CreateNameValueMap();
if (exchangeItem != null)
{
options.Add("Exchange", exchangeItem.FileURN);
}

ImportedComponentDefinition oImportCompDef = oPartCompDef.ReferenceComponents.ImportedComponents.CreateDataExchangeDefinition(exchangeFileUrn, options);
oPartCompDef.ReferenceComponents.ImportedComponents.Add(oImportCompDef);
}
txn.End();
}

 

0 Likes
531 Views
5 Replies
Replies (5)
Message 2 of 6

jadranko
Contributor
Contributor

Hello @sneha.sadaphal ,

 

CreateDataExchangeDefinition ignores the second argument.

You can omit creating the options object and passing it as an argument and replace your lines 1-14 with the following code:

PartDocument pDoc = _document as PartDocument;
PartComponentDefinition oPartCompDef = pDoc.ComponentDefinition;
if (pDoc != null)
{
    ImportedComponentDefinition oImportCompDef = oPartCompDef.ReferenceComponents.ImportedComponents.CreateDataExchangeDefinition(exchangeFileUrn);
    oPartCompDef.ReferenceComponents.ImportedComponents.Add(oImportCompDef);
}

 

Best regards,

Jadranko

0 Likes
Message 3 of 6

sneha.sadaphal
Advocate
Advocate

Hi @jadranko I have tried the same as you suggested but getting same error as earlier. 

0 Likes
Message 4 of 6

jadranko
Contributor
Contributor

Hello @sneha.sadaphal 

 

Please check two more things...

 

First, check that exchangeFileUrn actually is an urn of a Data Exchange container in Docs.

It should be a string looking something like this:

"urn:adsk.wipprod:dm.lineage:wfjaO3PZSwC2gWg2A1AvbQ"

Update: I've just seen in the article that it has to be prefixed like this:

"https://developer.api.autodesk.com/exchange/v1/exchanges?filters=attribute.exchangeFileUrn==urn:adsk.wipprod:dm.lineage:wfjaO3PZSwC2gWg2A1AvbQ"

 

Secondly, have you tried running it in an Assembly document instead of the Part document?

Here is an article describing how to do it:

Mod the machine: Import Data Exchange Model

 

Best regards,

Jadranko

0 Likes
Message 5 of 6

sneha.sadaphal
Advocate
Advocate

Hi @jadranko 
For first check, the exchange urn I am getting below as string
https://developer.api.autodesk.com/exchange/v1/exchanges?filters=attribute.exchangeFileUrn==urn:adsk...

 

For second check, yes, it is working as expected in assembly environment. 

0 Likes
Message 6 of 6

jadranko
Contributor
Contributor

Hi @sneha.sadaphal and @Yogesh_Shinde ,

 

I might be wrong, but it seems that it is not possible to reference Data Exchange from a part document.

It is mentioned in several places that Data Exchange could be used to bring the Data Exchange reference into assembly, although I could not find any specific statement that it cannot be used within a part.

 

By using latest beta of Data Exchange Connector for Inventor 2023 (not the built-in one), I managed to reference Data Exchange from a part document, but it seems that it actually created a STEP model on the fly and imported it instead.

 

If that is the case it probably should be mentioned in the API documentation.

More descriptive exception would be helpful as well. 

 

 

Best regards,

Jadranko

0 Likes