Batch export IDW to another location

Batch export IDW to another location

morrenengineering
Contributor Contributor
668 Views
2 Replies
Message 1 of 3

Batch export IDW to another location

morrenengineering
Contributor
Contributor

Hi,

You can copy an assembly via ilogic design copy, but then the IDW files will not be included. Now I have written a macro so that those IDW files are copied to a location. I can then place it in the appropriate folder. I then open the IAM, run ilogic and that's it. However, the Ilogic does not work properly yet, I think something is wrong with the saveas. Perhaps the code could be a bit simpler.

 

Sub Main()
    Dim oDoc As Document
    oDoc = ThisDoc.Document
    oDocName = System.IO.Path.GetDirectoryName(oDoc.FullFileName) & "\" & System.IO.Path.GetFileNameWithoutExtension(oDoc.FullFileName)
    
    If Not (oDoc.DocumentType = kAssemblyDocumentObject Or oDoc.DocumentType = kDrawingDocumentObject) Then
        MessageBox.Show("Please run this rule from the assembly or drawing files.", "iLogic")
        Exit Sub
    End If
    
    'get user input
    If MessageBox.Show ( _
        "This will create a IDW file for all of the files referenced by this document that have drawings files." _
        & vbLf & "This rule expects that the drawing file shares the same name and location as the component." _
        & vbLf & " " _
        & vbLf & "Are you sure you want to create IDW Drawings for all of the referenced documents?" _
        & vbLf & "This could take a while.", "iLogic  - Batch Output PDFs ",MessageBoxButtons.YesNo) = vbNo Then
        Exit Sub
    End If
        
    Dim oContext As TranslationContext
    Dim oOptions As NameValueMap
    Dim oDataMedium As DataMedium
    
    
    'oFolder = oDocName & " PDF Files"
	oFolder = "D:\IDW"
	
    If Not System.IO.Directory.Exists(oFolder) Then
        System.IO.Directory.CreateDirectory(oFolder)
    End If
    
    '- - - - - - - - - - - - -Component Drawings - - - - - - - - - - - -
    Dim oRefDoc As Document
    Dim oDrawDoc As DrawingDocument
    
    For Each oRefDoc In oDoc.AllReferencedDocuments
        oBaseName = System.IO.Path.GetFileNameWithoutExtension(oRefDoc.FullFileName)
        oPathAndName = System.IO.Path.GetDirectoryName(oRefDoc.FullFileName) & "\" & oBaseName
        If (System.IO.File.Exists(oPathAndName & ".idw")) Then
			oDrawDoc = ThisApplication.Documents.Open(oPathAndName & ".idw", True)
			
			On Error Resume Next

			'define the folder where you want to save the files
			oFolder = "D:\IDW\"
			'create the folder if it doesn't exist
			If Not System.IO.Directory.Exists(oFolder) Then 
    			System.IO.Directory.CreateDirectory(oFolder)
			End If
			'grab the filename
			oFileName = ThisDoc.FileName(False) 'without extension

			'save as a idw
			ThisDoc.Document.SaveAs(oFolder & oFileName & ".idw", True)
			
            oDrawDoc.Close
        Else
            oNoDwgString = oNoDwgString & vbLf & idwPathName
        End If
    Next
    '- - - - - - - - - - - - -
    
    '- - - - - - - - - - - - -Top Level Drawing - - - - - - - - - - - -
    oBaseName = System.IO.Path.GetFileNameWithoutExtension(oDoc.FullFileName)
    oPathAndName = System.IO.Path.GetDirectoryName(oDoc.FullFileName) & "\" & oBaseName
    oDataMedium.FileName = oFolder & "\" & oBaseName & ".idw"
    
    If oDoc.DocumentType = kAssemblyDocumentObject Then
        oDrawDoc = ThisApplication.Documents.Open(oPathAndName & ".idw", True)
		
       On Error Resume Next

			'define the folder where you want to save the files
			oFolder = "D:\IDW\"

			'grab the filename
			oFileName = ThisDoc.FileName(False) 'without extension

			'save as a idw
			ThisDoc.Document.SaveAs(oFolder & oFileName & ".idw", True)

			
			
        oDrawDoc.Close
    ElseIf oDoc.DocumentType = kDrawingDocumentObject Then
        oFileName = ThisDoc.FileName(False) 'without extension
		
			On Error Resume Next

			'define the folder where you want to save the files
			oFolder = "D:\IDW\"

			'grab the filename
			oFileName = ThisDoc.FileName(False) 'without extension

			'save as a idw
			ThisDoc.Document.SaveAs(oFolder & oFileName & ".idw", True)

			
			
        oDrawDoc.Close
    End If
    '- - - - - - - - - - - - -
    
    MessageBox.Show("New Files Created in: " & vbLf & oFolder, "iLogic")
    MsgBox("Files found without drawings: " & vbLf & oNoDwgString)
    Shell("explorer.exe " & oFolder,vbNormalFocus)
