Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.
MechMachineMan
359 Views, 1 Reply

Best Way to Define Seperate Documents

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.

 

I need to switch between multiple documents during one rule.

 

-> By Using oDoc = ThisApplication.ActiveDocuments<- Does this hold the same document even if i switch documents, or will it just pull the active                                              document again?

 

By using oDoc = ThisApplication.Documents.ItemByName()

 

BY using oDoc = ThisApplication.Documents.ItemByName().Open

 

Or with oDoc = .... .AddUsingTemplate()

 

Is there a difference in how they define and call the document?

 

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.

 

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.

 

 

Any help/insight would be helpful!

 

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:\" & oSheet.TitleBlock.GetResultText(oSheet.TitleBlock.Definition.Sketch.TextBoxes.Item(52))  & ".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

 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.


--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type