Loop errors out after 6 loops

Loop errors out after 6 loops

Preston_Reed
Advocate Advocate
642 Views
5 Replies
Message 1 of 6

Loop errors out after 6 loops

Preston_Reed
Advocate
Advocate

Hello, I am trying to test some automation stuff and i have code to place drawings.  It stops running after 6 loops and it seems to be related with numbers.  I cant get anything over 6 to run without error.  

 

In my folder I have 13 parts, all names Test1, Test2, Test3 and so on.  I did this because I was having an issue selecting all based off of file type.  If I set i = 7 or more it wont work and the loop stops at 7.  I changed i from integer to long and it didnt help.  Any suggestions as to why this happening?? 

 

Sub Main()
	PlaceView
End Sub
	
Sub PlaceView()
	
For i As Integer = 1 To 13
'Set a reference to the drawing document.
'This assumes a drawing document is active.
Dim oDrawDoc As DrawingDocument
oDrawDoc = ThisApplication.ActiveDocument

'Set a reference to the sheet format named "Custom D, 5 View"
Dim oFormat As SheetFormat
Try
oFormat = oDrawDoc.SheetFormats.Item("Custom D, 5 View")
Catch
MessageBox.Show("Error: C size, 4 view might not exist.", "iLogic")
Return
End Try

'Open the model document invisible
Dim oModel As Document
oModel = ThisApplication.Documents.Open("X:\My Documents\LOCAL PROJECTS\CONFIGURATORS\SC-SERIES_U20D\Parts\PartsTest\TEST"& i & ".ipt", False)

'Create a new sheet based on the sheet format using the specified model
Dim oSheet As Sheet
oSheet = oDrawDoc.Sheets.AddUsingSheetFormat(oFormat, oModel)

Next

End Sub
0 Likes
Accepted solutions (1)
643 Views
5 Replies
Replies (5)
Message 2 of 6

WCrihfield
Mentor
Mentor

Hi @Preston_Reed.  What is the error message saying?  If it is in English, can you screen capture the both tabs of the error message for us to take a look at.  What all file types are those Test1, Test2...files?  Are they all ".ipt" or ".iam" type files?

Also, for efficiency, I would move you loop starter line:

For i As Integer = 1 To 13

down to just before or after your oModel variable declaration line:

Dim oModel As Document

...because the stuff before that does not nee to repeat every time around.  Just a suggestion.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 6

Preston_Reed
Advocate
Advocate

Ok here is what the folder looks like, I just took all of the piece parts which usually have the name of something like BOTTOM, RIGHT, TOP ect and named them Test1 and so on in the folder.  I couldn't figure out how to run though the files and select only the .ipt files so i just named them Test1 in the folder to see if i could make something like this work.  

 

Here are the error messages.  I tried moving i as integer down right above oModel and i still have the same error

 

PREED7QR59_0-1658255975153.png

PREED7QR59_1-1658256029063.pngPREED7QR59_2-1658256168237.png

 

PREED7QR59_3-1658256198217.png

 

0 Likes
Message 4 of 6

Preston_Reed
Advocate
Advocate

Opps i replied to myself, see above

0 Likes
Message 5 of 6

WCrihfield
Mentor
Mentor
Accepted solution

The error indicates it is having trouble opening the document(s).

I'm still not really sure what may be causing the problem(s).

However, here is another way of getting all the part files (each is a String representing its FullFileName) in that directory into a collection, then looping through that directly.  Assuming that parts 1 through 13 are the only ones in there.

Dim oDrawDoc As DrawingDocument = ThisApplication.ActiveDocument
Dim oFormat As SheetFormat
Try
	oFormat = oDrawDoc.SheetFormats.Item("Custom D, 5 View")
Catch
	MessageBox.Show("Error: D size, 5 view might not exist.", "iLogic")
	Return
End Try
Dim oPath As String = "X:\My Documents\LOCAL PROJECTS\CONFIGURATORS\SC-SERIES_U20D\Parts\PartsTest\"
Dim oPartFiles As String() = System.IO.Directory.GetFiles(oPath, "*.ipt", System.IO.SearchOption.TopDirectoryOnly)
If IsNothing(oPartFiles) OrElse oPartFiles.Count = 0 Then Return
Dim oModel As Document
Dim oSheet As Sheet
For Each oPartFile In oPartFiles
	oModel = ThisApplication.Documents.Open(oPartFile, False)
	oSheet = oDrawDoc.Sheets.AddUsingSheetFormat(oFormat, oModel)
Next

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 6 of 6

Preston_Reed
Advocate
Advocate

That worked!  Thank you very much

0 Likes