Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - ThisAmplifierIsLoud

Pages: 1 ... 14 15 [16]
226
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 :


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)   

 

227
Ahhhhhh - these old eyes ... and the dark sunglasses ... ::)
I didn´t see the binaries, thank you, Eddy.

Now I will spy around a little, I hope this helps to solve the open issues of my magic script.

Best regards

Bernhard

228
Here´s a simple DXF file for demonstration.

Just load it into cambam, select in MACHINING any milling tool with
diameter of roundabout 2mm.

Start the script and enjoy the show !


@Eddy : I had a look at your suggestions for retrieving the dlls ... brrrrrr....
Too much stuff for me, have merci on my poor little computer.  ;D

Best regards

Bernhard

229
Feature Requests / Re: Maximum Depth Limit?
« on: November 14, 2018, 20:12:44 pm »
My vacuum pads made similar experiences... >:(
Setting the max depth would be great!

230
@Lloyd : Thank you, especially for the "Sir" !  ;D



Thanks, Eddy,

I´ll try that tomorrow, here in Germany is now time to open beer and watch TV.  ;D

But I was not lazy in between and translated the comments in my "magic script" into english
for a better readability for most of you.

A DXF file for demonstration I will create tomorrow, it should be completely free of my personal CAMBAM settings.

best regards

Bernhard

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]"
# x             - Name sets name of 1st Part
#               - no ProfileType
#               - will set the default values of MACHINING, no MOP is generated
# x          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 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"):  TODO
                    #    newdoc.MachiningOptions.Stock.StockSize.Y = float(OptionList[Index][1:])

                        

            
        else:  
            # create the MOP (depending on type)
            # Use all the drawing objects from the selected layer
            
            #special case : new Part (NT neues Teil)
            if (Type=="NT"):
                dummy=0
              
            
            # 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)
                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)



231
Hi everybody,

my name´s Bernhard (54), once upon a time I´ve been studying informatics.
I am using a selfmade CNC Router for my hobby.
I´m from germany, so please excuse my poor english.
I´m using CAMBAM since summer of 2017 and after learning how to use I really like it.

Now I want to start writing a few simple scripts in order get a speedup in my workflow.

But where to start ... I see the examples in VB and Python, and I see an API
to control Cambam. The API´s documentation is a little ... let´s say thin.
Maybe I am not asking the proper questions.

So it´s hard for me to start. I am speaking C/C++,
but not really Python or VB. But I can read it, (often) understand an existing code
and I can change/adapt it.


My workflow is : Creating DXF file using QCAD, put it into Cambam an create the GCode.
Works usually fine.
But I see me doing always the same stuff in Cambam, after changing the DXF file
doing the same things again and again.


What do I want to program / automize ?

I have usually 2.5D stuff, not very complex.
So my idea is :

Putting some informations for creating the MOPs and their order into the DXF-file´s layernames.
(f.e. MOP order, milling depth, number of holding tabs, CAM-Style ...)
Using a cambam script parse this information and create the MOPs. Done.

Most things I realized by changing the demo-script "Automate.py" after
reading the whole internet to get snippets of information, the most from this forum here.


Now my questions :


- Python or VB ? (python seems to easier to me.)

- is there a way to get some Intellisense/Autocompletion during script writing ?

- Actually I am able create a new part and naming it by scripting.
  But I did not find a way to overload the active part´s CAM-Style.
  (dealing with MOPs I can)
 
- Using python I could not find a way to read out, alter and rewrite the holding tab´s properties of a MOP.
  (especially number of tabs and setting to "auto" 

 
If you want to, I can put here my rudimentary quick´n´dirty script.
And I have to create a simple DXF file for demonstrating.


I would be glad get a little help. 


Best regards

Bernhard

Pages: 1 ... 14 15 [16]