Modify rebar number

Modify rebar number

maisoui
Advocate Advocate
8,645 Views
2 Replies
Message 1 of 3

Modify rebar number

maisoui
Advocate
Advocate

Hi,

 

I'd like to edit the parameter "Rebar Number" (REBAR_NUMBER) of a Rebar Element.

 

revit_api_rebar_number.png

 

The API prompts that this is a read-only parameter, but why ? My customers want to choose this number.

Is there a solution ?

 

Best regards,

--
Jonathan
Accepted solutions (1)
8,646 Views
2 Replies
Replies (2)
Message 2 of 3

jeremytammik
Autodesk
Autodesk
Accepted solution

Dear Jonathan,

 

Thank you for your query.

 

Many BIM properties are constrained in a certain manner that is not obvious when looking from an API point of view.

 

These aspects are generally driven by rules that are better understood looking at things from a product end user interface point of view.

 

Please be aware that the Revit API hardly ever supports any functionality that is not also available in the user interface.

 

You should therefore always research the optimal workflow and best practices to address your task at hand manually through the user interface first.

 

To do so, please discuss and analyse it with an application engineer, product usage expert, or product support.

 

Once you have got that part sorted out, it is time to step into the programming environment.

 

Now to directly address your rebar numbering question.

 

I had not run into this issue before, so I performed some Internet searches.

 

Here is the official help file and video on rebar numbering:

 

https://knowledge.autodesk.com/support/revit-products/learn-explore/caas/CloudHelp/cloudhelp/2015/EN...

 

Next, I found some hints on how the numbering is automated by Revit:

 

https://www.revit.news/2016/09/revit-reinforcement-keeping-a-check-on-bar-marks/

 

Rebar Number which automatically assigns bar marks to all reinforcing within the project making use of the partitions to generate a suitable bar mark.

 

revit-reinforcement-number-and-partition

 

... automatically synchronise the Rebar Number to the Schedule Mark (this was the method of bar marking prior to Revit 2015).

 

I also found a previous API related discussion thread here in the forum, although it addresses reading the numbers, not setting them.

 

Reading the rebar numbers from a varying rebar set:

 

https://forums.autodesk.com/t5/revit-api-forum/varying-rebarset-rebar-numbers/td-p/6659157

 

Finally, I found the answer to your question, in the developer’s guide included in the standard Revit help:

 

http://help.autodesk.com/view/RVT/2018/ENU/?guid=GUID-91C5087B-2E92-4276-878B-68FA8491D238

 

For the sake of completeness and easier future searches, I reproduce it here in full:

 

Numbering

 

Rebar is one of the categories of elements whose numbering can be controlled via the Revit API. The NumberingSchema and NumberingSchemaType classes can be used to define how rebar elements are to be organized for the purpose of numbering/tagging them. Each NumberingSchema controls numbering of elements of one particular kind. Instances of NumberingSchema are also elements and there is always only one of each type in every Revit document. Available types of all built-in numbering schemas are enumerated in NumberingSchemaTypes class.

 

Elements (e.g. Rebar) belonging to a particular schema (e.g. NumberingSchemaTypes.StructuralNumberingSchemas.Rebar) are organized and numbered in sequences. A sequence is a collection of elements that share the same numbering partition as defined by their respective values of the Partition parameter (NUMBER_PARTITION_PARAM). A numbering sequence must contain at least one element. In other words, a sequence is established once there is at least one element of which the partition parameter has a value that differs from other elements (in the same numbering schema). If the last element is removed (deleted or moved to a different sequence) then the empty sequence ceases to exist.

 

Elements get assigned to sequences either upon their creation (based on the then current numbering partition value), by explicitly modifying the Partition parameter of an element, or by using the AssignElementsToSequence() method. The AssignElementsToSequence() method is preferred over explicitly changing the Partition parameter, because the method applies changes to sequences and element numbers immediately, while changed parameters only go into effect after the current transaction is closed.

 

In addition to directly or indirectly changing the Partition parameter of elements, numbering sequences can be reorganized by using methods of the NumberingSchema class. The MoveSequence() method moves all elements of an existing sequence to a new sequence that does not exist yet in the schema, thus effectively renaming the Partition parameter on all the affected elements. The AppendSequence() method removes all elements from one sequence and appends them to elements of another existing sequence while applying the matching policy. The method MergeSequences() takes elements of all specified sequences and moves them all into a newly created sequence. All the merged elements will be renumbered and matched as needed based on the matching algorithm.

 

The sample below uses the MoveSequence() method to swap numbers for Rebar in two numbering sequences.

 

