Author Topic: Counting polylines in a layer  (Read 12787 times)

Offline dsnellen

  • Storm Trooper
  • ***
  • Posts: 108
    • View Profile
Counting polylines in a layer
« on: March 20, 2016, 15:03:08 pm »
I have searched the forum without finding an answer. Most of my projects have many individual entities. They are organized into layers named "Engraving", "Inside Cuts" and "Outside Cuts". The number of pieces in the Outside Cuts layer is how many total pieces in the projects. Right now I manually count them and it is error prone. Once you get past 100 pieces losing count is easy. Copying and pasting in a new layer will renumber the pieces but not necessarily in sequential order. Does anyone know of an easy way, aka automated, to count the pieces in a layer?

Thanks
Dave

P.S. It would be nice if the layer count was displayed in the layer info section........

Offline dh42

  • Administrator
  • CNC Jedi
  • *****
  • Posts: 7422
    • View Profile
    • Cambam V1.0 French Doc
Re: Counting polylines in a layer
« Reply #1 on: March 20, 2016, 16:01:58 pm »
Hello,

You can use this VB script to count the selected objects

Code: [Select]
' count selected

sub main

dim ct as long
Dim ent As Entity

    For Each ent In view.SelectedEntities
            ct = ct+1
        Next

app.log(ct & " Selected Objects ")


end sub

++
David

Offline dsnellen

  • Storm Trooper
  • ***
  • Posts: 108
    • View Profile
Re: Counting polylines in a layer
« Reply #2 on: March 20, 2016, 16:35:34 pm »
Thanks David. How do I run this?

Offline dh42

  • Administrator
  • CNC Jedi
  • *****
  • Posts: 7422
    • View Profile
    • Cambam V1.0 French Doc
Re: Counting polylines in a layer
« Reply #3 on: March 20, 2016, 17:01:53 pm »
Hello,

Quote
Thanks David. How do I run this?

Unzip and save the CountObject.vbs file in attachment (you can store it in your "Scripts" folder)

- 1 select the objects you want to count
- 2 menu script/open -> load the CountObject.vbs file.
- 3 in the script window, use the menu tools/compile (F5) to run the script (or hit F5 when the script window is selected)

the result appears in the bottom window (message window)

I can convert it to a plugin if you think it can be useful.

++
David

Offline dsnellen

  • Storm Trooper
  • ***
  • Posts: 108
    • View Profile
Re: Counting polylines in a layer
« Reply #4 on: March 20, 2016, 20:53:30 pm »
Thanks!! I got it now. I was selecting the layer, not the individual items in the layer.
Thanks a bunch.
Dave

Offline EddyCurrent

  • CNC Jedi
  • *****
  • Posts: 5269
  • Made in England
    • View Profile
Re: Counting polylines in a layer
« Reply #5 on: March 21, 2016, 21:18:48 pm »
Try this plugin, it counts up all types of entities on all layers, results are shown in the bottom message window.
Unzip the attached file and move the dll into CamBam's Plugin folder. It will appear as a new menu item called "Entity Counter" in the "Plugins" drop down menu.
Translation code has been added.
No need to select anything first.
« Last Edit: March 21, 2016, 22:20:19 pm by EddyCurrent »
Filmed in Supermarionation

Offline dsnellen

  • Storm Trooper
  • ***
  • Posts: 108
    • View Profile
Re: Counting polylines in a layer
« Reply #6 on: March 21, 2016, 23:39:02 pm »
Thanks! This is great. Many thanks to both of you. This is a BIG help. Dave

Offline dh42

  • Administrator
  • CNC Jedi
  • *****
  • Posts: 7422
    • View Profile
    • Cambam V1.0 French Doc
Re: Counting polylines in a layer
« Reply #7 on: March 22, 2016, 00:02:06 am »
Hello,

Eddy, maybe it can be useful to add the total count of objects in each layer and the total in the whole drawing (and why not, how many are selected in the whole drawing as my script :D )

++
David

Edit: moved in the plugin section
« Last Edit: March 22, 2016, 00:06:53 am by dh42 »

Offline dsnellen

  • Storm Trooper
  • ***
  • Posts: 108
    • View Profile
Re: Counting polylines in a layer
« Reply #8 on: March 22, 2016, 01:17:43 am »
Another problem that is giving me fits and is very time-consuming to fix. The attached CB shows an example part that is a polyline containing arcs and straight lines. The slots are matched to same size slots in other parts. Often times the parts have to be scaled so the slots get larger or smaller but the original width must be retained. The center line of the slot needs to remain in the same location. The boundary lines need to move outward or inward the same amount. Currently, I create a rectangle with the exact width and length. Then overlay/center the rectangle on the slot and move the slot corners to match the rectangle corners. On the attached CB, that is five individual operations.

Thinking/wondering if it would be possible to explode the part and rejoin the three sides of each slot as a polyline. Then select the polyline and tell a program how wide to make the slot. Bingo! Done. The connecting lines would need to be reattached and everything rejoined, but this is a simple task. Most parts have slots all the same width, but some have two or more slot width. Anyone have an idea how to automate this function?

Thanks
Dave

Offline EddyCurrent

  • CNC Jedi
  • *****
  • Posts: 5269
  • Made in England
    • View Profile
Re: Counting polylines in a layer
« Reply #9 on: March 22, 2016, 08:41:29 am »
The first thing that springs to mind is the Offset command.

If you had lines representing the slot centre lines you could use Edit->Offset to generate lines each side of it at a set distance. Not automatic but maybe an option.
It would help if there was an Offset command option that put a line each side of the centre line rather than just one side as it currently does.

Or, have the slots on a layer of their own so that only the other geometry is resized. The slots would stay in the same place and the same size. After the geometry was resized, the slots could be extended or trimmed to meet up again.
« Last Edit: March 22, 2016, 08:46:07 am by EddyCurrent »
Filmed in Supermarionation

Offline EddyCurrent

  • CNC Jedi
  • *****
  • Posts: 5269
  • Made in England
    • View Profile
Re: Counting polylines in a layer
« Reply #10 on: March 22, 2016, 11:37:08 am »
Hello,

Eddy, maybe it can be useful to add the total count of objects in each layer and the total in the whole drawing (and why not, how many are selected in the whole drawing as my script :D )

++
David

Edit: moved in the plugin section

Your wish is my command  :D

Is it okay just printing in the message window or would it be better using a Form with a text window ?
Filmed in Supermarionation

Offline dh42

  • Administrator
  • CNC Jedi
  • *****
  • Posts: 7422
    • View Profile
    • Cambam V1.0 French Doc
Re: Counting polylines in a layer
« Reply #11 on: March 22, 2016, 15:26:52 pm »
Hello Eddy

Quote
Is it okay just printing in the message window or would it be better using a Form with a text window ?

For my usage, it's sufficient, and we can copy/paste the contain of the message window with the Message Log Copy plugin if needed.

http://www.cambam.co.uk/forum/index.php?topic=2583.msg16073#msg16073

Maybe just add a ClearLogMessages() before writing the results.

++
David
« Last Edit: March 22, 2016, 15:34:44 pm by dh42 »

Offline EddyCurrent

  • CNC Jedi
  • *****
  • Posts: 5269
  • Made in England
    • View Profile
Re: Counting polylines in a layer
« Reply #12 on: January 09, 2017, 20:31:37 pm »
Update attached, version 2

Has been compiled with .NET version 4 assemblies and references to CamBam v1.0 dlls

Has been modified and tested to work on;

    Windows
    Linux

Works with CamBam version 1 ONLY
Filmed in Supermarionation

Offline dsnellen

  • Storm Trooper
  • ***
  • Posts: 108
    • View Profile
Re: Counting polylines in a layer
« Reply #13 on: January 10, 2017, 03:39:30 am »
Thanks Eddy,

Wanted you to know I am perfectly happy with Version 1. It does everything I wanted it to do. Thanks Dave