Pythonを使用してFreeCADで単純な柱を作成し、.stlファイルとしてエクスポートしたいと思います
私はこれまでに何をしましたか?
コードは次のとおりです。
# -*- 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__
+++++++++++++++++++++++++++++++++++++++++++++++++
GUI を閉じてターミナルを開き、次のように入力します。
"C:\Program Files\FreeCAD 0.18\bin\FreeCADCmd.exe" "C:\Users\totyped\Documents\pillar.py"
ソース: https://forum.freecadweb.org/viewtopic.php?t=23869
結果:これは端末に表示されるだけで、stl ファイルは作成されません。
また、警告やエラーメッセージも表示されません...
ノート
それで、スクリプトファイルをFreeCADmd.exeと同じディレクトリに置くとうまくいくことに気づきました。なんで ?私は見当もつかない。
編集
@sliptonic の提案に従って、スクリプト ファイルを次のように変更しようとしました。
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__
しかし、私はまだシリンダーを手に入れませんでした。おそらくログファイルが役立つでしょうか?ここにあります:
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
FreeCAD GUI内からマクロとして実行すると、動作して.stlシリンダーが作成されるため、奇妙です。