Assistance required with iLogic rule code for creation of DXF files

Assistance required with iLogic rule code for creation of DXF files

Anonymous
Not applicable
490 Views
1 Reply
Message 1 of 2

Assistance required with iLogic rule code for creation of DXF files

Anonymous
Not applicable

Hi everybody,

I am new to the forum and the use of iLogic.

 I have been tasked with the job of creating new model and drawing templates in order to simplify and automate key parts of the drawing process within the company.

I am currently working on an iLogic rule to automate the generation of DXF files if needed an have run into a error which is driving me nuts!  When I run the rule, I get the following message:

"Unspecified error (Exception from HRESULT: 0x80004005 (E_FAIL))"

Whilst I have some experience of VB, I am somewhat rusty and despite my best attempts to resolve this I have failed miserably.

The code I have written is as follows:

 

'____________________DXF Generator____________________

'Query user

Question = MessageBox.Show ("Do you require a DXF?" & vbNewLine & "NOTE! This will overwrite any existing DXF files with the same name!", "Export to DXF",MessageBoxButtons.YesNo,MessageBoxIcon.Question)

'Set condition dependent on answer

If Question = vbYes Then

 oPath = ThisDoc.Path  oFileName = ThisDoc.FileName(False) 'without extension  oRevNum = iProperties.Value("Project", "Revision Number") 

 oDXFAddIn = ThisApplication.ApplicationAddIns.ItemById("{C24E3AC4-122E-11D5-8E91-0010B541CD80}") 'get DXF Add-in

 oDocument = ThisApplication.ActiveDocument 'declare oDocument as this document  oContext = ThisApplication.TransientObjects.CreateTranslationContext 'declare oContext as TranslationContext

 oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism  

oOptions = ThisApplication.TransientObjects.CreateNameValueMap 'declare oOptions as NameValueMap object

 oDataMedium = ThisApplication.TransientObjects.CreateDataMedium  oFolder = oPath & "\DXF" 'Sets target folder

 If oDXFAddIn.HasSaveCopyAsOptions(oDocument, oContext, oOptions) Then  DXFIniFile = "C:\Vault Workspace\RAMLDXF.ini"  oOptions.Value("Export_Acad_IniFile") = DXFIniFile  End If

'Check for DXF folder and if it does not exist create one

If Not System.IO.Directory.Exists(oFolder) Then System.IO.Directory.CreateDirectory(oFolder)

'Set the DXF destination file & file name

oDataMedium.FileName = ThisDoc.PathAndFileName(False) oDataMedium.FileName = oFolder & "\" & oFileName & " Rev " & oRevNum & ".dxf"

On Error Goto handleDXFLock

 'Check if the idw has more than 1 sheet  If ThisDoc.Document.Sheets.Count > 1 Then  For sheet_count = 1 To ThisDoc.Document.Sheets.Count

 'If there are no sheets end operation

 If Len(Dir(oPath & oFileName & " Rev " & oRevNum & "_SHEET_" & sheet_count & ".dxf")) <> 0 Then  

Kill(oPath & oFileName & " Rev " & oRevNum & "_SHEET_" & sheet_count & ".dxf")

Else If Len(Dir(oPath & oFileName & " Rev " & oRevNum & ".dxf")) <> 0 Then  

Kill(oPath & oFileName & " Rev " & oRevNum & ".dxf")  

End If  Next sheet_count  

End If

'Publish document.

oDXFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)

End If

'Error message responses

handleDXFLock:

MessageBox.Show("DXF could not be saved!" & vbNewLine & "The file you are trying to overwrite may be open", "No DXF For you " & ThisApplication.GeneralOptions.UserName & "!")

Resume Next

MessageBox.Show("IDW and DXF have been saved to current document folder" , "Save IDW & DXF")

End If

 

Any assistance you guy's can give me will be much appreciated.

Thanks in advance,

Tony

0 Likes
491 Views
1 Reply
Reply (1)
Message 2 of 2

xiaodong_liang
Autodesk Support
Autodesk Support

Hi,

 

I tested with your code on a simple drawing. I just changed the ini file path to my folder. The code works well. Does the specific error occur with a specific drawing or step? I re-formated the code and enclosed it again.

 

  

'____________________DXF Generator____________________
'Query user
Question = MessageBox.Show ("Do you require a DXF?" & vbNewLine & "NOTE! This will overwrite any existing DXF files with the same name!", "Export to DXF",MessageBoxButtons.YesNo,MessageBoxIcon.Question)
'Set condition dependent on answer
If Question = vbYes Then
 oPath = ThisDoc.Path  
 oFileName = ThisDoc.FileName(False) 
 'without extension  oRevNum = iProperties.Value("Project", "Revision Number") 
 oDXFAddIn = ThisApplication.ApplicationAddIns.ItemById("{C24E3AC4-122E-11D5-8E91-0010B541CD80}") 'get DXF Add-in
 oDocument = ThisApplication.ActiveDocument 'declare oDocument as this document  
 oContext = ThisApplication.TransientObjects.CreateTranslationContext 'declare oContext as TranslationContext
 oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism  
 
oOptions = ThisApplication.TransientObjects.CreateNameValueMap 'declare oOptions as NameValueMap object
 oDataMedium = ThisApplication.TransientObjects.CreateDataMedium 
 oFolder = oPath & "\DXF" 'Sets target folder
 MessageBox.Show(oFolder, "Title")

 If oDXFAddIn.HasSaveCopyAsOptions(oDocument, oContext, oOptions) Then 
     DXFIniFile = "C:\temp\RAMLDXF.ini" 
    oOptions.Value("Export_Acad_IniFile") = DXFIniFile
 End If
'Check for DXF folder and if it does not exist create one
If Not System.IO.Directory.Exists(oFolder) Then 
    System.IO.Directory.CreateDirectory(oFolder)
End If
    'Set the DXF destination file & file name
    oDataMedium.FileName = ThisDoc.PathAndFileName(False) 
    oDataMedium.FileName = oFolder & "\" & oFileName & " Rev " & oRevNum & ".dxf"
    
    On Error Goto handleDXFLock
    'Check if the idw has more than 1 sheet 
    If ThisDoc.Document.Sheets.Count > 1 Then
        For sheet_count = 1 To ThisDoc.Document.Sheets.Count
        'If there are no sheets end operation
            If Len(Dir(oPath & oFileName & " Rev " & oRevNum & "_SHEET_" & sheet_count & ".dxf")) <> 0 Then  
                Kill(oPath & oFileName & " Rev " & oRevNum & "_SHEET_" & sheet_count & ".dxf")
            Else If Len(Dir(oPath & oFileName & " Rev " & oRevNum & ".dxf")) <> 0 Then  
                Kill(oPath & oFileName & " Rev " & oRevNum & ".dxf")  
            End If
        Next sheet_count  
    End If
'Publish document.
oDXFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)

'Error message responses
handleDXFLock:
MessageBox.Show("DXF could not be saved!" & vbNewLine & "The file you are trying to overwrite may be open", "No DXF For you " & ThisApplication.GeneralOptions.UserName & "!")
Resume Next
MessageBox.Show("IDW and DXF have been saved to current document folder" , "Save IDW & DXF")
End If

 

 

0 Likes