Error screenshot is attached and program is below, excuse the sloppy code as I'm very new to this and have been kinda Frankensteining it. I'm guessing it has something to do with my import or macOS but I have no idea. Thanks for any help!
First File
Code: Select all
import sys, os, glob
sys.path.append(os.path.dirname(__file__))
import FreeCAD, FreeCADGui
App = FreeCAD
import ImportGui, importDXF, Part, PartGui, Draft
from PySide import QtGui, QtCore
import open
#import openUI
open.File().exec_()
if open.File().result == open.userCancelled:
pass
if open.File().result == open.userOK:
pass
Code: Select all
class File(QtGui.QDialog):
""""""
def __init__(self):
super(File, self).__init__()
self.initUI()
def initUI(self):
self.result = userCancelled
# xLoc,yLoc,xDim,yDim
self.setGeometry( 250, 250, 300, 200)
self.setWindowTitle("Part Open")
self.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint)
#
self.savePaths = next(os.walk("/Users/FSBMBP005/Dropbox/Programming/projects/"))[1]
self.date = str(self.savePaths[0])
self.dateFullPaths = glob.glob("/Users/FSBMBP005/Dropbox/Programming/projects/"+self.date+"/DXF/*.dxf")
self.datePaths = []
for i in range(1, len(self.dateFullPaths)):
singleFile = os.path.basename(self.dateFullPaths[i])
self.datePaths.append(singleFile)
#
self.popupItems1 = (self.savePaths)
self.popupItems2 = (self.datePaths)
self.popup1 = QtGui.QComboBox(self)
self.popup1.addItems(self.popupItems1)
self.popup1.activated[str].connect(self.onPopup1)
self.popup1.move(50, 30)
self.popup2 = QtGui.QComboBox(self)
self.popup2.addItems(self.popupItems2)
self.popup2.activated[str].connect(self.onPopup2)
self.popup2.move(50, 55)
#
self.thicknessInput = QtGui.QLineEdit(self)
self.thicknessInput.setInputMask("99")
self.thicknessInput.setText("20")
self.thicknessInput.setFixedWidth(40)
self.thicknessInput.move(130, 90)
#
self.inLabel = QtGui.QLabel("Thickness", self)
self.inLabel .setFont('Courier')
self.inLabel .move(51, 96.5)
#
cancelButton = QtGui.QPushButton('Cancel', self)
cancelButton.clicked.connect(self.onCancel)
cancelButton.setAutoDefault(True)
cancelButton.move(7, 140)
#
okButton = QtGui.QPushButton('OK', self)
okButton.clicked.connect(self.onOk)
okButton.move(223, 140)
#
self.show()
#
def startFile(self):
self.partThickness = self.thicknessInput.text()
importDXF.open(u"/Users/FSBMBP005/Dropbox/Programming/Projects/"+self.popup1.currentText()+"/DXF/"+self.popup2.currentText())
partLines = FreeCAD.ActiveDocument.findObjects("Part::Feature")
for object in partLines:
FreeCADGui.Selection.addSelection(object)
Draft.makeSketch(FreeCADGui.Selection.getSelection(), autoconstraints=True)
FreeCAD.ActiveDocument.removeObject('Layer003')
for object in partLines:
FreeCAD.ActiveDocument.removeObject(object.Label)
#
FreeCAD.ActiveDocument.addObject("Part::Extrusion", "Stock")
extrude = FreeCAD.ActiveDocument.getObject("Stock")
extrude.Base = FreeCAD.ActiveDocument.getObject("Sketch")
extrude.Dir = FreeCAD.Vector(0,0,-1)
extrude.LengthFwd = self.partThickness
Gui.activeDocument().getObject("Stock").Transparency = 50
extrude.Solid = False
#
imageFile = str(self.popup2.currentText())[:-3]+"png"
App.activeDocument().addObject('Image::ImagePlane','topImage')
App.activeDocument().topImage.ImageFile = '/Users/FSBMBP005/Dropbox/Programming/projects/'+self.date+"/DXF/"+imageFile
App.activeDocument().topImage.Placement = App.Placement(App.Vector(0.000000,0.000000,0.000000),App.Rotation(0.000000,0.000000,0.000000,1.000000))
App.activeDocument().topImage.XSize=100.00
App.activeDocument().topImage.YSize=100.00
App.activeDocument().topImage.Visibility=False
#
App.activeDocument().addObject('Image::ImagePlane','bottomImage')
App.activeDocument().bottomImage.ImageFile = '/Users/FSBMBP005/Dropbox/Programming/projects/'+self.date+"/DXF/"+imageFile
App.activeDocument().bottomImage.Placement = App.Placement(App.Vector(0.000000,0.000000,-int(self.partThickness)),App.Rotation(0.000000,0.000000,0.000000,1.000000))
App.activeDocument().bottomImage.XSize=100.00
App.activeDocument().bottomImage.YSize=100.00
#
FreeCAD.ActiveDocument.recompute()
Gui.SendMsgToActiveView("ViewFit")
Gui.runCommand('Std_OrthographicCamera',1)
Gui.Transparency=40
fileName = str(self.popup2.currentText())[:-4]
App.ActiveDocument.saveAs(u"/Users/FSBMBP005/Dropbox/Programming/projects/support/#FR33/Scripts/TestParts/"+fileName+".FCStd")
#import and extrude drawing, import pictures at part thickness, save as file name
def onPopup1(self, selectedText):
self.date = selectedText
self.dateFullPaths = glob.glob("/Users/FSBMBP005/Dropbox/Programming/projects/"+self.date+"/DXF/*.dxf")
self.datePaths = []
for i in range(1, len(self.dateFullPaths)):
singleFile = os.path.basename(self.dateFullPaths[i])
self.datePaths.append(singleFile)
self.popup2.clear()
self.popup2.addItems(self.datePaths)
print(self.popup2.count())
def onPopup2(self, selectedText):
self.partPath = selectedText
def onCancel(self):
self.result = userCancelled
print("Cancelled")
self.close()
def onOk(self):
self.result = userOK
self.startFile()
self.close()
userCancelled = "Cancelled"
userOK = "OK"
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.19.24291 (Git)
Build type: Release
Branch: (HEAD detached at 0.19.2)
Hash: 7b5e18a0759de778b74d3a5c17eba9cb815035ac
Python version: 3.8.8
Qt version: 5.12.9
Coin version: 4.0.0
OCC version: 7.4.0
Locale: C/Default (C)