Announcements

The Autodesk Community Forums has a new look. Read more about what's changed on the Community Announcements board.

Exporting multi page DWG using Sheet Name for exported files

sam_dobell
Participant

Exporting multi page DWG using Sheet Name for exported files

sam_dobell
Participant
Participant

My team current creates part drawings with a part drawing & cutfile on different sheets in the same drawing file.

The current drawing template currently renames the sheets based on the first part placed on the drawing, and adds the "_CutFile" suffix if the view is a flat pattern.

 

I have been using the code below to export all open drawings to PDF & DWG in their own folder which works great, but each multi page DWG gets exported with the naming convension "DrawingName_SheetName"

 

Example 

A103-6-1001-TestPart.idw exports to

A103-6-1001-TestPart_A103-6-1001-TestPart.dwg

A103-6-1001-TestPart_A103-6-1001-TestPart_Cutfile.dwg

 

I would like to remove eveything before the underscore, and just have each file export with the sheet name only.

I have an idea about how to achieve this with the Sheet.Name property but unsure how to add it into the export rule below

 

Any help would be appreciated

 

  Sub main()

        For Each document As Document In ThisApplication.Documents.VisibleDocuments
            If (Document.DocumentType <> DocumentTypeEnum.kDrawingDocumentObject) Then
                Logger.Info("Skipped file: " + Document.FullFileName)
                Continue For

            End If

            Dim fileName As String = System.IO.Path.GetFileNameWithoutExtension(Document.FullFileName)
            Dim fileInfo As New System.IO.FileInfo(Document.FullFileName)
            Dim subFolder = fileInfo.Directory.CreateSubdirectory(fileName)

            Dim pdfFullFileName = System.IO.Path.Combine(subFolder.FullName, fileName + ".pdf")
            CreatePdf(pdfFullFileName)

            Dim dwgFullFileName = System.IO.Path.Combine(subFolder.FullName, fileName + ".dwg")
            CreateDwg(dwgFullFileName)

            Logger.Info("Created pdf and dwg from file: " + Document.FullFileName)
        Next
    End Sub

    Private Sub CreatePdf(fullFileName As String)
        ' Get the PDF add-in
        Dim pdfAddIn As ApplicationAddIn
        pdfAddIn = ThisApplication.ApplicationAddIns.ItemById("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}")

        ' Create the translation context
        Dim context As TranslationContext
        context = ThisApplication.TransientObjects.CreateTranslationContext
        context.Type = IOMechanismEnum.kFileBrowseIOMechanism

        ' Create the name-value map for options
        Dim options As NameValueMap
        options = ThisApplication.TransientObjects.CreateNameValueMap

        ' Set PDF export options
        options.Value("Remove_Line_Weights") = 1
        options.Value("All_Color_AS_Black") = 0
        options.Value("Vector_Resolution") = 400
        options.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintAllSheets

        ' Create the data medium for PDF
        Dim dataMediumPDF As DataMedium
        dataMediumPDF = ThisApplication.TransientObjects.CreateDataMedium
        dataMediumPDF.FileName = fullFileName

        ' Export the document to PDF
        If pdfAddIn.HasSaveCopyAsOptions(ThisDoc.Document, context, options) Then
            pdfAddIn.SaveCopyAs(ThisDoc.Document, context, options, dataMediumPDF)
        End If
    End Sub

    Private Sub CreateDwg(fullFileName As String)

        ' Get the DWG add-in
        Dim dwgAddIn As ApplicationAddIn = ThisApplication.ApplicationAddIns.ItemById("{C24E3AC2-122E-11D5-8E91-0010B541CD80}")

        ' Create the translation context
        Dim context As TranslationContext
        context = ThisApplication.TransientObjects.CreateTranslationContext
        context.Type = IOMechanismEnum.kFileBrowseIOMechanism

        ' Reset the options for DWG export
        Dim options = ThisApplication.TransientObjects.CreateNameValueMap

        ' Set DWG export options using an INI file
        Dim workspacePath As String = ThisApplication.DesignProjectManager.ActiveDesignProject.WorkspacePath
        Dim strIniFile As String = System.IO.Path.Combine(workspacePath, "zInventorStuff\iLogic\DWGExport.ini")
        ' Create the name-value that specifies the ini file to use.
        options.Value("Export_Acad_IniFile") = strIniFile

        ' Create the data medium for DWG
        Dim dataMediumDWG As DataMedium
        dataMediumDWG = ThisApplication.TransientObjects.CreateDataMedium
        dataMediumDWG.FileName = fullFileName

        ' Export the document to DWG
        If dwgAddIn.HasSaveCopyAsOptions(ThisDoc.Document, context, options) Then
            dwgAddIn.SaveCopyAs(ThisDoc.Document, context, options, dataMediumDWG)
        End If
    End Sub

 

