<?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 Best Way to Define Seperate Documents in Inventor Programming - iLogic, Macros, AddIns &amp; Apprentice</title>
    <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/best-way-to-define-seperate-documents/m-p/5557289#M54875</link>
    <description>&lt;P&gt;In my recent coding I came across some issues with defining documents and getting a LateGet Error, so I was wondering what the actual best practice for doing this is or what the difference may be.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to switch between multiple documents during one rule.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;-&amp;gt; By Using oDoc = ThisApplication.ActiveDocuments&amp;lt;- Does this hold the same document even if i switch documents, or will it just pull the active &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;document again?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;By using oDoc = ThisApplication.Documents.ItemByName()&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;BY using oDoc = ThisApplication.Documents.ItemByName().Open&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Or with oDoc = .... .AddUsingTemplate()&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there a difference in how they define and call the document?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This all results because I used the oDoc = ... .AddUsingTemplate and then called the file using oDoc later on, after switching documents multiple times, and then kept on getting a .LateGet / LateBinding error.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So for my work around, I had just added in a function that accessed the active document, which was my new document, to add a title block.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help/insight would be helpful!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;Sub Main()

For Each oSheet In ThisApplication.ActiveDocument.Sheets


		Dim sPromptStrings(4) As String
Try
		sPromptStrings(0) = oSheet.TitleBlock.GetResultText(oSheet.TitleBlock.Definition.Sketch.TextBoxes.Item(48)) ' Title
		sPromptStrings(1) = oSheet.TitleBlock.GetResultText(oSheet.TitleBlock.Definition.Sketch.TextBoxes.Item(49)) 'DESCRIPTION 1
		sPromptStrings(2) = oSheet.TitleBlock.GetResultText(oSheet.TitleBlock.Definition.Sketch.TextBoxes.Item(50)) 'DESCRIPTION 2
		sPromptStrings(3) = oSheet.TitleBlock.GetResultText(oSheet.TitleBlock.Definition.Sketch.TextBoxes.Item(52)) 'CUSTOMER DRAWING#
		sPromptStrings(4) = oSheet.TitleBlock.GetResultText(oSheet.TitleBlock.Definition.Sketch.TextBoxes.Item(53)) 'SCALE
		

Catch
End Try
		
		oFileDoc=ThisApplication.Documents.Add(kDrawingDocumentObject,"C:\User.idw", True)

		oSheet.CopyTo(oFileDoc)

		oFileDoc.Sheets.Item(oFileDoc.Sheets.Count).Activate
		
		oFile = "C:\" &amp;amp; oSheet.TitleBlock.GetResultText(oSheet.TitleBlock.Definition.Sketch.TextBoxes.Item(52))  &amp;amp; ".idw"
			'Directory and comments.
		
		oFileDoc.Activate
		
		If Not oFileDoc.ActiveSheet.TitleBlock Is Nothing Then
      		oFileDoc.ActiveSheet.TitleBlock.Delete
    	End If

		Dim oTitleBlock As Inventor.TitleBlock
		
		oAddTb
		
		MsgBox("oAddTb Ran Successfully!")
		ThisApplication.ActiveDocument.Sheets.Item(1).Delete
		ThisApplication.ActiveDocument.SaveAs(oFile, False)
'		oFileDoc.Close
Next
End Sub

Function oAddTb

		'Dim oSheet As Sheet = ThisApplication.ActiveDocument.Sheets.Item(ThisApplication.ActiveDocument.Sheets.Count)

		Dim oSheet As Sheet = ThisApplication.ActiveDocument.ActiveSheet

		Dim sPromptStrings(4) As String
		sPromptStrings(0) = "A" ' Title
		sPromptStrings(1) = "A"
		sPromptStrings(2) = "A"
		sPromptStrings(3) = "A"
		sPromptStrings(4) = "A"

		If Not oSheet.TitleBlock Is Nothing Then
      		oSheet.TitleBlock.Delete
    		End If
	
		Dim oTitleBlock As Inventor.TitleBlock
		oTitleBlock = oSheet.AddTitleBlock("LIB", ,sPromptStrings)

End Function&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;This is an example ( I am still running into issues passing the prompt strings to the function so that it can appropriately fill in my titleblock.) - oFileDoc was the part giving me issues.&lt;/P&gt;</description>
    <pubDate>Wed, 25 Mar 2015 17:37:32 GMT</pubDate>
    <dc:creator>MechMachineMan</dc:creator>
    <dc:date>2015-03-25T17:37:32Z</dc:date>
    <item>
      <title>Best Way to Define Seperate Documents</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/best-way-to-define-seperate-documents/m-p/5557289#M54875</link>
      <description>&lt;P&gt;In my recent coding I came across some issues with defining documents and getting a LateGet Error, so I was wondering what the actual best practice for doing this is or what the difference may be.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to switch between multiple documents during one rule.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;-&amp;gt; By Using oDoc = ThisApplication.ActiveDocuments&amp;lt;- Does this hold the same document even if i switch documents, or will it just pull the active &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;document again?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;By using oDoc = ThisApplication.Documents.ItemByName()&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;BY using oDoc = ThisApplication.Documents.ItemByName().Open&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Or with oDoc = .... .AddUsingTemplate()&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there a difference in how they define and call the document?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This all results because I used the oDoc = ... .AddUsingTemplate and then called the file using oDoc later on, after switching documents multiple times, and then kept on getting a .LateGet / LateBinding error.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So for my work around, I had just added in a function that accessed the active document, which was my new document, to add a title block.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help/insight would be helpful!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;Sub Main()

For Each oSheet In ThisApplication.ActiveDocument.Sheets


		Dim sPromptStrings(4) As String
Try
		sPromptStrings(0) = oSheet.TitleBlock.GetResultText(oSheet.TitleBlock.Definition.Sketch.TextBoxes.Item(48)) ' Title
		sPromptStrings(1) = oSheet.TitleBlock.GetResultText(oSheet.TitleBlock.Definition.Sketch.TextBoxes.Item(49)) 'DESCRIPTION 1
		sPromptStrings(2) = oSheet.TitleBlock.GetResultText(oSheet.TitleBlock.Definition.Sketch.TextBoxes.Item(50)) 'DESCRIPTION 2
		sPromptStrings(3) = oSheet.TitleBlock.GetResultText(oSheet.TitleBlock.Definition.Sketch.TextBoxes.Item(52)) 'CUSTOMER DRAWING#
		sPromptStrings(4) = oSheet.TitleBlock.GetResultText(oSheet.TitleBlock.Definition.Sketch.TextBoxes.Item(53)) 'SCALE
		

Catch
End Try
		
		oFileDoc=ThisApplication.Documents.Add(kDrawingDocumentObject,"C:\User.idw", True)

		oSheet.CopyTo(oFileDoc)

		oFileDoc.Sheets.Item(oFileDoc.Sheets.Count).Activate
		
		oFile = "C:\" &amp;amp; oSheet.TitleBlock.GetResultText(oSheet.TitleBlock.Definition.Sketch.TextBoxes.Item(52))  &amp;amp; ".idw"
			'Directory and comments.
		
		oFileDoc.Activate
		
		If Not oFileDoc.ActiveSheet.TitleBlock Is Nothing Then
      		oFileDoc.ActiveSheet.TitleBlock.Delete
    	End If

		Dim oTitleBlock As Inventor.TitleBlock
		
		oAddTb
		
		MsgBox("oAddTb Ran Successfully!")
		ThisApplication.ActiveDocument.Sheets.Item(1).Delete
		ThisApplication.ActiveDocument.SaveAs(oFile, False)
'		oFileDoc.Close
Next
End Sub

Function oAddTb

		'Dim oSheet As Sheet = ThisApplication.ActiveDocument.Sheets.Item(ThisApplication.ActiveDocument.Sheets.Count)

		Dim oSheet As Sheet = ThisApplication.ActiveDocument.ActiveSheet

		Dim sPromptStrings(4) As String
		sPromptStrings(0) = "A" ' Title
		sPromptStrings(1) = "A"
		sPromptStrings(2) = "A"
		sPromptStrings(3) = "A"
		sPromptStrings(4) = "A"

		If Not oSheet.TitleBlock Is Nothing Then
      		oSheet.TitleBlock.Delete
    		End If
	
		Dim oTitleBlock As Inventor.TitleBlock
		oTitleBlock = oSheet.AddTitleBlock("LIB", ,sPromptStrings)

End Function&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;This is an example ( I am still running into issues passing the prompt strings to the function so that it can appropriately fill in my titleblock.) - oFileDoc was the part giving me issues.&lt;/P&gt;</description>
      <pubDate>Wed, 25 Mar 2015 17:37:32 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/best-way-to-define-seperate-documents/m-p/5557289#M54875</guid>
      <dc:creator>MechMachineMan</dc:creator>
      <dc:date>2015-03-25T17:37:32Z</dc:date>
    </item>
    <item>
      <title>Re: Best Way to Define Seperate Documents</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/best-way-to-define-seperate-documents/m-p/5557687#M54881</link>
      <description>&lt;P&gt;I fully fixed the problem I was having. It arose because I was being lazy and not defining variables as I used them, which caused the .LateBinding.LateGet error to continuously appear.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Looking upon msdn, that error is caused when variables are not declared. Henceforth, I went through my program and pre-declared everything, and now it works perfect.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 25 Mar 2015 22:07:17 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/best-way-to-define-seperate-documents/m-p/5557687#M54881</guid>
      <dc:creator>MechMachineMan</dc:creator>
      <dc:date>2015-03-25T22:07:17Z</dc:date>
    </item>
  </channel>
</rss>

