iLogic to Batch Export PDF and DXF

iLogic to Batch Export PDF and DXF

esaldana
Enthusiast Enthusiast
4,144 Views
12 Replies
Message 1 of 13

iLogic to Batch Export PDF and DXF

esaldana
Enthusiast
Enthusiast

Good morning everyone,

I found this great code (shown below) at: AutoDesk Inventor - Batch Exporting PDFs & DXFs with iLogic - Thingimajigs,

done by Lance: Lance Skelly | GrabCAD

Is really good, and saving me a lot of time when exporting,

the question I have is if there is a way to export only the profile of my parts when exporting to DXF's and not the whole title block and dimensions? any suggestions are welcome.

Thanks you,

 

code:

Sub Main()
  Dim myDate As String = Now().ToString("yyyy-MM-dd HHmmss")
  myDate = myDate.Replace(":","")  ' & " - " & TypeString
 userChoice = InputRadioBox("Defined the scope", "This Document", "All Open Documents", True, Title := "Defined the scope")
 UserSelectedActionList = New String(){"DXF & PDF", "PDF Only", "DXF Only"}
  UserSelectedAction = InputListBox("What action must be performed with selected views?", _
          UserSelectedActionList, UserSelectedActionList(0), Title := "Action to Perform", ListName := "Options")
      Select UserSelectedAction
   Case "DXF & PDF": UserSelectedAction = 3
   Case "PDF Only": UserSelectedAction = 1
   Case "DXF Only":    UserSelectedAction = 2
   End Select
 If userChoice Then
   Call MakePDFFromDoc(ThisApplication.ActiveDocument, myDate, UserSelectedAction)
  Else
   For Each oDoc In ThisApplication.Documents
    If oDoc.DocumentType = kDrawingDocumentObject
     Try
      If Len(oDoc.File.FullFileName)>0 Then
       Call MakePDFFromDoc(oDoc, myDate, UserSelectedAction)
      End If
     Catch
     End Try
    End If
   Next
  End If
 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 & "\iLogic PDF's (" & DateString & ")"
 '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 & ".dxf", True) 'For DXF's
  End If
  'oDocument.SaveAs(oFolder & "\" & ThisDoc.ChangeExtension(".dxf"), True) 'For DXF's
  '------end of iLogic-------
 End Sub

 

0 Likes
Accepted solutions (1)
4,145 Views
12 Replies
Replies (12)
Message 2 of 13

Curtis_Waguespack
Consultant
Consultant

Hi @esaldana 

 

You can turn off the layers of the objects you don't want to include and then do the export, then turn the layers back on.

 

Here is a PDF export example that demonstrates this.

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

 

oPath = ThisDoc.Path
oFileName = ThisDoc.FileName(False) 'without extension

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

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

