Print idw file from a list

Print idw file from a list

aries.1482
Enthusiast Enthusiast
853 Views
8 Replies
Message 1 of 9

Print idw file from a list

aries.1482
Enthusiast
Enthusiast

Hi, I have a list of file path (txt or excel) like this:

C:\folder 1\a.idw

C:\folder 2\b.idw

C:\folder 3\c.idw

...

I need ilogic to do:

- Open a.idw, print and close

- Open b.idw, print and close

... and so on

If there isn't *.idw in the path location, it will bypass and continue with next file.

Please help me! Thank you.

 

0 Likes
Accepted solutions (1)
854 Views
8 Replies
Replies (8)
Message 2 of 9

bhavik4244
Collaborator
Collaborator

@aries.1482 

 

There could be a solution with iLogic, however, have you ever tried to do it with Task Schedular? It's really good.


Bhavik Suthar
Message 3 of 9

Michael.Navara
Advisor
Advisor
Accepted solution

Here is sample code. You need to implement printMgr setup and loading of idw files list

 

Sub main
	Dim idwPaths As String() = LoadIdwPaths()

	For Each idwPath As String In idwPaths
		If Not System.IO.File.Exists(idwPath) Then 
			Logger.Warn("File not found{0}{1}", vbCrLf, idwPath)
			Continue For
		End If
		Try
			Dim drawingDoc As DrawingDocument = ThisApplication.Documents.Open(idwPath)
			Dim printMgr As PrintManager = drawingDoc.PrintManager

			'SETUP printMgr HERE

			printMgr.SubmitPrint()
			drawingDoc.Close(True)
		Catch ex As Exception
			Logger.Error("Print failed{0}{1}", vbCrLf, ex.Message)
		End Try

	Next
End Sub
Function LoadIdwPaths() As String()
'Implement your idw list source here
	Dim idwPaths As String() = {
		"C:\folder 1\a.idw",
		"C:\folder 2\b.idw",
		"C:\folder 3\c.idw"
	}
	Return idwPaths
End Function

 

Message 4 of 9

aries.1482
Enthusiast
Enthusiast

Yes, I tried Task Scheduler, but the problem is I want to print any file with exactly order in the list. Task Scheduler only print all file with random order.

0 Likes
Message 5 of 9

WCrihfield
Mentor
Mentor

If you want to retrieve this type of data with an iLogic rule, you first need to make the decision mentioned in your first posts, whether the source will be a text file, or an Excel spreadsheet, because the process and code needed to do so will vary greatly for each process.  Once you have decided on file type, next decide on how the data will be laid out within that file, because you will need to know when trying to work with it from code.  For instance, if you are planning on having a title line/row or column header line/row, then the actual data will be starting on some lower line/row, you will need to know that when attempting to retrieve data from that file, so you don't try to process title or column header data or empty lines/rows as file location data.  You will most likely have to set the code up so that when it tries to process a line/row that contains no data, it will exit the rule, so it doesn't continue to run endlessly.  Then, you will also need to avoid empty lines/rows in the middle of your list.

 

Once we know how you plan on specifying file location & name (hard coded, File Open dialog, etc), file type, and how data is laid out within, we may be able to further define the data retrieval portion of the code.  Then the printing loop code is fairly basic, as you can see from @Michael.Navara's code.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 6 of 9

aries.1482
Enthusiast
Enthusiast

Thanks, it works well. But I must paste the list, anyway to get path from external list file: "list.txt"?

0 Likes
Message 7 of 9

aries.1482
Enthusiast
Enthusiast

I use txt file type for the list, (I think it is more simply than excel) contain only idw file path in separate line with out blank line.

(Sorry, English is not my language and may be I can't explain more clearly)

0 Likes
Message 8 of 9

Michael.Navara
Advisor
Advisor

This is very easy to implement. Much easier then read data from Excel 😉

For more information about OpenFileDialog and its options see here

https://docs.microsoft.com/en-us/dotnet/api/system.windows.forms.openfiledialog?view=netframework-4....

 

 

Imports System.Windows.Forms

Sub Main
    Dim idwPaths = LoadIdwPaths()
    Logger.Debug("Files to print:" & vbcrlf & String.Join(vbCrLf, idwPaths))
End Sub


Function LoadIdwPaths() As String()

    Dim openFileDialog As New OpenFileDialog()
    openFileDialog.Filter = "All files|*.*|Text files|*.txt|Csv files|*.csv"
    openFileDialog.FilterIndex = 2

    If openFileDialog.ShowDialog <> DialogResult.OK Then Return New String() {}

    Dim fileName = openFileDialog.FileName
    'Select appropriate encoding, 
    'especially when you use some non-ASCII chars in path and file names
    Dim encoding = System.Text.Encoding.UTF8

    Dim lines = System.IO.File.ReadAllLines(fileName, encoding)

    Return lines
End Function

 

Message 9 of 9

aries.1482
Enthusiast
Enthusiast

Thank you. U saved my day.

0 Likes