Export DWG time

Export DWG time

Rsilvers23
Contributor Contributor
537 Views
1 Reply
Message 1 of 2

Export DWG time

Rsilvers23
Contributor
Contributor

We have multi-sheet IDW that we then save each sheet to an individual DWG that gets named whatever the "Project Number" is for the model on that sheet. If I go to File, SaveAs, Autodcad DWG and select all pages, it takes less than a minute for a 20 sheet drawing. I will then have to rename all the DWG files and be done.

The code I wrote below gets the "Project Number" first model on the sheet and exports each DWG with the correct file name... problem is it takes over 7 minutes for the same 20 sheet drawing. This uses the DWG Addin function but is there another method that works more efficiently? I have a hard time believing this is the best I'm gonna get so I'm hopeful I did something wrong or there is a better method. Anyone have any suggestions?

 

' Get the DWG translator Add-In.
Dim DWGAddIn As TranslatorAddIn
DWGAddIn = ThisApplication.ApplicationAddIns.ItemById("{C24E3AC2-122E-11D5-8E91-0010B541CD80}")

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

Dim oContext As TranslationContext
oContext = ThisApplication.TransientObjects.CreateTranslationContext
oContext.Type = 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 DWGAddIn.HasSaveCopyAsOptions(oDoc, oContext, oOptions) Then
    Dim strIniFile As String
    strIniFile = "\\fdg-vault\Design Data\iLogic\FDG-IDW-EXPORT-DWG.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
Dim oPath = ThisDoc.Path
Dim oSheet As Sheet
Dim DWGName As String
Dim DwgNo As String
Dim oDrawingView As DrawingView

For Each oSheet In oDoc.Sheets

	'Grab the first drawing view on the sheet & model
    oDrawingView = oSheet.DrawingViews(1)
	oModel = oDrawingView.ReferencedDocumentDescriptor.ReferencedDocument
	
	'Grab the Project iproperty of the first drawing view model
    DwgNo = oModel.PropertySets.Item(3).Item("Project").Value
		
	DWGName = oPath & "\" & DwgNo & ".dwg"
	'MessageBox.Show(DWGName, "Title")

    oDataMedium.FileName = DWGName

	'Publish document.
	Call DWGAddIn.SaveCopyAs(oDoc, oContext, oOptions, oDataMedium)
	
Next
0 Likes
538 Views
1 Reply
Reply (1)
Message 2 of 2

Rsilvers23
Contributor
Contributor

I think I figured out why it was taking so long... it was only referencing the first sheet when it exported the DWG's. I missed "oSheet.Activate" so it would never move to the next. I also changed to not get the project number of the model in the 1st view, instead it uses the sheet name and if any pages are marked "Exclude from printing" it skips that sheet.

 

Below is the updated code... hope it helps someone out!

 

' Get the DWG translator Add-In.
Dim DWGAddIn As TranslatorAddIn
DWGAddIn = ThisApplication.ApplicationAddIns.ItemById("{C24E3AC2-122E-11D5-8E91-0010B541CD80}")

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

Dim oContext As TranslationContext
oContext = ThisApplication.TransientObjects.CreateTranslationContext
oContext.Type = 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 DWGAddIn.HasSaveCopyAsOptions(oDoc, oContext, oOptions) Then
    Dim strIniFile As String
    strIniFile = "\\fdg-vault\Design Data\iLogic\FDG-IDW-EXPORT-DWG.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
Dim oPath = ThisDoc.Path
Dim oSheet As Sheet
Dim DWGName As String
Dim DwgNo As String
Dim oDwgNo As String
Dim oDrawingView As DrawingView
Dim oOmit1 As String = "OBS"

For Each oSheet In oDoc.Sheets
	oSheet.Activate
	
	'Grab the first drawing view on the sheet & model
'    oDrawingView = oSheet.DrawingViews(1)
'	oModel = oDrawingView.ReferencedDocumentDescriptor.ReferencedDocument
	
	'Grab the Project iproperty of the first drawing view model
'    DwgNo = oModel.PropertySets.Item(3).Item("Project").Value
	oDwgNo = oSheet.Name
	
		If oSheet.ExcludeFromPrinting = True Then 'sheet settings
		
'		If oDwgNo.Contains(oOmit1) = True Then
		'MessageBox.Show("OBS - Not exporting", "OBS-Ilogic")
		Continue For
	End If

	DwgNo = oDwgNo.Split(":")(0)
'	MessageBox.Show(DwgNo, "File name without :#")
	
	DWGName = oPath & "\" & DwgNo & ".dwg"
'	MessageBox.Show(DWGName, "Title")

    oDataMedium.FileName = DWGName

	'Publish document.	
	Call DWGAddIn.SaveCopyAs(oDoc, oContext, oOptions, oDataMedium)
	
Next

 

0 Likes