Author Topic: Unmachined Areas (Python script)  (Read 9441 times)

Offline billt

  • Droid
  • **
  • Posts: 90
    • View Profile
Unmachined Areas (Python script)
« on: March 22, 2015, 02:36:21 am »
Hi Guys.

Lloyd proposed a need for a feature to determine the correct cutter size for a path:
http://www.cambam.co.uk/forum/index.php?topic=4659.msg34601#msg34601
And I see that Dave Benson is making good progress on a plugin to address this exact issue:
http://www.cambam.co.uk/forum/index.php?topic=4665.msg34707#msg34707

I have been tweaking around with Python and the boolean geometry features in CamBam and have a different approach.
Basically I use the RegionFiller_InsideOutsideOffsets method to do the dirty work.
Using a very large number for the Stepover and using Tool Diameter for Margin creates a single set of fill lines.
These resultant fill lines simulate the outside edge of the cutter path.
The beauty of using this method is that it accounts for interactions between adjacent paths (thanks Andy!).
Then offsetting these back toward the original path gives the inside edge of the cutter path.
Finally subtracting the cut path from the original leaves polylines which represent the areas that will be left uncut.
The outside cut requires creating an external border to get it to work, but the same concepts apply.
By scanning through the uncut areas, you can determine if the path needs to be changed or a different cutter is required.

The script is automated using a windows form for selecting the tool size and inside/outside cut.
You will want to update the Tool List at the top of the script for your different tool sizes.
The script creates a new layer "Unmachined Areas" to place the resultant polylines.
The results sometimes include some unclosed junk polylines, but for the most part results look good.

Probably not a super-useful script, but hopefully the concepts will help for other scripts/plugins.
In fact, I will next be tweaking on an alternate V-carve script/plugin using the boolean methods.
Thanks to Dave Benson for suggesting use of ILSpy to explore the CamBam methods.

Cheers - BillT

Rev 21-Mar-15 - initial release

Online lloydsp

  • CNC Jedi
  • *****
  • Posts: 8289
    • View Profile
Re: Unmachined Areas (Python script)
« Reply #1 on: March 22, 2015, 02:42:09 am »
Bill,
Thank you!  Every new approach gives us more tools.

I won't be in a position to try your idea for some days yet, but I will explore it.  It certainly can be the basis of another utility.

Lloyd
"Pyro for Fun and Profit for More Than Fifty Years"

Offline dave benson

  • CNC Jedi
  • *****
  • Posts: 1322
    • View Profile
Re: Unmachined Areas (Python script)
« Reply #2 on: March 22, 2015, 03:17:31 am »
Hi Billt
congratulations on thinking outside of the square good job.
Dave.

Offline dave benson

  • CNC Jedi
  • *****
  • Posts: 1322
    • View Profile
Re: Unmachined Areas (Python script)
« Reply #3 on: March 22, 2015, 04:15:48 am »
HI Bill
Well that was educational.
After downloading the script and using it on some shapes I've now realised the full power of shape lists and have just realised that if you iterate through the end mill diameters from largest to smallest and check until  there are no uncut  areas left, that is the size of (the largest end mill to cut your shape) and all using the CB inbuilt methods. Just Brilliant.
Dave. 

Offline dh42

  • Administrator
  • CNC Jedi
  • *****
  • Posts: 6013
    • View Profile
    • Cambam V1.0 French Doc
Re: Unmachined Areas (Python script)
« Reply #4 on: March 22, 2015, 20:01:18 pm »
Hello,

Very nice, and also usefull for me, I often have remachining to do with smaller tool.

A question ; why the use of the script change the CamBam appearance ? (picture)

++
David

Offline EddyCurrent

  • CNC Jedi
  • *****
  • Posts: 4383
    • View Profile
Re: Unmachined Areas (Python script)
« Reply #5 on: March 22, 2015, 20:30:55 pm »
Yes it's good thinking and a shorter script than I imagined it would be, spot on Bill
Made in England

