Create a folder based on idw file name and store pdf & dxf in the file ( global rules)

Create a folder based on idw file name and store pdf & dxf in the file ( global rules)

tchappleA6VPF
Participant Participant
527 Views
6 Replies
Message 1 of 7

Create a folder based on idw file name and store pdf & dxf in the file ( global rules)

tchappleA6VPF
Participant
Participant

Hi There,

 

I have been using global rules so that all cad users can export drawings via an ilogic rule to save a bit of time, this exports a pdf & a dxf and puts it in respective folders called "dxf" & "pdf". 

 

I have now modified this so that the ilogic sends the outputs to a shared location on sharepoint. what I would like to do is add code so that for example drawing no 12345 gets exported as pdf & dxf and a placed in a folder called 12345.

 

please would anybody be able to advise what I need to add to my code?

 

oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism  
' Create a NameValueMap object  
Dim oOptions As NameValueMap  
oOptions = ThisApplication.TransientObjects.CreateNameValueMap  
' Create a DataMedium object  
Dim oDataMedium As DataMedium  
oDataMedium = ThisApplication.TransientObjects.CreateDataMedium  
' Check whether the translator has 'SaveCopyAs' options  
If DXFAddIn.HasSaveCopyAsOptions(oDocument, oContext, oOptions) Then  
Dim strIniFile As String  
strIniFile = "<u+202a>T:\Design Data\DWG-DXF\exportdxf.ini"  
' Create the name-value that specifies the ini file to use.  
oOptions.Value("Export_Acad_IniFile") = strIniFile  
End If  
'Set the destination file name 
oFileName = ThisDoc.FileName(False) 'without extension
oRevNum = iProperties.Value("project", "revision number")
oFolder =  System.Environment.GetFolderPath(System.Environment.SpecialFolder.UserProfile) + "\OneDrive - Air Control Industries Limited\Published Drawings"
oDataMedium.FileName = oFolder &amp;ext "\" ext.Typ&amp;ext oFileName  e = IOM&amp;eNa ".DXF"
'Publish document.  
DXFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)  
'Launch the dxf file in whatever application Windows is set to open this document type with  
i = MessageBox.Show("Preview the DXF file?", "Title",MessageBoxButtons.YesNo,MessageBoxIcon.Question)  
If i = vbYes Then ThisDoc.Launch(oDataMedium.FileName) 
	
oPath = ThisDoc.Path
oFileName = ThisDoc.FileName(ions(oDFalse) 'without extension
oRevNum = iProperties.Value("project", "revision number")
oPDFAddIn = ThisApplication.ApplicationAddIns.ItemById _
("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}")
oDocument = ThisApplication.ActiveDocument
oContext = ThisApplication.TransientObjects.CreateTranslationContext
oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
oOptions = ThisApplication.TransientObjects.CreateNameValueMap
oDataMedium = ThisApplication.TransientObjects.CreateDataMedium 


If oPDFAddIn.HasSaveCopyAsOptions(oDocument, oContext, oOptions) Then
oOptions.Value("All_Color_AS_Black") = 0
oOptions.Value("Remove_Line_Weights") = 1
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 =  System.Environment.GetFolderPath(System.Environment.SpecialFolder.UserProfile) + "\OneDrive - Air Control Industries Limited\Published Drawings"


'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"


'Publish document
oPDFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium) 
'------end of iLogic-------	
	

 

0 Likes
Accepted solutions (1)
528 Views
6 Replies
Replies (6)
Message 2 of 7

A.Acheson
Mentor
Mentor

Here is a quick sample for creating a folder with filename as folder name. 

 

Dim FileName As String = ThisDoc.FileName(False) 'without extension
Dim Path As String = ThisDoc.Path
Dim
ExportFolder As String = Path & “\” & FileName

If Not System.IO.Directory.Exists(ExportFolder) Then
System.IO.Directory.CreateDirectory(ExportFolder)
End If

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
Message 3 of 7

tchappleA6VPF
Participant
Participant

Hi There,

 

