Python .split TextNote

Hi,
Not sure why split does not work. I select text nodes
[0] 00.15
[1] 01.152
and should replace 1st one with None


ControlTextNode_V12.dyn (4.0 KB)

Typically that warning is given when you have mixed tabs and spaces. It is very important to use only tabs. The indentation might look correct, but if they are not identical python is not happy.

Dear Michal,
It should work now :wink:
ControlTextNode_V12.dyn (4.0 KB)

@Alberto_Tono thanks for help. I run your script and unfortunately got this warning.

Warning: IronPythonEvaluator.EvaluateIronPythonScript operation failed. _
Traceback (most recent call last):
_ File “”, line 42, in

AttributeError: ‘TextNote’ object has no attribute ‘split’

so this is issue line:

	if len(i.split('.')) > 0:

from my code:

from re import search

    atext3 = []
    atext4 = []

    #unwrap all elements to use with API
    elements = []
    for i in IN[0]:
    	elements.append(UnwrapElement(i))

    TransactionManager.Instance.EnsureInTransaction(doc)

    for i in elements:
    	id = i.Id
    	k = str(i.Text)
    	atext3.append(k)
    	if not len(list(i.Text)) > 5:
    		if len(i.split('.')) > 0:
    			if i.split('.')[0:2].isdigit():
    				if i.split('.')[3:].isdigit():
    					i.Text = ''
    					atext4.append(i.Text)

    TransactionManager.Instance.TransactionTaskDone()

    #Assign your output to the OUT variable
    OUT = atext3, atext4

could you share the .rvt file also please
what revit and dynamo are you using also?!

I am using now 16.0.1161.0 20160720_0715(x64) Update6 for R2 and Dynamo 1.2.0.2960. Revit - this is simple just go to Drafting view and create few text notes then Select Elements in Dynamo.
I think issue is when I try to get text from element and then perform .split on that… I tested to assing string to k before perform this function.

I have the same issue with 2016 I think it is about the attribute “split” isn’t implemented in Revit 2016.
But I am not so sure about that. I apologize I am not able to help you. :frowning:
The Image is about Revit 2017. There it works.

Can you tell us input and desired output? Tried to understand code, but failed :smiley:

@Tomasz_Puchala
Hi,
I am trying to find way to filter text and got 4 methods but can not get it to work right now.
So I want to find text that follow my logic…in this example “DigitDigit.DigitDigit” this text will be replaced with “” Nothing . (i.Text = '') Anyway this search could be any complex logic. In python those works but in Dynamo not really.

ps, No idea why conde is not recognized

  1. Simple If
if not len(list(i.Text)) > 5:
    		if len(i.split('.')) > 0:
    			if i.split('.')[0:2].isdigit():
    				if i.split('.')[3:].isdigit():
    					i.Text = ''
  1. Function A
for i in elements:
    match = search('\d{2}\.\d{2}$',i.strip())
    if match: 
        atext1.append(match.string)
        i.Text= ''
  1. Function B
from re import search
for i in elements:
	k = i.Text
	match=search('\d{2}\.\d{2}$',k.strip())
	if match: atext1.append(match.string)
		i.Text= ''
  1. Function C
for i in elements:
    id = i.Id
    k = i.Text
    if k.split('.')[0:2].isdigit():
        i.Text= ''

Hi,
sth like this?

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 *

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


#The inputs to this node will be stored as a list in the IN variable.

#from re import search

atext3 = []
atext4 = []


#unwrap all elements to use with API
elements = []
for i in IN[0]:
	elements.append(UnwrapElement(i))


b=[]
for i in elements:
	k = str(i.Text)
	atext3.append(k)
for j in atext3:
	if len(j) >= 5 and j[2] == '.':
		if j[0:2].isdigit() and j[3:].isdigit():	
			atext4.append('')
		else:
			atext4.append(j)
	else:
		atext4.append(j)
    


#Assign your output to the OUT variable
OUT =  atext3,atext4
1 Like

@Tomasz_Puchala
Hi Tomasz I think I got it. Had to do some modification but here is final product.

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 *

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


#The inputs to this node will be stored as a list in the IN variable.

#from re import search

atext3 = []
atextTrue = []
atextFalse = []
atextAll = []

#unwrap all elements to use with API
elements = []
for i in IN[0]:
	elements.append(UnwrapElement(i))

TransactionManager.Instance.EnsureInTransaction(doc)

for i in elements:
	atext3 = i.Text
	if len(atext3) == 5 and atext3[2] == '.':
		if atext3[0:2].isdigit() and atext3[3:5].isdigit():
			i.Text = 'deletedTEXT'		
			atextTrue.append(i.Text)
	else:
		atextFalse.append(i.Text)
		
	atextAll.append(i)

TransactionManager.Instance.TransactionTaskDone()

#Assign your output to the OUT variable
OUT =  atextTrue, atextFalse, atextAll
2 Likes