- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi all and thanks in advance for any help given.
The problem that I am looking to solve is I'm sure quite simple. When creating a new assembly from a template file named "Hopper Fabrication.iam" I want to trigger the creation and placement of a new part from a template called "Master Hopper.ipt" and put it inside the new assembly.
So far I have the following
Dim oTemplate As String = "C:\Users\Public\Documents\Templates\Master Hopper.ipt" Dim oDoc As AssemblyDocument = ThisApplication.ActiveDocument Dim oDocumentDefinition As AssemblyComponentDefinition = oDoc.ComponentDefinition Dim oTG As TransientGeometry = ThisApplication.TransientGeometry Dim oMatrix As Matrix = oTG.CreateMatrix oDocumentDefinition.Occurrences.Add(oTemplate,oMatrix)
This is placing the actual template in rather than creating a new part based on the template rather than creating a new in-place compoent based on the named template
Can anyone help me out please.
Mike
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi,
Use code something like this creating a part using the defined template.
Set oPartDoc = ThisApplication.Documents.Add(kPartDocumentObject, oTemplate)
Hope this helps.
Best regards,
sam
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
in your case while using vb.net/ilogic, this could work.
Dim oPartDoc as PartDocument = ThisApplication.Documents.Add(kPartDocumentObject, oTemplate)
regards,
sam
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi @mikejones
The place new component command creates the new document invisible in Inventor and then places it into the assembly. It creates a document only in inventor memory, so no filepath exists meaning occurrences.add will not work.
You'll have to add by component definition. like this ![]()
Dim oTemplate As String = "C:\Users\Public\Documents\Templates\Master Hopper.ipt" Dim oDoc As AssemblyDocument = ThisApplication.ActiveDocument Dim oDocumentDefinition As AssemblyComponentDefinition = oDoc.ComponentDefinition Dim oTG As TransientGeometry = ThisApplication.TransientGeometry Dim oMatrix As Matrix = oTG.CreateMatrix Dim pDoc As PartDocument = ThisApplication.Documents.Add(DocumentTypeEnum.kPartDocumentObject, oTemplate, False) oDocumentDefinition.Occurrences.AddByComponentDefinition(pDoc.ComponentDefinition, oMatrix)
Jhoel Forshav
Download my free Inventor Addin - Hole Projector
LinkedIn | Ideas | Contributions | Blog posts | Website
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Thanks for the reply @JhoelForshav
I tried the code you suggested but it stops with the following error
Error in rule: New Hopper, in document: Hopper Fabrication.iam
The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))
And this from the More Info tab
System.ArgumentException: The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))
at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
at Inventor.Documents.Add(DocumentTypeEnum DocumentType, String TemplateFileName, Boolean CreateVisible)
at ThisRule.Main()
at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
at iLogic.RuleEvalContainer.ExecRuleEval(String execRule)
Any ideas?
Mike
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Actually @JhoelForshav you're code works fine, there was a typo in the file name that I put in for the template so thank you very much for your help on this.
Mike
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi @JhoelForshav. The code you gave me works great but I am having a problem in getting the new part file to save for the first time. Is there anything that can be added in the code to make sure that both the iam and ipt files will save together ?
Mike
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi @mikejones
The document will save with the assembly as long as it has a filename. Since you haven't specified a filename for it yet, Inventor wouldn't know where to save it. You can just add a filepath to the document:
Dim oTemplate As String = "C:\Users\Public\Documents\Templates\Master Hopper.ipt" Dim oDoc As AssemblyDocument = ThisApplication.ActiveDocument Dim oDocumentDefinition As AssemblyComponentDefinition = oDoc.ComponentDefinition Dim oTG As TransientGeometry = ThisApplication.TransientGeometry Dim oMatrix As Matrix = oTG.CreateMatrix Dim pDoc As PartDocument = ThisApplication.Documents.Add(DocumentTypeEnum.kPartDocumentObject, oTemplate, False) pDoc.FullFileName = ThisDoc.Path & "\some name.ipt" 'Add a filepath oDocumentDefinition.Occurrences.AddByComponentDefinition(pDoc.ComponentDefinition, oMatrix) oDoc.Save
Of course, the assembly has to have a filepath aswell for the save command to work. But I'm assuming in this case it has already been saved at some time ![]()
If you want to use SaveAs on the assembly that would work too anyways, but then you cannot use ThisDoc.Path before as in the example above, becase if the assembly hasn't been saved ThisDoc.Path is nothing.
Jhoel Forshav
Download my free Inventor Addin - Hole Projector
LinkedIn | Ideas | Contributions | Blog posts | Website
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I would have a similar question, I have to make sure that when I create a new assembly it also creates a part called Skel, preferably which will then be saved in the same destination as the assembly.