I have used this and modified my code which now looks like the below, it is creating a folder with the same name as the file, but the dxf and pdf output are not being put into this created file. what am I doing wrong?

' Get the DXF translator Add-In.  
Dim DXFAddIn As TranslatorAddIn  
DXFAddIn = ThisApplication.ApplicationAddIns.ItemById("{C24E3AC4-122E-11D5-8E91-0010B541CD80}")  
'Set a reference to the active document (the document to be published).  
Dim oDocument As Document  
oDocument = ThisApplication.ActiveDocument  
Dim oContext As TranslationContext  
oContext = ThisApplication.TransientObjects.CreateTranslationContext  
oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism  
' Create a NameValueMap object  
Dim oOptions As NameValueMap  
oOptions = ThisApplication.TransientObjects.CreateNameValueMap  
' Create a DataMedium object  
Dim oDataMedium As DataMedium  
oDataMedium = ThisApplication.TransientObjects.CreateDataMedium  
' Check whether the translator has 'SaveCopyAs' options  
If DXFAddIn.HasSaveCopyAsOptions(oDocument, oContext, oOptions) Then  
Dim strIniFile As String  
strIniFile = "<u+202a>T:\Design Data\DWG-DXF\exportdxf.ini"  
' Create the name-value that specifies the ini file to use.  
oOptions.Value("Export_Acad_IniFile") = strIniFile  
End If  
'Set the destination file name 
oFileName = ThisDoc.FileName(False) 'without extension
oRevNum = iProperties.Value("project", "revision number")
oFolder = System.Environment.GetFolderPath(System.Environment.SpecialFolder.UserProfile) + "\OneDrive - Air Control Industries Limited\Published Drawings"

'Check for the PDF folder and create it if it does not exist
If Not System.IO.Directory.Exists(oFolder &amp; th oFileName) Then
    System.IO.Directory.CreateDirectory(oFolder n  
DXF&amp;eNa oFileName)
End If

oDataMedium.FileName = oFolder ctory(o&amp;eNa "\" eName)
&amp;eNa oFileName  End If
&amp;eNa ".DXF"
'Publish document.  
DXFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)  
'Launch the dxf file in whatever applicatiE-11D5-on Windows is set to open this document type with  
i = MessageBox.Show("Preview the DXF file?", "Title",MessageBoxButtons.YesNo,MessageBoxIcon.Question)  
If i = vbYes Then ThisDoc.Launch(oDataMedium.FileName) 
	
oPath = ThisDoc.Path
oFileName = ThisDoc.FileName(False) 'without extension
oRevNum = iProperties.Value("project", "revision number")
oPDFAddIn = ThisApplication.ApplicationAddIns.ItemById _
("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}")
oDocument = ThisApplication.ActiveDocument
oContext = ThisApplication.TransientObjects.CreateTranslationContext
oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
oOptions = ThisApplication.TransientObjects.CreateNameValueMap
oDataMedium = ThisApplication.TransientObjects.CreateDataMedium 


If oPDFAddIn.HasSaveCopyAsOptions(oDocument, oContext, oOptions) Then
oOptions.Value("All_Color_AS_Black") = 0
oOptions.Value("Remove_Line_Weights") = 1
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 =  System.Environment.GetFolderPath(System.Environment.SpecialFolder.UserProfile) + "\OneDrive - Air Control Industries Limited\Published Drawings\"


'Check for the PDF folder and create it if it does not exist
If Not System.IO.Directory.Exists(oFolder & oFileName) Then
    System.IO.Directory.CreateDirectory(oFolder & oFileName)
End If


 'Set the PDF target file name
oDataMedium.FileName = oFolder & "\" & oFileName  & ".pdf"


'Publish document
oPDFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium) 
'------end of iLogic-------	
	

 

0 Likes
Message 4 of 7

A.Acheson
Mentor
Mentor

I don’t think this line here is producing a meaningful filename. You can place the string in a message box and see does the outcome look correct. I normally use the option explicit on in the header which will catch undeclared object variables. In this rule you will have many. Take a screenshot of what you find. Not all are critical but you may find some that will help you. You can switch it on by typing “Option Explicit On” into the header of the rule. 

