AnsweredAssumed Answered

Saving DXF of drawing in VBA fails

Question asked by Chris Dault on May 14, 2020

Question about some api weirdness. Using SW2019 sp4 and VBA:

 

Saving a PDF of a drawing using ModelDocExtension.SaveAs2 works fine and will overwrite file if it already exists.

Example:

If Not swExt.SaveAs2(sTar, swSaveAsCurrentVersion, swSaveAsOptions_Silent, swExData, "", False, lErr, lWarn) Then
   Debug.Print "File: " & sTar & ", Error: " & lErr & ", Warning: " & lWarn
End If

 

Saving a DXF file of the same drawing with the same line of code will fail with error 256 (256 or 0x100 = File name extension does not match the SOLIDWORKS document type).

(EDIT: this was an error in my own code which was updating the model reference without also updating the model extension.)

I'm instead using the obsolete ModelDoc2.SaveAs4, which does indeed save the DXF file just fine.

Example:

If Not swModel.SaveAs4(sTar, swSaveAsCurrentVersion, swSaveAsOptions_Silent, lErr, lWarn) Then
   Debug.Print "File: " & sTar & ", Error: " & lErr & ", Warning: " & lWarn
End If

However, this method will fail with an error 1 (1 or 0x1 - swGenericSaveError) if the file already exists, and will NOT overwrite. (EDIT: This is still happening with overwriting DXF files but not PDF files, regardless of which method I use)

 

My questions are:
   Is there a documented reason why ModelDocExtension.SaveAs2 doesn't work with DXF? (Withdrawn: see above edit)
   Is ModelDoc2.SaveAs4 supposed to overwrite? If not, how can I force it to overwrite?

 

Thanks in advance for any help.

(EDIT2: I think this has to do with PDM workflow permissions. Assuming answered for now).

Outcomes