Beispielskripten

Aus CamBam Wiki
Wechseln zu: Navigation, Suche

MOP Automate VB and Python scripts

COMMENTS

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: #

  1. mop-automate.py

from CamBam.CAM import * from CamBam.UI import CamBamUI from CamBam.Values import *

  1. TO CHANGE...

source_file = "C:\\CamBam\\cbfiles\\aluskids.dxf" out_filename = "C:\\dump\\test.cb"

  1. Open a source file
  2. note: the second parameter '1' opens the file synchronously rather than in a worker thread

CamBamUI.MainUI.OpenFile(source_file,1)

  1. The 'doc' global variable is always the CADFile before any file opens,
  2. so we create a new varialbe pointing to the newly opened active file...

newdoc = CamBamUI.MainUI.ActiveView.CADFile

  1. draw some shapes...

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)

  1. set any machining options required...

newdoc.MachiningOptions.PostProcessor = "Mach3-CutViewer" newdoc.MachiningOptions.FastPlungeHeight = 0.1

  1. Select All...

CamBamUI.MainUI.ActiveView.SelectAllVisibleGeometry()

  1. Convert to polylines...

PolylineUtils.PolyLinesConvert(CamBamUI.MainUI.ActiveView)

  1. The gui operation runs in a worker process, so wait for the
  2. thinking message to disapear...

while CamBamUI.MainUI.ActiveView.CurrentEditMode is not None: app.Sleep(1)

  1. Edit - Join

PolylineUtils.JoinPolyLines(CamBamUI.MainUI.ActiveView,0.001)

  1. wait for the thinking message to disapear...

while CamBamUI.MainUI.ActiveView.CurrentEditMode is not None: app.Sleep(1)

  1. create a profile mop
  2. Use all the drawing objects from the first layer...

profile=MOPProfile(newdoc,newdoc.Layers[0].Entities.ToArray())

  1. Use all the drawing objects from the last layer...
  2. profile=MOPProfile(newdoc,newdoc.Layers[newdoc.Layers.Count-1].Entities.ToArray())
  3. Use all the drawing objects from a layer with a specific name...
  4. profile=MOPProfile(newdoc,newdoc.Layers["LAYER_03"].Entities.ToArray())
  1. Set the profile style property...

profile.Style="cutout"

  1. Other properties are based on the generic CBValue class
  2. Some examples of how these properties should be set...

profile.ToolDiameter = CBValue[float](0.8) profile.InsideOutside = CBValue[InsideOutsideOptions](InsideOutsideOptions.Inside)

  1. add the machine op to the drawing...

CamBamUI.MainUI.InsertMOP(profile)

  1. save the current drawing...

newdoc.Save(out_filename)

  1. create g-code output

CAMUtils.GenerateGCodeOutput(view)

VB-Script Version: ' ' mop-automate.vbs ' sub main

' TO CHANGE... dim source_file = "C:\CamBam\cbfiles\aluskids.dxf" dim out_filename = "C:\dump\test.cb"

' Open a source file ' note: the second parameter '1' opens the file synchronously rather than in a worker thread CamBamUI.MainUI.OpenFile(source_file,1)

' The 'doc' global variable is always the CADFile before any file opens, ' so we create a new varialbe pointing to the newly opened active file... dim newdoc = CamBamUI.MainUI.ActiveView.CADFile

' draw some shapes... 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)

' set any machining options required... newdoc.MachiningOptions.PostProcessor = "Mach3-CutViewer" newdoc.MachiningOptions.FastPlungeHeight = 0.1

' Select All... CamBamUI.MainUI.ActiveView.SelectAllVisibleGeometry()

' Convert to polylines... PolylineUtils.PolyLinesConvert(CamBamUI.MainUI.ActiveView) ' The gui operation runs in a worker process, so wait for the ' thinking message to disapear... while not CamBamUI.MainUI.ActiveView.CurrentEditMode is nothing app.Sleep(1) end while

' Edit - Join PolylineUtils.JoinPolyLines(CamBamUI.MainUI.ActiveView,0.001) ' wait for the thinking message to disapear... while not CamBamUI.MainUI.ActiveView.CurrentEditMode is nothing app.Sleep(1) end while

' create a profile mop ' Use all the drawing objects from the first layer... ' dim profile = new CamBam.CAM.MOPProfile(newdoc,newdoc.Layers(0).Entities.ToArray()) ' Use all the drawing objects from the last layer... ' dim profile = new CamBam.CAM.MOPProfile(newdoc,newdoc.Layers(newdoc.Layers.Count-1).Entities.ToArray()) ' Use all the drawing objects from a layer with a specific name... dim profile = new CamBam.CAM.MOPProfile(newdoc,newdoc.Layers("LAYER_03").Entities.ToArray())

' Set the profile style property... profile.Style = "cutout"

' Other properties are based on the generic CBValue class ' Some examples of how these properties should be set... ' Note: CBValue(of type) syntax not working in current release ' as extra .dlls need to be referenced in the VB script host. ' user alternative syntax...

dim td = profile.ToolDiameter td.SetValue(0.8) profile.ToolDiameter = td

dim io = profile.InsideOutside io.SetValue(CamBam.CAM.InsideOutsideOptions.Inside) profile.InsideOutside = io

' add the machine op to the drawing... CamBamUI.MainUI.InsertMOP(profile)

' save the current drawing... newdoc.Save(out_filename)

' create g-code output CamBam.CAM.CAMUtils.GenerateGCodeOutput(view)

end sub