<?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 Re: iLogic Design Copy - make multiple copies? in Inventor Programming - iLogic, Macros, AddIns &amp; Apprentice</title>
    <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/ilogic-design-copy-make-multiple-copies/m-p/11875987#M151041</link>
    <description>&lt;P&gt;I know its old but this might help someone, this only works if you run it from within a assembly that contains the assembly you want to copy and the code is a mess.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;' Display a message box to the user with instructions
Dim userResponse = MessageBox.Show("To use this function a few things to note:" &amp;amp; vbNewLine &amp;amp; _
    "   - You use it from the Main Assembly, not from the assembly you want to copy" &amp;amp; vbNewLine &amp;amp; _
    "   - It doesn't work for assemblies within assemblies", "Frametek Ilogic Copy V.1.0", MessageBoxButtons.OKCancel)

' If the user clicked OK in the message box
If userResponse = vbOK Then
    ' Prompt the user to pick the assembly to copy
    Dim pickedAssembly As Object
    pickedAssembly = ThisServer.CommandManager.Pick(SelectionFilterEnum.kAssemblyOccurrenceFilter, "Pick Assembly To Copy")

    ' Cast the picked assembly as a Document
    Dim pickedDocument As Document
    pickedDocument = pickedAssembly.Definition.Document

    ' Get the filename of the picked document
    Dim pickedDocFileName As String = Right(pickedDocument.FullDocumentName, (Len(pickedDocument.FullDocumentName) - (Left(pickedDocument.FullDocumentName, Len(pickedDocument.FullDocumentName)).LastIndexOf("\") + 1)))
    MessageBox.Show(pickedDocFileName , "Title")

    ' Ask the user how many copies they would like
    Dim numCopies = InputBox("How many times would you like to copy the assembly?", "How Many Copies?", "1")

    ' Set a prefix for the copied files
    Dim filePrefix As Integer = 0

    ' Loop to create the copies
    Do
        filePrefix += 1

        ' For each copy
        For i = 1 To numCopies
            ' Determine the save location for the copied assembly
            Dim saveLocation As String
            saveLocation = Left(pickedDocument.FullFileName, Len(pickedDocument.FullFileName) - 4) &amp;amp; "" &amp;amp; filePrefix &amp;amp; ".iam"

            ' If a file already exists at the save location, skip to the next iteration
            If System.IO.File.Exists(saveLocation) Then
                Continue Do
            End If

            ' Save a copy of the picked document
            pickedDocument.SaveAs(saveLocation, True)

            ' Open the copied document
            Dim copiedDoc As Document
            copiedDoc = ThisApplication.Documents.Open(saveLocation, False)

            ' Get the component definition of the copied document
            Dim copiedDocCompDef As AssemblyComponentDefinition = copiedDoc.ComponentDefinition

            ' For each component occurrence in the copied document
            For Each compOcc As ComponentOccurrence In copiedDocCompDef.Occurrences
                ' If the component occurrence name does not end with ":1", skip to the next iteration
                If Right(compOcc.Name, 2) &amp;lt;&amp;gt; ":1" Then
                    Continue For
                End If

                ' Open the referenced document of the component occurrence
                Dim refDoc As Document = ThisApplication.Documents.Open(compOcc.ReferencedDocumentDescriptor.FullDocumentName, False)

                ' Determine the save location for the referenced document
                Dim refDocSaveLocation As String = Left(refDoc.FullFileName, (Left(refDoc.FullFileName, Len(refDoc.FullFileName)).LastIndexOf("\") + 2)) &amp;amp; _
                    Left(Strings.Mid(refDoc.FullFileName, (Left(refDoc.FullFileName, Len(refDoc.FullFileName)).LastIndexOf("\") + 2)), Len(Strings.Mid(refDoc.FullFileName, (Left(refDoc.FullFileName, Len(refDoc.FullFileName)).LastIndexOf("\") + 2))) - 4) &amp;amp; _
                    "_" &amp;amp; filePrefix &amp;amp; ".ipt"

                ' If a file already exists at the save location, skip to the next iteration
                If System.IO.File.Exists(refDocSaveLocation) Then
                    Continue For
                End If

                ' Save a copy of the referenced document
                refDoc.SaveAs(refDocSaveLocation, True)

                ' Replace the component occurrence with the copied referenced document
                compOcc.Replace(refDocSaveLocation, True)
                refDoc.Close()
            Next

            ' Update and save the copied document
            copiedDoc.Update()
            copiedDoc.Save()
            copiedDoc.Close()
        Next
    Loop Until filePrefix &amp;gt;= numCopies
End If&lt;/LI-CODE&gt;</description>
    <pubDate>Thu, 21 Dec 2023 06:26:07 GMT</pubDate>
    <dc:creator>clive.w66LR9</dc:creator>
    <dc:date>2023-12-21T06:26:07Z</dc:date>
    <item>
      <title>iLogic Design Copy - make multiple copies?</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/ilogic-design-copy-make-multiple-copies/m-p/8214915#M87984</link>
      <description>&lt;P&gt;Hi everyone!&lt;/P&gt;&lt;P&gt;I am wondering if anyone has automated making multiple copies with the iLogic Design Copy tool.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I make 10 to 15 copies almost every time I use this tool and it has become quite tedious.&amp;nbsp; Is there a way to automate this for multiple copies? The only change for each iteration is an incrementing prefix (i.e. "30_01_", "30_02_").&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any suggestions?&lt;/P&gt;</description>
      <pubDate>Tue, 21 Aug 2018 19:16:04 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/ilogic-design-copy-make-multiple-copies/m-p/8214915#M87984</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2018-08-21T19:16:04Z</dc:date>
    </item>
    <item>
      <title>Re: iLogic Design Copy - make multiple copies?</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/ilogic-design-copy-make-multiple-copies/m-p/8215157#M87985</link>
      <description>&lt;P&gt;Ooops! Wrong forum.&lt;/P&gt;&lt;P&gt;&lt;A href="https://forums.autodesk.com/t5/inventor-customization/ilogic-design-copy-making-multiple-copies/td-p/8215143 " target="_blank"&gt;Re-posted in customization forum.&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 21 Aug 2018 21:04:42 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/ilogic-design-copy-make-multiple-copies/m-p/8215157#M87985</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2018-08-21T21:04:42Z</dc:date>
    </item>
    <item>
      <title>Re: iLogic Design Copy - make multiple copies?</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/ilogic-design-copy-make-multiple-copies/m-p/11875987#M151041</link>
      <description>&lt;P&gt;I know its old but this might help someone, this only works if you run it from within a assembly that contains the assembly you want to copy and the code is a mess.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;' Display a message box to the user with instructions
Dim userResponse = MessageBox.Show("To use this function a few things to note:" &amp;amp; vbNewLine &amp;amp; _
    "   - You use it from the Main Assembly, not from the assembly you want to copy" &amp;amp; vbNewLine &amp;amp; _
    "   - It doesn't work for assemblies within assemblies", "Frametek Ilogic Copy V.1.0", MessageBoxButtons.OKCancel)

' If the user clicked OK in the message box
If userResponse = vbOK Then
    ' Prompt the user to pick the assembly to copy
    Dim pickedAssembly As Object
    pickedAssembly = ThisServer.CommandManager.Pick(SelectionFilterEnum.kAssemblyOccurrenceFilter, "Pick Assembly To Copy")

    ' Cast the picked assembly as a Document
    Dim pickedDocument As Document
    pickedDocument = pickedAssembly.Definition.Document

    ' Get the filename of the picked document
    Dim pickedDocFileName As String = Right(pickedDocument.FullDocumentName, (Len(pickedDocument.FullDocumentName) - (Left(pickedDocument.FullDocumentName, Len(pickedDocument.FullDocumentName)).LastIndexOf("\") + 1)))
    MessageBox.Show(pickedDocFileName , "Title")

    ' Ask the user how many copies they would like
    Dim numCopies = InputBox("How many times would you like to copy the assembly?", "How Many Copies?", "1")

    ' Set a prefix for the copied files
    Dim filePrefix As Integer = 0

    ' Loop to create the copies
    Do
        filePrefix += 1

        ' For each copy
        For i = 1 To numCopies
            ' Determine the save location for the copied assembly
            Dim saveLocation As String
            saveLocation = Left(pickedDocument.FullFileName, Len(pickedDocument.FullFileName) - 4) &amp;amp; "" &amp;amp; filePrefix &amp;amp; ".iam"

            ' If a file already exists at the save location, skip to the next iteration
            If System.IO.File.Exists(saveLocation) Then
                Continue Do
            End If

            ' Save a copy of the picked document
            pickedDocument.SaveAs(saveLocation, True)

            ' Open the copied document
            Dim copiedDoc As Document
            copiedDoc = ThisApplication.Documents.Open(saveLocation, False)

            ' Get the component definition of the copied document
            Dim copiedDocCompDef As AssemblyComponentDefinition = copiedDoc.ComponentDefinition

            ' For each component occurrence in the copied document
            For Each compOcc As ComponentOccurrence In copiedDocCompDef.Occurrences
                ' If the component occurrence name does not end with ":1", skip to the next iteration
                If Right(compOcc.Name, 2) &amp;lt;&amp;gt; ":1" Then
                    Continue For
                End If

                ' Open the referenced document of the component occurrence
                Dim refDoc As Document = ThisApplication.Documents.Open(compOcc.ReferencedDocumentDescriptor.FullDocumentName, False)

                ' Determine the save location for the referenced document
                Dim refDocSaveLocation As String = Left(refDoc.FullFileName, (Left(refDoc.FullFileName, Len(refDoc.FullFileName)).LastIndexOf("\") + 2)) &amp;amp; _
                    Left(Strings.Mid(refDoc.FullFileName, (Left(refDoc.FullFileName, Len(refDoc.FullFileName)).LastIndexOf("\") + 2)), Len(Strings.Mid(refDoc.FullFileName, (Left(refDoc.FullFileName, Len(refDoc.FullFileName)).LastIndexOf("\") + 2))) - 4) &amp;amp; _
                    "_" &amp;amp; filePrefix &amp;amp; ".ipt"

                ' If a file already exists at the save location, skip to the next iteration
                If System.IO.File.Exists(refDocSaveLocation) Then
                    Continue For
                End If

                ' Save a copy of the referenced document
                refDoc.SaveAs(refDocSaveLocation, True)

                ' Replace the component occurrence with the copied referenced document
                compOcc.Replace(refDocSaveLocation, True)
                refDoc.Close()
            Next

            ' Update and save the copied document
            copiedDoc.Update()
            copiedDoc.Save()
            copiedDoc.Close()
        Next
    Loop Until filePrefix &amp;gt;= numCopies
End If&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 21 Dec 2023 06:26:07 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/ilogic-design-copy-make-multiple-copies/m-p/11875987#M151041</guid>
      <dc:creator>clive.w66LR9</dc:creator>
      <dc:date>2023-12-21T06:26:07Z</dc:date>
    </item>
  </channel>
</rss>

