Hey, im brand new to inventor and i was given this code to use in my assembly. How to execute it? I never did this before.
Any help will be appreciated with a smile 🙂
I am using inventor 2010 / routing
thanks!
Sub CreateDerivedPartFromAssembly() 'Set a reference to the current assembly document. Dim AsmDoc As AssemblyDocument Set AsmDoc = ThisApplication.ActiveDocument 'Create the name of the new part Dim PartFileName As String PartFileName = Left(AsmDoc.FullDocumentName, Len(AsmDoc.FullDocumentName) - 4) & ".ipt" 'Make a new part file Dim oPartDoc As PartDocument Set oPartDoc = ThisApplication.Documents.Add(kPartDocumentObject, ThisApplication.FileManager.GetTemplateFile(kPartDocumentObject)) 'Create a derived part feature Dim oDerivedAsmDef As DerivedAssemblyDefinition Set oDerivedAsmDef = oPartDoc.ComponentDefinition.ReferenceComponents.DerivedAssemblyComponents.CreateDefinition(AsmDoc.FullDocumentName) Call oPartDoc.ComponentDefinition.ReferenceComponents.DerivedAssemblyComponents.Add(oDerivedAsmDef) 'Break the link to the assembly oPartDoc.ComponentDefinition.ReferenceComponents.DerivedAssemblyComponents.Item(1).BreakLinkToFile 'Copy the iProperties from the assembly to the part Dim Text As String oPartDoc.PropertySets.Item("Design Tracking Properties").Item("Description").value = _ AsmDoc.PropertySets.Item("Design Tracking Properties").Item("Description").value oPartDoc.PropertySets.Item("Summary Information").Item("Comments").value = _ AsmDoc.PropertySets.Item("Summary Information").Item("Comments").value 'Save the part On Error GoTo ErrorHandler: oPartDoc.SaveAs PartFileName, False On Error GoTo 0 AsmDoc.Close oPartDoc.Activate Exit Sub ErrorHandler: MsgBox ("A file with the same name already exists." & Chr(13) & "You may want to delete the existing file and re-do this process.") oPartDoc.Close (True) Exit Sub End Sub
Solved! Go to Solution.
Solved by Curtis_Waguespack. Go to Solution.
Hi m.teleguz1,
I think this link should answer your questions:
http://download.autodesk.com/us/community/mfg/Part_1.pdf
I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com
Hi! There seems to be some formatting issue with some capital letters in the code. When I copy and paste the code to Inventor VBA Editor, question mark follows some 'D' or 'F'letter. You should see those lines of code highlighted in red.
Here is what you need to do.
1) Start new assembly file in Inventor.
2) Save it.
3) Go to Tools -> VBA Editor -> Copy and Paste the code to a module or function under ApplicationProject.
4) Correct the formatting errors I mentioned earlier.
5) Run.
The code seem to create a derive assembly part and break the link. That is what I saw on my machine.
Thanks!
Thank you once again for explaining this, Can someone help me fix this code? I never coded before.
😕
Thanks!
Hi m.teleguz1,
I copied the code you posted but didn't see any issues when pasting it into a new module. I've attached the same code in a *.txt file for you to try. You can copy and paste it from this file, and all should be well.
I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com