Author Topic: [VB script] Make Stock from objects  (Read 35864 times)

Offline dh42

  • Administrator
  • CNC Jedi
  • *****
  • Posts: 6078
    • View Profile
    • Cambam V1.0 French Doc
[VB script] Make Stock from objects
« on: August 29, 2013, 18:52:04 pm »
Hello,

I just finished a script to help to define stock.

There is tree ways to use it.

1- with a polyrectangle selected

in this case, the script use the X and Y size of the rectangle and ask for stock surface and thickness.

2 - With one or more 3D surfaces selected

in this case the X, Y and Z size and position are taken from the extremas of the selected surfaces ; in addition the script ask for an oversize value for X and Y and for a bottom oversize value. Both are 0 by default

3 - With both 3D surfaces and ONE polyrectangle selected.

In this case, the X and Y size and pos are taken from the rectangle, the stock surface and the thickness are taken from the 3D surfaces. the script ask for an additional bottom oversize too.

Hope it enjoy CutViewer users ;)

http://screencast.com/t/Qgz2dz7c

++
David
« Last Edit: August 29, 2013, 19:15:28 pm by dh42 »

Offline csirocnc

  • Storm Trooper
  • ***
  • Posts: 146
  • Howell V4
    • View Profile
Re: [VB script] Make Stock from objects
« Reply #1 on: August 30, 2013, 07:41:25 am »
I like it, nice work
Now we just need some "round stock" support  ;)
1st CamBam Licence sale
in Australia

Offline kvom

  • CNC Jedi
  • *****
  • Posts: 1579
    • View Profile
Re: [VB script] Make Stock from objects
« Reply #2 on: August 30, 2013, 10:42:39 am »
I define round stock by drawing a circle in a separate level with separate color.  Works fine, although obviously it won't be passed to Cutviewer (does CV support round stock?)

Offline pixelmaker

  • CNC Jedi
  • *****
  • Posts: 1756
    • View Profile
    • pixelmaker
Re: [VB script] Make Stock from objects
« Reply #3 on: August 30, 2013, 12:01:15 pm »
Hello David,

this is a very helpfull script. Thank for this.

Quote
I define round stock by drawing a circle in a separate level with separate color.  Works fine
If I use other then a rectangle I get a
"The selected entities are not usable to do a stock"

ralf

Offline dh42

  • Administrator
  • CNC Jedi
  • *****
  • Posts: 6078
    • View Profile
    • Cambam V1.0 French Doc
Re: [VB script] Make Stock from objects
« Reply #4 on: August 30, 2013, 12:58:22 pm »

If I use other then a rectangle I get a
"The selected entities are not usable to do a stock"

ralf

Hello ;)

Yes on CB we can only define rectangular stock currently (but CV can use cylinder and cylinder with an hole).

I restrict the 2d selection to a rectangle because it's a shape very easy to modify with the mouse to adjust the size and location of the stock.

maybe in the future, if I find how to do  ::) , I'll add a load/save option for the stock, but I'm not sure that I can open a 'file requester' in VBscript ; a lot off things that are in VB are not in VBS (or I don't know how to use it... )

++
David

Offline dh42

  • Administrator
  • CNC Jedi
  • *****
  • Posts: 6078
    • View Profile
    • Cambam V1.0 French Doc
Re: [VB script] Make Stock from objects
« Reply #5 on: August 30, 2013, 13:12:58 pm »
I define round stock by drawing a circle in a separate level with separate color.  Works fine, although obviously it won't be passed to Cutviewer (does CV support round stock?)

Hello,

A way to use a round with CV.

Add the stock definition in the 'custom file header' as in the attached file.

... humm .. I think, I might have to add this option to the script for future update ...

++
David

Offline dh42

  • Administrator
  • CNC Jedi
  • *****
  • Posts: 6078
    • View Profile
    • Cambam V1.0 French Doc
Re: [VB script] Make Stock from objects
« Reply #6 on: November 17, 2013, 19:27:34 pm »
Hello,

Here is a new script designed to do round stock (only) for use with Cutviewer

A new layer is created and a round stock is drawn on it.

A cutviewer definition is also created and written in the File Header.

You can use a stock with a hole in center.

How to use it.

- draw a circle that represent the diameter of the stock (and it's location X Y)

- run the script and answer to the questions

If a square stock already exists, it will be deleted. The color for the stock layer is taken from the normal stock color.

note that if you have already definitions in the File Header they will be replaced by the cutviewer stock definition.


++
David
« Last Edit: April 06, 2020, 01:52:20 am by dh42 »

Offline csirocnc

  • Storm Trooper
  • ***
  • Posts: 146
  • Howell V4
    • View Profile
Re: [VB script] Make Stock from objects
« Reply #7 on: November 18, 2013, 02:13:45 am »
I like it, Nice work. :)
I can now cross it off my christmas list.
1st CamBam Licence sale
in Australia

Offline dh42

  • Administrator
  • CNC Jedi
  • *****
  • Posts: 6078
    • View Profile
    • Cambam V1.0 French Doc
Re: [VB script] Make Stock from objects
« Reply #8 on: November 18, 2013, 18:52:35 pm »
Quote
I can now cross it off my christmas list.

 ;D ;D

Offline lloydsp

  • CNC Jedi
  • *****
  • Posts: 8318
    • View Profile
Re: [VB script] Make Stock from objects
« Reply #9 on: January 03, 2014, 02:59:46 am »
Ok, David.

Here's a more generalized version of the MakeStock script in the form of a vb plugin.
Place in the programfiles/plugins folder as usual.

It will create a stock item for the machining tab, one part, or any number of selected parts.

Select one or more rectangles and/or surfaces as the source for the stock.  The largest extents will be used.
Select one part, multiple parts, or no parts.

Click on "tools/make stock from drawing object".

If you have selected drawing objects (and if they are suitable as stock sources)

Then, if no parts are selected, you will be given a choice to make the stock for the machining tab, or abort, otherwise, stock will be made for every selected part.

Please work it out, and let me know of problems.  Source after debugging ! <G>

No... no language translation, yet.

LLoyd

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

Offline BR52

  • Wookie
  • ****
  • Posts: 335
    • View Profile
Re: [VB script] Make Stock from objects
« Reply #10 on: January 03, 2014, 09:27:44 am »
Hi LLoyd,

You forgot to put the source code.  ::)

   Armando

Offline lloydsp

  • CNC Jedi
  • *****
  • Posts: 8318
    • View Profile
Re: [VB script] Make Stock from objects
« Reply #11 on: January 03, 2014, 11:42:18 am »
No, Armando... I wanted to expose it to scrutiny before publishing the source.

The code is UGLY... but it doesn't have to be 'buggy', too! <G>

Actually, I've already discovered something I don't like about it.  I never fully exercised the features of the algorithm I started with, until after I'd gotten the UI figured out.  

It doesn't do what I think it should.  Ideally, if one selects several drawing objects... it should create a stock item that reflects stock for the extents of the drawing objects, not just the one largest (or first) object in the list.  And, if one selects several objects for which to create one stock, then it just makes sense that ANY shape should be allowed (but only when multiples are selected), since no single shape will be used to describe the stock -- it will just be an 'extents' stock.

To that end, I'll be altering the routine this evening.  Perhaps, also, I'll spend a bit of time 'prettying it up', so my old, rusty 1980's non-structured language skills don't show so glaringly! <G>

THEN I'll publish the source (I promise!)

Lloyd
« Last Edit: January 03, 2014, 12:49:41 pm by lloydsp »
"Pyro for Fun and Profit for More Than Fifty Years"

Offline dh42

  • Administrator
  • CNC Jedi
  • *****
  • Posts: 6078
    • View Profile
    • Cambam V1.0 French Doc
Re: [VB script] Make Stock from objects
« Reply #12 on: January 03, 2014, 15:17:46 pm »
Hello,

Quote
No... no language translation, yet.

I spent some hours on that, but with no luck  :-\

Quote
It doesn't do what I think it should.  Ideally, if one selects several drawing objects... it should create a stock item that reflects stock for the extents of the drawing objects, not just the one largest (or first) object in the list.  And, if one selects several objects for which to create one stock, then it just makes sense that ANY shape should be allowed (but only when multiples are selected), since no single shape will be used to describe the stock -- it will just be an 'extents' stock.

Yes, in my script, it's the sub:

FindStockMax (objmin as Point3F, objmax as Point3F, byref stockmin as Point3F, byref stockmax as Point3F, first as boolean)

that do this job.

++
David

Offline lloydsp

  • CNC Jedi
  • *****
  • Posts: 8318
    • View Profile
Re: [VB script] Make Stock from objects
« Reply #13 on: January 03, 2014, 15:27:19 pm »
David,
I took your entire script with all of its 'find' elements, and incorporated it into this without modifications to your logic.  You got credits in the docs! <G>

It doesn't work as expected with (say) four rectangles all touching points at 0,0.
I think it needs to be changed to use a "get objects extremas" function to work as I would think it should.

But... maybe I somehow accidentally smutched your logic.  Not intentionally, though.

Lloyd
« Last Edit: January 03, 2014, 15:32:41 pm by lloydsp »
"Pyro for Fun and Profit for More Than Fifty Years"

Offline dh42

  • Administrator
  • CNC Jedi
  • *****
  • Posts: 6078
    • View Profile
    • Cambam V1.0 French Doc
Re: [VB script] Make Stock from objects
« Reply #14 on: January 03, 2014, 15:32:38 pm »
Quote
I took your entire script with all of its 'find' elements, and incorporated it into this without modifications to your logic.  You got credits in the docs! <G>

With translation in C# ? or in VB

Quote
It doesn't work as expected with (say) four rectangles all touching points at 0,0.

Yes it's right, the script is designed to handle only one rectangle and multiple 3D surfaces, not multiple 2D shapes.

++
David