Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

how to solve Catastrophic failure during SaveCopyAs operation during geometry export operation?

0 REPLIES 0
Reply
Message 1 of 1
mirhan.ozdemir39YZT
131 Views, 0 Replies

how to solve Catastrophic failure during SaveCopyAs operation during geometry export operation?

mirhan.ozdemir39YZT
Participant
Participant

Hi everyone,

I am working on a geometry export operation using VBScript, but I'm encountering an error when I try to run my script in batch mode. However, when I open the software and run the script in the VBA editor, it works perfectly.

 

Below is the error I receive when running it in batch mode:

mirhanozdemir39YZT_0-1725283314598.png

The line 91 is " Call oCADTranslator.SaveCopyAs(oDoc, oContext, oOptions, oData)"

 

' Here is my full VBscript:

 

' Initialize the logging mechanism
Dim fso, logFile
Set fso = CreateObject("Scripting.FileSystemObject")
Set logFile = fso.CreateTextFile("C:\Users\wj2078\Desktop\Coding Examples\inventor_batch_mode\logfile.txt", True) ' Adjust the log file path as needed

logFile.WriteLine "Script started..."

' Initialize Inventor application
Dim oApp
Set oApp = CreateObject("Inventor.Application")

' Set Inventor to be visible (adjust to True/False based on testing needs)
oApp.Visible = False ' Set to True for visibility; False for batch mode

logFile.WriteLine "Inventor initialized. Visibility set to: " & oApp.Visible


' Check if CAD Translator Add-In is available and active
Dim oCADTranslator
Set oCADTranslator = oApp.ApplicationAddIns.ItemById("{533E9A98-FC3B-11D4-8E7E-0010B541CD80}")


If oCADTranslator Is Nothing Then
MsgBox "Could not access CAD translator."
logFile.WriteLine "CAD Translator is not available."
oApp.Quit
logFile.Close
WScript.Quit
End If

If Not oCADTranslator.Activated Then
MsgBox "Activating CAD Translator."
oCADTranslator.Activate
logFile.WriteLine "CAD Translator activated."
End If


oApp.SilentOperation = True

' Open the document
Dim oDoc
Dim filePath
filePath = "C:\Users\wj2078\Desktop\Coding Examples\inventor_batch_mode\Octet(1 0 0)_Derrived.ipt"
Set oDoc = oApp.Documents.Open(filePath, True)

' Update the document
oDoc.Update


' Ensure the document is open
If oDoc Is Nothing Then
MsgBox "Document could not be opened.", vbCritical
logFile.WriteLine "Document could not be opened: " & filePath
oApp.Quit
logFile.Close
WScript.Quit
End If

logFile.WriteLine "Document opened successfully: " & filePath

' Create a translation context
Dim oContext
Set oContext = oApp.TransientObjects.CreateTranslationContext
logFile.WriteLine "Translation context created."

' Create options for the CAD export
Dim oOptions
Set oOptions = oApp.TransientObjects.CreateNameValueMap

If oCADTranslator.HasSaveCopyAsOptions(oDoc, oContext, oOptions) Then

' Set accuracy to Medium (1) - can be adjusted to Low (0) or High (2)
oOptions.Value("Resolution") = 1
logFile.WriteLine "CAD Resolution set to Medium (1)."

' Set output file type: 0 - binary, 1 - ASCII
oOptions.Value("OutputFileType") = 0
logFile.WriteLine "CAD OutputFileType set to ASCII (1)."

oContext.Type = kFileBrowseIOMechanism

' Set up the data medium with the target file path
Dim oData
Set oData = oApp.TransientObjects.CreateDataMedium

' output file name
oData.FileName = "C:\Users\wj2078\Desktop\Coding Examples\inventor_batch_mode\Octet(1 0 0)_Derrived.stl"
logFile.WriteLine "CAD output path set: " & oData.FileName

' Export the file
Call oCADTranslator.SaveCopyAs(oDoc, oContext, oOptions, oData)
logFile.WriteLine "CAD file successfully exported."
Else
logFile.WriteLine "CAD Translator did not provide SaveCopyAs options."
End If

' Save and close the document
oDoc.Save
oDoc.Close
logFile.WriteLine "Document saved and closed."

' Quit Inventor application
oApp.Quit
logFile.WriteLine "Inventor application quit."

' Close the log file
logFile.Close

'oApp.SilentOperation = False

