Control over individual paths: is there a better way?

Here's the place for discussion related to CAM/CNC and the development of the Path module.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
burgerking
Posts: 5
Joined: Wed Feb 19, 2020 9:47 pm

Control over individual paths: is there a better way?

Post by burgerking »

Hi!

Thanks again to this community for the help so far. This post is a continuation of: https://forum.freecadweb.org/viewtopic. ... 5&start=10

I managed to solve my particular problem, but it is not ideal.

EARLIER APPROACH: I am able to get the basic GCODE from GCodeStr = sPath.toGCode(), but I do not know how to insert custom commands (like those below) into this, and it gives me no control over the individual paths. As I mentioned, when using the toGCode() method, adjacent paths alternate cutting directions.

NEW APPROACH: Basically, I generate a new unique path for each new offset. This clutters the FC model window, and I assume is really bad with regards to speed of processing. Here is the code:

With a sketch 'Sketch':

Code: Select all

import FreeCAD
import FreeCAD as App
import Path, PathCommands
import numpy as np

Fobj = FreeCAD.activeDocument().addObject('Path::FeatureArea','FeatureArea')
Fobj.Sources = [ FreeCAD.activeDocument().Sketch, ]
gCode_out = [] 
offsets = np.linspace(1.1, 2.2, 15) 

def genGcode(offsets, Fobj, gCode_out):
# Generate a path around the shape for each offset, and make sure we output GCODE in the correct format.
	
	for oset_counter, oset in enumerate(offsets):
		n = oset#/1000.0    
		Fobj.Offset = n
		Fobj.ExtraPass = 0
		Fobj.JoinType = u"Miter"
		Fobj.MiterLimit = 10.00
		Fobj.Shape
		App.activeDocument().recompute(None,True,True)
		pArea = Path.Area()
		pArea.add(Fobj.Shape)
		sPath = Path.fromShapes(pArea.getShape(), orientation=1)
		Path.show(sPath)
		GCodeStr = sPath.toGCode()
			
		g1_counter = 0
		g2_counter = 0
		g3_counter = 0

		for i in sPath.Commands:
			if i.Name=='G0':
				if i.Parameters!={}:
					gCode_out.append('BEAMOFF')
					gCode_out.append(i.toGCode())

			if i.Name=='G1':
				if g1_counter==0:
					gCode_out.append('CALL_BLASTAWAY')
				gCode_out.append(i.toGCode())
				g1_counter+=1

			if i.Name=='G2':
				if g2_counter==0:
					gCode_out.append('CALL_BLASTAWAY')
				gCode_out.append(i.toGCode())
				g2_counter+=1

			if i.Name=='G3':
				if g3_counter==0:
					gCode_out.append('CALL_BLASTAWAY')
				gCode_out.append(i.toGCode())
				g3_counter+=1

			if i.Name=='G90':
				pass

		App.activeDocument().recompute(None,True,True)

	return gCode_out


gCode_out = genGcode(offsets, Fobj, gCode_out)
***
Is there a better way? I am new enough to python that I assume this is a bad hack. At very least, can all these paths be reconsolidated in some way?
***
Thanks!
Post Reply