This ilogic code works on my machine but not a colleagues - export dxf/dwg - parameter is incorrect

This ilogic code works on my machine but not a colleagues - export dxf/dwg - parameter is incorrect

andrew_canfield
Collaborator Collaborator
446 Views
4 Replies
Message 1 of 5

This ilogic code works on my machine but not a colleagues - export dxf/dwg - parameter is incorrect

andrew_canfield
Collaborator
Collaborator

 

Hello

With some help (from this forum) the code to export a list of .idw files to dwg, dxf, pdf is working - but only on my machine!

(actually pdf will work on a colleagues machine - maybe it's the .ini file - will test tomorrow).

 

Below is a section of the code - if you edit the file path ( 4th line down) to a .idw can you export a dxf ( will need to create an .ini file & save here - %USERPROFILE%\Desktop\Batch Export\ACad2013.ini - by manually exporting to dxf first & saving the configuration) 

 

 

 

Sub Main
	
	Dim PathList As String
	'enter a file path to a .idw 
	PathList = "C:\Vault Views\Drawings\025913-DRWG-06475.idw"

ThisDoc.Launch(PathList)
Dim doc As Document = ThisApplication.ActiveDocument
For Each oDoc In ThisApplication.Documents
		If oDoc.DocumentType = DocumentTypeEnum.kDrawingDocumentObject Then
			Call PrintDxf(oDoc)
		End If
Next  
		Call doc.Close(True)

End Sub


Sub PrintDxf(oDoc As Document)	
	
Dim oFolder As String = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Desktop) & "\Batch Export\Dxf"
If Not System.IO.Directory.Exists(oFolder) Then 
    System.IO.Directory.CreateDirectory(oFolder)
End If
'strip out file extension
FileName1 = Left(oDoc.DisplayName, Len(oDoc.DisplayName))
FileName2 = Right(FileName1, 4)
If FileName2 = ".idw" Then ex = 4 Else ex =0
path_and_name = ThisDoc.PathAndFileName(False) ' without extension
oFileName = Left(FileName1,(Len(FileName1)-ex))
MessageBox.Show(oFileName, FileName1)



'Date: 26.09.2016
'Author: Reg Hasell - robbed off forum by AC
' Version 1.0
'
'It will Do a very basic check to see if the file already exists, (I did not want to slow the process down too much
'It will then Create a DWG file in the export directory.
'The major benefit is that it will also add the current Revision to the filename.

' Future development will also update the filename with a prompted date.

'Dim oDoc As Document
'oDoc = ThisApplication.ActiveDocument
	Dim DWGAddIn As TranslatorAddIn
	DWGAddIn = ThisApplication.ApplicationAddIns.ItemById("{C24E3AC2-122E-11D5-8E91-0010B541CD80}")
	Dim oDocument As Document
	oDocument = ThisApplication.ActiveDocument
	
	oRevNum = oDocument.PropertySets.Item("Inventor User Defined Properties").Item("Issue").Value
	
	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 oDataMediumDWG As DataMedium
    oDataMediumDWG = ThisApplication.TransientObjects.CreateDataMedium

oDataMedium = ThisApplication.TransientObjects.CreateDataMedium

		Dim strIniFile As String
		
'FROM INVENTOR EXPORT A DXF & SAVE THE .ini file
		strIniFile = "%USERPROFILE%\Desktop\Batch Export\ACad2013.ini"
		
        oOptions.Value("Export_Acad_IniFile") = strIniFile		
		oFolder = (System.Environment.GetFolderPath(System.Environment.SpecialFolder.Desktop) & "\Batch Export\dxf\")& dName

	oDataMediumDWG.FileName =oFolder + oFileName &"."& oRevNum &".dxf"

MessageBox.Show(oFolder, "oFolder")
MessageBox.Show(oFileName, "oFileName")
MessageBox.Show(oRevNum , "oRevNum ")

	
'''--- Publish document.
DWGAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMediumDWG)

End Sub

Error being seen on a different machine is:

 

Parameter Incorrect.PNGexport dfx.PNG

Regards

 

Andrew

0 Likes
Accepted solutions (1)
447 Views
4 Replies
Replies (4)
Message 2 of 5

WCrihfield
Mentor
Mentor

Judging by your description, the file path specified for the .ini file, and the second error image, I would definitely suspect that the .ini file is not being found on the other machine.  I am not currently using Vault, so I don't know if that first drawing file path would be causing any problems on the other machine or not, but it also looks like a local path.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 3 of 5

JelteDeJong
Mentor
Mentor
Accepted solution

I'm not sure why it didn't work. but I found some things that could go wrong. I changed a couple of things in your rule to improve it a bit. have a look if this works better for you.

Sub Main()
    Dim oFileDlg As Inventor.FileDialog = Nothing
    ThisApplication.CreateFileDialog(oFileDlg)

    oFileDlg.InitialDirectory = "C:\Vault Views\Drawings"
    oFileDlg.Filter = "*.idw|*.idw"
    oFileDlg.ShowOpen()

    Dim doc As Document = ThisApplication.Documents.Open(oFileDlg.FileName)
    If doc.DocumentType = DocumentTypeEnum.kDrawingDocumentObject Then
        PrintDxf(doc)
    End If
    doc.Close(True)
End Sub

Sub PrintDxf(oDoc As Document)

    Dim folder As String = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Desktop)
    folder = IO.Path.Combine(folder, "Batch Export\Dxf")
    If Not System.IO.Directory.Exists(folder) Then
        System.IO.Directory.CreateDirectory(folder)
    End If

    Dim fileNameWithoutExt = IO.Path.GetFileNameWithoutExtension(oDoc.DisplayName)
    Dim revNr As String = "-"
    Try
        revNr = oDoc.PropertySets.Item("Inventor User Defined Properties").Item("Issue").Value
    Catch ex As Exception
    End Try
    Dim newFileName = String.Format("{0}.{1}.dxf", fileNameWithoutExt, revNr)
    Dim newFullFileName = IO.Path.Combine(folder, newFileName)

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

    ' Create a NameValueMap object
    Dim oOptions As NameValueMap = ThisApplication.TransientObjects.CreateNameValueMap
    oOptions.Value("Export_Acad_IniFile") = "c:\temp\DxfExport.ini" ' "%USERPROFILE%\Desktop\Batch Export\ACad2013.ini"

    ' Create a DataMedium object
    Dim oDataMediumDWG As DataMedium = ThisApplication.TransientObjects.CreateDataMedium
    oDataMediumDWG.FileName = newFullFileName

    '''--- Publish document.
    Dim DWGAddIn As TranslatorAddIn = ThisApplication.ApplicationAddIns.ItemById("{C24E3AC2-122E-11D5-8E91-0010B541CD80}")
    DWGAddIn.SaveCopyAs(oDoc, oContext, oOptions, oDataMediumDWG)

End Sub

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

Message 4 of 5

andrew_canfield
Collaborator
Collaborator

It's working but I don't know why!

The other users machine was new (ish) - the code failed at first.

One of the test drawings was opened & manually exported as a dwg to test.

The code was reran & it worked - happy days.

Thanks for the help.

Attached is the working project (mark 1) obviously very clunky - maybe next year I'll have figured out how to have something like this running silently in Apprentice! (Hopefully someone can build on the idea to speed it up)

(if unzipping the path needs to be Desktop\Batch Export - the unzip can bury the folder a layer down).

  1. Create a list of file paths
  2. Save in the Batch Export Folder
  3. run the rule
  4. point the rule at the list & confirm the row count
  5. the list can be seen in this parameter when loaded
  6. run
  7. the output is to these folders

BatchExport.png

 

Don't forget the manual dwg/dxf output before running!

 

Regards

 

Andrew

0 Likes
Message 5 of 5

WCrihfield
Mentor
Mentor

Just a quick tag on note about that process, and why you might have to export one manually first to get it to work.  When you don't specify an .ini file for it to use, or it can't find that file (within something like a Try...Catch), it will basically try to export the DXF the same way it was done the last time.  Problem is, if you often change any of those settings, you don't know how things may have been set-up the last time you exported a DXF.  So doing a manual export, and setting things up the way you want, just ahead of a batch of DXF exports, will normally work.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes