Numbering every second paragraph

Hi, I got python code going to number the text automatically but it numbers empty paragraphs between notes for spacing. Does anyone got any ideas to make it skip every second paragraphs or something? Cheers.

import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)

clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

from System.Collections.Generic import *

clr.AddReference("RevitAPI")
import Autodesk
from Autodesk.Revit.DB import *
import System

doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application

dataEnteringNode = IN

textNotes = IN[0]

if not isinstance(textNotes, list):
	textNotes = [textNotes]


TransactionManager.Instance.EnsureInTransaction(doc)

for textNote in textNotes:

	textNote = UnwrapElement(textNote)
	formatText = textNote.GetFormattedText()
	textRange = formatText.AsTextRange()
	listType = System.Enum.Parse(Autodesk.Revit.DB.ListType, "ArabicNumbers")
	formatText.SetListType(textRange,listType)
	formatText.SetListStartNumber(textRange, IN[1])
	formatText.SetAllCapsStatus(True)
	textNote.SetFormattedText(formatText)
	
TransactionManager.Instance.TransactionTaskDone()

OUT = textNotes

Replace all your doubled new line characters with a new line character and one line’s worth of spaces/tabs followed by a zero width space character and then a beeline character. This should ensure you get the ‘visual space’ you want without causing a new paragraph.

1 Like

@haaadif Try this: Bullet Text.dyn (5.7 KB)

import clr
clr.AddReference("RevitServices")
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

clr.AddReference("RevitAPI")
import Autodesk
from Autodesk.Revit.DB import *

import System
from System.Collections.Generic import *

doc = DocumentManager.Instance.CurrentDBDocument

textNotes = IN[0]

if not isinstance(textNotes, list):
	textNotes = [textNotes]

TransactionManager.Instance.EnsureInTransaction(doc)
for textNote in textNotes:
	textNote = UnwrapElement(textNote)
	textNote.Text = "\v\r".join([x for x in textNote.Text.split("\r") if x])	
	formatText = textNote.GetFormattedText()
	textRange = formatText.AsTextRange()
	listType = System.Enum.Parse(Autodesk.Revit.DB.ListType, "ArabicNumbers")
	formatText.SetListType(textRange,listType)
	formatText.SetListStartNumber(textRange, IN[1])
	formatText.SetAllCapsStatus(True)
	textNote.SetFormattedText(formatText)	
TransactionManager.Instance.TransactionTaskDone()

OUT = textNotes
4 Likes

Hi @AmolShah,

The code works perfectly - thank you!

1 Like