<?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: Batch replace titleblock in Inventor Programming Forum</title>
    <link>https://forums.autodesk.com/t5/inventor-programming-forum/batch-replace-titleblock/m-p/11369771#M33951</link>
    <description>&lt;P&gt;I think that you can use the method that &lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/576681"&gt;@CCarreiras&lt;/a&gt; proposes but you will need to select the files your self &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt; But if you want to do it a bit more automated way...&lt;/P&gt;
&lt;P&gt;I did have a look at your rule. (I could not test it by the way) I found some points.&lt;/P&gt;
&lt;P&gt;The template file is opened and closed a lot. I moved those actions outside the loop.&lt;/P&gt;
&lt;P&gt;On line 23 I found "ThisDoc.Document" I found that strange and I believe you need to use the object "oDrawDoc".&lt;/P&gt;
&lt;P&gt;I have added some try/catch blocks so if something goes wrong you can tell us where &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Try this rule:&lt;/P&gt;
&lt;LI-CODE lang="visual-basic"&gt;Dim oDoc As Document = ThisDoc.Document

If MessageBox.Show(
		"This will change all title blocks in IDW file for all of the files referenced by this document that have drawings files." _
		&amp;amp; vbLf &amp;amp; "This rule expects that the drawing file shares the same name and location as the component." _
		&amp;amp; vbLf &amp;amp; " " _
		&amp;amp; vbLf &amp;amp; "Are you sure you want to create IDW Drawings for all of the referenced documents?" _
		&amp;amp; vbLf &amp;amp; "This could take a while.", "iLogic  - Batch Output PDFs ", MessageBoxButtons.YesNo) = vbNo Then
    Exit Sub
End If

Dim templateFileName As String = "D:\data\Autodesk - Morren\3. Inventor templates\Morrenbv.idw"
Dim templateDoc As DrawingDocument = ThisApplication.Documents.Open(templateFileName, False)
Dim templateTitleBloc As TitleBlockDefinition = templateDoc.TitleBlockDefinitions.Item("GL bv")

'- - - - - - - - - - - - -Component Drawings - - - - - - - - - - - -
Dim oDrawDoc As DrawingDocument
Dim newTitleBlok As TitleBlockDefinition
Dim oNoDwgString, idwPathName As String
For Each oRefDoc As Document In oDoc.AllReferencedDocuments
    Dim oBaseName = System.IO.Path.GetFileNameWithoutExtension(oRefDoc.FullFileName)
    Dim oPathAndName = System.IO.Path.GetDirectoryName(oRefDoc.FullFileName) &amp;amp; "\" &amp;amp; oBaseName
    If (System.IO.File.Exists(oPathAndName &amp;amp; ".idw")) Then

        Try
            oDrawDoc = ThisApplication.Documents.Open(oPathAndName &amp;amp; ".idw", True)
            newTitleBlok = templateTitleBloc.CopyTo(oDrawDoc, True)
        Catch ex As Exception
            MsgBox("Something went wrong while copy TitleBlockDefinition to file: " &amp;amp; oDrawDoc.FullFileName)
        End Try

        For Each sheet As Sheet In oDrawDoc.Sheets
            Try
                Dim oldTitleblock As TitleBlock = Sheet.TitleBlock
                If (oldTitleblock IsNot Nothing) Then
                    oldTitleblock.Delete()
                End If
                Sheet.AddTitleBlock(newTitleBlok)
            Catch ex As Exception
                MsgBox(String.Format("something went wrong on sheet '{0}' in file '{1}'",
                                     Sheet.Name, oDrawDoc.FullFileName))
            End Try
        Next

        oDrawDoc.Close()
        oDrawDoc = Nothing
    Else
        idwPathName = oRefDoc.FullFileName
        oNoDwgString = oNoDwgString &amp;amp; vbLf &amp;amp; idwPathName
    End If
Next

templateDoc.Close(True)

