226
Scripts and Plugins / Re: Need help to start scripting (especially automated MOP creation)
« on: November 15, 2018, 12:43:16 pm »
Another "Aaaaaaahhh" !
I figured out setting the Machining stocksize´s Z and the new part´s CAMStyle.
Enough success for this day !
Not so much issues are open :
- generate n holding tabs and set Tab method to automatic
- Cut ordering a=O Level First a=T Depth First
The actual script, if you want to play around with it :
I figured out setting the Machining stocksize´s Z and the new part´s CAMStyle.
Enough success for this day !
Not so much issues are open :
- generate n holding tabs and set Tab method to automatic
- Cut ordering a=O Level First a=T Depth First
The actual script, if you want to play around with it :
Code: [Select]
#
# _BG_AUTO_MAGIC.py
#
# create MOPs based upon infos written in DXF Layer names
#
# Layer 0 will be ignored
# only layers using names beginning with a number can auto-create MOPs
#
#
# LAYERNAME STYLE : Number Name ProfileType [options]
# ProfileTypes (not case-senitive)
# innen (=inside)
# aussen (=outside)
# tasche (=pocket)
# gravur (=engrave)
# NT (Neues Teil anlegen / create a new Part)
#
# Options :
# Caaaaa CAM-Style
# Tn.nnn Tiefe, wird automatisch negativ / Target depth, will be converted to negtive value
# Zn.nnn Zustellung / depth increment
# An.nnn Aufmass / roughing clearance
# x Hn n Haltestege generieren / generate n holding tabs and set Tab method to automatic
# Wn.nnn Werkstückoberfläche / Stock Surface
# In Innenecken räumen 0=nein 1=ja / Corner overcut 0=no 1=yes
# Sn.nnn seitliche Zustellung 0.00 ... 1.00 / stepover
# Vnnnnn Vorschub / feed speed
# Nnnnnn Drehzahl / spindle speed
# Dn.nnnn Durchmesser / Tool diameter
# x Ra O-Obere Ebene zuerst T-Tiefe zuerst / Cut ordering a=O Level First a=T Depth First
#
# Special Case : Layer "00 name [options]"
# - Name sets name of 1st Part
# - no ProfileType
# - will set the default values of MACHINING, no MOP is generated
# Mn.nnn Materialdicke / stock size Z
# Baaaaa Bibliothek / MACHINING default CAM library (must exist, there is no check)
# Caaaaa CAM-Style / MACHINING default CAM styl (must exist, there is no check)
#
# x = not implemented
#
from CamBam.CAM import *
from CamBam.UI import *
from CamBam.Values import *
TypeList = ["INNEN", "AUSSEN", "TASCHE", "BOHREN", "GRAVUR", "NT"]
# 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
#REMEMBER !!! always ignore the layer "0" !!!
################################################################################
# first of all, let´s re-sort the layers by the numbers given in the layer´s name
################################################################################
for i in range (0, newdoc.Layers.Count-1) :
# if a number is defined, extract it
if(newdoc.Layers[i].Name !="0"): # ignore layer "0"
TokenList = newdoc.Layers[i].Name.split()
if (TokenList[0].isnumeric()) :
ActualNumber = int(TokenList[0])
# run through the following layers and look for smaller numbers given in the layer´s name
for Index in range (i+1,newdoc.Layers.Count) :
if(newdoc.Layers[i].Name !="0"): # ignore layer "0"
# extract defined number from layernames
TokenList = newdoc.Layers[Index].Name.split()
if (TokenList[0].isnumeric()) :
FollowingNumber = int(TokenList[0])
#compare following to actual number
if (FollowingNumber < ActualNumber) :
#if smaller, change layer order
newdoc.ChangeLayerOrder(Index,i)
ActualNumber = FollowingNumber
################################################################################
# Remove all parts
################################################################################
newdoc.Parts.Clear()
################################################################################
# now process all layers with a leading number, except layer 0
################################################################################
for i in range (0, newdoc.Layers.Count) :
if(newdoc.Layers[i].Name !="0"): # ignore layer "0"
# if a number is defined, extract it
TokenList = newdoc.Layers[i].Name.split()
Number = 0
Name = ""
PartName = ""
Type = ""
OptionList= ""
if (TokenList[0].isnumeric()) :
if len(TokenList) > 0 :
Number = int(TokenList[0])
if len(TokenList) > 1 :
Name = TokenList[1]
PartName = Name
if len(TokenList) > 2 :
Type = str(TokenList[2]).upper()
if len(TokenList) > 3 :
OptionList = TokenList[3:]
# special case : Default definitions given in Layer 00
if TokenList[0] == "00":
# create a new part
PartName = Name
CamBamUI.MainUI.ActiveView.CADFile.CreatePart(PartName)
CamBamUI.MainUI.ActiveView.CADFile.SetActivePart(PartName)
# scan the paramters
if len(TokenList) > 2 :
OptionList = TokenList[2:]
for Index in range (0, len(OptionList)) :
Command = OptionList[Index].upper()[0]
if (Command=="B"):
newdoc.MachiningOptions.StyleLibrary = OptionList[Index][1:]
if (Command=="C"):
newdoc.MachiningOptions.Style = OptionList[Index][1:]
if (Command=="M"):
# get existing data
Buffer = newdoc.MachiningOptions.Stock.StockSize
#overload stocksize Z
a=Point3F(Buffer.X, Buffer.Y, (float) (OptionList[Index][1:]))
newdoc.MachiningOptions.Stock.StockSize = a
else:
# create the MOP (depending on type)
# Use all the drawing objects from the selected layer
# default profile. just for the python parser, will be overloaded later on
profile=MOPProfile(newdoc,newdoc.Layers[i].Entities.ToArray())
if Type not in TypeList:
app.log ("Illegal type : " + Type + "\nLAYER : " + newdoc.Layers[i].Name + "\nbetter use " + str(TypeList))
quit()
if (Type == "INNEN"):
profile=MOPProfile(newdoc,newdoc.Layers[i].Entities.ToArray())
profile.InsideOutside = CBValue[InsideOutsideOptions](InsideOutsideOptions.Inside)
if (Type == "AUSSEN"):
profile=MOPProfile(newdoc,newdoc.Layers[i].Entities.ToArray())
profile.InsideOutside = CBValue[InsideOutsideOptions](InsideOutsideOptions.Outside)
if (Type == "TASCHE"):
profile=MOPPocket(newdoc,newdoc.Layers[i].Entities.ToArray())
if (Type == "GRAVUR"):
profile=MOPEngrave(newdoc,newdoc.Layers[i].Entities.ToArray())
if (Type == "NT"):
PartName = Name
CamBamUI.MainUI.ActiveView.CADFile.CreatePart(PartName)
CamBamUI.MainUI.ActiveView.CADFile.SetActivePart(PartName) # search for a overloading MOP´s style
for Index in range (0, len(OptionList)) :
Command = OptionList[Index].upper()[0]
if (Command=="C"):
newdoc.ActivePart.Style = OptionList[Index][1:]
break # use only the first one
continue
# search for a overloading MOP´s style
for Index in range (0, len(OptionList)) :
Command = OptionList[Index].upper()[0]
if (Command=="C"):
profile.Style = OptionList[Index][1:]
break # use only the first one
# set the MOP´s name
profile.Name = newdoc.Layers[i].Name
app.log(profile.Name)
# process the options
for Index in range (0, len(OptionList)) :
Command = OptionList[Index].upper()[0]
Parameter = OptionList[Index][1:]
if (Command=="T"):
profile.TargetDepth = CBValue[float](-(float) (Parameter))
if (Command=="Z"):
profile.DepthIncrement = CBValue[float]((float) (Parameter))
if (Command=="V"):
profile.CutFeedrate = CBValue[float]((float) (Parameter))
if (Command=="N"):
profile.SpindleSpeed = CBValue[int]((int) (Parameter))
if (Command=="S"):
profile.StepOver = CBValue[float]((float) (Parameter))
if (Command=="A"):
profile.RoughingClearance = CBValue[float]((float) (Parameter))
if (Command=="W"):
profile.StockSurface = CBValue[float]((float) (Parameter))
if (Command=="I"):
if (Parameter == "0"):
profile.CornerOvercut = CBValue[bool] (bool (0))
if (Parameter == "1"):
profile.CornerOvercut = CBValue[bool] (bool (1))
if (Command=="D"):
profile.ToolDiameter = profile.ToolDiameter.NewValue((float) (Parameter))
# wait for the thinking message to disapear...
while CamBamUI.MainUI.ActiveView.CurrentEditMode is not None:
app.Sleep(1)
# add the machine op to the drawing...
CamBamUI.MainUI.InsertMOP(profile)
# wait for the thinking message to disapear...
while CamBamUI.MainUI.ActiveView.CurrentEditMode is not None:
app.Sleep(1)
#######################################
# generate and show all toolspaths
#######################################
CAMUtils.GenerateToolpaths(view)
# wait for the thinking message to disapear...
while view.CurrentEditMode is not None:
app.Sleep(1)



