Here is a sample file that I have been working with, but any .dxf file that was done in inch (Imperial) scale will do.
https://www.dropbox.com/s/ijhrpdzm4pu90 ... UTFILE.dxf (external link)
What I am wanting to do is develop a script that will scale each line, polyline, spline, arc, circle, etc., individually. Scaling all the lines, arcs, etc. in a group with the Draft, Scale tool leaves a single, un-editable clone. (and don't even get me started on clones ) I would like to scale this drawing by 25.4, which should result in a properly sized, 1:1 scale drawing in metric units that is intact.
I have been struggling with a couple of things. How to get the script to pick individual objects from the list and then, how to get the script to go to the next object. (for-next in Python)
I have a small script that almost does what I want with a single line, but the result is a "shape" and I'm not so far able to hit on the right syntax to do the Draft.upgrade to convert it to a Wire, though I would really like it if there were some way to convert it to a Line
Code: Select all
# INCH TO METRIC CONVERTER FOR IMPORTED DRAWINGS AND PARTS DONE IN IMPERIAL UNITS # FreeCAD VERSION 0.14 dev from PyQt4 import QtCore, QtGui import FreeCAD, FreeCADGui, Draft class p(): def proceed(self): try: # Line Scaling scalefactor=25.4 inchLine = FreeCAD.ActiveDocument.Line matrix=FreeCAD.Matrix() matrix.scale(scalefactor,scalefactor,scalefactor) metricLine=inchLine.Shape.copy() metricLine.transformShape(matrix) newMetricLine=FreeCAD.ActiveDocument.addObject('Part::Feature','Line') newMetricLine.Shape=metricLine inchLine.ViewObject.Visibility=False #something here to convert shape to line? except: FreeCAD.Console.PrintError("UNABLE TO COMPLY") self.close() def close(self): self.dialog.hide() def __init__(self): self.dialog = None self.s1 = None # Make dialog box and get input to proceed self.dialog = QtGui.QDialog() self.dialog.resize(260,100) self.dialog.setWindowTitle("Inch to Metric Scale") b1 = QtGui.QVBoxLayout(self.dialog) t1 = QtGui.QLabel("WARNING:\n Only use once pre drawing!\n Scales drawing by 25.4") b1.addWidget(t1) okbox = QtGui.QDialogButtonBox(self.dialog) okbox.setOrientation(QtCore.Qt.Horizontal) okbox.setStandardButtons(QtGui.QDialogButtonBox.Cancel|QtGui.QDialogButtonBox.Ok) b1.addWidget(okbox) QtCore.QObject.connect(okbox, QtCore.SIGNAL("accepted()"), self.proceed) QtCore.QObject.connect(okbox, QtCore.SIGNAL("rejected()"), self.close) QtCore.QMetaObject.connectSlotsByName(self.dialog) self.dialog.show() self.dialog.exec_() p()
Are there any scripts out there that would give a good example of how this might be done or any good pointers as to how I could get it to work?
Does any of this make any sense?
Oh, and be warned, I am far to new to Python to make much any sense out of it yet. What I have above was hacked together and modified from other peoples work / examples. What I have above only works because I spent lots of time reading error messages in the Report View in FreeCAD, then doctoring it up line by line.