MessageBox.Show("Title blocks are changed")
MsgBox("Files found without drawings: " &amp;amp; vbLf &amp;amp; oNoDwgString)&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 19 Aug 2022 19:55:37 GMT</pubDate>
    <dc:creator>JelteDeJong</dc:creator>
    <dc:date>2022-08-19T19:55:37Z</dc:date>
    <item>
      <title>Batch replace titleblock</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/batch-replace-titleblock/m-p/11368531#M33945</link>
      <description>&lt;P&gt;some of my clients want to have their own titleblock. Then nothing changes to the properties, but to the appearance. I already made some code for this, but it doesn't work. It crashes on the part from line 24 to line 40, while this works in a separate ilogic rule&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;SPAN&gt;Sub&lt;/SPAN&gt; &lt;SPAN&gt;Main&lt;/SPAN&gt;()
	&lt;SPAN&gt;Dim&lt;/SPAN&gt; &lt;SPAN&gt;oDoc&lt;/SPAN&gt; &lt;SPAN&gt;As&lt;/SPAN&gt; &lt;SPAN&gt;Document&lt;/SPAN&gt; = &lt;SPAN&gt;ThisDoc&lt;/SPAN&gt;.&lt;SPAN&gt;Document&lt;/SPAN&gt;
        
	&lt;SPAN&gt;If&lt;/SPAN&gt; &lt;SPAN&gt;MessageBox&lt;/SPAN&gt;.&lt;SPAN&gt;Show&lt;/SPAN&gt; ( _
		&lt;SPAN&gt;"This will change all title blocks in IDW file for all of the files referenced by this document that have drawings files."&lt;/SPAN&gt; _
		&amp;amp; &lt;SPAN&gt;vbLf&lt;/SPAN&gt; &amp;amp; &lt;SPAN&gt;"This rule expects that the drawing file shares the same name and location as the component."&lt;/SPAN&gt; _
		&amp;amp; &lt;SPAN&gt;vbLf&lt;/SPAN&gt; &amp;amp; &lt;SPAN&gt;" "&lt;/SPAN&gt; _
		&amp;amp; &lt;SPAN&gt;vbLf&lt;/SPAN&gt; &amp;amp; &lt;SPAN&gt;"Are you sure you want to create IDW Drawings for all of the referenced documents?"&lt;/SPAN&gt; _
		&amp;amp; &lt;SPAN&gt;vbLf&lt;/SPAN&gt; &amp;amp; &lt;SPAN&gt;"This could take a while."&lt;/SPAN&gt;, &lt;SPAN&gt;"iLogic  - Batch Output PDFs "&lt;/SPAN&gt;,&lt;SPAN&gt;MessageBoxButtons&lt;/SPAN&gt;.&lt;SPAN&gt;YesNo&lt;/SPAN&gt;) = &lt;SPAN&gt;vbNo&lt;/SPAN&gt; &lt;SPAN&gt;Then&lt;/SPAN&gt;
		&lt;SPAN&gt;Exit&lt;/SPAN&gt; &lt;SPAN&gt;Sub&lt;/SPAN&gt;
	&lt;SPAN&gt;End&lt;/SPAN&gt; &lt;SPAN&gt;If&lt;/SPAN&gt;
	
    &lt;SPAN&gt;'- - - - - - - - - - - - -Component Drawings - - - - - - - - - - - -&lt;/SPAN&gt;
	&lt;SPAN&gt;Dim&lt;/SPAN&gt; &lt;SPAN&gt;oDrawDoc&lt;/SPAN&gt; &lt;SPAN&gt;As&lt;/SPAN&gt; &lt;SPAN&gt;DrawingDocument&lt;/SPAN&gt;
	&lt;SPAN&gt;Dim&lt;/SPAN&gt; &lt;SPAN&gt;oNoDwgString&lt;/SPAN&gt;, &lt;SPAN&gt;idwPathName&lt;/SPAN&gt; &lt;SPAN&gt;As&lt;/SPAN&gt; &lt;SPAN&gt;String&lt;/SPAN&gt;
    &lt;SPAN&gt;For&lt;/SPAN&gt; &lt;SPAN&gt;Each&lt;/SPAN&gt; &lt;SPAN&gt;oRefDoc&lt;/SPAN&gt; &lt;SPAN&gt;As&lt;/SPAN&gt; &lt;SPAN&gt;Document&lt;/SPAN&gt; &lt;SPAN&gt;In&lt;/SPAN&gt; &lt;SPAN&gt;oDoc&lt;/SPAN&gt;.&lt;SPAN&gt;AllReferencedDocuments&lt;/SPAN&gt;
        &lt;SPAN&gt;oBaseName&lt;/SPAN&gt; = &lt;SPAN&gt;System&lt;/SPAN&gt;.&lt;SPAN&gt;IO&lt;/SPAN&gt;.&lt;SPAN&gt;Path&lt;/SPAN&gt;.&lt;SPAN&gt;GetFileNameWithoutExtension&lt;/SPAN&gt;(&lt;SPAN&gt;oRefDoc&lt;/SPAN&gt;.&lt;SPAN&gt;FullFileName&lt;/SPAN&gt;)
        &lt;SPAN&gt;oPathAndName&lt;/SPAN&gt; = &lt;SPAN&gt;System&lt;/SPAN&gt;.&lt;SPAN&gt;IO&lt;/SPAN&gt;.&lt;SPAN&gt;Path&lt;/SPAN&gt;.&lt;SPAN&gt;GetDirectoryName&lt;/SPAN&gt;(&lt;SPAN&gt;oRefDoc&lt;/SPAN&gt;.&lt;SPAN&gt;FullFileName&lt;/SPAN&gt;) &amp;amp; &lt;SPAN&gt;"\"&lt;/SPAN&gt; &amp;amp; &lt;SPAN&gt;oBaseName&lt;/SPAN&gt;
        &lt;SPAN&gt;If&lt;/SPAN&gt; (&lt;SPAN&gt;System&lt;/SPAN&gt;.&lt;SPAN&gt;IO&lt;/SPAN&gt;.&lt;SPAN&gt;File&lt;/SPAN&gt;.&lt;SPAN&gt;Exists&lt;/SPAN&gt;(&lt;SPAN&gt;oPathAndName&lt;/SPAN&gt; &amp;amp; &lt;SPAN&gt;".idw"&lt;/SPAN&gt;)) &lt;SPAN&gt;Then&lt;/SPAN&gt;
			&lt;SPAN&gt;oDrawDoc&lt;/SPAN&gt; = &lt;SPAN&gt;ThisApplication&lt;/SPAN&gt;.&lt;SPAN&gt;Documents&lt;/SPAN&gt;.&lt;SPAN&gt;Open&lt;/SPAN&gt;(&lt;SPAN&gt;oPathAndName&lt;/SPAN&gt; &amp;amp; &lt;SPAN&gt;".idw"&lt;/SPAN&gt;, &lt;SPAN&gt;True&lt;/SPAN&gt;)
			&lt;SPAN&gt;'save copy of it to other directory&lt;/SPAN&gt;
			
					&lt;SPAN&gt;Dim&lt;/SPAN&gt; &lt;SPAN&gt;doc&lt;/SPAN&gt; &lt;SPAN&gt;As&lt;/SPAN&gt; &lt;SPAN&gt;DrawingDocument&lt;/SPAN&gt; = &lt;SPAN&gt;ThisDoc&lt;/SPAN&gt;.&lt;SPAN&gt;Document&lt;/SPAN&gt;
					&lt;SPAN&gt;Dim&lt;/SPAN&gt; &lt;SPAN&gt;templateFileName&lt;/SPAN&gt; &lt;SPAN&gt;As&lt;/SPAN&gt; &lt;SPAN&gt;String&lt;/SPAN&gt; = &lt;SPAN&gt;"D:\data\Autodesk - Morren\3. Inventor templates\Morrenbv.idw"&lt;/SPAN&gt;
					&lt;SPAN&gt;Dim&lt;/SPAN&gt; &lt;SPAN&gt;templateDoc&lt;/SPAN&gt; &lt;SPAN&gt;As&lt;/SPAN&gt; &lt;SPAN&gt;DrawingDocument&lt;/SPAN&gt; = &lt;SPAN&gt;ThisApplication&lt;/SPAN&gt;.&lt;SPAN&gt;Documents&lt;/SPAN&gt;.&lt;SPAN&gt;Open&lt;/SPAN&gt;(&lt;SPAN&gt;templateFileName&lt;/SPAN&gt;, &lt;SPAN&gt;False&lt;/SPAN&gt;)

				&lt;SPAN&gt;' copy your titleblock to original drawing&lt;/SPAN&gt;
				&lt;SPAN&gt;Dim&lt;/SPAN&gt; &lt;SPAN&gt;templateTitleBloc&lt;/SPAN&gt; &lt;SPAN&gt;As&lt;/SPAN&gt; &lt;SPAN&gt;TitleBlockDefinition&lt;/SPAN&gt; = &lt;SPAN&gt;templateDoc&lt;/SPAN&gt;.&lt;SPAN&gt;TitleBlockDefinitions&lt;/SPAN&gt;.&lt;SPAN&gt;Item&lt;/SPAN&gt;(&lt;SPAN&gt;"GL bv"&lt;/SPAN&gt;)
				&lt;SPAN&gt;Dim&lt;/SPAN&gt; &lt;SPAN&gt;newTitleBlok&lt;/SPAN&gt; &lt;SPAN&gt;As&lt;/SPAN&gt; &lt;SPAN&gt;TitleBlockDefinition&lt;/SPAN&gt; = &lt;SPAN&gt;templateTitleBloc&lt;/SPAN&gt;.&lt;SPAN&gt;CopyTo&lt;/SPAN&gt;(&lt;SPAN&gt;doc&lt;/SPAN&gt;, &lt;SPAN&gt;True&lt;/SPAN&gt;)
				&lt;SPAN&gt;' close the template document&lt;/SPAN&gt;
				&lt;SPAN&gt;templateDoc&lt;/SPAN&gt;.&lt;SPAN&gt;Close&lt;/SPAN&gt;(&lt;SPAN&gt;True&lt;/SPAN&gt;)
				
				&lt;SPAN&gt;For&lt;/SPAN&gt; &lt;SPAN&gt;Each&lt;/SPAN&gt; &lt;SPAN&gt;sheet&lt;/SPAN&gt; &lt;SPAN&gt;As&lt;/SPAN&gt; &lt;SPAN&gt;Sheet&lt;/SPAN&gt; &lt;SPAN&gt;In&lt;/SPAN&gt; &lt;SPAN&gt;doc&lt;/SPAN&gt;.&lt;SPAN&gt;Sheets&lt;/SPAN&gt;
				    &lt;SPAN&gt;Dim&lt;/SPAN&gt; &lt;SPAN&gt;oldTitleblock&lt;/SPAN&gt; &lt;SPAN&gt;As&lt;/SPAN&gt; &lt;SPAN&gt;TitleBlock&lt;/SPAN&gt; = &lt;SPAN&gt;Sheet&lt;/SPAN&gt;.&lt;SPAN&gt;TitleBlock&lt;/SPAN&gt;
				    &lt;SPAN&gt;If&lt;/SPAN&gt; (&lt;SPAN&gt;oldTitleblock&lt;/SPAN&gt; &lt;SPAN&gt;IsNot&lt;/SPAN&gt; &lt;SPAN&gt;Nothing&lt;/SPAN&gt;) &lt;SPAN&gt;Then&lt;/SPAN&gt;
				        &lt;SPAN&gt;oldTitleblock&lt;/SPAN&gt;.&lt;SPAN&gt;Delete&lt;/SPAN&gt;()
				    &lt;SPAN&gt;End&lt;/SPAN&gt; &lt;SPAN&gt;If&lt;/SPAN&gt;
				    &lt;SPAN&gt;Sheet&lt;/SPAN&gt;.&lt;SPAN&gt;AddTitleBlock&lt;/SPAN&gt;(&lt;SPAN&gt;newTitleBlok&lt;/SPAN&gt;)
				&lt;SPAN&gt;Next&lt;/SPAN&gt;

			&lt;SPAN&gt;'oDrawDoc.SaveAs(oFolder &amp;amp; oBaseName &amp;amp; ".idw", True)&lt;/SPAN&gt;
            &lt;SPAN&gt;oDrawDoc&lt;/SPAN&gt;.&lt;SPAN&gt;Close&lt;/SPAN&gt;
			&lt;SPAN&gt;oDrawDoc&lt;/SPAN&gt; = &lt;SPAN&gt;Nothing&lt;/SPAN&gt;
        &lt;SPAN&gt;Else&lt;/SPAN&gt;
			&lt;SPAN&gt;idwPathName&lt;/SPAN&gt; = &lt;SPAN&gt;oRefDoc&lt;/SPAN&gt;.&lt;SPAN&gt;FullFileName&lt;/SPAN&gt;
            &lt;SPAN&gt;oNoDwgString&lt;/SPAN&gt; = &lt;SPAN&gt;oNoDwgString&lt;/SPAN&gt; &amp;amp; &lt;SPAN&gt;vbLf&lt;/SPAN&gt; &amp;amp; &lt;SPAN&gt;idwPathName&lt;/SPAN&gt;
        &lt;SPAN&gt;End&lt;/SPAN&gt; &lt;SPAN&gt;If&lt;/SPAN&gt;
    &lt;SPAN&gt;Next&lt;/SPAN&gt;
    
    
    &lt;SPAN&gt;MessageBox&lt;/SPAN&gt;.&lt;SPAN&gt;Show&lt;/SPAN&gt;(&lt;SPAN&gt;"Title blocks are changed"&lt;/SPAN&gt;)
    &lt;SPAN&gt;MsgBox&lt;/SPAN&gt;(&lt;SPAN&gt;"Files found without drawings: "&lt;/SPAN&gt; &amp;amp; &lt;SPAN&gt;vbLf&lt;/SPAN&gt; &amp;amp; &lt;SPAN&gt;oNoDwgString&lt;/SPAN&gt;)