0 Likes
Reply
267 Views
5 Replies
Replies (5)

WCrihfield
Mentor
Mentor

Hi @sam_dobell.  Although I do not need to export multi-sheet drawings to DXF or DWG formats where I work, I have been involved in very similar forum discussions about trying to customize the names of the individual resulting files for each sheet before, and I remember it being pretty complicated.  It seems like the simplest way to handle this situation is to predict the resulting 'FullFileNames' of the DXF/DWG files it will produce.  Then after the export steps are all finished, change the names of those existing files the way you want.  This is because we supply the whole DrawingDocument to the export method, not just one sheet at a time.  So, although we can influence the drawing name portion of it, the sheet name portion of the file names seem to be automatically generated by the translator add-in's export method.

 

Seems like I have seen folks rename their sheets just before the export process, then change them back after the export process, but that is a lot of extra steps and processing, and often not resulting in satisfactory results. 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes

jnowel
Advocate
Advocate

my workaround here is to send each sheet for export but it requires a different ini file where:

 

jnowel_0-1728481176862.png

 

 

All Sheets=No

 


Edited Main Subroutine

 

 

 Sub Main()

        For Each document As Document In ThisApplication.Documents.VisibleDocuments
            If (Document.DocumentType <> DocumentTypeEnum.kDrawingDocumentObject) Then
                Logger.Info("Skipped file: " + Document.FullFileName)
                Continue For
            End If
			
			'with the DWG Export Config ini file, you need to activate the DrawingDocument for export
			Document.Activate

            Dim fileName As String = System.IO.Path.GetFileNameWithoutExtension(Document.FullFileName)
            Dim fileInfo As New System.IO.FileInfo(Document.FullFileName)
            Dim subFolder = fileInfo.Directory.CreateSubdirectory(fileName)

            Dim pdfFullFileName = System.IO.Path.Combine(subFolder.FullName, fileName + ".pdf")
            CreatePdf(pdfFullFileName)
			
			'And run the DWG export rule per sheet
			For Each oSheet As Sheet In Document.Sheets
				oSheet.Activate
	            Dim dwgFullFileName As String = Trim(Split(oSheet.Name, ":")(0)) &  ".dwg"
	            CreateDwg(dwgFullFileName)
			Next oSheet
			
            Logger.Info("Created pdf and dwg from file: " + Document.FullFileName)
        Next
    End Sub

 


in  video attached, i have customized the dwgFullFileName to other details like revision and sheet number.
(not shown in above code, but can easily be configured as such)

edit: not sure why the uploaded video was so low-resolution.


WCrihfield
Mentor
Mentor

That's certainly one way of doing it.  It's been a while since I last looked into this process, since I do not use it myself.  Seems to me like another strategy was...while iterating through each sheet, set the Sheet.ExcludeFromCount and the Sheet.ExcludeFromPrinting properties to False (include) for the one sheet you want to export, while setting all other sheets to True (exclude), then do the export within the loop, then on to the next sheet, and so on.  Just another way of exporting a single sheet at a time.  I do not recall if that let you have total control of each file name, but it seems like it should.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes

jnowel
Advocate
Advocate

Changing Sheet.ExcludeFromCount midrule would mess up the drawing if "Total Number of Sheets" is included in the Drawing titleblock.

WCrihfield
Mentor
Mentor

Good point.  That was one of the drawbacks, and complications of doing things that way in previous discussions, and one of the reasons I first suggested just changing the file names of the resulting files by code, after they get generated.  Just seems simpler to me, but I do tend to think about processes like these a bit differently than most, also.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes