1
Automation Interface, Add-Ins and Tools / Re: How to use ImportInternalDocumentArtifact()?
« on: May 28, 2025, 04:45:15 am »
I’d like to share my findings after experimenting with ImportInternalDocumentArtifact() for adding internal documents to Artifact elements. Initially, I thought the method was broken, but it turns out I had made a few mistakes — including falling into an undocumented trap.
These methods basically work as expected:
1. Stereotype blocks the file import
If the Artifact element has a Stereotype set, then ImportInternalDocumentArtifact() silently fails and returns false.
Workaround:
2. Artifact element name is overwritten
Calling ImportInternalDocumentArtifact() will automatically rename the element (element.Name) to match the imported file name. It can be also changed, reverted to the original name, if required.
3. Element.Files have nothing to do with internal documents
They only concern the external ones.
Hope this helps others avoid the same confusion.
Let me know if there are other obstacles or undocumented behaviors.
Thanks!
These methods basically work as expected:
- Element.ImportInternalDocumentArtifact(filePath) – imports the specified file as an internal document of the element
- Element.IsInternalDocArtifact – indicates whether this element is an internal document Artifact
- Element.ExportInternalDocumentArtifact(filePath) – exports the internal document to a file
1. Stereotype blocks the file import
If the Artifact element has a Stereotype set, then ImportInternalDocumentArtifact() silently fails and returns false.
Workaround:
Code: [Select]
var origStereotype = artifact.StereotypeEx;
artifact.StereotypeEx = "";
artifact.ImportInternalDocumentArtifact(filePath);
artifact.StereotypeEx = origStereotype;
artifact.Update();
2. Artifact element name is overwritten
Calling ImportInternalDocumentArtifact() will automatically rename the element (element.Name) to match the imported file name. It can be also changed, reverted to the original name, if required.
3. Element.Files have nothing to do with internal documents
They only concern the external ones.
Hope this helps others avoid the same confusion.
Let me know if there are other obstacles or undocumented behaviors.
Thanks!