Beispielskripten: Unterschied zwischen den Versionen

Aus CamBam Wiki
Wechseln zu: Navigation, Suche
 
(12 dazwischenliegende Versionen desselben Benutzers werden nicht angezeigt)
Zeile 1: Zeile 1:
 +
Diese Beispielskripten zeigen in erster Linie Schnittstellen auf, mit denen CamBam und Objekte in CamBam in Skripten angesprochen werden können. Es geht dabei weniger über den Sinn der Skripten als um die Verwendeten Variablen.
 +
 
== MOP Automate VB and Python scripts ==
 
== MOP Automate VB and Python scripts ==
  
Zeile 14: Zeile 16:
 
* saving a drawing and creating g-code
 
* saving a drawing and creating g-code
 
*  
 
*  
Python version:
+
==== Python version:====
 
<code>  
 
<code>  
#
+
[http://www.google.com/search?client=safari&rls=en&q=cambam.pixelmaker.eu/pages/phocadownload/scripten/mop-automate.py.zip mop.automate.py]</code>
# mop-automate.py
 
#
 
from CamBam.CAM import *
 
from CamBam.UI import CamBamUI
 
from CamBam.Values import *
 
  
# TO CHANGE...
+
==== VB-Script Version: ====
 +
<code>[http://www.google.com/search?client=safari&rls=en&q=cambam.pixelmaker.eu/pages/phocadownload/scripten/mop-automate.vbs.zip mop.automate.vbs]</code>
 +
</code>
 +
----
 +
== Tool Library Automation Python scripts ==
  
source_file = "C:\\CamBam\\cbfiles\\aluskids.dxf"
+
Maintaining large lists of tools in different libraries and across different applications can be a tedious business.
out_filename = "C:\\dump\\test.cb"
 
  
# Open a source file
+
This script is intended to demonstrate various methods to aid tool library maintenance, including:
# 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,
+
Finding tool libraries by name
# so we create a new varialbe pointing to the newly opened active file...
+
Adding new or removing existing tool libraries
newdoc = CamBamUI.MainUI.ActiveView.CADFile
+
Enumerating tools within a library
 
+
Copying tools from one library to another
# draw some shapes...
+
Finding tools in a library by tool number
poly=Polyline()
+
Removing and creating new tool definitions
poly.Add(8,5,0)
+
Writing tools to external files (such as a CSV text file)
poly.Add(22,5,0)
+
==== Python version:====
poly.Add(25,15,0)
+
<code>[http://www.google.com/search?client=safari&rls=en&q=cambam.pixelmaker.eu/pages/phocadownload/scripten/tool-library.py.zip tool-library.py]</code>
poly.Add(15,25,0)
+
</code>
poly.Add(5,15,0)
+
----
poly.Closed=1
+
[[Bild:Gears-t.jpg|thumb|Eine Animation in CamBam]]
newdoc.Add(poly)
+
== Gear Rotation Animation Python Script ==
 
 
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...
+
This script takes a pre-drawn group of gear outlines (generated using the CamBam gear generator), then animates them using a series of relationship rules within the script.
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
+
This script requires CamBam 0.9.8N or later.
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
+
This script demonstrates:
# 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...
+
Importing a helper Python module.
profile.Style="cutout"
+
Defining a Python class.
 +
Animating objects by changing their transformation property.
  
# Other properties are based on the generic CBValue class
+
<code>[http://www.google.com/search?client=safari&rls=en&q=cambam.pixelmaker.eu/pages/phocadownload/scripten/gear-animate-source.zip gear-animate-source.zip and Samplefiles]</code>
# 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)
+
[[Bild:Sloped-lines.png|thumb|Abgeschrägte Linien]]
  
# create g-code output
+
== Sloped Lines VBScript ==
CAMUtils.GenerateGCodeOutput(view)
+
This script was created in response to query on how to generate a toolpath for a slot that slopes along the Z axis.
</code>
 
  
VB-Script Version:
+
The script will generate a sequence of polylines that can be used as the source for an engraving operation.
<code>'
 
' mop-automate.vbs
 
'
 
sub main
 
  
' TO CHANGE...
+
The script was extended so that it can also produce a series of parallel sloped lines to machine a sloped surface.
dim source_file = "C:\CamBam\cbfiles\aluskids.dxf"
 
dim out_filename = "C:\dump\test.cb"
 
  
' Open a source file
+
The following parameters are used to control the script:
' 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,
+
x1, y1 : The coordinates of the first control point.
' so we create a new varialbe pointing to the newly opened active file...
+
x2, y2 : The coordinates of the second control point.
dim newdoc = CamBamUI.MainUI.ActiveView.CADFile
+
Target Depth : The deepest Z coordinate of the slot or surface.
+
Depth Increment : The maximum depth per cut.
' draw some shapes...
+
Width : The width of the surface to cut. Use 0 to machine a slot. The tool diameter is not taken into account.
dim poly = new Polyline()
+
Stepover : The distance between each parallel cut for a surface.
poly.Add(8,5,0)
+
Once the polylines are created, select them all, then insert an Engraving machine operation.
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...
+
The engraving operation should have Target Depth set to 0 and Optimisation Mode set to None, so that the machining operation will follow the source polylines exactly, in the order they were created.
newdoc.MachiningOptions.PostProcessor = "Mach3-CutViewer"
 
newdoc.MachiningOptions.FastPlungeHeight = 0.1
 
  
' Select All...
+
<code>[http://www.google.com/search?client=safari&rls=en&q=cambam.pixelmaker.eu/pages/phocadownload/scripten/sloped-lines.vbs.zip sloped-lines.vbs.zip]</code>
CamBamUI.MainUI.ActiveView.SelectAllVisibleGeometry()
+
----
+
== Invert3D VBScript ==
' Convert to polylines...
+
3D Meshes are built from many triangular faces. Each triangle has a 'normal', which is a direction vector perpendicular to the triangular face. The order of the points around the triangle will determine the normal direction. CamBam uses a 'Right Hand Rule', so that if the fingers of your right hand curl in the direction that the triangle points are ordered, your thumb will point in the direction of the normal.
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
+
Normal vectors are used to determine the outside facing direction of each face. When displaying meshes, faces pointing away from the viewer are often ignored by the display routines. If meshes are wound using a 'Left Hand Rule', this can result in the models appearing dark or hard to see in the CamBam drawing display.
' 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...
+
The following script will reverse the winding direction of all selected mesh objects.
profile.Style = "cutout"
 
  
' Other properties are based on the generic CBValue class
+
<code>[http://www.google.com/search?client=safari&rls=en&q=cambam.pixelmaker.eu/pages/phocadownload/scripten/invert-3d.vbs.zip invert-3d.vbs.zip]</code>
' 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
 
</code>
 

Aktuelle Version vom 21. April 2013, 14:53 Uhr

Diese Beispielskripten zeigen in erster Linie Schnittstellen auf, mit denen CamBam und Objekte in CamBam in Skripten angesprochen werden können. Es geht dabei weniger über den Sinn der Skripten als um die Verwendeten Variablen.

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

VB-Script Version:

mop.automate.vbs


Tool Library Automation Python scripts

Maintaining large lists of tools in different libraries and across different applications can be a tedious business.

This script is intended to demonstrate various methods to aid tool library maintenance, including:

Finding tool libraries by name Adding new or removing existing tool libraries Enumerating tools within a library Copying tools from one library to another Finding tools in a library by tool number Removing and creating new tool definitions Writing tools to external files (such as a CSV text file)

Python version:

tool-library.py


Fehler beim Erstellen des Vorschaubildes: Datei fehlt
Eine Animation in CamBam

Gear Rotation Animation Python Script

This script takes a pre-drawn group of gear outlines (generated using the CamBam gear generator), then animates them using a series of relationship rules within the script.

This script requires CamBam 0.9.8N or later.

This script demonstrates:

Importing a helper Python module. Defining a Python class. Animating objects by changing their transformation property.

gear-animate-source.zip and Samplefiles



Fehler beim Erstellen des Vorschaubildes: Datei fehlt
Abgeschrägte Linien

Sloped Lines VBScript

This script was created in response to query on how to generate a toolpath for a slot that slopes along the Z axis.

The script will generate a sequence of polylines that can be used as the source for an engraving operation.

The script was extended so that it can also produce a series of parallel sloped lines to machine a sloped surface.

The following parameters are used to control the script:

x1, y1 : The coordinates of the first control point. x2, y2 : The coordinates of the second control point. Target Depth : The deepest Z coordinate of the slot or surface. Depth Increment : The maximum depth per cut. Width : The width of the surface to cut. Use 0 to machine a slot. The tool diameter is not taken into account. Stepover : The distance between each parallel cut for a surface. Once the polylines are created, select them all, then insert an Engraving machine operation.

The engraving operation should have Target Depth set to 0 and Optimisation Mode set to None, so that the machining operation will follow the source polylines exactly, in the order they were created.

sloped-lines.vbs.zip


Invert3D VBScript

3D Meshes are built from many triangular faces. Each triangle has a 'normal', which is a direction vector perpendicular to the triangular face. The order of the points around the triangle will determine the normal direction. CamBam uses a 'Right Hand Rule', so that if the fingers of your right hand curl in the direction that the triangle points are ordered, your thumb will point in the direction of the normal.

Normal vectors are used to determine the outside facing direction of each face. When displaying meshes, faces pointing away from the viewer are often ignored by the display routines. If meshes are wound using a 'Left Hand Rule', this can result in the models appearing dark or hard to see in the CamBam drawing display.

The following script will reverse the winding direction of all selected mesh objects.

invert-3d.vbs.zip