28 November 2012
MOP Automate VB and Python scripts
This script will automate the process of opening a source file, insert machining operations,
set various properties and produce g-code.
These scripts demonstrate:
- opening a CAD file (.dxf in this example)
- drawing some extra shapes into the drawing
- setting machining options
- Call asynchronous CAD functions such as
Edit -> Join and Edit -> Convert to polyline
- creating a machining operation from objects in a drawing layer
- setting machining operation properties
- saving a drawing and creating g-code
Python version...
VBScript version...
from CamBam.CAM import *
from CamBam.UI import CamBamUI
from CamBam.Values import *
source_file = "C:\\CamBam\\cbfiles\\aluskids.dxf"
out_filename = "C:\\dump\\test.cb"
CamBamUI.MainUI.OpenFile(source_file,1)
newdoc = CamBamUI.MainUI.ActiveView.CADFile
poly=Polyline()
poly.Add(8,5,0)
poly.Add(22,5,0)
poly.Add(25,15,0)
poly.Add(15,25,0)
poly.Add(5,15,0)
poly.Closed=1
newdoc.Add(poly)
circle=Circle()
circle.Center=Point3F(-30,15,0)
circle.Diameter=15
newdoc.Add(circle)
newdoc.MachiningOptions.PostProcessor = "Mach3-CutViewer"
newdoc.MachiningOptions.FastPlungeHeight = 0.1
CamBamUI.MainUI.ActiveView.SelectAllVisibleGeometry()
PolylineUtils.PolyLinesConvert(CamBamUI.MainUI.ActiveView)
while CamBamUI.MainUI.ActiveView.CurrentEditMode is not None:
app.Sleep(1)
PolylineUtils.JoinPolyLines(CamBamUI.MainUI.ActiveView,0.001)
while CamBamUI.MainUI.ActiveView.CurrentEditMode is not None:
app.Sleep(1)
profile=MOPProfile(newdoc,newdoc.Layers[0].Entities.ToArray())
profile.Style="cutout"
profile.ToolDiameter = CBValue[float](0.8)
profile.InsideOutside = CBValue[InsideOutsideOptions](InsideOutsideOptions.Inside)
CamBamUI.MainUI.InsertMOP(profile)
newdoc.Save(out_filename)
CAMUtils.GenerateGCodeOutput(view)
sub main
dim source_file = "C:\CamBam\cbfiles\aluskids.dxf"
dim out_filename = "C:\dump\test.cb"
CamBamUI.MainUI.OpenFile(source_file,1)
dim newdoc = CamBamUI.MainUI.ActiveView.CADFile
dim poly = new Polyline()
poly.Add(8,5,0)
poly.Add(22,5,0)
poly.Add(25,15,0)
poly.Add(15,25,0)
poly.Add(5,15,0)
poly.Closed=True
newdoc.Add(poly)
dim circle = new Circle()
circle.Center = new Point3F(-30,15,0)
circle.Diameter=15
newdoc.Add(circle)
newdoc.MachiningOptions.PostProcessor = "Mach3-CutViewer"
newdoc.MachiningOptions.FastPlungeHeight = 0.1
CamBamUI.MainUI.ActiveView.SelectAllVisibleGeometry()
PolylineUtils.PolyLinesConvert(CamBamUI.MainUI.ActiveView)
while not CamBamUI.MainUI.ActiveView.CurrentEditMode is nothing
app.Sleep(1)
end while
PolylineUtils.JoinPolyLines(CamBamUI.MainUI.ActiveView,0.001)
while not CamBamUI.MainUI.ActiveView.CurrentEditMode is nothing
app.Sleep(1)
end while
dim profile = new CamBam.CAM.MOPProfile(newdoc,newdoc.Layers("LAYER_03").Entities.ToArray())
profile.Style = "cutout"
dim td = profile.ToolDiameter
td.SetValue(0.8)
profile.ToolDiameter = td
dim io = profile.InsideOutside
io.SetValue(CamBam.CAM.InsideOutsideOptions.Inside)
profile.InsideOutside = io
CamBamUI.MainUI.InsertMOP(profile)
newdoc.Save(out_filename)
CamBam.CAM.CAMUtils.GenerateGCodeOutput(view)
end sub