&lt;SPAN&gt;End&lt;/SPAN&gt; &lt;SPAN&gt;Sub&lt;/SPAN&gt;

&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 19 Aug 2022 10:29:49 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/batch-replace-titleblock/m-p/11368531#M33945</guid>
      <dc:creator>morrenengineering</dc:creator>
      <dc:date>2022-08-19T10:29:49Z</dc:date>
    </item>
    <item>
      <title>Re: Batch replace titleblock</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/batch-replace-titleblock/m-p/11368558#M33946</link>
      <description>&lt;P&gt;Hi!&lt;/P&gt;&lt;P&gt;Autodesk has a tool do to that, why d'ont you use it?&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="ccarreiras_0-1660903128058.png" style="width: 600px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1105697iCDF780A0BA0CB9FC/image-size/medium?v=v2&amp;amp;px=400" role="button" title="ccarreiras_0-1660903128058.png" alt="ccarreiras_0-1660903128058.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 19 Aug 2022 09:58:53 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/batch-replace-titleblock/m-p/11368558#M33946</guid>
      <dc:creator>CCarreiras</dc:creator>
      <dc:date>2022-08-19T09:58:53Z</dc:date>
    </item>
    <item>
      <title>Re: Batch replace titleblock</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/batch-replace-titleblock/m-p/11368570#M33947</link>
      <description>&lt;P&gt;Then I have only the information in the file, not the replacement of the title block in the drawing&lt;/P&gt;</description>
      <pubDate>Fri, 19 Aug 2022 10:05:24 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/batch-replace-titleblock/m-p/11368570#M33947</guid>
      <dc:creator>morrenengineering</dc:creator>
      <dc:date>2022-08-19T10:05:24Z</dc:date>
    </item>
    <item>
      <title>Re: Batch replace titleblock</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/batch-replace-titleblock/m-p/11368610#M33948</link>
      <description>&lt;P&gt;This tool is exactly for changing the title block (among other options, borders etc) based on a newly designed title block, including all property fields, and this can be done in a batch by selecting all the files you want change at the same time.&lt;/P&gt;</description>
      <pubDate>Fri, 19 Aug 2022 10:28:04 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/batch-replace-titleblock/m-p/11368610#M33948</guid>
      <dc:creator>CCarreiras</dc:creator>
      <dc:date>2022-08-19T10:28:04Z</dc:date>
    </item>
    <item>
      <title>Re: Batch replace titleblock</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/batch-replace-titleblock/m-p/11368948#M33949</link>
      <description>&lt;P&gt;I do not want to change the title block, I want to replace the title block&lt;/P&gt;</description>
      <pubDate>Fri, 19 Aug 2022 13:39:42 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/batch-replace-titleblock/m-p/11368948#M33949</guid>
      <dc:creator>morrenengineering</dc:creator>
      <dc:date>2022-08-19T13:39:42Z</dc:date>
    </item>
    <item>
      <title>Re: Batch replace titleblock</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/batch-replace-titleblock/m-p/11369693#M33950</link>
      <description>&lt;P&gt;Hi &lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/3528914"&gt;@morrenengineering&lt;/a&gt;.&lt;/P&gt;
