02-18-2021
10:15 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
02-18-2021
10:15 AM
How to update document assets from library?
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
02-19-2021
12:29 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
02-19-2021
12:29 AM
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
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
02-19-2021
01:04 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
02-19-2021
01:04 AM
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.
03-29-2024
12:52 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report