Beispielskripten: Unterschied zwischen den Versionen

Aus CamBam Wiki
Wechseln zu: Navigation, Suche
Zeile 14: Zeile 14:
 
* saving a drawing and creating g-code
 
* saving a drawing and creating g-code
 
*  
 
*  
Python version:
+
=== Python version: ===
<code>  
+
<nowiki>  
 
#
 
#
 
# mop-automate.py
 
# mop-automate.py
Zeile 95: Zeile 95:
 
# create g-code output
 
# create g-code output
 
CAMUtils.GenerateGCodeOutput(view)
 
CAMUtils.GenerateGCodeOutput(view)
</code>
+
</nowiki>
  
VB-Script Version:
+
=== VB-Script Version: ===
 
<code>'
 
<code>'
 
' mop-automate.vbs
 
' mop-automate.vbs

Version vom 21. April 2013, 14:17 Uhr

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:

# # mop-automate.py # from CamBam.CAM import * from CamBam.UI import CamBamUI from CamBam.Values import * # TO CHANGE... source_file = "C:\\CamBam\\cbfiles\\aluskids.dxf" 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... newdoc = CamBamUI.MainUI.ActiveView.CADFile # 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) # 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 CamBamUI.MainUI.ActiveView.CurrentEditMode is not None: app.Sleep(1) # Edit - Join PolylineUtils.JoinPolyLines(CamBamUI.MainUI.ActiveView,0.001) # wait for the thinking message to disapear... while CamBamUI.MainUI.ActiveView.CurrentEditMode is not None: app.Sleep(1) # create a profile mop # Use all the drawing objects from the first layer... profile=MOPProfile(newdoc,newdoc.Layers[0].Entities.ToArray()) # Use all the drawing objects from the last layer... # profile=MOPProfile(newdoc,newdoc.Layers[newdoc.Layers.Count-1].Entities.ToArray()) # Use all the drawing objects from a layer with a specific name... # profile=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... profile.ToolDiameter = CBValue[float](0.8) profile.InsideOutside = CBValue[InsideOutsideOptions](InsideOutsideOptions.Inside) # add the machine op to the drawing... CamBamUI.MainUI.InsertMOP(profile) # save the current drawing... newdoc.Save(out_filename) # 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