&lt;P&gt;Within your code, try getting rid of this line of code:&lt;/P&gt;
&lt;LI-CODE lang="general"&gt;Dim doc As DrawingDocument = ThisDoc.Document&lt;/LI-CODE&gt;
&lt;P&gt;...because you already have a reverence to the drawing document (oDrawDoc).&lt;/P&gt;
&lt;P&gt;Then find/replace all following uses of the 'doc' variable with 'oDrawDoc' instead.&lt;/P&gt;
&lt;P&gt;Change:&lt;/P&gt;
&lt;LI-CODE lang="general"&gt;Dim newTitleBlok As TitleBlockDefinition = templateTitleBloc.CopyTo(doc, True)&lt;/LI-CODE&gt;
&lt;P&gt;to&lt;/P&gt;
&lt;LI-CODE lang="general"&gt;Dim newTitleBlok As TitleBlockDefinition = templateTitleBloc.CopyTo(oDrawDoc, True)&lt;/LI-CODE&gt;
&lt;P&gt;Change:&lt;/P&gt;
&lt;LI-CODE lang="general"&gt;For Each sheet As Sheet In doc.Sheets&lt;/LI-CODE&gt;
&lt;P&gt;to&lt;/P&gt;
&lt;LI-CODE lang="general"&gt;For Each sheet As Sheet In oDrawDoc.Sheets&lt;/LI-CODE&gt;
&lt;P&gt;...and un-comment out your SaveAs line, because it is already using the oDrawDoc variable.&lt;/P&gt;
&lt;P&gt;Just my thoughts based on what I see.&lt;/P&gt;</description>
      <pubDate>Fri, 19 Aug 2022 18:57:31 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/batch-replace-titleblock/m-p/11369693#M33950</guid>
      <dc:creator>WCrihfield</dc:creator>
      <dc:date>2022-08-19T18:57:31Z</dc:date>
    </item>
    <item>
      <title>Re: Batch replace titleblock</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/batch-replace-titleblock/m-p/11369771#M33951</link>
      <description>&lt;P&gt;I think that you can use the method that &lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/576681"&gt;@CCarreiras&lt;/a&gt; proposes but you will need to select the files your self &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt; But if you want to do it a bit more automated way...&lt;/P&gt;
