4

Recently I have been working on an assignment to convert five file formats (.dae, .stl, .step, igs, obj) to .stl. using FreeCAD Python console and help from people on StackOverflow and FreeCAD forum, I was able to do that.

The last part of this assignment is to convert .sldprt (Solidworks Parts File) to .stl. Unfortunately, FreeCAD does not support importing this file format and I can not use its Python console to convert this file format to .stl.

I have been searching Python APIs that can read/export .sldprt files but I haven't been able to find any. I did find some online sources (GradCAD, Datakit Cross manager etc.) but I need to accomplish this by a Python script (preferably Python 2).

Is there another way I can convert .sldprt file to .stl using Python? Can someone point me in the right direction where to start?

273K
  • 29,503
  • 10
  • 41
  • 64
Umar Dastgir
  • 688
  • 9
  • 25

2 Answers2

4

Since sldprt is a proprietary format, you are only able to do that if SOLIDWORKS is installed on the executing machine. This is done with the SOLIDWORKS API. With that condition out of the way, you will need to write some sort of bridge between Python and the SOLIDWORKS COM API objects which is a big hassle. If this is a school assignment, I would suggest you write a console application in C# or VB.NET that opens the file and converts it to whatever target format. You can command that application from your Python program.

There are a bunch of cloud services that can do CAD files conversion. Those can be a good alternative if you can't afford a SOLIDWORKS license or don't have access to one.

Amen Jlili
  • 1,884
  • 4
  • 28
  • 51
4

Autodesk Fusion 360 use a Python API and also import cad files from SolidWorks and export to other formats, check this examples:

  1. import
  2. export
efirvida
  • 4,592
  • 3
  • 42
  • 68
  • Thanks for the answer! I went through the API and it looks pretty good. I did find a link to export to .stl. However, I don't find any reference to importing a .sldprt file. Are you sure a .sldprt file can be imported/handled by Autodesk Python API? – Umar Dastgir May 01 '19 at 23:30
  • @UmarDastgir, I really don´t know I never used, but Fusion 360 can import sldprt files. take a look to this thread, http://help.autodesk.com/view/fusion360/ENU/?caas=caas/discussion/t5/Fusion-360-API-and-Scripts/Cant-import-file/td-p/7248535.html... maybe **app.importManager.createFusionArchiveImportOptions()** work – efirvida May 02 '19 at 01:39