DWG TranslatorAddIn PrintRangeEnum.kPrintCurrentSheet prints all sheet

DWG TranslatorAddIn PrintRangeEnum.kPrintCurrentSheet prints all sheet

mallorn
Advocate Advocate
393 Views
3 Replies
Message 1 of 4

DWG TranslatorAddIn PrintRangeEnum.kPrintCurrentSheet prints all sheet

mallorn
Advocate
Advocate

Hello, I have my script like below, but I'm getting still all sheet/pages exported instead of the current:

BASICALLY I want only first page for DWG... (but I can't find where to set PrintRangeEnum to a value - I can find only examples for PrintManager)

Code:

Dim oDoc As Document
Dim doDWG, doPDF As Boolean

vbBoxQuestion = MessageBox.Show("Export DWGs?" & vbLf & vbLf & "Cancel to Eport DWGs without PDFs", "EXPORT PDF AND DWG FOR ALL OPENED DOCUMENTS", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2)
        If vbBoxQuestion = vbYes Then
            doDWG = True
			doPDF = True
        Else If vbBoxQuestion = vbCancel Then
			doDWG = True
			doPDF = False
		Else 
			doDWG = False
			doPDF = True
		End If


'[ for PDF export:
Dim oPDFAddIn As TranslatorAddIn
oPDFAddIn = ThisApplication.ApplicationAddIns.ItemById("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}")
oContext = ThisApplication.TransientObjects.CreateTranslationContext
oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
oPDFOptions = ThisApplication.TransientObjects.CreateNameValueMap
oDataMediumPDF = ThisApplication.TransientObjects.CreateDataMedium

'set PDF Options
	Dim PDFExportFilename As String = ".pdf"
	'If oPDFAddIn.HasSaveCopyAsOptions(oDataMedium, oContext, oOptions) Then
	'If oPDFAddIn.HasSaveCopyAsOptions(oDoc, oContext, oOptions) Then
		oPDFOptions.Value("All_Color_AS_Black") = 0
		oPDFOptions.Value("Remove_Line_Weights") = 0
		oPDFOptions.Value("Vector_Resolution") = 300
		oPDFOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintAllSheets
	'End If
'] For PDF export:

	'[ for DWG export:
		Dim DWGExportFilename As String = ".dwg"
		Dim oDWGAddIn As TranslatorAddIn
		oDWGAddIn = ThisApplication.ApplicationAddIns.ItemById("{C24E3AC2-122E-11D5-8E91-0010B541CD80}")
		Dim oDataMediumDWG As DataMedium
	    oDataMediumDWG = ThisApplication.TransientObjects.CreateDataMedium
		oDWGOptions = ThisApplication.TransientObjects.CreateNameValueMap
		oDWGOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintCurrentSheet
	'] for DWG export:




For Each oDoc In ThisApplication.Documents
	If oDoc.DocumentType = DocumentTypeEnum.kDrawingDocumentObject Then
		Dim fileNameCore As String = Left(oDoc.FullDocumentName, oDoc.FullDocumentName.Length-4)
		
		
		'Set the PDF target file name
		If doPDF = True Then
		oDataMediumPDF.FileName = fileNameCore & PDFExportFilename
		Logger.Trace(fileNameCore & PDFExportFilename)
		End If 
	
		If doDWG = True Then 
			oDataMediumDWG.FileName = fileNameCore & DWGExportFilename
			Logger.Trace(fileNameCore & DWGExportFilename)
		End If 
		
		
		Try 
			'Publish document
			If doPDF = True Then
				oPDFAddIn.SaveCopyAs(oDoc, oContext, oPDFOptions, oDataMediumPDF)
			End If 	
			
			If doDWG = True Then
				oDWGAddIn.SaveCopyAs(oDoc, oContext, oDWGOptions, oDataMediumDWG)
			End If
		Catch
			MessageBox.Show("Error writing out file", "iLogic")
			bError = True
		End Try

	End If
Next

MessageBox.Show("Done.", "Exporting")

 

-------------------------
Tomasz Malinowski
0 Likes
Accepted solutions (1)
394 Views
3 Replies
Replies (3)
Message 2 of 4

TA.Fehr
Advocate
Advocate

I may be missing something, but it looks like your code is set to print all sheets as pdf and the current sheet as DWG.

The DWG sheet range is set in your code PrintRangeEnum.kPrintCurrentSheet and PrintRangeEnum.kPrintAllSheets for PDF. So as written you should get two files for each document that is open. PDF's that include all the sheets, and a DWG that hast he current sheet.

Is this not what you're getting?

0 Likes
Message 3 of 4

mallorn
Advocate
Advocate

I get 1 file for PDF with all sheets (as I want) and as many DWGs as number of sheets... PrintRangeEnum.kPrintCurrentSheet does not make only 1 file with current sheet for DWG export...

I get more dwg files than 1, if I have more sheets.

-------------------------
Tomasz Malinowski
0 Likes
Message 4 of 4

jjstr8
Collaborator
Collaborator
Accepted solution

The only valid option for the DWG export is to specify the INI settings file.  In your INI file, if the 'ALL SHEETS' line is set to 'No', the active sheet is what gets exported with name given in oDataMediumDWG.

 

oOptions.Value("Export_Acad_IniFile") = <string with full ini filename>

 

I suggest doing a manual 'Export to DWG' from any drawing and using that to create a separate INI with all of the settings.  From the Save As dialog box, switch the Save as Type to AutoCAD DWG and click on Options.  Uncheck 'All Sheets' on the second page of settings and click 'Save Configuration' to save a new INI file.  Use the full path and filename of that file in the code above.

 

 

 

 

0 Likes