I wonder why just this was missing from the command line options. In my case, is a typical operation when preparing the machining. The outline layer from the geda/pcb program is exported to svg then processed to gcode. However, I did not found other way how to generate a gcode including the support structure other than shifting the model down by the pcb board thickness and setting the margins to fixed with lower z also equal to the board thickness.
Additionally, the svg sometimes has the polygon winding problems so I also needed to have the polygons revised in the batch mode.
So I created a patch:
--- /home/kamil/src/pycam-0.5.1-orig/pycam
+++ /home/kamil/src/pycam-0.5.1/pycam
@@ -416,6 +416,16 @@
process_bounds = Bounds(Bounds.TYPE_FIXED_MARGIN, offset, offset)
process_bounds.set_reference(bounds)
tps.set_bounds(process_bounds)
+
+ model_shift_nums = parse_triple_float(opts.model_shift)
+ if opts.model_revise:
+ model.revise_directions()
+ if not model_shift_nums is None :
+ model.shift( *model_shift_nums )
+ if not opts.model_scale is None :
+ if opts.model_scale != 0 :
+ model.scale( opts.model_scale )
+
if opts.export_gcode:
# generate the toolpath
start_time = time.time()
@@ -573,6 +583,16 @@
group_general.add_option("-v", "--version", dest="show_version",
default=False, action="store_true", help="output the current " \
+ "version of PyCAM and exit")
+ group_general.add_option("", "--model-shift", dest="model_shift",
+ default="", action="store", type="string",
+ help="comma-separated x/y/z combination of the model initial" \
+ + " shift (e.g. '0,0,-2.5')")
+ group_general.add_option("", "--model-scale", dest="model_scale",
+ default="1", action="store", type="float",
+ help="scale ratio to be applied to the model")
+ group_general.add_option("", "--model-revise", dest="model_revise",
+ default=False, action="store_true", help="perform revise " \
+ + "direction function on model load.")
# export options
group_export.add_option("", "--export-gcode", dest="export_gcode",
default=None, action="store", type="string",
Last edit: khorak 2014-03-08
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Could you please elaborate upon your use case? Maybe it would be useful for others, as well …
If your point is just a static scaling for all models, you could apply the following patch:
--- src/pycam/Gui/Project.py (Revision 1101)+++ src/pycam/Gui/Project.py (Arbeitskopie)@@ -3258,6 +3258,7 @@
if model:
self._store_undo_state()
self.model = model
+ self.model.scale(2.0)
self.last_model_uri = None
# do some initialization
self._update_all_model_attributes()
Alternatively you could use a script similar to the following to perform some batch operations. Just save this code as a text file (preferably in the base directory of PyCAM), enable its executable flag and run it with the input and output filenames as parameters:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#!/usr/bin/env pythonimportsysimportos# import the local pycam module pathsys.path.insert(0,os.path.join(os.path.dirname(__file__),"src"))frompycam.Importersimportdetect_file_typeif__name__=="__main__":iflen(sys.argv)!=3:print>>sys.stderr,"Parameters: INPUT OUTPUT"sys.exit(1)input_file,output_file=sys.argv[1:3]ifnotos.path.isfile(input_file):print>>sys.stderr,"Input file '%s' does not exist"%input_fileextension,importer=detect_file_type(input_file)model=importer(input_file)model.scale(2.0)out=open(output_file,"w")model.export().write(out)out.close()
The example simply performs a "scale by factor 2" - but you can use other functions, as well. See src/pycam/Geometry/Model.py for all possible operations.
Hope this helps,
Lars
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Ich greife durch ein Java-Tool im command-line Modus auf pycam zu.
Problem 1:
Alle Modelle sollen um einen Faktor gestaucht werden.
Habe die Einstellung unter src/pycam/Gui/Project.py bereits ausprobiert, jedoch verändert sich dann nur der voreingestellten Wert in der GUI, per command-line bleibt bei mir alles beim alten.
Problem 2:
Saftey-Height. gcode_safety_height kann man auch unter src/pycam/Gui/Project.py nur für die GUI einstellen.
Könnte man beide Probleme Hardcodieren oder über eine command-line argument bzw. conf-File lösen.
Vielen Lieben Dank schon einmal im Voraus.
Bis dann,
B.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
zu Problem 1: versuche es mit folgendem Patch des Start-Skripts:
--- pycam (Revision 1121)+++ pycam (Arbeitskopie)@@ -165,7 +165,7 @@
", ".join(EXAMPLE_MODEL_LOCATIONS)))
return pycam.Importers.TestModel.get_test_model()
-def load_model_file(filename, program_locations, unit=None):+def load_model_file(filename, program_locations, scale=1.0, unit=None):
uri = pycam.Utils.URIHandler(filename)
if uri.is_local():
uri = pycam.Utils.URIHandler(os.path.expanduser(str(filename)))
@@ -174,6 +174,8 @@
return None
importer = pycam.Importers.detect_file_type(uri)[1]
model = importer(uri, program_locations=program_locations, unit=unit)
+ if scale != 1:+ model.scale(scale)
if not model:
log.warn("Failed to load the model file (%s)." % uri)
return None
@@ -351,10 +353,10 @@
if isinstance(model, basestring):
model = load_model_file(model,
program_locations=program_locations,
- unit=opts.unit_size)+ scale=opts.scale_model, unit=opts.unit_size)
else:
model = load_model_file(inputfile,
- program_locations=program_locations, unit=opts.unit_size)+ program_locations=program_locations, scale=opts.scale_model, unit=opts.unit_size)
if not model:
# something went wrong - we quit
return EXIT_CODES["load_model_failed"]
@@ -574,6 +576,8 @@
group_general.add_option("-v", "--version", dest="show_version",
default=False, action="store_true", help="output the current " \
+ "version of PyCAM and exit")
+ group_general.add_option("", "--scale", dest="scale_model",+ action="store", type="float", default=1.0, help="Scale model on load")
# export options
group_export.add_option("", "--export-gcode", dest="export_gcode",
default=None, action="store", type="string",
Die obigen Aenderungen habe ich nicht getestet, aber nun sollte bei allen Kommandozeilen-Operationen der Parameter "-scale" beachtet werden. Bei Verwendung der GUI wird der Wert ignoriert.
Diese Funktion wird auch in der naechsten Version von PyCAM verfuegbar sein, allerdings wird sie sicherlich anders heissen …
Zu Problem 2: eigentlich sollte safety-height bei Kommandozeilen-Operationen beachtet werden ("-safety-height"). Klappt das nicht? In der GUI wird der Wert jeweils aus der PyCAM-Konfigurationsdatei ausgelesen.
Oder was ist dein Plan?
weitermachen,
Lars
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi!
Is there a way to scale a model via a command line option or even better via the conf file?
Thanks for help, really appreciate!
B.
I wonder why just this was missing from the command line options. In my case, is a typical operation when preparing the machining. The outline layer from the geda/pcb program is exported to svg then processed to gcode. However, I did not found other way how to generate a gcode including the support structure other than shifting the model down by the pcb board thickness and setting the margins to fixed with lower z also equal to the board thickness.
Additionally, the svg sometimes has the polygon winding problems so I also needed to have the polygons revised in the batch mode.
So I created a patch:
Last edit: khorak 2014-03-08
Hi bhae,
currently this is not implemented.
Could you please elaborate upon your use case? Maybe it would be useful for others, as well …
If your point is just a static scaling for all models, you could apply the following patch:
Alternatively you could use a script similar to the following to perform some batch operations. Just save this code as a text file (preferably in the base directory of PyCAM), enable its executable flag and run it with the input and output filenames as parameters:
The example simply performs a "scale by factor 2" - but you can use other functions, as well. See src/pycam/Geometry/Model.py for all possible operations.
Hope this helps,
Lars
Hallo Lars!
vielen herzlichen Dank für Deine Antwort.
Ich greife durch ein Java-Tool im command-line Modus auf pycam zu.
Problem 1:
Alle Modelle sollen um einen Faktor gestaucht werden.
Habe die Einstellung unter src/pycam/Gui/Project.py bereits ausprobiert, jedoch verändert sich dann nur der voreingestellten Wert in der GUI, per command-line bleibt bei mir alles beim alten.
Problem 2:
Saftey-Height. gcode_safety_height kann man auch unter src/pycam/Gui/Project.py nur für die GUI einstellen.
Könnte man beide Probleme Hardcodieren oder über eine command-line argument bzw. conf-File lösen.
Vielen Lieben Dank schon einmal im Voraus.
Bis dann,
B.
Hi B,
nun gut - machen wir auf Deutsch weiter :)
zu Problem 1: versuche es mit folgendem Patch des Start-Skripts:
Die obigen Aenderungen habe ich nicht getestet, aber nun sollte bei allen Kommandozeilen-Operationen der Parameter "-scale" beachtet werden. Bei Verwendung der GUI wird der Wert ignoriert.
Diese Funktion wird auch in der naechsten Version von PyCAM verfuegbar sein, allerdings wird sie sicherlich anders heissen …
Zu Problem 2: eigentlich sollte safety-height bei Kommandozeilen-Operationen beachtet werden ("-safety-height"). Klappt das nicht? In der GUI wird der Wert jeweils aus der PyCAM-Konfigurationsdatei ausgelesen.
Oder was ist dein Plan?
weitermachen,
Lars