How to update document assets from library?

How to update document assets from library?

C-Hoppen
Advocate Advocate
673 Views
4 Replies
Message 1 of 5

How to update document assets from library?

C-Hoppen
Advocate
Advocate

Hello,

this always crashes

 

 

Inventor.PartDocument partDocument = (Inventor.PartDocument)refDocument;
List<Inventor.Asset> updateList = new List<Inventor.Asset>();
foreach (Inventor.MaterialAsset materialAsset in partDocument.MaterialAssets)
{
	try
	{
		updateList.Add(oApp.ActiveMaterialLibrary.MaterialAssets[materialAsset.DisplayName]);
	}
	catch { }
}

foreach (Inventor.Asset asset in updateList)
	try
	{
		asset.CopyTo(partDocument, ReplaceExisting: true); // <---- THROWS AN EXCEPTION
	}
	catch { }

 

 

 What could be the reason for this problem?

Thanks,

Chris

0 Likes
674 Views
4 Replies
Replies (4)
Message 2 of 5

C-Hoppen
Advocate
Advocate

I tried to do it with VBA but same problem.

I noticed that there is a difference in the signature of CopyTo between VBA and the API doc.

 

API

ReplaceExisting: Optional input Boolean that specifies whether replace the existing asset if an asset of the same name exists.

 

VBA

CopyTo.jpg

So I tried this

Dim docMaterial As MaterialAsset
Set docMaterial = ThisDocument.ActiveMaterial

Dim libMaterial As MaterialAsset
Set libMaterial = ThisApplication.ActiveMaterialLibrary.MaterialAssets.Item(docMaterial.DisplayName)

Set docMaterial = libMaterial.CopyTo(ThisDocument.MaterialAssets, docMaterial)

 

and this

Dim docMaterial As asset // <-- why does this always turn to lower case?
Set docMaterial = ThisDocument.ActiveMaterial

Dim libMaterial As asset
Set libMaterial = ThisApplication.ActiveMaterialLibrary.MaterialAssets.Item(docMaterial.DisplayName)

Set docMaterial = libMaterial.CopyTo(ThisDocument.Assets, docMaterial)


and this (as desribed in the API docs)

Set docMaterial = libMaterial.CopyTo(ThisDocument.Assets, True)


and it always chrashes at CopyTo.

 

How can I update a existing MaterialAsset from a library?

 

Thanks,

Christoph

0 Likes
Message 3 of 5

C-Hoppen
Advocate
Advocate

Added:

This question also relates to AppearanceAsset. Same Problem!

I can update the one active material by

 

 

ThisDocument.ComponentDefinition.Material.UpdateFromGlobal

 

 

but this doesn't update the materials appearance.

0 Likes
Message 4 of 5

c_hoppen
Advocate
Advocate

Is there no solution? I need to update Material and Appearance Assets?

Regards

Christoph

0 Likes
Message 5 of 5

mfoster9TD82
Advocate
Advocate

I'm running into this issue also. Did you ever find a solution?

0 Likes