&lt;P&gt;I did have a look at your rule. (I could not test it by the way) I found some points.&lt;/P&gt;
&lt;P&gt;The template file is opened and closed a lot. I moved those actions outside the loop.&lt;/P&gt;
&lt;P&gt;On line 23 I found "ThisDoc.Document" I found that strange and I believe you need to use the object "oDrawDoc".&lt;/P&gt;
&lt;P&gt;I have added some try/catch blocks so if something goes wrong you can tell us where &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Try this rule:&lt;/P&gt;
&lt;LI-CODE lang="visual-basic"&gt;Dim oDoc As Document = ThisDoc.Document

If MessageBox.Show(
		"This will change all title blocks in IDW file for all of the files referenced by this document that have drawings files." _
		&amp;amp; vbLf &amp;amp; "This rule expects that the drawing file shares the same name and location as the component." _
		&amp;amp; vbLf &amp;amp; " " _
		&amp;amp; vbLf &amp;amp; "Are you sure you want to create IDW Drawings for all of the referenced documents?" _
		&amp;amp; vbLf &amp;amp; "This could take a while.", "iLogic  - Batch Output PDFs ", MessageBoxButtons.YesNo) = vbNo Then
    Exit Sub
End If

Dim templateFileName As String = "D:\data\Autodesk - Morren\3. Inventor templates\Morrenbv.idw"
Dim templateDoc As DrawingDocument = ThisApplication.Documents.Open(templateFileName, False)
Dim templateTitleBloc As TitleBlockDefinition = templateDoc.TitleBlockDefinitions.Item("GL bv")

