Trying to make a Serial Number coding in parameters

Hello. Im trying to make a script where i can generate a serial number, and add it to an assembly code.
My problem is that i want to restart the serial number for each assembly code.
111.001 111.002 111.003 123.003
I dont know if i have to split the categories with wall types, or i can make it restart for each assembly code.

First - you are applying this by type. Do you want unused types to also get a serial number? If so, you need to collect the types at the start rather than the walls in use. But if you just want the walls in use - you’re good.

Second - this is collecting just basic walls. Curtain and stacked walls are exclude. So if you want those, you’ll need a different collector.
If you just want basic walls - it is faster and more targeted to just run a FilteredElementCollector with Python. I do that for most of my selections.

myWallTypes = FilteredElementCollector(doc).OfClass(WallType).ToElements()
myBasicWalls = [wall for wall in myWallTypes if wall.Kind.ToString() == "Basic"]

Next, don’t use the category dropdown unless you are after this as an input. This node has a habit of changing on you. Next time you open it it might say doors. Not sure what causes that, but better to use a code block with “Walls”; and pipe it to > Category.ByName.

Are your serial numbers always the same for each project and wall? If so - this is just grabbing the walls in an unsorted fashion and applying a SN. Or is there some logic that needs to be applied to the SN sequence? If a wall is deleted - that serial number is gone from the walls in the project - but still on the wall type in the project.

I think it would be better to pick up all the serial numbers in the project and then increment from the end - if there are already SN’s in use or start at 1 and increment based on a loop.
So with some assumptions:

  • Get all wall types loaded in project.
  • Get all walls used in the project
  • Get all serial numbers on wall types loaded in the project.
  • Pull the last SN in use off the wall types and strip that back to the integer and add one for your starting value.
  • Remove all the walls in use that already have a SN so you aren’t changing past data.
  • Count the walls that need serial numbers.
  • Loop from your starting number for the number of wall that need new info. and increment +1 each time,

Thanks. I only need used types of walls, but that also Curtain and stacked walls.
The serial number can be different depends on the project, it is only the assembly code that is the same for each type of construction
221 = Outerwall
113 = Bathroom floors
The serial number is a way to describe a wall type so as shown before, the assembly code describes ex and outer wall, and the serial number describes which kind of outer wall it is. EX Brick wall 200mm could be 001, and Brick wall 450 is 002. So more a SN for each type than the typical ID Revit gives to the walls.

SN = Serial Number.

If you need all walls, including curtain and stacked, I’d use a FilteredElementCollector.

myWalls = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Walls).WhereElementIsElementType().ToElements()
myWalls = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Walls).WhereElementIsNotElementType().ToElements()

The first will give you all wall types. The second will give you all walls in the project.
But it seems like much of what you want to do is just good office standards in the creation of your wall types.

All walls have a Function parameter that can be set for either Interior or Exterior, Interior, Soffit, Retaining, Core-shaft. This could be used to pick up the use of the wall. It is a parameter that is little used inside Revit and was originally designed to facilitate export to DWG layer standards. But is usable in your case for classification.

Our office uses a UL designation prefix in our wall type naming to further classify the partition type. I don’t know if a similar system exists in your jurisdiction.

  1. Metal Partition
  2. Shaftwall
  3. Wood Partition
  4. etc.

As far as the numbers for your serial numbers go, you can generate the right number of serial numbers for your wall with a couple of variables and the count of your walls.

To group them by assembly code, you’ll need to pull the assembly code parameter off each wall and filter each by the code into sorted groups and then count each of those groups for a number to restart your counter. The below is pretty verbose, but should give you the idea. Note, that all of this this is much more streamlined if you just do it in python code.

I have tried to fix the problem about sorting the walls by assembly code. But now the problem as i see it, is that i need to split the list into different list, so i can run the SN generator.

Except the fact, that I maybe don’t get all types of walls, but the most important thing, is that i need to generate the right SN/TN

Have you looked at the GroupByKey node? It should do what you need.
I can’t really comment much more as the images are too small to read.

I don’t know if this post might be of some use?