Message 1 of 6
How to convert assembly to weldment?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello fellow programmer,
this is my fist time posting here. I currently develop a addin in c# for Inventor and at this time I try to create a weldment assembly. So I tried the following:
public void OrderOccurencesInWeldAssembly(List<Inventor.ComponentOccurrence> oocs)
{
// Getting the active doc as assembly document from a static management class
var MainAssembly = InventorApp.ActiveDocument.ToAssemblyDoc();
var MainDefinition = MainAssembly.instance.ComponentDefinition;
// searching the template
string weldtemplate = InventorApp.Application.FileManager.GetTemplateFile(Inventor.DocumentTypeEnum.kAssemblyDocumentObject);
string path = System.IO.Path.GetDirectoryName(weldtemplate);
string WeldmentFile = System.IO.Directory.GetFiles(path, "Weldment.iam").FirstOrDefault();
if (string.IsNullOrEmpty(WeldmentFile))
throw new FileNotFoundException("Standard Weldment.iam not found!");
var newSubAssembly = (Inventor.AssemblyDocument)InventorApp.Application.Documents.Add(Inventor.DocumentTypeEnum.kAssemblyDocumentObject, WeldmentFile, CreateVisible: false);
var newSubOccurrence = MainDefinition.Occurrences.AddByComponentDefinition((Inventor.ComponentDefinition)(newSubAssembly.ComponentDefinition), InventorApp.TransientGeometry.CreateMatrix());
var pane = MainAssembly.instance.BrowserPanes.ActivePane;
foreach (Inventor.ComponentOccurrence occurrence in oocs)
{
var newSubNode = pane.GetBrowserNodeFromObject(newSubOccurrence);
Inventor.BrowserNode targetNode = null;
for (int i = newSubNode.BrowserNodes.Count; i > 1; i--)
{
if (newSubNode.BrowserNodes[i].Visible)
{
targetNode = newSubNode.BrowserNodes[i];
break;
}
}
if (targetNode != null)
{
var SourceNode = pane.GetBrowserNodeFromObject(occurrence);
pane.Reorder(targetNode, false, SourceNode); // Unknown Error
}
}
}
But on the "Reorder" call their is an unknown error.
If I try the "same" with a normal assemlby it works.
Here is an example:
public void OrderOccurencesInAssembly(List<Inventor.ComponentOccurrence> oocs)
{
// Getting the active doc as assembly document from a static management class
var MainAssembly = InventorApp.ActiveDocument.ToAssemblyDoc();
var MainDefinition = MainAssembly.instance.ComponentDefinition;
var newSubAssembly = (Inventor.AssemblyDocument)InventorApp.Application.Documents.Add(Inventor.DocumentTypeEnum.kAssemblyDocumentObject, CreateVisible: false);
var newSubOccurrence = MainDefinition.Occurrences.AddByComponentDefinition((Inventor.ComponentDefinition)(newSubAssembly.ComponentDefinition), InventorApp.TransientGeometry.CreateMatrix());
var pane = MainAssembly.instance.BrowserPanes.ActivePane;
foreach (Inventor.ComponentOccurrence occurrence in oocs)
{
var newSubNode = pane.GetBrowserNodeFromObject(newSubOccurrence);
Inventor.BrowserNode targetNode = null;
for (int i = newSubNode.BrowserNodes.Count; i > 1; i--)
{
if (newSubNode.BrowserNodes[i].Visible)
{
targetNode = newSubNode.BrowserNodes[i];
break;
}
}
if (targetNode != null)
{
var SourceNode = pane.GetBrowserNodeFromObject(occurrence);
pane.Reorder(targetNode, false, SourceNode); // No Error
}
}
}
Can someone help me find a solution, either to create and add Occurences to a new Weldment or how to convert an existing assembly to a Weldment?