Code Region: Swap numbers

 

  /// <summary>
  /// This method uses multiple moving operations to swap numbers
  /// for Rebars in two numbering sequences. The sequences are
  /// identified by the names of two numbering partitions.
  /// </summary>
  /// <param name="document">Document to modify</param>
  /// <param name="part1">Name of the partition of one numbering sequence</param>
  /// <param name="part2">Name of the partition of another numbering sequence</param>
  private void SwapNumberingSequences(Document document, string part1, string part2)
  {
    // Obtain a schema object for a particular kind of elements 
    NumberingSchema schema = NumberingSchema.GetNumberingSchema(
      document,NumberingSchemaTypes.StructuralNumberingSchemas.Rebar);
  
    using (Transaction transaction = new Transaction(document))
    {
      // Changes to numbering sequences must be made inside a transaction
      transaction.Start("Swap Numbering Sequences");
  
      // We will use a temporary partition for the swap operation,
      // for the move operation only works if the target partition 
      // does not exist yet in the same numbering schema.
      // (We assume this TEMPORARY partition does not exist.)
      string tempPartition = "TEMPORARY";
  
      // Step 1
      // First we move all elements from one sequence into 
      // a partition we know does not exist. This action will
      // create the temporary partition and remove the original
      // one (part1).
      schema.MoveSequence(part1, tempPartition);
  
      // Step 2
      // With the sequence in partition 'part1' removed
      // we can now move elements from the second sequence to it.
      // This action will re-create a sequence in partition 'part1'
      // and remove the sequence in partition 'part2'
      schema.MoveSequence(part2, part1);
  
      // Step 3
      // Finally, we can move elements 'parked' in the temporary
      // sequence to partition 'part2', for that partition was
      // removed in the previous step and thus can now be created
      // again. The temporary partition will be automatically 
      // removed upon completing this step.
      schema.MoveSequence(tempPartition, part2);
  
      transaction.Commit();
    }
  }

 

Elements in different sequences are numbered independently, meaning that there may be elements with the same number in two sequences even though the elements are different. Likewise, there may be perfectly identical elements in two or more sequences bearing different numbers. However, within each one numbering sequence any two identical elements will always have the same number, while different elements will never have the same number within a numbering sequence.

 

Enumerable elements are always numbered automatically upon their creation. Each new element will get an incrementally higher number. However, new elements that match existing elements within the same sequence will get the same number assigned. Elements will keep their assigned numbers as long as it is possible. This means, for example, that if some previously created rebar elements get deleted, all remaining elements (within the same numbering sequence) will keep their numbers, which may result in gaps in the respective numbering sequence. Gaps can be removed by invoking RemoveGaps() for sequences in which gaps are not desired.

 

The following example consolidates the numbers on Rebar elements by removing any remaining gaps in numbering sequences and setting the start number of each sequence so numbers in sequences do not overlap.

 

Code Region: Consolidate Rebar numbers

 

 

  private void ConsolidateRebarNumbers(Document document)
  {
    // Obtain a schema object for a particular kind of elements 
    NumberingSchema schema = NumberingSchema.GetNumberingSchema(
      document,NumberingSchemaTypes.StructuralNumberingSchemas.Rebar);
  
    // Collect the names of partitions of all the numbering
    // sequences currently contained in the schema
    IList<string> sequences = schema.GetNumberingSequences();
  
    using (Transaction transaction = new Transaction(document))
    {
      // Changes to numbers must be made inside a transaction
      transaction.Start("Consolidate Rebar Numbers");
  
      // First we make sure numbers in all sequences are consecutive
      // by removing possible gaps in numbers. Note: RemoveGaps does
      // nothing for a sequence where there are no gaps present.
  
      // We also want to find what the maximum range of numbers is
      // of all the sequences (the one the widest span of used numbers)
      int maxRange = 0;
  
      foreach (string name in sequences)
      {
        schema.RemoveGaps(name);
  
        // Here we use First() from the Linq extension.
        // There is always at least one range in every sequence,
        // and after gaps are closed there is exactly one range.
        IntegerRange range = schema.GetNumbers(name).First();  
        int rangeSpan = 1 + (range.High - range.Low);
        if (rangeSpan > maxRange)
        {
          maxRange = rangeSpan;
        }
      }
  
      // Next we give sequences different start numbers
      // starting with 100 and then stepping by at least
      // the maximum range we found in the previous step
      int startNumber = 100;
  
      // We round the range up to the closest 100
      int step = 100 * (int)((maxRange + 99) / 100.0);
  
      foreach (string name in sequences)
      {
        schema.ShiftNumbers(name, startNumber);
        startNumber += step;
      }
  
      transaction.Commit();
    }
  }

 

Numbers are stored as values of a numbering parameter on each numbered element. The Id of the parameter is obtained by querying the NumberingSchema.NumberingParameterId property. The value of the number can be obtained by querying the parameter for the respective numbered element. The value is read-only and thus cannot be set; it is always computed based on relations of elements across numbering partitions and the matching policy within the numbering sequence of each element.

 

Even though numbers are always assigned automatically to all elements of a schema, the method ChangeNumber() gives the programmer a way to explicitly overwrite a specific number as long as the new number is unique in the numbering sequence. The caller specifies a number to be changed and a new value that is to be applied, providing the value does not exist yet in the same numbering sequence.

 

I hope this helps.

 

This shows once again how important it is to be aware of multiple official in-depth Revit API documentation sources we have access to.

 

Oh, and I also notice your question on arch-pub.com:

 

http://www.arch-pub.com/Modify-rebar-number_10895719.html

 

I added this answer there as well... nope, cannot... I suppose it just mirrors this site?

 

Cheers,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 3 of 3

maisoui
Advocate
Advocate

Hi Jeremy,

 

Thank you so much for your complete answer.

I don't know the website http://www.arch-pub.com, it is just a mirror.

 

Best regards

--
Jonathan
0 Likes