oDataMedium.FileName = oFolder ctory(o&amp;eNa "\" eName)
&amp;eNa oFileName  End If
&amp;eNa ".DXF"

 I would focus on doing one operation for now the dxf. Remove the pdf code and place into a notepad file for later. 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 5 of 7

tchappleA6VPF
Participant
Participant

I have removed the pdf bit and followed your advice. I am getting the following errors. I'm getting almost the outcome I need. ( it is creating the folder and file with the name I want, but it is not putting the dxf in the file that gets created)

tchappleA6VPF_0-1676305620319.png

tchappleA6VPF_1-1676305682355.png

 

 

0 Likes
Message 6 of 7

tchappleA6VPF
Participant
Participant
Accepted solution

Hi there, just a quick update. 

 

I used Chat GPT to generate me some code, and it works perfectly. 

' Get the DXF and PDF translator Add-Ins.  
Dim DXFAddIn As TranslatorAddIn  
DXFAddIn = ThisApplication.ApplicationAddIns.ItemById("{C24E3AC4-122E-11D5-8E91-0010B541CD80}")  

Dim PDFAddIn As TranslatorAddIn
PDFAddIn = ThisApplication.ApplicationAddIns.ItemById("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}")  

'Set a reference to the active document (the document to be published).  
Dim oDocument As Document  
oDocument = ThisApplication.ActiveDocument  

Dim oContext As TranslationContext  
oContext = ThisApplication.TransientObjects.CreateTranslationContext  
oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism  

' Create a NameValueMap object  
Dim oOptions As NameValueMap  
oOptions = ThisApplication.TransientObjects.CreateNameValueMap  

' Create a DataMedium object for DXF  
Dim oDataMediumDXF As DataMedium  
oDataMediumDXF = ThisApplication.TransientObjects.CreateDataMedium  

' Create a DataMedium object for PDF  
Dim oDataMediumPDF As DataMedium
oDataMediumPDF = ThisApplication.TransientObjects.CreateDataMedium

' Check whether the translators have 'SaveCopyAs' options  
If DXFAddIn.HasSaveCopyAsOptions(oDocument, oContext, oOptions) Then  
    Dim strIniFile As String  
    strIniFile = "T:\Design Data\DWG-DXF\exportdxf.ini"
    ' Create the name-value that specifies the ini file to use for PDF export.
    oOptions.Value("ExportPdfConfigurationFile") = strIniFile  
End If  

'Set the destination folder and filename
oFileName = ThisDoc.FileName(False) 'without extension
oRevNum = iProperties.Value("project", "revision number")

oFolder = System.Environment.GetFolderPath(System.Environment.SpecialFolder.UserProfile) + "\OneDrive - Air Control Industries Limited\Published Drawings" & "\" & oFileName & "\" & oRevNum

'Check for the 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 DXF file name and path
oDataMediumDXF.FileName = oFolder & "\" & oFileName  & ".DXF"

' Set the PDF file name and path
oDataMediumPDF.FileName = oFolder & "\" & oFileName & ".PDF"

'Publish document as DXF 
DXFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMediumDXF)  

'Publish document as PDF 
PDFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMediumPDF)

'Launch the DXF file in whatever application Windows is set to open this document type with  
i = MessageBox.Show("Preview the DXF file?", "Title",MessageBoxButtons.YesNo,MessageBoxIcon.Question)  
If i = vbYes Then ThisDoc.Launch(oDataMediumDXF.FileName) 

'Launch the PDF file in whatever application Windows is set to open this document type with  
i = MessageBox.Show("Preview the PDF file?", "Title",MessageBoxButtons.YesNo,MessageBoxIcon.Question)  
If i = vbYes Then ThisDoc.Launch(oDataMediumPDF.FileName)
0 Likes
Message 7 of 7

A.Acheson
Mentor
Mentor

I suppose ChatGPT is another method. Here is the API help in VBA for dxf translator if you wanted to declare the variables more precisely. Out of interest did you find the error you were getting? Was it the dxf filename? 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes