Author Topic: Avoid filename prompts in GenerateGCodeOutput  (Read 166 times)

Offline billo

  • Ewok
  • *
  • Posts: 14
    • View Profile
Avoid filename prompts in GenerateGCodeOutput
« on: January 23, 2023, 16:54:00 pm »
I'm looping over Parts and calling CAMUtils.GenerateGCodeOutput to produce a separate .nc file for each Part.

This puts up a file prompt dialog for each part. That works fine, but I have a large number of Parts and would like to provide a filename in script to avoid the file prompts.

Is this possible?

Bill

Offline EddyCurrent

  • CNC Jedi
  • *****
  • Posts: 5137
  • Made in England
    • View Profile
« Last Edit: January 23, 2023, 20:02:10 pm by EddyCurrent »
Filmed in Supermarionation

Offline billo

  • Ewok
  • *
  • Posts: 14
    • View Profile
Re: Avoid filename prompts in GenerateGCodeOutput
« Reply #2 on: January 24, 2023, 17:13:15 pm »
I think I'm making a little progress. CAMPart has a field called OutFile that seems to have some effect, sometimes.

After setting this property I'm still being prompted for a filename, and the proposed filename is not what is in the OutFile property.

Here is my latest attempt:

Code: [Select]
from CamBam.CAM import *
from CamBam.UI import CamBamUI

view = CamBamUI.MainUI.ActiveView
doc = view.CADFile

folder = "C:\\CamBamTemp"

for part in doc.Parts:
    part.OutFile = "{0}\\{1}.nc".format(folder, part.Name)
    print part.OutFile
    #view.DrawingTree.ReloadTree() # doesn't fix
    CAMUtils.GenerateGCodeOutput(view, part, None) # how to avoid prompt here
    while view.CurrentEditMode is not None: app.Sleep(1) #wait


Actually, the more I test, it appears that the OutFile field does nothing. Even if you use the CamBam UI, click on the three-dot button, and enter a filename, the interactive "Produce gcode" command seems to ignore it.

If anyone uses "Out File", even in the interactive UI, could you tell us what it does?

Thx,
Bill
« Last Edit: January 24, 2023, 21:07:01 pm by billo »

Offline Dragonfly

  • CNC Jedi
  • *****
  • Posts: 2588
    • View Profile
Re: Avoid filename prompts in GenerateGCodeOutput
« Reply #3 on: January 25, 2023, 14:57:49 pm »
I am using the property to send my .nc files to a particular folder. (Via the file save dialog, of course). Once saved for the first time consecutive save is without the dialog.
The path (Linux) is given in this form /home/Public/!_MOP/{$cbfile.name}.nc. Embedded in the default CB template.
This is for normal workflow. Never tried to create file with a script.

Offline billo

  • Ewok
  • *
  • Posts: 14
    • View Profile
Re: Avoid filename prompts in GenerateGCodeOutput
« Reply #4 on: January 28, 2023, 16:58:28 pm »
Thanks to the hint from Dragonfly I think I have it working without ANY prompts.

The only real change is to GenerateGcode on Machining, not on individual Parts.

Code: [Select]
from CamBam.CAM import *
from CamBam.UI import CamBamUI

import System.IO

folder = "C:\MyLocalFiles\CamBamTemp"
folderPieces = "{}\{}".format(folder, "Pieces") # create a subfolder for some Parts

view = CamBamUI.MainUI.ActiveView
doc = view.CADFile

def Main():
    # create output folders if they don't yet exist
    if (not System.IO.Directory.Exists(folder)): System.IO.Directory.CreateDirectory(folder)
    if (not System.IO.Directory.Exists(folderPieces)): System.IO.Directory.CreateDirectory(folderPieces)

    # set OutFile for all parts (but not in MachinIng)
    for part in doc.Parts:
        outfileFolder = folder
        if (part.Name.startswith("Piece")): outfileFolder = folderPieces
        outfile = "{0}\{1}.nc".format(outfileFolder, part.Name)
       
        System.IO.File.Delete(outfile) # avoid the "overwrite" confirmation prompt
        part.OutFile = outfile
       
    CAMUtils.GenerateGCodeOutput(view) # generate gcode on Machining, not on individual Parts
    wait()
   
def wait():
    while view.CurrentEditMode is not None: app.Sleep(1)
   
Main()

Update: I believe you also have to save to a .cb file with "doc.Save(filename)" sometime before calling GenerateGcode to trigger some magic file naming.
« Last Edit: January 28, 2023, 18:53:06 pm by billo »