<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic How to Execute Code? in Inventor Programming Forum</title>
    <link>https://forums.autodesk.com/t5/inventor-programming-forum/how-to-execute-code/m-p/3820160#M131566</link>
    <description>&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help will be appreciated with a smile &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am using inventor 2010 / routing&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thanks!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;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) &amp;amp; ".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." &amp;amp; Chr(13) &amp;amp; "You may want to delete the existing file and re-do this process.")
    oPartDoc.Close (True)
    Exit Sub
End Sub&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 01 Apr 2013 20:53:23 GMT</pubDate>
    <dc:creator>DeerSpotter</dc:creator>
    <dc:date>2013-04-01T20:53:23Z</dc:date>
    <item>
      <title>How to Execute Code?</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/how-to-execute-code/m-p/3820160#M131566</link>
      <description>&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help will be appreciated with a smile &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am using inventor 2010 / routing&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thanks!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;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) &amp;amp; ".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." &amp;amp; Chr(13) &amp;amp; "You may want to delete the existing file and re-do this process.")
    oPartDoc.Close (True)
    Exit Sub
End Sub&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 01 Apr 2013 20:53:23 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/how-to-execute-code/m-p/3820160#M131566</guid>
      <dc:creator>DeerSpotter</dc:creator>
      <dc:date>2013-04-01T20:53:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to Execute Code?</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/how-to-execute-code/m-p/3820200#M131567</link>
      <description>&lt;P&gt;Hi m.teleguz1,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I think this link should answer your questions:&lt;/P&gt;&lt;P&gt;&lt;A target="_blank" href="http://download.autodesk.com/us/community/mfg/Part_1.pdf"&gt;http://download.autodesk.com/us/community/mfg/Part_1.pdf&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I hope this helps.&lt;BR /&gt;Best of luck to you in all of your Inventor pursuits,&lt;BR /&gt;Curtis&lt;BR /&gt;&lt;A target="_blank" href="http://inventortrenches.blogspot.com"&gt;http://inventortrenches.blogspot.com&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 01 Apr 2013 21:40:37 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/how-to-execute-code/m-p/3820200#M131567</guid>
      <dc:creator>Curtis_W</dc:creator>
      <dc:date>2013-04-01T21:40:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to Execute Code?</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/how-to-execute-code/m-p/3820204#M131568</link>
      <description>&lt;P&gt;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&amp;nbsp;of code&amp;nbsp;highlighted in red.&lt;/P&gt;
&lt;P&gt;Here is what you need to do.&lt;/P&gt;
&lt;P&gt;1) Start new assembly file in Inventor.&lt;/P&gt;
&lt;P&gt;2) Save it.&lt;/P&gt;
&lt;P&gt;3) Go to Tools -&amp;gt; VBA Editor -&amp;gt; Copy and Paste the code to a module or function under ApplicationProject.&lt;/P&gt;
&lt;P&gt;4) Correct the formatting errors I mentioned earlier.&lt;/P&gt;
&lt;P&gt;5) Run.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The code seem to create a derive assembly part and break the link. That is what I saw on my machine.&lt;/P&gt;
&lt;P&gt;Thanks!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 01 Apr 2013 21:44:14 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/how-to-execute-code/m-p/3820204#M131568</guid>
      <dc:creator>johnsonshiue</dc:creator>
      <dc:date>2013-04-01T21:44:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to Execute Code?</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/how-to-execute-code/m-p/3820532#M131569</link>
      <description>&lt;P&gt;Thank you once again for explaining this, Can someone help me fix this code? I never coded before.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-unicode-emoji" title=":confused_face:"&gt;😕&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 02 Apr 2013 11:48:28 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/how-to-execute-code/m-p/3820532#M131569</guid>
      <dc:creator>DeerSpotter</dc:creator>
      <dc:date>2013-04-02T11:48:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to Execute Code?</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/how-to-execute-code/m-p/3821293#M131570</link>
      <description>&lt;P&gt;Hi m.teleguz1,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I hope this helps.&lt;BR /&gt;Best of luck to you in all of your Inventor pursuits,&lt;BR /&gt;Curtis&lt;BR /&gt;&lt;A target="_blank" href="http://inventortrenches.blogspot.com"&gt;http://inventortrenches.blogspot.com&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 02 Apr 2013 19:48:56 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/how-to-execute-code/m-p/3821293#M131570</guid>
      <dc:creator>Curtis_W</dc:creator>
      <dc:date>2013-04-02T19:48:56Z</dc:date>
    </item>
  </channel>
</rss>

