Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to Execute Code?

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
DeerSpotter
604 Views, 4 Replies

How to Execute Code?

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

 

Image and video hosting by TinyPic
..........................................................................................................................
Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.
..........................................................................................................................


See My LinkedIn Profile
4 REPLIES 4
Message 2 of 5

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

Message 3 of 5
johnsonshiue
in reply to: DeerSpotter

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!

 



Johnson Shiue (johnson.shiue@autodesk.com)
Software Test Engineer
Message 4 of 5
DeerSpotter
in reply to: johnsonshiue

Thank you once again for explaining this, Can someone help me fix this code? I never coded before.

 

😕

 

Thanks!

 

Image and video hosting by TinyPic
..........................................................................................................................
Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.
..........................................................................................................................


See My LinkedIn Profile
Message 5 of 5

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

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report