6040 CNC Path Macro for fast text engraving plus video

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
CoderMusashi
Posts: 92
Joined: Mon Nov 19, 2018 8:26 pm

6040 CNC Path Macro for fast text engraving plus video

Post by CoderMusashi »

I am posting this here first and the video link in the tutorial section of the forum. Hope you enjoy the video and the macro that goes with it. I made it for a new FreeCAD and 6040 user. Before running the macro change your font location in the macro.. I commented out what a windows path might look like..

The link to the video https://youtu.be/DsRkUlEwouY

The Macro

Code: Select all

import Part
import Draft
import Sketcher
doc = App.newDocument("Unnamed")

#Create our table bed Sketch
App.activeDocument().addObject('Sketcher::SketchObject', 'Sketch')
App.activeDocument().Sketch.Placement = App.Placement(App.Vector(0.000000, 0.000000, 0.000000), App.Rotation(0.000000, 0.000000, 0.000000, 1.000000))
App.activeDocument().Sketch.MapMode = "Deactivated"
geoList = []
geoList.append(Part.LineSegment(App.Vector(0.000000,0.000000,0),App.Vector(19,0.000000,0)))
geoList.append(Part.LineSegment(App.Vector(19,0.000000,0),App.Vector(19,30,0)))
geoList.append(Part.LineSegment(App.Vector(19,30,0),App.Vector(0.000000,30,0)))
geoList.append(Part.LineSegment(App.Vector(0.000000,30,0),App.Vector(0.000000,0.000000,0)))
App.getDocument('Unnamed').getObject('Sketch').addGeometry(geoList,False)
conList = []
conList.append(Sketcher.Constraint('Coincident',0,2,1,1))
conList.append(Sketcher.Constraint('Coincident',1,2,2,1))
conList.append(Sketcher.Constraint('Coincident',2,2,3,1))
conList.append(Sketcher.Constraint('Coincident',3,2,0,1))
conList.append(Sketcher.Constraint('Horizontal',0))
conList.append(Sketcher.Constraint('Horizontal',2))
conList.append(Sketcher.Constraint('Vertical',1))
conList.append(Sketcher.Constraint('Vertical',3))
App.getDocument('Unnamed').getObject('Sketch').addConstraint(conList)
del geoList, conList

App.getDocument('Unnamed').getObject('Sketch').addConstraint(Sketcher.Constraint('Coincident',0,1,-1,1)) 
App.getDocument('Unnamed').getObject('Sketch').addConstraint(Sketcher.Constraint('DistanceX',2,2,2,1,19)) 
App.getDocument('Unnamed').getObject('Sketch').setDatum(9,App.Units.Quantity('19 in'))
App.getDocument('Unnamed').getObject('Sketch').addConstraint(Sketcher.Constraint('DistanceY',3,2,3,1,30)) 
App.getDocument('Unnamed').getObject('Sketch').setDatum(10,App.Units.Quantity('30 in'))
App.ActiveDocument.recompute()
#End of Table Bed Sketch

#Create Text and move it

ourstring = "Go Get The $" 

#for windows operating systems use 
#FontFile="C:/Windows/Fonts/ANTQUAB.TTF"
#in the next line of code replacing /usr/share

ss=Draft.make_shapestring(String=ourstring , FontFile="/usr/share/fonts/truetype/padauk/Padauk-Regular.ttf", Size=38.099999999999994, Tracking=0.0)

plm=FreeCAD.Placement()
plm.Base=FreeCAD.Vector(0.0, 0.0, 0.0)
plm.Rotation.Q=(0.0, 0.0, 0.0, 1.0)
ss.Placement=plm
ss.Support=None
Draft.autogroup(ss)
App.activeDocument().recompute(None,True,True)

FreeCAD.getDocument('Unnamed').getObject('ShapeString').Placement = App.Placement(App.Vector(127.0000,50.8000,0.0000),App.Rotation(App.Vector(0.0000,0.0000,1.0000),90.0000))
#End of Create Text

#Make 2D wire from the ShapeString
sv0 = Draft.make_shape2dview(FreeCAD.ActiveDocument.ShapeString, FreeCAD.Vector(-0.0, -0.0, 1.0))
App.ActiveDocument.recompute()

#now create the path
import PathCommands
FreeCAD.activeDocument().addObject('Path::FeatureShape','PathShape')
FreeCAD.activeDocument().PathShape.Sources = [ FreeCAD.activeDocument().Shape2DView, ]
App.ActiveDocument.recompute()

#inspect the Path Gcode just created
import PathScripts.PathInspect
PathScripts.PathInspect.show(FreeCAD.ActiveDocument.PathShape)
To get the GCode in inches I suggest First you create a Job and then run the below code in the Python Console to add your PathShape to the job. You will now be able to post your code out like any other Path created in the job. See the video for visual help https://youtu.be/OwOfs_p5wKk

Code: Select all

import PathScripts.PathUtils
PathScripts.PathUtils.addToJob(App.ActiveDocument.PathShape)
Post Reply