Modify batchplot export not to open all IDW after cancel

Modify batchplot export not to open all IDW after cancel

koenroovers
Enthusiast Enthusiast
110 Views
2 Replies
Message 1 of 3

Modify batchplot export not to open all IDW after cancel

koenroovers
Enthusiast
Enthusiast

Hello, 

 

I have a batchplot export, found on this forum and it works like a charm.

Only thing i want to change is when somebody cancels the operation using the X in the command window the ilogic cancels. Now all drawings are opened and closed even if you try to cancel.

 

Can somebody help me?

 

Thank you.

 

Sub Main()
	
	Dim mylist As New List(Of String)
	Dim sFiles As New List(Of String)
	
    ' Create a new FileDialog object.
    Dim oFileDlg As Inventor.FileDialog
     ThisApplication.CreateFileDialog(oFileDlg)

    ' Define the filter to select part and assembly files or any file.
    oFileDlg.Filter = "Inventor Files (*.idw ;*.dwg)|*.idw;*.dwg|All Files (*.*)|*.*"

    ' Define the drawing files filter to be the default filter.
    oFileDlg.FilterIndex = 1

    ' Set the title for the dialog.
    oFileDlg.DialogTitle = "Select drawings"

    ' Set the initial directory that will be displayed in the dialog.
    oFileDlg.InitialDirectory = "C:\Users\Enter Name Here"
	oFileDlg.MultiSelectEnabled = True
'    oFileDlg.ShowSave
	 oFileDlg.ShowOpen
	 
	If oFileDlg.FileName = Nothing Then	
	    ElseIf oFileDlg.FileName <> "" Then
			
			'Process the multi selected files which form a  pipe like "C\123.ipt|C\124.ipt"
			mylist = oFileDlg.FileName.Split("|").ToList
			
			For Each item In mylist
				sFiles.Add(item.ToString)
			Next
		End If
		
  Dim myDate As String = Now().ToString("dd-MM-yyyy")
  myDate = myDate.Replace(":","")  ' & " - " & TypeString
 UserSelectedActionList = New String(){"DWG & PDF", "PDF Only", "DWG Only"}
  UserSelectedAction = InputListBox("What action must be performed with selected drawings?", _
          UserSelectedActionList, UserSelectedActionList(0), Title := "Action to Perform", ListName := "Options")
      Select UserSelectedAction
   Case "DWG & PDF": UserSelectedAction = 3
   Case "PDF Only": UserSelectedAction = 1
   Case "DWG Only" : UserSelectedAction = 2
	 	   
   End Select
   
	For Each sFile As String In sFiles	
		Dim oDoc As DrawingDocument = ThisApplication.Documents.Open(sFile, True)
     	         'Call your pdf sub routine here. 
				 Call MakePDFFromDoc(oDoc, myDate, UserSelectedAction)
				 oDoc.Close
	Next
	
	
	'Clear the list
	sFiles.Clear
 
 End Sub
	
 Sub MakePDFFromDoc(ByRef oDocument As Document, DateString As String, UserSelectedAction As Integer)
 ' oPath = oDocument.Path
 ' oFileName = oDocument.FileName(False) 'without extension
  'oDocument = ThisApplication.ActiveDocument
  oPDFAddIn = ThisApplication.ApplicationAddIns.ItemById _
  ("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}")
  oContext = ThisApplication.TransientObjects.CreateTranslationContext
  oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
  oOptions = ThisApplication.TransientObjects.CreateNameValueMap
  oDataMedium = ThisApplication.TransientObjects.CreateDataMedium
 oFullFileName = oDocument.File.FullFileName
  oPath = Left(oFullFileName, InStrRev(oFullFileName, "\")-1)
  oFileName = Right(oFullFileName, Len(oFullFileName)-InStrRev(oFullFileName, "\"))
  oFilePart = Left(oFileName, InStrRev(oFileName, ".")-1)
 'oRevNum = oDocument.iProperties.Value("Project", "Revision Number")
  'oDocument = ThisApplication.ActiveDocument
 ' If oPDFAddIn.HasSaveCopyAsOptions(oDataMedium, oContext, oOptions) Then
  oOptions.Value("All_Color_AS_Black") = 0
  oOptions.Value("Remove_Line_Weights") = 0
  oOptions.Value("Vector_Resolution") = 400
  oOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintAllSheets
  'oOptions.Value("Custom_Begin_Sheet") = 2
  'oOptions.Value("Custom_End_Sheet") = 4
 ' End If
 'get PDF target folder path
  'oFolder = Left(oPath, InStrRev(oPath, "\")) & "PDF"
  oFolder = oPath 
  oDirectoryName = System.IO.Path.GetDirectoryName(oFullFileName)
 'Check for the PDF folder and create it if it does not exist
  If Not System.IO.Directory.Exists(oFolder) Then
   System.IO.Directory.CreateDirectory(oFolder)
  End If
 'Set the PDF target file name
  oDataMedium.FileName = oFolder & "\" & oFilePart & ".pdf"
 'Publish document
  If (UserSelectedAction = 1) Or (UserSelectedAction = 3) Then
   oPDFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)'For PDF's
  End If
  If (UserSelectedAction = 2) Or (UserSelectedAction = 3) Then
   oDocument.SaveAs(oFolder & "\" & oFilePart & ".dwg", True) 'For DWG's
  End If
  'oDocument.SaveAs(oFolder & "\" & ThisDoc.ChangeExtension(".DWG"), True) 'For DWG's
  '------end of iLogic-------
 End Sub
0 Likes
111 Views
2 Replies
Replies (2)
Message 2 of 3

WCrihfield
Mentor
Mentor

Hi @koenroovers.  This looks like a good candidate for using an Inventor.ProgressBar.  It may not be the simplest or easiest to add and use properly, but is probably what you would want.  Using it would require including additional code routines, and variables that are declared between those routines, so that all routines can access them though, and would need to include at least one 'event handler'.  When we use one of these, we can include a cancel button in the progress bar.  But its not as simple as it sounds, because there is no association between the ProgressBar or its cancel button and any other code processes.  So, you would 'listen for if/when the user clicks that cancel button (the ProgressBar.OnCancel Event), and when that event happens, some code within the Sub routine handling that event can change the value of a globally shared Boolean type variable (declared between the major code routines).  Then, in your 'Main' code, just inside a 'loop' of files, it should check the value of that Boolean variable, to see if the user has clicked that cancel button, and if they have, exit the loop without going any further.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 3

J-Camper
Advisor
Advisor

If you want the cutout to be the user selection point, then you can add a Case Else statement to handle any case that you didn't explicitly program for.  In that case you exit the rule.  You can add an alert for feedback if you want:

Select UserSelectedAction
   Case "DWG & PDF": UserSelectedAction = 3
   Case "PDF Only": UserSelectedAction = 1
   Case "DWG Only" : UserSelectedAction = 2
   Case Else : Logger.Trace("Unprogrammed responce. Nothing Will Happen."): Exit Sub
End Select

 

 

I would also early exit if the filename is nothing instead of letting the iLogic continue to ask the next prompt:

If oFileDlg.FileName = Nothing Then	
	Exit Sub 'No filename, so do nothing
ElseIf oFileDlg.FileName <> "" Then
	
	'Process the multi selected files which form a  pipe like "C\123.ipt|C\124.ipt"
	mylist = oFileDlg.FileName.Split("|").ToList
	
	For Each item In mylist
		sFiles.Add(item.ToString)
	Next
End If

 

0 Likes