'- - - - - - - - - - - - -Component Drawings - - - - - - - - - - - -
Dim oDrawDoc As DrawingDocument
Dim newTitleBlok As TitleBlockDefinition
Dim oNoDwgString, idwPathName As String
For Each oRefDoc As Document In oDoc.AllReferencedDocuments
    Dim oBaseName = System.IO.Path.GetFileNameWithoutExtension(oRefDoc.FullFileName)
    Dim oPathAndName = System.IO.Path.GetDirectoryName(oRefDoc.FullFileName) &amp;amp; "\" &amp;amp; oBaseName
    If (System.IO.File.Exists(oPathAndName &amp;amp; ".idw")) Then

        Try
            oDrawDoc = ThisApplication.Documents.Open(oPathAndName &amp;amp; ".idw", True)
            newTitleBlok = templateTitleBloc.CopyTo(oDrawDoc, True)
        Catch ex As Exception
            MsgBox("Something went wrong while copy TitleBlockDefinition to file: " &amp;amp; oDrawDoc.FullFileName)
        End Try

        For Each sheet As Sheet In oDrawDoc.Sheets
            Try
                Dim oldTitleblock As TitleBlock = Sheet.TitleBlock
                If (oldTitleblock IsNot Nothing) Then
                    oldTitleblock.Delete()
                End If
                Sheet.AddTitleBlock(newTitleBlok)
            Catch ex As Exception
                MsgBox(String.Format("something went wrong on sheet '{0}' in file '{1}'",
                                     Sheet.Name, oDrawDoc.FullFileName))
            End Try
        Next

        oDrawDoc.Close()
        oDrawDoc = Nothing
    Else
        idwPathName = oRefDoc.FullFileName
        oNoDwgString = oNoDwgString &amp;amp; vbLf &amp;amp; idwPathName
    End If
Next

templateDoc.Close(True)

MessageBox.Show("Title blocks are changed")
MsgBox("Files found without drawings: " &amp;amp; vbLf &amp;amp; oNoDwgString)&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 19 Aug 2022 19:55:37 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/batch-replace-titleblock/m-p/11369771#M33951</guid>
      <dc:creator>JelteDeJong</dc:creator>
      <dc:date>2022-08-19T19:55:37Z</dc:date>
    </item>
  </channel>
</rss>