Offline billt

  • Droid
  • **
  • Posts: 90
    • View Profile
Re: Unmachined Areas (Python script)
« Reply #6 on: March 23, 2015, 00:23:51 am »
Thanks for the comments guys!
I admire all of your works and am glad to contribute to the community.

Dave - right, ShapeList stores a list of Polylines and Regions, and has methods to work on all objects at once such as Region, Union, Offset...

David - I am guessing that the Windows Form defaults changes the window appearance - nothing in the Main code would affect the view itself.

The public methods are really powerful.
Most things you can do in a few menu clicks, and it should only take a few lines of code to duplicate.
For going right from menu clicks to script code, it would be really useful to have a "macro recorder".
It would store the menu clicks, value entries, etc. to a text file for re-use or inspection for building scripts.
I have no idea how to do this, so I will ask for help as a new Scripts/Plugin topic.

Cheers - BillT

Online lloydsp

  • CNC Jedi
  • *****
  • Posts: 8289
    • View Profile
Re: Unmachined Areas (Python script)
« Reply #7 on: March 23, 2015, 00:41:55 am »
That's a neat idea, Bill!

MOST advanced productivity softs have macro-recorders.

I'll bet, with some work, a plugin could be written to do that.

There is a mild danger to that.  It would be difficult to actually share macros among users, unless one specified what other plugins were active (and used) when recording it.

Lloyd
"Pyro for Fun and Profit for More Than Fifty Years"

Offline dh42

  • Administrator
  • CNC Jedi
  • *****
  • Posts: 6013
    • View Profile
    • Cambam V1.0 French Doc
Re: Unmachined Areas (Python script)
« Reply #8 on: March 23, 2015, 00:56:36 am »
I remember that Ralf (pixelmaker) ask for this macro-recorder ... there is a while, we are not able to do that at this moment , but yet, maybe ...

++
David

Offline billt

  • Droid
  • **
  • Posts: 90
    • View Profile
Re: Unmachined Areas (Python script)
« Reply #9 on: March 23, 2015, 01:09:08 am »
I was composing the new post and realized that the UndoBuffer stores all of the actions.
Maybe the macro recorder will be easier than I thought...
It could just involve outputting the the UndoBuffer to a text file.
Right, for sharing it would potentially not be compatible with scripts/plugins, but would be fine with CamBam native methods.
Cheers - BillT

Online lloydsp

  • CNC Jedi
  • *****
  • Posts: 8289
    • View Profile
Re: Unmachined Areas (Python script)
« Reply #10 on: March 23, 2015, 01:14:32 am »
Additionally, some plugins don't properly record to the undo buffer.

But for native functions, sure!

Lloyd
"Pyro for Fun and Profit for More Than Fifty Years"

Offline EddyCurrent

  • CNC Jedi
  • *****
  • Posts: 4383
    • View Profile
Re: Unmachined Areas - Re. Macro Creator
« Reply #11 on: May 22, 2015, 09:01:55 am »
I remember that Ralf (pixelmaker) ask for this macro-recorder ... there is a while, we are not able to do that at this moment , but yet, maybe ...

++
David

This has been mentioned before; http://ahkscript.org/docs/misc/Macros.htm
Autohotkey.
« Last Edit: May 22, 2015, 09:03:40 am by EddyCurrent »
Made in England

Offline dh42

  • Administrator
  • CNC Jedi
  • *****
  • Posts: 6013
    • View Profile
    • Cambam V1.0 French Doc
Re: Unmachined Areas (Python script)
« Reply #12 on: May 22, 2015, 14:03:11 pm »
Hello,

I'm not sure, but I guess that when Ralf ask for that, it's to do video for tutorials ..

Example, you do the tuto in your own language and records the actions (and the video too), then you change the language and replay the commands to do the video in another language .... but ... depending of the language the properties are not at the same position in the list, and for the menu, if they are always in the same position, the text are shorter in English that in French or German ... that means that we can't just record a pixel position on the screen ; with need to record a command ...

++
David