Filtering out special characters

Hello everyone, is there an effective way to filter out special characters within Dynamo. I want to filter them out from the view names so that views with the name does not get renamed.

Hello @annickad and welcome to the forum…do you mean something here ?

2 Likes

One way to do it in python :snake: , there will be a bunch more…

a

find_these = "\:\{}[]|;<>?'~]"

name_result = []
view_result = []

names = IN[0]
views = IN[1]

for n,v in zip(names,views):
   check = 0
   for f in find_these:
        if f in n:
            check = + 1
            break
            
   if check != 1:         
       name_result.append(n) 
       view_result.append(v)
       
OUT = name_result,view_result
2 Likes

Hello, possible also to do with the work already done.

Cordially
christian.stan

2 Likes

Hi,
a solution using NamingUtils

import clr
import sys
import System
#import Revit API
clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *
import Autodesk.Revit.DB as DB
#import transactionManager and DocumentManager (RevitServices is specific to Dynamo)
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument

toList = lambda x : x if isinstance(x, list) else [x]

lstElement = toList(UnwrapElement(IN[0]))

OUT = [e for e in lstElement if e is not None and DB.NamingUtils.IsValidName(e.Name)]
3 Likes