Friday, 24 January 2020

Create a simple cylinder using command-line FreeCAD

I would like to create a simple pillar in FreeCAD using python and the export it as .stl file enter image description here What have I done so far?
  1. Recorded a macro of me creating a cylinder (Part) and exporting it as an stl file. der
  2. I copy and paste the text from the macro into a python file, which I named "pillar.py"
Here is the code:
# -*- coding: utf-8 -*-

+++++++++++++++++++++++++++++++++++++++++++++++++
import FreeCAD
import Part
import Mesh


App.ActiveDocument.addObject("Part::Cylinder","Cylinder")
App.ActiveDocument.ActiveObject.Label = "Cylinder"
App.ActiveDocument.recompute()

__objs__=[]
__objs__.append(FreeCAD.getDocument("Unnamed").getObject("Cylinder"))
Mesh.export(__objs__,u"C:/Users/totyped/Desktop/pillar_2.stl")

del __objs__
+++++++++++++++++++++++++++++++++++++++++++++++++
  1. I closed the GUI and open the terminal, and I type:
    "C:\Program Files\FreeCAD 0.18\bin\FreeCADCmd.exe" "C:\Users\totyped\Documents\pillar.py"
Source: https://forum.freecadweb.org/viewtopic.php?t=23869
The result: It just shows this on the terminal, but does not create any stl file.
enter image description here
It also does not give any warning or error message...
Any help to make this work, would be highly appreciated.
IMPORTANT: SO, I noticed that it will work, if I put the script file into the same directory as FreeCADmd.exe. Why ? I have no clue...
EDIT: So, as suggested by @sliptonic I tried to change the script file to:
import FreeCAD
import Part
import Mesh

App.newDocument("Unnamed")
App.ActiveDocument.addObject("Part::Cylinder","Cylinder")
App.ActiveDocument.ActiveObject.Label = "Cylinder"
App.ActiveDocument.recompute()

__objs__=[]
__objs__.append(FreeCAD.getDocument("Unnamed").getObject("Cylinder"))
Mesh.export(__objs__,u"pillar_2.stl")

del __objs__
but I still did not get any cylinder. Maybe the log file can help? Here it is:
Msg: FreeCAD 0.18, Libs: 0.18R4 (GitTag)
(c) Juergen Riegel, Werner Mayer, Yorik van Havre 2001-2019
  #####                 ####  ###   ####  
  #                    #      # #   #   # 
  #     ##  #### ####  #     #   #  #   # 
  ####  # # #  # #  #  #     #####  #   # 
  #     #   #### ####  #    #     # #   # 
  #     #   #    #     #    #     # #   #  ##  ##  ##
  #     #   #### ####   ### #     # ####   ##  ##  ##

Log: Time = Wed Jan 22 10:17:07 2020
Log: AppDataSkipVendor = true
Log: AppHomePath = C:/Program Files/FreeCAD 0.18/
Log: AppTempPath = C:\Users\Henry\AppData\Local\Temp\
Log: BinPath = C:/Program Files/FreeCAD 0.18/bin\
Log: BuildRepositoryURL = git://github.com/FreeCAD/FreeCAD.git releases/FreeCAD-0-18
Log: BuildRevision = 4 (GitTag)
Log: BuildRevisionBranch = releases/FreeCAD-0-18
Log: BuildRevisionDate = 2019/10/22 16:53:35
Log: BuildRevisionHash = 980bf9060e28555fecd9e3462f68ca74007b70f8
Log: BuildVersionMajor = 0
Log: BuildVersionMinor = 18
Log: CopyrightInfo = (c) Juergen Riegel, Werner Mayer, Yorik van Havre 2001-2019
  #####                 ####  ###   ####  
  #                    #      # #   #   # 
  #     ##  #### ####  #     #   #  #   # 
  ####  # # #  # #  #  #     #####  #   # 
  #     #   #### ####  #    #     # #   # 
  #     #   #    #     #    #     # #   #  ##  ##  ##
  #     #   #### ####   ### #     # ####   ##  ##  ##


