Inventor Customization

Reply
Distinguished Contributor
m.teleguz1
Posts: 189
Registered: ‎04-01-2013
Message 1 of 5 (313 Views)
Accepted Solution

How to Execute Code?

313 Views, 4 Replies
04-01-2013 01:51 PM

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 :smileyhappy:

 

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.
..........................................................................................................................
Privacy warning: Since I live in a country that has traded liberty for the illusion of security, all of your posts to me are being monitored and saved by the United States Government.

*Expert Elite*
Curtis_Waguespack
Posts: 2,780
Registered: ‎03-08-2006
Message 2 of 5 (292 Views)

Re: How to Execute Code?

04-01-2013 02:40 PM in reply to: m.teleguz1

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



  solution.png  Did you find this reply helpful ? If so please use the Accept as Solution or  Kudos button below.





Employee
johnsonshiue
Posts: 1,910
Registered: ‎04-30-2008
Message 3 of 5 (291 Views)

Re: How to Execute Code?

04-01-2013 02:44 PM in reply to: m.teleguz1

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)
Principal SQA Engineer, Inventor
Mechanical Design
Autodesk, Inc.

Distinguished Contributor
m.teleguz1
Posts: 189
Registered: ‎04-01-2013
Message 4 of 5 (262 Views)

Re: How to Execute Code?

04-02-2013 04:48 AM 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.
..........................................................................................................................
Privacy warning: Since I live in a country that has traded liberty for the illusion of security, all of your posts to me are being monitored and saved by the United States Government.

*Expert Elite*
Curtis_Waguespack
Posts: 2,780
Registered: ‎03-08-2006
Message 5 of 5 (238 Views)

Re: How to Execute Code?

04-02-2013 12:48 PM in reply to: m.teleguz1

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



  solution.png  Did you find this reply helpful ? If so please use the Accept as Solution or  Kudos button below.





You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community


Inventor Exchange Apps

Created by the community for the community, Autodesk Exchange Apps for Autodesk Inventor helps you achieve greater speed, accuracy, and automation from concept to manufacturing.

Connect with Inventor

Twitter

Facebook

Blogs

Pinterest

Youtube