' Notify the user (optional)
MsgBox "CAD export process completed."

 

'Thanks in advance for your guidance!

 

 

0 Likes

how to solve Catastrophic failure during SaveCopyAs operation during geometry export operation?

Hi everyone,

I am working on a geometry export operation using VBScript, but I'm encountering an error when I try to run my script in batch mode. However, when I open the software and run the script in the VBA editor, it works perfectly.

 

Below is the error I receive when running it in batch mode:

mirhanozdemir39YZT_0-1725283314598.png

The line 91 is " Call oCADTranslator.SaveCopyAs(oDoc, oContext, oOptions, oData)"

 

' Here is my full VBscript:

 

' Initialize the logging mechanism
Dim fso, logFile
Set fso = CreateObject("Scripting.FileSystemObject")
Set logFile = fso.CreateTextFile("C:\Users\wj2078\Desktop\Coding Examples\inventor_batch_mode\logfile.txt", True) ' Adjust the log file path as needed

logFile.WriteLine "Script started..."

' Initialize Inventor application
Dim oApp
Set oApp = CreateObject("Inventor.Application")

' Set Inventor to be visible (adjust to True/False based on testing needs)
oApp.Visible = False ' Set to True for visibility; False for batch mode

logFile.WriteLine "Inventor initialized. Visibility set to: " & oApp.Visible


' Check if CAD Translator Add-In is available and active
Dim oCADTranslator
Set oCADTranslator = oApp.ApplicationAddIns.ItemById("{533E9A98-FC3B-11D4-8E7E-0010B541CD80}")


If oCADTranslator Is Nothing Then
MsgBox "Could not access CAD translator."
logFile.WriteLine "CAD Translator is not available."
oApp.Quit
logFile.Close
WScript.Quit
End If

If Not oCADTranslator.Activated Then
MsgBox "Activating CAD Translator."
oCADTranslator.Activate
logFile.WriteLine "CAD Translator activated."
End If


oApp.SilentOperation = True

' Open the document
Dim oDoc
Dim filePath
filePath = "C:\Users\wj2078\Desktop\Coding Examples\inventor_batch_mode\Octet(1 0 0)_Derrived.ipt"
Set oDoc = oApp.Documents.Open(filePath, True)

' Update the document
oDoc.Update


' Ensure the document is open
If oDoc Is Nothing Then
MsgBox "Document could not be opened.", vbCritical
logFile.WriteLine "Document could not be opened: " & filePath
oApp.Quit
logFile.Close
WScript.Quit
End If

logFile.WriteLine "Document opened successfully: " & filePath

' Create a translation context
Dim oContext
Set oContext = oApp.TransientObjects.CreateTranslationContext
logFile.WriteLine "Translation context created."

' Create options for the CAD export
Dim oOptions
Set oOptions = oApp.TransientObjects.CreateNameValueMap

If oCADTranslator.HasSaveCopyAsOptions(oDoc, oContext, oOptions) Then

' Set accuracy to Medium (1) - can be adjusted to Low (0) or High (2)
oOptions.Value("Resolution") = 1
logFile.WriteLine "CAD Resolution set to Medium (1)."

' Set output file type: 0 - binary, 1 - ASCII
oOptions.Value("OutputFileType") = 0
logFile.WriteLine "CAD OutputFileType set to ASCII (1)."

oContext.Type = kFileBrowseIOMechanism

' Set up the data medium with the target file path
Dim oData
Set oData = oApp.TransientObjects.CreateDataMedium

' output file name
oData.FileName = "C:\Users\wj2078\Desktop\Coding Examples\inventor_batch_mode\Octet(1 0 0)_Derrived.stl"
logFile.WriteLine "CAD output path set: " & oData.FileName

' Export the file
Call oCADTranslator.SaveCopyAs(oDoc, oContext, oOptions, oData)
logFile.WriteLine "CAD file successfully exported."
Else
logFile.WriteLine "CAD Translator did not provide SaveCopyAs options."
End If

' Save and close the document
oDoc.Save
oDoc.Close
logFile.WriteLine "Document saved and closed."

' Quit Inventor application
oApp.Quit
logFile.WriteLine "Inventor application quit."

' Close the log file
logFile.Close

'oApp.SilentOperation = False

' Notify the user (optional)
MsgBox "CAD export process completed."

 

'Thanks in advance for your guidance!

 

 

Labels (4)
0 REPLIES 0

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report