How to convert assembly to weldment?

How to convert assembly to weldment?

mj7VABJ
Explorer Explorer
584 Views
5 Replies
Message 1 of 6

How to convert assembly to weldment?

mj7VABJ
Explorer
Explorer

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?

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

mj7VABJ
Explorer
Explorer

Okay I figured out that changing the subtype of the document to "{28EC8354-9024-440F-A8A2-0E0E55D635B0}" will change it to a weldmentassembly.

But if I change it before I add the Occurrences I still become an error, if I change the Subtype after the Occurrences are added it works.

0 Likes
Message 3 of 6

WCrihfield
Mentor
Mentor

Hi @mj7VABJ.  When you create a weldment type assembly, one of the first things that gets set is the AssemblyComponentDefinition.BOMStructure Property gets set to BOMStructureEnum.kInseparableBOMStructure.  I assume that this setting is one of the reasons why reordering things gets denied after that point.  If you need to do things in a specific order of operations, and the 'Reorder' method is not working when done in that order, you could try changing that BOMStructure to 'kNormalBOMStructure' temporarily while you use the 'Reorder' method, then change it back.  Just an untested theory.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 4 of 6

mj7VABJ
Explorer
Explorer

Thank you I will give it a try.

 

Perhaps you or someone else can also help me with another thing. Is there a way to create weldments preperations and weldbeads through the API, I cannot find methods in the reference guide.

0 Likes
Message 5 of 6

WCrihfield
Mentor
Mentor

Hi @mj7VABJ.  I have never tried adding welds to a weldment using Inventor's API yet, so but I am also not sure if it is possible yet.  However, I do believe it is possible to add Preparations and/or Machining features to a weldment type assembly though Inventor's API.  I know how to access all of that stuff, but I honestly do not have much personal experience creating them by code yet, because I haven't needed to.  The first step is to create a WeldmentComponentDefinition Type variable, then set its value from the AssemblyDocument.ComponentDefinition (but only if that assembly is already a weldment type).  Then that more specific type of ComponentDefinition has more Properties specific to weldments.  One for Machining, one for Preparations, and several related to welds themselves.  The Property named Welds is similar to the other two I mentioned, and is a gateway for entering into that specific type of 'Edit Mode' of the assembly, and any existing Weldbeads.  While the WeldsComponentDefinition is where I believe we would eventually be able to create new weld beads through, if that capability were available.  Right now, it is a bit of a mystery.  I know that it sort of represents the main Node in the Browser Tree that you would normally have to expand to get to the weld beads, but I haven't found much use for it yet.  When you are looping through the 'ComponentOccurrences' of the main Weldment assembly, one of the components 'Definition' usually returns this WeldsComponentDefinition, and you often need to filter it out, to avoid the potential errors, because it is not a 'normal' component.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 6 of 6

mj7VABJ
Explorer
Explorer

Oh wow it seems you have a deep knowledge of the API, I only started a month ago and I think I have barely scratched the surface.

 

I managed to get a WeldmentComponentDefinition object/class but for me it looks like I can only read information from the weldments. I think I need to tinker a bit with the StartEdit() function and what I can do with it. The API so far has been very clear and well documented, but everything with weldments is a bit of a mystery to me.

 

Thank you for your help and for pointing me in the right direction.

0 Likes