Log: Debug = 0
Log: DocPath = C:/Program Files/FreeCAD 0.18/doc\
Log: ExeName = FreeCAD
Log: ExeVendor = FreeCAD
Log: ExeVersion = 0.18
Log: LoggingFile = 1
Log: LoggingFileName = C:\Users\Henry\AppData\Roaming\FreeCAD\FreeCAD.log
Log: OpenFile0 = pillar.py
Log: OpenFileCount = 1
Log: PATH = C:\Program Files\FreeCAD 0.18\bin\Library\bin;C:\Users\Henry\Anaconda3;C:\Users\Henry\Anaconda3\Library\mingw-w64\bin;C:\Users\Henry\Anaconda3\Library\usr\bin;C:\Users\Henry\Anaconda3\Library\bin;C:\Users\Henry\Anaconda3\Scripts;C:\Users\Henry\Anaconda3\bin;C:\Users\Henry\Anaconda3\condabin;C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1\bin;C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1\libnvvp;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0;C:\WINDOWS\System32\OpenSSH;C:\Program Files\MATLAB\R2019a\bin;C:\Program Files\NVIDIA Corporation\NVIDIA NGX;C:\Program Files\MATLAB\MATLAB Runtime\v94\runtime\win64;C:\Program Files (x86)\Wolfram Research\WolframScript;C:\Program Files (x86)\QuickTime\QTSystem;C:\Users\Henry\AppData\Local\Microsoft\WindowsApps;C:\Users\Henry\AppData\Local\Programs\MiKTeX 2.9\miktex\bin\x64
Log: PythonSearchPath = C:\Program Files\FreeCAD 0.18\bin\python36.zip;C:\Program Files\FreeCAD 0.18\bin\DLLs;C:\Program Files\FreeCAD 0.18\bin\lib;C:\Program Files\FreeCAD 0.18\bin
Log: RunMode = Exit
Log: SystemParameter = C:\Users\Henry\AppData\Roaming\FreeCAD\system.cfg
Log: UserAppData = C:\Users\Henry\AppData\Roaming\FreeCAD\
Log: UserHomePath = C:\Users\Henry\Documents
Log: UserParameter = C:\Users\Henry\AppData\Roaming\FreeCAD\user.cfg
Log: Verbose = 
Log: Create Application
Log: Run App init script
Log: Init: starting App::FreeCADInit.py
Log: Init:   Searching for modules...
Log: Init:      Initializing C:\Program Files\FreeCAD 0.18\Mod\AddonManager... done
Log: Init:      Initializing C:\Program Files\FreeCAD 0.18\Mod\Arch... done
Log: Init:      Initializing C:\Program Files\FreeCAD 0.18\Mod\Complete... done
Log: Init:      Initializing C:\Program Files\FreeCAD 0.18\Mod\Draft... done
Log: Init:      Initializing C:\Program Files\FreeCAD 0.18\Mod\Drawing... done
Log: Init:      Initializing C:\Program Files\FreeCAD 0.18\Mod\Fem... done
Log: Init:      Initializing C:\Program Files\FreeCAD 0.18\Mod\Idf... done
Log: Init:      Initializing C:\Program Files\FreeCAD 0.18\Mod\Image... done
Log: Init:      Initializing C:\Program Files\FreeCAD 0.18\Mod\Import... done
Log: Init:      Initializing C:\Program Files\FreeCAD 0.18\Mod\Inspection... done
Log: Init:      Initializing C:\Program Files\FreeCAD 0.18\Mod\Material... done
Log: Init:      Initializing C:\Program Files\FreeCAD 0.18\Mod\Measure... done
Log: Init:      Initializing C:\Program Files\FreeCAD 0.18\Mod\Mesh... done
Log: Init:      Initializing C:\Program Files\FreeCAD 0.18\Mod\MeshPart... done
Log: Init:      Initializing C:\Program Files\FreeCAD 0.18\Mod\OpenSCAD... done
Log: Init:      Initializing C:\Program Files\FreeCAD 0.18\Mod\Part... done
Log: Init:      Initializing C:\Program Files\FreeCAD 0.18\Mod\PartDesign... done
Log: Init:      Initializing C:\Program Files\FreeCAD 0.18\Mod\Path... done
Log: Init:      Initializing C:\Program Files\FreeCAD 0.18\Mod\Plot(Init.py not found)... ignore
Log: Init:      Initializing C:\Program Files\FreeCAD 0.18\Mod\Points... done
Log: Init:      Initializing C:\Program Files\FreeCAD 0.18\Mod\Raytracing... done
Log: Init:      Initializing C:\Program Files\FreeCAD 0.18\Mod\Robot... done
Log: Init:      Initializing C:\Program Files\FreeCAD 0.18\Mod\Ship(Init.py not found)... ignore
Log: Init:      Initializing C:\Program Files\FreeCAD 0.18\Mod\Show(Init.py not found)... ignore
Log: Init:      Initializing C:\Program Files\FreeCAD 0.18\Mod\Sketcher... done
Log: Init:      Initializing C:\Program Files\FreeCAD 0.18\Mod\Spreadsheet... done
Log: Init:      Initializing C:\Program Files\FreeCAD 0.18\Mod\Start... done
Log: Init:      Initializing C:\Program Files\FreeCAD 0.18\Mod\Surface... done
Log: Init:      Initializing C:\Program Files\FreeCAD 0.18\Mod\TechDraw... done
Log: Init:      Initializing C:\Program Files\FreeCAD 0.18\Mod\Test... done
Log: Init:      Initializing C:\Program Files\FreeCAD 0.18\Mod\Tux(Init.py not found)... ignore
Log: Init:      Initializing C:\Program Files\FreeCAD 0.18\Mod\Web... done
Log: Using C:\Program Files\FreeCAD 0.18\Mod as module path!
Log: System path after init:
Log:    C:\Program Files\FreeCAD 0.18\bin
Log:    C:\Program Files\FreeCAD 0.18\Mod\AddonManager
Log:    C:\Program Files\FreeCAD 0.18\Mod\Arch
Log:    C:\Program Files\FreeCAD 0.18\Mod\Complete
Log:    C:\Program Files\FreeCAD 0.18\Mod\Draft
Log:    C:\Program Files\FreeCAD 0.18\Mod\Drawing
Log:    C:\Program Files\FreeCAD 0.18\Mod\Fem
Log:    C:\Program Files\FreeCAD 0.18\Mod\Idf
Log:    C:\Program Files\FreeCAD 0.18\Mod\Image
Log:    C:\Program Files\FreeCAD 0.18\Mod\Import
Log:    C:\Program Files\FreeCAD 0.18\Mod\Inspection
Log:    C:\Program Files\FreeCAD 0.18\Mod\Material
Log:    C:\Program Files\FreeCAD 0.18\Mod\Measure
Log:    C:\Program Files\FreeCAD 0.18\Mod\Mesh
Log:    C:\Program Files\FreeCAD 0.18\Mod\MeshPart
Log:    C:\Program Files\FreeCAD 0.18\Mod\OpenSCAD
Log:    C:\Program Files\FreeCAD 0.18\Mod\Part
Log:    C:\Program Files\FreeCAD 0.18\Mod\PartDesign
Log:    C:\Program Files\FreeCAD 0.18\Mod\Path
Log:    C:\Program Files\FreeCAD 0.18\Mod\Plot
Log:    C:\Program Files\FreeCAD 0.18\Mod\Points
Log:    C:\Program Files\FreeCAD 0.18\Mod\Raytracing
Log:    C:\Program Files\FreeCAD 0.18\Mod\Robot
Log:    C:\Program Files\FreeCAD 0.18\Mod\Ship
Log:    C:\Program Files\FreeCAD 0.18\Mod\Show
Log:    C:\Program Files\FreeCAD 0.18\Mod\Sketcher
Log:    C:\Program Files\FreeCAD 0.18\Mod\Spreadsheet
Log:    C:\Program Files\FreeCAD 0.18\Mod\Start
Log:    C:\Program Files\FreeCAD 0.18\Mod\Surface
Log:    C:\Program Files\FreeCAD 0.18\Mod\TechDraw
Log:    C:\Program Files\FreeCAD 0.18\Mod\Test
Log:    C:\Program Files\FreeCAD 0.18\Mod\Tux
Log:    C:\Program Files\FreeCAD 0.18\Mod\Web
Log:    C:\Program Files\FreeCAD 0.18\bin\Library\bin
Log:    C:\Users\Henry\Anaconda3
Log:    C:\Users\Henry\Anaconda3\Library\mingw-w64\bin
Log:    C:\Users\Henry\Anaconda3\Library\usr\bin
Log:    C:\Users\Henry\Anaconda3\Library\bin
Log:    C:\Users\Henry\Anaconda3\Scripts
Log:    C:\Users\Henry\Anaconda3\bin
Log:    C:\Users\Henry\Anaconda3\condabin
Log:    C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1\bin
Log:    C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1\libnvvp
Log:    C:\WINDOWS\system32
Log:    C:\WINDOWS
Log:    C:\WINDOWS\System32\Wbem
Log:    C:\WINDOWS\System32\WindowsPowerShell\v1.0
Log:    C:\WINDOWS\System32\OpenSSH
Log:    C:\Program Files\MATLAB\R2019a\bin
Log:    C:\Program Files\NVIDIA Corporation\NVIDIA NGX
Log:    C:\Program Files\MATLAB\MATLAB Runtime\v94\runtime\win64
Log:    C:\Program Files (x86)\Wolfram Research\WolframScript
Log:    C:\Program Files (x86)\QuickTime\QTSystem
Log:    C:\Users\Henry\AppData\Local\Microsoft\WindowsApps
Log:    C:\Users\Henry\AppData\Local\Programs\MiKTeX 2.9\miktex\bin\x64
Log: Init: App::FreeCADInit.py done
Log: Init: Processing command line files
Log: Init:     Processing file: pillar.py
Log: Exiting on purpose
Log: FreeCAD terminating...
Log: Saving system parameter...
Log: Saving system parameter...done
Log: Saving user parameter...
Log: Saving user parameter...done
It's weird because if I run is as a macro from within the FreeCAD GUI it works and creates the .stl cylinder


from Create a simple cylinder using command-line FreeCAD

No comments:

Post a Comment