Since each simulation needs to be completed, I used the QRunnable function to let the simulation be carried out in it and export the simulation results. But the FreeCAD program will crash every time at the end of the script.
Below is part of my code.
Code: Select all
FREECADPATH = "D:\\FreeCAD\\bin"
SIMULATORPATH="D:\\FreeCAD\\lib"
BINVOXPATH="E:\\111Masterarbeit\\Github\\Ausarbeitung\\utils"
import os
import sys
sys.path.append(FREECADPATH)
sys.path.append(SIMULATORPATH)
sys.path.append(BINVOXPATH)
import math
import numpy as np
import csv
import pandas as pd
#import PathSimulator
import FreeCAD as App
import FreeCADGui as Gui
from FreeCAD import Base, Rotation, Vector
import Part
import Path
import Draft
from math import pi, sin, cos
from PathScripts import PathJob
from PathScripts import PathJobGui
from PathScripts import PathProfile
from PathScripts import PathAdaptive
from PathScripts import PathPocket
import PathScripts.PathDressupDogbone as PathDressupDogbone
import PathScripts.PathDressupHoldingTags as PathDressupHoldingTags
from PathScripts import PathGeom
from PathScripts import PathPostProcessor
from PathScripts import PathUtil
DOC=FreeCAD.openDocument('E:/111Masterarbeit/Github/Ausarbeitung/Model mit binvox/Rechteckpocket2.FCStd')
DOC.recompute()
DOC = FreeCAD.activeDocument()
DOC.recompute()
Part1 = DOC.getObject('Part__Feature')
result = pd.read_csv('E:/111Masterarbeit/Github/Ausarbeitung/CSV/Pocket-Result.csv')
x=result.shape[1]
y=result.shape[0]
print(result.iloc[0][1])
print(int(result.iloc[0][2]))
if int(result.iloc[0][1]) == 10:
facName = 'Face{:d}'.format(int(result.iloc[0][2]))
print(facName)
Gui.activateWorkbench("PathWorkbench")
job = PathJob.Create('Job', [Part1], None)
job.ViewObject.Proxy = PathJobGui.ViewProvider(job.ViewObject)
#Profile Creat
profile = PathProfile.Create('Profile')
profile.setExpression('StepDown', None)
profile.StepDown = 10
profile.processHoles = True
profile.processPerimeter = True
profile.recompute()
DOC.recompute()
#Pocket
pocket = PathPocket.Create('Pocket')
pocket.Base = (Part1 , facName)
pocket.setExpression('StepDown', None)
pocket.StepDown = 5
pocket.recompute()
DOC.recompute()
#Simulation
from PathScripts import PathSimulatorGui as a
from time import sleep
from PyQt5.QtCore import (QCoreApplication, QObject, QRunnable, QThread,QThreadPool, pyqtSignal)
class Runnable(QRunnable):
def run(self):
count = 0
app = QCoreApplication.instance()
while a.pathSimulation.iprogress < a.pathSimulation.numCommands :
sleep(1)
print("Tasks are finished")
a.pathSimulation.accept()
#app.quit()
DOC.recompute()
FreeCADGui.Control.closeDialog()
# export
Gui.Selection.addSelection('Rechteckpocket2', 'CutMaterial')
__objs__ = []
__objs__.append(FreeCAD.getDocument("Rechteckpocket2").getObject("CutMaterial"))
import Mesh
Mesh.export(__objs__, u"E:/111Masterarbeit/Github/Ausarbeitung/ModelCutmaterial/Rechteckpocket-CutMaterial.stl")
print("export finished")
del __objs__
DOC.recompute()
DOC.removeObject('CutMaterial')
DOC.recompute()
Gui.runCommand('Path_Simulator',0)
a.pathSimulation.SetupSimulation() #Simulation Reset
a.pathSimulation.SimFF()
runnable = Runnable()
QThreadPool.globalInstance().start(runnable)
My FreeCAD version information is as follows.
Code: Select all
OS: Windows 10 Version 2009
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.19.24291 (Git)
Build type: Release
Branch: releases/FreeCAD-0-19
Hash: 7b5e18a0759de778b74d3a5c17eba9cb815035ac
Python version: 3.8.6+
Qt version: 5.15.2
Coin version: 4.0.1
OCC version: 7.5.0