Author Topic: Woodworking Joints - Finger Joints Script  (Read 25035 times)

Offline EddyCurrent

  • CNC Jedi
  • *****
  • Posts: 4463
    • View Profile
Woodworking Joints - Finger Joints Script
« on: December 26, 2014, 23:03:06 pm »
Here's my first CamBam script  ;D

If you saw my new woodworking jig here; http://www.cambam.co.uk/forum/index.php?topic=4538.msg33143#msg33143
you can see it allows for cutting of joints on the ends of timber rather than it lying flat on the machine bed.

To install the script it needs to be extracted into your 'scripts' folder as usual, but also a new sub folder called 'images' has to created in the scripts folder. The images in the archive then have to be extracted into the new 'images' folder.

I've used the Windows Form ideas by Lloyd in this thread; http://www.cambam.co.uk/forum/index.php?topic=4542.msg33182#msg33182

I can't imagine this will be widely used due to the nature of the machine modifications but maybe some ideas will be useful, please give me your feedback.

I've added an image to show what it looks like in CutViewerMill

Thank you.

Edit: I forgot to mention, I'm not sure how it works with inches seeing as it's coded for metric.
Also there are 2 layers. one for each mating piece of timber, my plan was to enable the machining operations one at a time to generated two G-code files for the cutting. This allows changeover of the timber in the machine without hassle.
A comments layer is added so the parameters can be seen when the file is reused at a future time.
« Last Edit: December 26, 2014, 23:10:50 pm by EddyCurrent »
Made in England

Offline lloydsp

  • CNC Jedi
  • *****
  • Posts: 8331
    • View Profile
Re: Woodworking Joints - Finger Joints Script
« Reply #1 on: December 26, 2014, 23:45:57 pm »
Very nice, Eddy!  I do a bit of woodworking (and more, now that I have the Shop Sabre).

If I might recommend... create the desired file tree with the correctly-named images folder in your own scripts directory, then just zip the tree.  When the user unzips it, it will re-create the tree.

I'd also recommend changing the name of the images folder to something like "Finger_Joint_images", so that it's not ambiguous, and also leaves room for other 'images' files.

And you can control the extended precision of some of those variables that display out to ten digits by using a string.format command, like:

    Comment(0) = string.format("Stock WIDTH = {0:0.0000}",FJ_StockWidth)


This form takes the first variable after the string definition, and formats it to 4 characters right of the decimal place.

That's a useful script, Eddy.  

I also meant to mention that, BOY, you really took off with the windowing code!  You actually got ahead of me.  I JUST got to the point where I released mine I had been working on for two days... and there yours was, already! Good job.

Thanks.

Lloyd
« Last Edit: December 27, 2014, 00:12:28 am by lloydsp »
"Pyro for Fun and Profit for More Than Fifty Years"

Offline lloydsp

  • CNC Jedi
  • *****
  • Posts: 8331
    • View Profile
Re: Woodworking Joints - Finger Joints Script
« Reply #2 on: December 27, 2014, 00:23:48 am »
Oh.... one more thing.  It's not a suggestion or criticism, but an 'answer' to one of your program comments.

You can add your own input validation "on the fly" while the input form is still in context by creating event handlers for each text box that needs validating.  When an event triggers, you can do anything from just checking the range to running a 'dummy' of the entire routine to check for problems, and alerting the user if there are any.  You can alert them with a popup message box, or by hidden labels in the form you make visible when there's a problem.

One way is to use the control.TextChanged property to trigger an event.

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

Offline EddyCurrent

  • CNC Jedi
  • *****
  • Posts: 4463
    • View Profile
Re: Woodworking Joints - Finger Joints Script
« Reply #3 on: December 27, 2014, 09:47:29 am »
Lloyd, thanks for the suggestions, I've added an update but I still have to crack the validation part, bit rusty after 30 year spell off programming.

Changes in 1.2

1. Zip file willl create folder structure in 'scripts' folder
1. images sub folder renamed to 'Finger_Joint_Images'
2. Formatted text better on 'Comments' layer
3. added meaningful title to error message box
4. Minor changes to some text


Edit: okay getting validation sorted now  ;)
« Last Edit: December 27, 2014, 11:15:13 am by EddyCurrent »
Made in England

Offline dave benson

  • CNC Jedi
  • *****
  • Posts: 1345
    • View Profile
Re: Woodworking Joints - Finger Joints Script
« Reply #4 on: December 27, 2014, 10:15:45 am »
Hi Eddycurrent
Wow you and Lloyd have been busy, Great contributions to the forum.
I like what you have done in such a short time, Nice work.
Dave.

Offline lloydsp

  • CNC Jedi
  • *****
  • Posts: 8331
    • View Profile
Re: Woodworking Joints - Finger Joints Script
« Reply #5 on: December 27, 2014, 13:53:33 pm »
I have to say that Eddy is faster at 'relearning' what he's forgotten than I am.

Dave, I use this great CamBam software daily for 'work' <G>, but half the fun of using it is because it's so extensible... and you can't have that part of the fun until you start exploring scripts and plugins.

When I started on this forum, there was scant-to-nothing available to explain how to use the CamBam objects and methods.  Scripts were almost all just simple, stand-alone things. 

But now we have quite a number of folks here who've explored the system enough to answer just about any question about interfacing to the system.  Each of us, it seems, holds different pieces to the puzzle.

So don't be timid about getting into scripting, even if you've never programmed before.  If you need to do something CamBam won't do natively, just WRITE IT!  You've got lots of supporting cast.

Just dive in!  The water's fine!

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

Offline lloydsp

  • CNC Jedi
  • *****
  • Posts: 8331
    • View Profile
