Strange error

Strange error

Anonymous
Not applicable
855 Views
4 Replies
Message 1 of 5

Strange error

Anonymous
Not applicable

Hello,

 

We've been using this rule quite a while. All of a sudden i get this error (attachment). The strange things are that;

- nothing has changed to the code,

- and only on my computer i get the error, my colleagues can run the same code on their computer without any problems (same Windows and Inventor version).

 

	aPath = ThisDoc.Path
	iPropParNum = iProperties.Value("Project", "Part Number")
	iPropRevNum = iProperties.Value("Project", "Revision Number")
	aFolder = aPath & "\" & "DWG"
	aDWG = ThisApplication.ApplicationAddIns.ItemById("{C24E3AC2-122E-11D5-8E91-0010B541CD80}")
	aDoc = ThisApplication.ActiveDocument
	transObjs = ThisApplication.TransientObjects
	aContext = transObjs.CreateTranslationContext
	aContext.Type = kFileBrowseIOMechanism
	
	aOptions = transObjs.CreateNameValueMap
	If aDWG.HasSaveCopyAsOptions(aDoc, aContext, aOptions) Then
	End If
	
	Dim aDataMedium As DataMedium
	aDataMedium = ThisApplication.TransientObjects.CreateDataMedium
	aDataMedium.FileName = aFolder & "\" & iPropParNum & " rev" & iPropRevNum & " - 2D drawing" & ".dwg"
	aName = aDataMedium.FileName
	
	aDWG.SaveCopyAs(doc, context, options, oDataMedium)
	
	If System.IO.File.Exists( aFolder & "\" & " rev" & " - 2D drawing" & ".dwg" ) = True Then
	System.IO.File.Delete( aFolder & "\" & " rev" & " - 2D drawing" & ".dwg" )
	End If
	
	If System.IO.File.Exists( aFolder & "\" & iPropParNum & " rev" & " - 2D drawing" & ".dwg" ) = True Then
	System.IO.File.Move( aFolder & "\" & iPropParNum & " rev" & " - 2D drawing" & ".dwg", aFolder & "\" & iPropParNum & " - 2D drawing" & ".dwg" )
	End If

 

Does anybody know how this can be solved? Any help is welcome!

 

Thanks,

Stan

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

rossano_praderi
Collaborator
Collaborator
Accepted solution

Hi,

this is your code with few modifications (I cleaned up the code for my comfort), the error is generated by your code because you didn't check if the folder exist before exporting the file.

 

aPath = ThisDoc.Path
aFolder = aPath & "\DWG\"
iPropParNum = iProperties.Value("Project", "Part Number")
If Not iPropParNum = "" Then
	If Not System.IO.Directory.Exists(aFolder) Then
		System.IO.Directory.CreateDirectory(aFolder)
	End If
	iPropRevNum = iProperties.Value("Project", "Revision Number")
	aDataMedium = ThisApplication.TransientObjects.CreateDataMedium
	aName = aFolder & iPropParNum & " rev" & iPropRevNum & " - 2D drawing.dwg"
	aDataMedium.FileName = aName
	aDWG = ThisApplication.ApplicationAddIns.ItemById("{C24E3AC2-122E-11D5-8E91-0010B541CD80}") 
	aDoc = ThisApplication.ActiveDocument  
	transObjs = ThisApplication.TransientObjects 
	aContext = transObjs.CreateTranslationContext 
	aContext.Type = kFileBrowseIOMechanism 
	
	aOptions = transObjs.CreateNameValueMap 
'	If aDWG.HasSaveCopyAsOptions(aDoc, aContext, aOptions) Then
'	End If

	aDWG.SaveCopyAs(aDoc, aContext, aOptions, aDataMedium)
	
	If System.IO.File.Exists(aFolder & " rev - 2D drawing.dwg") = True Then
		System.IO.File.Delete(aFolder & " rev - 2D drawing.dwg")
	End If
	
	If System.IO.File.Exists(aFolder & iPropParNum & " rev - 2D drawing.dwg") = True Then
		System.IO.File.Move(aFolder & iPropParNum & " rev - 2D drawing.dwg", aFolder & iPropParNum & " - 2D drawing.dwg")
	End If
End If

 

Bregs

Rossano Praderi



--------------------------------------
If my post answers your question, please click the "Accept as Solution"
button. This helps everyone find answers more quickly!
---------------
Message 3 of 5

Anonymous
Not applicable

Thank you, it works! Only one problem, it exports to a .zip file with fonts and the image used in my template, and i have no idea why it's doing that...

0 Likes
Message 4 of 5

rossano_praderi
Collaborator
Collaborator
Accepted solution

Hi, you have to setup your options through the inventor interface.

 

  1. Open a drawing document
  2. Use the SaveAsCopy command
  3. On the DialogBox select the file format "Autocad Dwg"
  4. Click on Options and make your settings
  5. Create the .INI file with your settings by using the save configuration buttom in the second DialogBox
  6. Now write full path and file name of your .INI in the follow code lines (right now in your code you will find the commented lines)

 

If aDWG.HasSaveCopyAsOptions(aDoc, aContext, aOptions) Then
   strIniFile="NAME_OF_YOUR_INI_FILE.INI"
   oOptions.Value("Export_Acad_IniFile") = strIniFile
End If

 

Bregs

Rossano Praderi



--------------------------------------
If my post answers your question, please click the "Accept as Solution"
button. This helps everyone find answers more quickly!
---------------
Message 5 of 5

Anonymous
Not applicable
Thank you, that worked!
0 Likes