'get PDF target folder path
oFolder = Left(oPath, InStrRev(oPath, "\")) & "PDF"


'add layers to collection
Dim oCollection As ObjectCollection
oCollection = ThisApplication.TransientObjects.CreateObjectCollection
oLayers = ThisApplication.ActiveDocument.StylesManager.Layers
oCollection.Add(oLayers(("Title (ANSI)")))
oCollection.Add(oLayers(("Border (ANSI)")))
oCollection.Add(oLayers(("Dimension (ANSI)")))

'turn layers off
For Each oLayer In oCollection
	oLayer.visible = False 
Next
ThisApplication.ActiveView.Update()

'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 & "\" & oFileName & ".pdf"
oPDFAddIn.SaveCopyAs(ThisApplication.ActiveDocument, oContext, oOptions, oDataMedium)'For PDF's

MessageBox.Show("PDF saved to: " & oFolder, "iLogic")
Process.Start(oFolder) 

'turn layers back on
For Each oLayer In oCollection
	oLayer.visible = True 
Next

 

EESignature

Message 3 of 13

esaldana
Enthusiast
Enthusiast

Thank you Curtis,

I applied the section of the layers on/off to the existing code and it works really well,

Not to be too demanding this morning, but is there any way to instead of cancelling the layers that I don't want, just export to dxf the flatten portion , I'm using exclusively sheet metal and all that I always need is the flat pattern to be either lasered or punched. Usually I used the export from the actual sheet metal part but that way I have to go one by one, while this code is batching from the drawings which is nice.

thanks for you help,

 

Eric

0 Likes
Message 4 of 13

Curtis_Waguespack
Consultant
Consultant

Hi @esaldana , 


So you want to run the rule from the assembly file and export DXFs for all sheet metal part flat patterns?

 

Or you want to run the rule from a drawing file of the assembly and export DXFs for all sheet metal part flat patterns?

 

Or you want to run the rule from drawing file that contains views of multiple flat patterns and export DXFs for all sheet metal part flat patterns?

 

 

 

EESignature

0 Likes
Message 5 of 13

esaldana
Enthusiast
Enthusiast

Hi @Curtis_Waguespack ,

really appreciate your attention to this message,

Wherever is the easiest, I will always have a single file (DWG) with several sheets (assembly drawing firs, then the sub-assemblies and finally all the parts) and need to create a single PDF with all those sheets included, finally I need to create DXFs' for all the parts having a flat pattern on them.

What do you suggest me?  It could be from either the top assembly or top drawing.

Honestly what I liked it from that original code was being able to select from either export only PDF or DXF or both and also the creation of folder with time stamp, so I could know my latest output.

But it can be different as soon it accomplish the tasks.

 

Thank you,

 

Eric

Message 6 of 13

Curtis_Waguespack
Consultant
Consultant

Hi @esaldana 

I would run this from the top level drawing, but you can run it from the top level assembly...

 

if you run it from the assembly, you get a PDF of the assembly, which I'm not sure sure is useful...

 

This runs through all the referenced files and DXFs out the sheet metal flat patterns... if there is no flat pattern it will create it, so you might see the model open and close in that case.

 

I just set it to output to a temp folder, but you can set the folder as needed... there are a few examples commented out for this also.

 

Post back if it's not exactly what you're after, it can likely be tweaked to be what you're after.

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

Sub Main()
	
  	Dim myDate As String = Now().ToString("yyyy-MM-dd HH:mm:ss")	
	myDate = myDate.Replace(":", ".")  

	'change this as needed
	oRoot = "C:\Temp\"
'	oRoot = ThisDoc.Path 'use the document's containing folder path

	'change this as needed
	oSuffix = "Outputs" 
	'oSuffix = iProperties.Value("Project", "Project") 'use the document's Project#
	'oSuffix = iProperties.Value("Project", "Part Number") 'use the document's Part#
	
	'get target folder path
	oFolder = oRoot & "\" & oSuffix & " (" & myDate & ")"
	
	'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
	
	'open the folder
	Process.Start(oFolder) 
	
	Dim oDoc As Document
	oDoc = ThisApplication.ActiveDocument	
	
	'PDF of the file you're running it this from
	Call PDF_Out(oDoc, oFolder)
	
	'Loop through all referenced documents
	j= 1
	For Each oDoc In ThisApplication.ActiveDocument.AllReferencedDocuments	
		oName = oDoc.DisplayName
		ck = j Mod 2 
		If ck = 0 Then 
			oFlicker = ".......... "
		Else
			oFlicker = ".... "	
		End If
		ThisApplication.StatusBarText = "Processing DXF" & oFlicker & oName
		j = j + 1 

		'created DXF's of sheetmetal parts
		Call DXF_Out(oDoc, oFolder)
	
	Next

	
	ThisApplication.StatusBarText = "Done!!!!!"
End Sub
 
 
 Sub DXF_Out(ByRef oDoc As Document, oFolder As String)
	
	oFullFileName = oDoc.FullFileName
	oFileName = Right(oFullFileName, Len(oFullFileName) - InStrRev(oFullFileName, "\"))
	oName = Left(oFileName, InStrRev(oFileName, ".") - 1) 'name without extension

	'look at only Sheet metal parts
	If oDoc.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then

		Dim oCompDef As SheetMetalComponentDefinition
		oCompDef = oDoc.ComponentDefinition		
		
		i = 0
		For Each oBody In oCompDef.SurfaceBodies
			If oBody.IsSolid = True Then
				i = i +1
			End If
		Next

		If i > 1 Then
		 	Exit Sub
		End If 

		'check for flat pattern	
		If oCompDef.HasFlatPattern = False Then 
			oCompDef.Unfold 
			oCreated_Flat = True
		Else 'if flat pattern exists		
			oCompDef.FlatPattern.Edit 
		End If
		
		sOut = "FLAT PATTERN DXF?AcadVersion=2000&OuterProfileLayer=IV_INTERIOR_PROFILES"
		sFullDXFname = oFolder & "\" & oName & ".dxf"
		
		'Output the DXF
		oCompDef.DataIO.WriteDataToFile(sOut, sFullDXFname)
		
		oCompDef.FlatPattern.ExitEdit
		Try
		If oCreated_Flat = True Then oDoc.Save
		Catch
		End Try
		oDoc.Close
	End If


 End Sub

Sub PDF_Out(ByRef oDocument As Document, oFolder As String)

	ThisApplication.StatusBarText = "Processing PDF.........." & oDocument.displayname
	oFullFileName = oDocument.FullFilename	
	oFileName = Right(oFullFileName, Len(oFullFileName) - InStrRev(oFullFileName, "\"))
	oName = Left(oFileName, InStrRev(oFileName, ".") -1) 'name without extension
	sFullPDFname = oFolder & "\" & oName & ".pdf"	
	
	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

	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

	'Set the PDF target file name
	oDataMedium.FileName = sFullPDFname
	'output the PDF
	oPDFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)		
End Sub

 

EESignature

0 Likes
Message 7 of 13

esaldana
Enthusiast
Enthusiast

Hi @Curtis_Waguespack ,

 

The PDF goes really well and fast, 

but is the only file in that temp folder,

I have the following error message:

 

esaldana_0-1622829311750.png

 

esaldana_1-1622829381482.png

 

I have absolutely no idea of the error meaning,

Do you see something there?

 

Thank you Curtis,

 

 

 

 

0 Likes
Message 8 of 13

Curtis_Waguespack
Consultant
Consultant

Hi @esaldana 

 

I just ran this on one of Autodesk's sample assemblies and the DXF part hit an error with that assembly in trying to access the sheet metal part files... so I added a missing line to open the files... it was probably accessing files in Inventor's memory when I ran this earlier.... so the error didn't happen...

 

Give this a try and see if that resolved it.

 

If not, What version of Inventor are you using?.... and can you provide a simple file set that demonstrates the problem, to test?

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

 

 

 

Sub Main()
	
  	Dim myDate As String = Now().ToString("yyyy-MM-dd HH:mm:ss")	
	myDate = myDate.Replace(":", ".")  

	'change this as needed
	oRoot = "C:\Temp"
	'oRoot = ThisDoc.Path 'use the document's containing folder path

	'change this as needed
	oSuffix = "Outputs" 
	'oSuffix = iProperties.Value("Project", "Project") 'use the document's Project#
	'oSuffix = iProperties.Value("Project", "Part Number") 'use the document's Part#
	
	'get target folder path
	oFolder = oRoot & "\" & oSuffix & " (" & myDate & ")"
	
	'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
	
	'open the folder
	Process.Start(oFolder) 
	
	Dim oDoc As Document
	oDoc = ThisApplication.ActiveDocument	
	
	'PDF of the file you're running it this from
	Call PDF_Out(oDoc, oFolder)
	
	'Loop through all referenced documents
	j= 1
	For Each oDoc In ThisApplication.ActiveDocument.AllReferencedDocuments	
		oName = oDoc.DisplayName
		ck = j Mod 2 
		If ck = 0 Then 
			oFlicker = ".......... "
		Else
			oFlicker = ".... "	
		End If
		ThisApplication.StatusBarText = "Processing DXF" & oFlicker & oName
		j = j + 1 

		'created DXF's of sheetmetal parts
		Call DXF_Out(oDoc, oFolder)
	
	Next

	
	ThisApplication.StatusBarText = "Done!!!!!"
End Sub
 
 
 Sub DXF_Out(ByRef oDoc As Document, oFolder As String)
	oCreated_Flat = False
	oFullFileName = oDoc.FullFileName
	oFileName = Right(oFullFileName, Len(oFullFileName) - InStrRev(oFullFileName, "\"))
	oName = Left(oFileName, InStrRev(oFileName, ".") - 1) 'name without extension
	Logger.Info("oName: " & oName)
	'look at only Sheet metal parts
	If oDoc.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then
		Logger.Info("Is Sheetmetal")
		Dim oCompDef As SheetMetalComponentDefinition
		oCompDef = oDoc.ComponentDefinition		
		
		i = 0
		For Each oBody In oCompDef.SurfaceBodies
			If oBody.IsSolid = True Then
				i = i +1
			End If
		Next

		If i > 1 Then
		 	Exit Sub
		End If 

		'check for flat pattern	
		If oCompDef.HasFlatPattern = False Then 
			Logger.Info("HasFlatPattern: " & HasFlatPattern)
			oCompDef.Unfold 
			oCreated_Flat = True
		Else 'if flat pattern exists
			Logger.Info("Trying to get flatpattern...")
			ThisApplication.Documents.Open(oFullFileName, True)
			oCompDef.FlatPattern.Edit 
		End If
		
		sOut = "FLAT PATTERN DXF?AcadVersion=2000&OuterProfileLayer=IV_INTERIOR_PROFILES"
		sFullDXFname = oFolder & "\" & oName & ".dxf"
		Logger.Info("sFullDXFname: " & sFullDXFname)
		'Output the DXF
		oCompDef.DataIO.WriteDataToFile(sOut, sFullDXFname)
		
		oCompDef.FlatPattern.ExitEdit
		Try
		If oCreated_Flat = True Then oDoc.Save
		Catch
		End Try
		oDoc.Close
	End If


 End Sub

Sub PDF_Out(ByRef oDocument As Document, oFolder As String)

	ThisApplication.StatusBarText = "Processing PDF.........." & oDocument.displayname
	oFullFileName = oDocument.FullFilename	
	oFileName = Right(oFullFileName, Len(oFullFileName) - InStrRev(oFullFileName, "\"))
	oName = Left(oFileName, InStrRev(oFileName, ".") -1) 'name without extension
	sFullPDFname = oFolder & "\" & oName & ".pdf"	
	
	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

	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

	'Set the PDF target file name
	oDataMedium.FileName = sFullPDFname
	'output the PDF
	oPDFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)		
End Sub

 

 

EESignature

0 Likes
Message 9 of 13

esaldana
Enthusiast
Enthusiast

Hi @Curtis_Waguespack ,

so close.

This time one of the DXF's was created (the 3rd one in the drawing, see attached PDF),  but not the others, got an error message after creating the first DXF.

I'm using Inventor 2020

 

Thank you Curtis,

 

esaldana_0-1622832825122.png

0 Likes
Message 10 of 13

Curtis_Waguespack
Consultant
Consultant
Accepted solution

Hi @esaldana 

 

Note sure what the issue is, but I added some debugging and error catching to this version, so maybe you can figure out what it's tripping on...

 

Go to the View tab , User Interface button/pulldown, and check the iLogic Log option, they you can watch the log and see if you can tell what the issue is with the part file.

 

If not, I'd need to have the files to test, if you can share them, you can zip them and attach them here.

 

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

 

Curtis_W_0-1622833870784.png

 

 

Sub Main()
	
  	Dim myDate As String = Now().ToString("yyyy-MM-dd HH:mm:ss")	
	myDate = myDate.Replace(":", ".")  

	'change this as needed
	oRoot = "C:\Temp"
	'oRoot = ThisDoc.Path 'use the document's containing folder path

	'change this as needed
	oSuffix = "Outputs" 
	'oSuffix = iProperties.Value("Project", "Project") 'use the document's Project#
	'oSuffix = iProperties.Value("Project", "Part Number") 'use the document's Part#
	
	'get target folder path
	oFolder = oRoot & "\" & oSuffix & " (" & myDate & ")"
	
	'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
	
	'open the folder
	Process.Start(oFolder) 
	
	Dim oDoc As Document
	oDoc = ThisApplication.ActiveDocument	
	
	'PDF of the file you're running it this from
	Call PDF_Out(oDoc, oFolder)
	
	'Loop through all referenced documents
	j= 1
	For Each oDoc In ThisApplication.ActiveDocument.AllReferencedDocuments	
		oName = oDoc.DisplayName
		ck = j Mod 2 
		If ck = 0 Then 
			oFlicker = ".......... "
		Else
			oFlicker = ".... "	
		End If
		ThisApplication.StatusBarText = "Processing DXF" & oFlicker & oName
		j = j + 1 

		'created DXF's of sheetmetal parts
		Call DXF_Out(oDoc, oFolder)
	
	Next

	
	ThisApplication.StatusBarText = "Done!!!!!"
End Sub
 
 
 Sub DXF_Out(ByRef oDoc As Document, oFolder As String)
	oCreated_Flat = False
	oFullFileName = oDoc.FullFileName
	oFileName = Right(oFullFileName, Len(oFullFileName) - InStrRev(oFullFileName, "\"))
	oName = Left(oFileName, InStrRev(oFileName, ".") - 1) 'name without extension	
	'look at only Sheet metal parts
	If oDoc.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then
		Logger.Info("File Name: " & oFileName)
		Logger.Info("Is Sheetmetal")
		Dim oCompDef As SheetMetalComponentDefinition
		oCompDef = oDoc.ComponentDefinition		
		
		i = 0
		Logger.Info("Looking at solid bodies....")
		For Each oBody In oCompDef.SurfaceBodies
			If oBody.IsSolid = True Then
				i = i +1
			End If
		Next

		If i > 1 Then
		 	Exit Sub
		End If 
		Logger.Info(".....solid bodies ok")

		'check for flat pattern	
		If oCompDef.HasFlatPattern = False Then 
			Logger.Info("HasFlatPattern: " & oCompDef.HasFlatPattern)
			Logger.Info("/////////////\\\\\\\\\\\\ Trying to create flatpattern...")
			Try
				oCompDef.Unfold 
				oCreated_Flat = True
			Catch ex As Exception
				oCreated_Flat = False
				Logger.Info("Problem creating flat!!!!")
				Logger.Info(ex.Message)
			End Try
		Else 'if flat pattern exists
			Logger.Info("HasFlatPattern: " & oCompDef.HasFlatPattern)
			Logger.Info("Trying to get flatpattern...")
			ThisApplication.Documents.Open(oFullFileName, True)
			Try
				oCompDef.FlatPattern.Edit 
			Catch ex As Exception
				Logger.Info("Problem editing flat!!!!")
				Logger.Info(ex.Message)
			End Try
		End If
		
		sOut = "FLAT PATTERN DXF?AcadVersion=2000&OuterProfileLayer=IV_INTERIOR_PROFILES"
		sFullDXFname = oFolder & "\" & oName & ".dxf"
		'Output the DXF
		oCompDef.DataIO.WriteDataToFile(sOut, sFullDXFname)
		Try
			Logger.Info("DXF created!!!:  " & sFullDXFname)
		Catch ex As Exception
			Logger.Info("Problem creating DXF!!!!")
			Logger.Info(ex.Message)
		End Try		
		
		oCompDef.FlatPattern.ExitEdit
		
		Try
			If oCreated_Flat = True Then oDoc.Save
		Catch ex As Exception
			Logger.Info("Saving the file.")
			Logger.Info(ex.Message)
		End Try
		
		oDoc.Close
		Logger.Info("*******************")
	End If


 End Sub

Sub PDF_Out(ByRef oDocument As Document, oFolder As String)

	ThisApplication.StatusBarText = "Processing PDF.........." & oDocument.displayname
	oFullFileName = oDocument.FullFilename	
	oFileName = Right(oFullFileName, Len(oFullFileName) - InStrRev(oFullFileName, "\"))
	oName = Left(oFileName, InStrRev(oFileName, ".") -1) 'name without extension
	sFullPDFname = oFolder & "\" & oName & ".pdf"	
	
	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

	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

	'Set the PDF target file name
	oDataMedium.FileName = sFullPDFname
	'output the PDF
	oPDFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)		
End Sub

 

 

 

EESignature

Message 11 of 13

ErnestoGL
Explorer
Explorer
Thank you for this rule, it´s really amazing. I´ve been trying to modify the rule in order to get the "Title" ipropertie from the part file as a PDF file name and adding the revision number at the end but I´ve not get it. Im realatively new in iLogic and programming, doy you have any ideas guys?
0 Likes
Message 12 of 13

ryan_holtonVREQV
Community Visitor
Community Visitor

Hi,

 

Would you be able to alter this code so that I can pick the save destination / file path each time rather than it automatically saving to a specified location.

 

Thanks

0 Likes
Message 13 of 13

ALadZ339U
Observer
Observer

can i pleaswe get the code to save the pdf and dxf file in same folder where the original drawing file is ?

0 Likes