Beispielskripten: Unterschied zwischen den Versionen

Aus CamBam Wiki
Wechseln zu: Navigation, Suche
 
(13 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 ==
=== COMMENTS ===
 
  
 
This script will automate the process of opening a source file, insert machining operations, set various properties and produce g-code.
 
This script will automate the process of opening a source file, insert machining operations, set various properties and produce g-code.
Zeile 6: Zeile 7:
 
These scripts demonstrate:
 
These scripts demonstrate:
  
opening a CAD file (.dxf in this example)
+
* opening a CAD file (.dxf in this example)
drawing some extra shapes into the drawing
+
* drawing some extra shapes into the drawing
setting machining options
+
* setting machining options
Call asynchronous CAD functions such as
+
* Call asynchronous CAD functions such as
Edit -> Join and Edit -> Convert to polyline
+
* Edit -> Join and Edit -> Convert to polyline
creating a machining operation from objects in a drawing layer
+
* creating a machining operation from objects in a drawing layer
setting machining operation properties
+
* setting machining operation properties
saving a drawing and creating g-code
+
* saving a drawing and creating g-code
 +
*
 +
==== Python version:====
 +
<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>
  
Python version:
+
==== VB-Script Version: ====
<code> #
+
<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>
# mop-automate.py
+
</code>
#
+
----
from CamBam.CAM import *
+
== Tool Library Automation Python scripts ==
from CamBam.UI import CamBamUI
 
from CamBam.Values import *
 
  
# TO CHANGE...
+
Maintaining large lists of tools in different libraries and across different applications can be a tedious business.
  
source_file = "C:\\CamBam\\cbfiles\\aluskids.dxf"
+
This script is intended to demonstrate various methods to aid tool library maintenance, including:
out_filename = "C:\\dump\\test.cb"
 
  
# Open a source file
+
Finding tool libraries by name
# note: the second parameter '1' opens the file synchronously rather than in a worker thread
+
Adding new or removing existing tool libraries
CamBamUI.MainUI.OpenFile(source_file,1)
+
Enumerating tools within a library
 
+
Copying tools from one library to another
# The 'doc' global variable is always the CADFile before any file opens,
+
Finding tools in a library by tool number
# so we create a new varialbe pointing to the newly opened active file...
+
Removing and creating new tool definitions
newdoc = CamBamUI.MainUI.ActiveView.CADFile
+
Writing tools to external files (such as a CSV text file)
 
+
==== Python version:====
# draw some shapes...
+
<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=Polyline()
+
</code>
poly.Add(8,5,0)
+
----
poly.Add(22,5,0)
+
[[Bild:Gears-t.jpg|thumb|Eine Animation in CamBam]]
poly.Add(25,15,0)
+
== Gear Rotation Animation Python Script ==
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...
+
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.
newdoc.Save(out_filename)
 
  
# create g-code output
+
This script requires CamBam 0.9.8N or later.
CAMUtils.GenerateGCodeOutput(view)
 
</code>
 
  
VB-Script Version:
+
This script demonstrates:
<code>'
 
' mop-automate.vbs
 
'
 
sub main
 
  
' TO CHANGE...
+
Importing a helper Python module.
dim source_file = "C:\CamBam\cbfiles\aluskids.dxf"
+
Defining a Python class.
dim out_filename = "C:\dump\test.cb"
+
Animating objects by changing their transformation property.
  
' Open a source file
+
<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>
' 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"
+
[[Bild:Sloped-lines.png|thumb|Abgeschrägte Linien]]
newdoc.MachiningOptions.FastPlungeHeight = 0.1
 
  
' Select All...
+
== Sloped Lines VBScript ==
CamBamUI.MainUI.ActiveView.SelectAllVisibleGeometry()
+
This script was created in response to query on how to generate a toolpath for a slot that slopes along the Z axis.
 
' 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
+
The script will generate a sequence of polylines that can be used as the source for an engraving operation.
' 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 script was extended so that it can also produce a series of parallel sloped lines to machine a sloped surface.
profile.Style = "cutout"
 
  
' Other properties are based on the generic CBValue class
+
The following parameters are used to control the script:
' 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
+
x1, y1 : The coordinates of the first control point.
td.SetValue(0.8)
+
x2, y2 : The coordinates of the second control point.
profile.ToolDiameter = td
+
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.
  
dim io = profile.InsideOutside
+
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.
io.SetValue(CamBam.CAM.InsideOutsideOptions.Inside)
 
profile.InsideOutside = io
 
  
' add the machine op to the drawing...
+
<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.InsertMOP(profile)
+
----
 +
== 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.
  
' save the current drawing...
+
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.
newdoc.Save(out_filename)
 
  
' create g-code output
+
The following script will reverse the winding direction of all selected mesh objects.
CamBam.CAM.CAMUtils.GenerateGCodeOutput(view)
 
  
end sub
+
<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>
</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