Author Topic: Number generator (VB script)  (Read 4326 times)

Offline dh42

  • Administrator
  • CNC Jedi
  • *****
  • Posts: 7422
    • View Profile
    • Cambam V1.0 French Doc
Number generator (VB script)
« on: May 03, 2024, 22:42:55 pm »
Hello

I often needs to add a lot of numbers in my drawing, to identify parts, to make numbers on rules or meter number and so one.

For this, I often use a "generic" text contained "00" that I copy/paste at the right place or that I dispatch using "array copy", "polar array copy" or the "copy to point list" plugin.

But after the copy is done, I need to manually edit each text object to set the right number.

So I decided to write this small script to automate this job. (because I have a job to do that need around 80 part to renumber)

Select all the text objects to renumber, in the order you want to number them and run the script.

In the script, you can define the variables "start" that will contain the start number, "stepvalue" that will contain the step and "formatstring" that will contain the format to use for the numbers.

Code: [Select]
' dh42 05/2024
' numérotation incrémental d'une sélection d'objets texte
' incremental numbering of a selection of text objects

sub main

        Dim start As Double, stepvalue As Double, currentvalue As Double
        Dim formatstring As String
       
        '########################
        formatstring = "00"
        start = 1
        stepvalue = 1
        '########################

        currentvalue = start
       
        Dim s As MText

        If CamBamUI.MainUI.ActiveView.SelectedEntities.Length > 0 Then

            For Each ent As Entity In CamBamUI.MainUI.ActiveView.SelectedEntities

                If TypeOf ent Is MText Then

                    s = ent
                    s.Text = Format(currentvalue, formatstring)
                    s.Update
                    currentvalue = currentvalue + stepvalue

                End If

            Next ent

        End If

end sub

Unzip the attached file and save it in your script folder.

I hope it can be useful for some.

Note VB script are not working on Linux version and on 64bits CamBam Windows version ; If needed I can turn it into a plugin so it will works on all versions.

++
David

Offline EddyCurrent

  • CNC Jedi
  • *****
  • Posts: 5269
  • Made in England
    • View Profile
Re: Number generator (VB script)
« Reply #1 on: May 04, 2024, 19:47:59 pm »
Here's a Python version that works with 64bit version 1

Code: [Select]
# dh42 05/2024
# numérotation incrémental d'une sélection d'objets texte
# incremental numbering of a selection of text objects

start = 1.0
stepvalue = 1.0
currentvalue = start
formatstring = "00"

if len(CamBamUI.MainUI.ActiveView.SelectedEntities) > 0:
  for ent in CamBamUI.MainUI.ActiveView.SelectedEntities:
    if ent.GetType().Name == "MText":
      ent.Text = format(currentvalue, formatstring)
      ent.Update()
      currentvalue = currentvalue + stepvalue



Filmed in Supermarionation

Offline dh42

  • Administrator
  • CNC Jedi
  • *****
  • Posts: 7422
    • View Profile
    • Cambam V1.0 French Doc
Re: Number generator (VB script)
« Reply #2 on: May 04, 2024, 20:06:14 pm »
Hello

Thanks Eddy ;)

(I'm still allergic to python  ;D)

++
David

Offline EddyCurrent

  • CNC Jedi
  • *****
  • Posts: 5269
  • Made in England
    • View Profile
Re: Number generator (VB script)
« Reply #3 on: May 04, 2024, 20:43:11 pm »
So am I but I thought I'd give it a try.
Filmed in Supermarionation