Re: Woodworking Joints - Finger Joints Script
« Reply #6 on: December 27, 2014, 15:19:46 pm »
Eddy,
The comments are nicely truncated in the display now.  However, the values in the MOp fields are still showing with those long, unwieldy fractional parts.

Somehow, I didn't notice that before I suggested re-formatting the outputs.

Instead, you can fix both places with one treatment -- using either Math.Round or Math.Truncate

First, truncate.  This works to just truncate to 'precision' digits
(note -- Math.truncate truncates at the decimal point, which is why we multiply by 'precision' value before truncating)

static double[] pow10 = { 1e0, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9, 1e10 }
public static double Truncate(this double x, int precision)
{
    if (precision < 0)
        throw new ArgumentException()
    end if

    if (precision == 0)
        return Math.Truncate(x)
    end if

    double m = precision >= pow10.Length ? Math.Pow(10, precision) : pow10[precision]
    return Math.Truncate(x * m) / m
}

And this serves to round (up or down):

rounded = Math.Round(2.22939393, 3) '  Returns 2.229

Lloyd
« Last Edit: December 27, 2014, 15:25:01 pm by lloydsp »
"Pyro for Fun and Profit for More Than Fifty Years"

Offline EddyCurrent

  • CNC Jedi
  • *****
  • Posts: 4463
    • View Profile
Re: Woodworking Joints - Finger Joints Script
« Reply #7 on: December 27, 2014, 17:08:50 pm »
Thank you for comments and suggestions, now updated to v1.3

Changes in v1.3

1. Numbers rounded down to 3 decimal places
2. As values are entered, the Tool Diameter value is calculated to largest possible
3. Tool Diameter box will not allow entry of a value larger than maximum possible

Ideally the Tool Diameter value should be entered last.
Made in England

Offline lloydsp

  • CNC Jedi
  • *****
  • Posts: 8331
    • View Profile
Re: Woodworking Joints - Finger Joints Script
« Reply #8 on: December 27, 2014, 17:20:37 pm »
Something's not quite right Eddy.

The comments get truncated to integers, even though the figures in the MOp are OK.

(edit... nope!  I forgot the depth of cut is greater than thickness by the fit tolerance, so that's OK)



Also, the fingers seem too narrow for the stock.

I might not have noticed that last thing in prior versions, and I will have to re-install to check.

Image below

LLoyd
« Last Edit: December 27, 2014, 17:32:29 pm by lloydsp »
"Pyro for Fun and Profit for More Than Fifty Years"

Offline EddyCurrent

  • CNC Jedi
  • *****
  • Posts: 4463
    • View Profile
Re: Woodworking Joints - Finger Joints Script
« Reply #9 on: December 27, 2014, 17:38:59 pm »
Lloyd, fingers too narraow was a bug (oversight)

Changes in v1.4

1. Bug if selecting default values fixed
2. Lloyd's Hidden scripting window code added ( I like it  :D)
Made in England

Offline lloydsp

  • CNC Jedi
  • *****
  • Posts: 8331
    • View Profile
Re: Woodworking Joints - Finger Joints Script
« Reply #10 on: December 27, 2014, 17:42:19 pm »
Bingo!  And it's pretty!  ;D

(you're fast!)

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

Offline lloydsp

  • CNC Jedi
  • *****
  • Posts: 8331
    • View Profile
Re: Woodworking Joints - Finger Joints Script
« Reply #11 on: December 27, 2014, 17:47:43 pm »
Also, Eddy,

(not your issue)

There's an inadequacy in that show/hide thing I posted.  Sometimes, it hides the main CamBam window, even if the scripting window is the current top window.

I'll fiddle that out.  It may need to be identified by its form.Text element as well as "activeform".

It always seems to work with a fresh instance of CamBam, but randomly fails after it's been run at least once.

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

Offline EddyCurrent

  • CNC Jedi
  • *****
  • Posts: 4463
    • View Profile
Re: Woodworking Joints - Finger Joints Script
« Reply #12 on: December 27, 2014, 17:48:57 pm »
Bingo!  And it's pretty!  ;D

(you're fast!)

Lloyd

Probably thanks to good music and a selection of England's finest ales  ;D  ;D

Edit: I need to change the way each finger lowerleft position is calculated because when I start on other joints this is going to be a better way. I'm thinking a pointlist but as yet I know very little about it.
Or maybe I'll just use an array as it's more familiar.
« Last Edit: December 27, 2014, 19:19:59 pm by EddyCurrent »
Made in England

Offline dh42

  • Administrator
  • CNC Jedi
  • *****
  • Posts: 6133
    • View Profile
    • Cambam V1.0 French Doc
Re: Woodworking Joints - Finger Joints Script
« Reply #13 on: December 27, 2014, 20:17:05 pm »
Hello guys,

it's a very good job you have done here  :D; a wealth of useful information (and a useful plugin too) ..

Quote
I'm thinking a pointlist but as yet I know very little about it.

a little use of Pointlist in this script, if that can help.
http://www.cambam.co.uk/forum/index.php?topic=4449.0

++
David


Offline lloydsp

  • CNC Jedi
  • *****
  • Posts: 8331
    • View Profile
Re: Woodworking Joints - Finger Joints Script
« Reply #14 on: December 27, 2014, 23:17:21 pm »
Eddy,
In reading your source code (nice!), I noticed something that's not a bug, but it will cause some folks an inconvenience.

You expressly set the post-processor to Mach3-Cutviewer.  Ehh.... I don't want that, because I have set a default post-processor for my machine, and it's not Mach3.

So, in order to machine the file, I must manually change the post-processor first.

Just a nit... easy to fix on my end.

Lloyd

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