sketchucation logo sketchucation
    • Login
    πŸ€‘ SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

    Reset the naming

    Scheduled Pinned Locked Moved Plugins
    3 Posts 2 Posters 214 Views 2 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • D Offline
      dedmin
      last edited by

      If I have

      @unknownuser said:

      comp#2
      comp#3
      test#4
      test#12

      How to reset the naming to start back from 0

      @unknownuser said:

      comp
      comp#1
      test
      test#1

      1 Reply Last reply Reply Quote 0
      • TIGT Offline
        TIG Moderator
        last edited by

        If you have known names it's easier...
        You can get all of your components' names thus
        names=[] defs=model.definitions defs.each{|d|names << d.name}
        You then need to find the 'family names' for the sets of components.
        families=[] names.each{|name| if name.include?("#") families << name.split("#")[0..-2].join("#") else families << name end } families.uniq!
        Now look for the 'family' members...
        dsets=[] families.each{|family| dset=[family] defs.each{|d| dset << d if d.name.includes?(family) } dsets << dset }
        Now we have the list of 'dsets' of all definitions by 'family'.
        The array is in the form [name, defn1, defn2,...]
        To ensure that the renaming doesn't affect existing defs with the same name you need to rename ALL in a set and then rename them in order after the 'family' again.
        dsets.each{|dset| family=dset[0] randst=rand.to_s dset[1..-1].each{|d|d.name=d.name+randst} dset.[1..-1].each{|d|d.name=family}### they will auto increment*** }
        So now all of the definitions should be renamed in order.
        ***To start the renaming from ''#1 use ...d.name=family+"#1"} then there'll be no 'comp' as the first one will be 'comp#1'...

        TIG

        1 Reply Last reply Reply Quote 0
        • D Offline
          dedmin
          last edited by

          Thanks! πŸ‘ πŸ‘

          1 Reply Last reply Reply Quote 0
          • 1 / 1
          • First post
            Last post
          Buy SketchPlus
          Buy SUbD
          Buy WrapR
          Buy eBook
          Buy Modelur
          Buy Vertex Tools
          Buy SketchCuisine
          Buy FormFonts

          Advertisement