End Sub


 

0 Likes
Accepted solutions (1)
669 Views
2 Replies
Replies (2)
Message 2 of 3

WCrihfield
Mentor
Mentor
Accepted solution

I copied your code over into the iLogic rule editor and deleted, condensed, and modified a few things.  Give this version a try.  I eliminated a bunch of those ThisDoc uses throughout the middle part of the rule, because it seemed like they would not be targeting the correct document, and were not necessary in my opinion.

Sub Main()
	'ThisDoc will primarily target the 'local' document (document this rule is saved within) if one exists
	'if used in an external rule, it will target the document that was 'active' when the rule first started
	Dim oDoc As Document = ThisDoc.Document
        
	If Not (oDoc.DocumentType = kAssemblyDocumentObject Or oDoc.DocumentType = kDrawingDocumentObject) Then
		MessageBox.Show("Please run this rule from the assembly or drawing files.", "iLogic")
		Exit Sub
	End If

	'get user input
	If MessageBox.Show ( _
		"This will create a IDW file for all of the files referenced by this document that have drawings files." _
		& vbLf & "This rule expects that the drawing file shares the same name and location as the component." _
		& vbLf & " " _
		& vbLf & "Are you sure you want to create IDW Drawings for all of the referenced documents?" _
		& vbLf & "This could take a while.", "iLogic  - Batch Output PDFs ",MessageBoxButtons.YesNo) = vbNo Then
		Exit Sub
	End If
	
	oMainDocPath = System.IO.Path.GetDirectoryName(oDoc.FullFileName)
	oMainDocName = System.IO.Path.GetFileNameWithoutExtension(oDoc.FullFileName)
	oMainDocPathAndName = oMainDocPath & "\" & oMainDocName
	
	oFolder = "D:\IDW\"
	
    If Not System.IO.Directory.Exists(oFolder) Then
        System.IO.Directory.CreateDirectory(oFolder)
    End If
    
    '- - - - - - - - - - - - -Component Drawings - - - - - - - - - - - -
	Dim oDrawDoc As DrawingDocument
	Dim oNoDwgString, idwPathName As String
    For Each oRefDoc As Document In oDoc.AllReferencedDocuments
        oBaseName = System.IO.Path.GetFileNameWithoutExtension(oRefDoc.FullFileName)
        oPathAndName = System.IO.Path.GetDirectoryName(oRefDoc.FullFileName) & "\" & oBaseName
        If (System.IO.File.Exists(oPathAndName & ".idw")) Then
			oDrawDoc = ThisApplication.Documents.Open(oPathAndName & ".idw", True)
			'save copy of it to other directory
			oDrawDoc.SaveAs(oFolder & oBaseName & ".idw", True)
            oDrawDoc.Close
			oDrawDoc = Nothing
        Else
			idwPathName = oRefDoc.FullFileName
            oNoDwgString = oNoDwgString & vbLf & idwPathName
        End If
    Next
    
    '- - - - - - - - - - - - -Top Level Drawing - - - - - - - - - - - -
	If oDoc.DocumentType = kAssemblyDocumentObject Then
		If (System.IO.File.Exists(oMainDocPathAndName & ".idw")) Then
			oDrawDoc = ThisApplication.Documents.Open(oMainDocPathAndName & ".idw", True)
			oDrawDoc.SaveAs(oFolder & oMainDocName & ".idw", True)
			oDrawDoc.Close
			oDrawDoc = Nothing
		End If
    ElseIf oDoc.DocumentType = kDrawingDocumentObject Then
		oDrawDoc = oDoc
		oDrawDoc.SaveAs(oFolder & oMainDocName & ".idw", True)
        oDrawDoc.Close
		oDrawDoc = Nothing
    End If
    '- - - - - - - - - - - - -
    
    MessageBox.Show("New Files Created in: " & vbLf & oFolder, "iLogic")
    MsgBox("Files found without drawings: " & vbLf & oNoDwgString)
    Shell("explorer.exe " & oFolder,vbNormalFocus)
End Sub

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 3

gsimeon724
Observer
Observer

You can do this with an App on the App Store Called Fyenite. Change locations and change file names. Fyenite 

0 Likes