{ "Uuid": "e56fc43e89664db793209b9fb66a7efc", "IsCustomNode": false, "Description": "", "Name": "26_find_replace_parameter", "ElementResolver": { "ResolutionMap": {} }, "Inputs": [], "Outputs": [], "Nodes": [ { "ConcreteType": "CoreNodeModels.Input.StringInput, CoreNodeModels", "Id": "fffd25f1e67640b1a35a98d32d6655de", "NodeType": "StringInputNode", "Inputs": [], "Outputs": [ { "Id": "4d56745c9ca048ae9a50e4bb0a2a0e3d", "Name": "", "Description": "String", "UsingDefaultValue": false, "Level": 2, "UseLevels": false, "KeepListStructure": false } ], "Replication": "Disabled", "Description": "Creates a string", "InputValue": "Walls" }, { "ConcreteType": "CoreNodeModels.Input.StringInput, CoreNodeModels", "Id": "4ce44eab9ee44fe29aceab8e90a556f3", "NodeType": "StringInputNode", "Inputs": [], "Outputs": [ { "Id": "7907b472cc7a4963975d600fb5d0abbc", "Name": "", "Description": "String", "UsingDefaultValue": false, "Level": 2, "UseLevels": false, "KeepListStructure": false } ], "Replication": "Disabled", "Description": "Creates a string", "InputValue": "Comments" }, { "ConcreteType": "CoreNodeModels.Input.StringInput, CoreNodeModels", "Id": "2709dc8469a94765939167b3a3a58a40", "NodeType": "StringInputNode", "Inputs": [], "Outputs": [ { "Id": "b1a7c7d9182a4ad98e15c1efa2d20c00", "Name": "", "Description": "String", "UsingDefaultValue": false, "Level": 2, "UseLevels": false, "KeepListStructure": false } ], "Replication": "Disabled", "Description": "Creates a string", "InputValue": "old" }, { "ConcreteType": "CoreNodeModels.Input.StringInput, CoreNodeModels", "Id": "4861b311ea1749ce889a06dc692e8569", "NodeType": "StringInputNode", "Inputs": [], "Outputs": [ { "Id": "c1fbcbeb74214bdf98e769192e5f6259", "Name": "", "Description": "String", "UsingDefaultValue": false, "Level": 2, "UseLevels": false, "KeepListStructure": false } ], "Replication": "Disabled", "Description": "Creates a string", "InputValue": "new" }, { "ConcreteType": "CoreNodeModels.Input.StringInput, CoreNodeModels", "Id": "03f4a29c1cba45b391bee70fa1a34fc7", "NodeType": "StringInputNode", "Inputs": [], "Outputs": [ { "Id": "4d54d06387e94f3887d0e00cb5b79e1b", "Name": "", "Description": "String", "UsingDefaultValue": false, "Level": 2, "UseLevels": false, "KeepListStructure": false } ], "Replication": "Disabled", "Description": "Creates a string", "InputValue": "False" }, { "ConcreteType": "PythonNodeModels.PythonNode, PythonNodeModels", "Code": "# -*- coding: utf-8 -*-\r\n# Micro — Buscar y reemplazar texto en un parámetro (categoría o selección).\r\n#\r\n# IN[0] : categoría (ej. Walls, Furniture)\r\n# IN[1] : nombre del parámetro (str)\r\n# IN[2] : texto a buscar (str)\r\n# IN[3] : texto de reemplazo (str)\r\n# IN[4] : True = solo elementos seleccionados en Revit\r\n#\r\n# Salida: conteo de instancias modificadas.\r\n\r\nimport sys\r\n\r\nimport clr\r\nclr.AddReference('RevitAPI')\r\nclr.AddReference('RevitServices')\r\nfrom Autodesk.Revit.DB import FilteredElementCollector, BuiltInCategory, StorageType\r\nfrom RevitServices.Persistence import DocumentManager\r\nfrom RevitServices.Transactions import TransactionManager\r\n\r\n_PY3 = sys.version_info[0] >= 3\r\ndoc = DocumentManager.Instance.CurrentDBDocument\r\n\r\n\r\ndef _ustr(value):\r\n if value is None:\r\n return ''\r\n if _PY3:\r\n return str(value).strip()\r\n try:\r\n if isinstance(value, unicode):\r\n return value.strip()\r\n except NameError:\r\n pass\r\n return str(value).strip()\r\n\r\n\r\ndef _exc_str(ex):\r\n if _PY3:\r\n return str(ex)\r\n try:\r\n return unicode(ex)\r\n except NameError:\r\n return str(ex)\r\n\r\n\r\ndef _to_py_list(obj, max_index=256):\r\n if obj is None:\r\n return []\r\n if isinstance(obj, (list, tuple)):\r\n return list(obj)\r\n try:\r\n return list(obj)\r\n except TypeError:\r\n pass\r\n out = []\r\n for i in range(max_index):\r\n try:\r\n out.append(obj[i])\r\n except Exception:\r\n break\r\n return out\r\n\r\n\r\ndef _dynamo_in_ports():\r\n raw = globals().get('IN', [])\r\n ports = _to_py_list(raw, max_index=32)\r\n if len(ports) == 0 and raw is not None:\r\n tmp = []\r\n for i in range(32):\r\n try:\r\n tmp.append(raw[i])\r\n except Exception:\r\n break\r\n ports = tmp\r\n return ports\r\n\r\n\r\ndef _as_bool(val):\r\n if val is None:\r\n return False\r\n if isinstance(val, bool):\r\n return val\r\n if isinstance(val, int):\r\n return bool(val)\r\n s = _ustr(val).lower()\r\n if s in ('false', 'falso', '0', 'no', 'n', '', 'off'):\r\n return False\r\n if s in ('true', 'verdadero', '1', 'yes', 'si', 'sí', 'on'):\r\n return True\r\n try:\r\n return bool(int(float(s)))\r\n except Exception:\r\n return bool(val)\r\n\r\n\r\ndef _bic(cat_str):\r\n try:\r\n s = _ustr(cat_str).strip()\r\n name = s if s.startswith('OST_') else 'OST_' + s.replace(' ', '')\r\n return getattr(BuiltInCategory, name)\r\n except Exception:\r\n return None\r\n\r\n\r\ndef _elements(cat, use_sel):\r\n if _as_bool(use_sel):\r\n uidoc = DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument\r\n ids = uidoc.Selection.GetElementIds()\r\n return [doc.GetElement(i) for i in ids]\r\n bic = _bic(cat)\r\n if bic is None:\r\n return []\r\n return list(FilteredElementCollector(doc).OfCategory(bic).WhereElementIsNotElementType().ToElements())\r\n\r\n\r\n_ports = _dynamo_in_ports()\r\ncat = _ustr(_ports[0]) if len(_ports) > 0 else ''\r\npname = _ustr(_ports[1]) if len(_ports) > 1 else ''\r\nfind_s = _ustr(_ports[2]) if len(_ports) > 2 and _ports[2] is not None else ''\r\nrepl_s = _ustr(_ports[3]) if len(_ports) > 3 and _ports[3] is not None else ''\r\nuse_sel = _as_bool(_ports[4]) if len(_ports) > 4 else False\r\n\r\nif not pname or (not use_sel and not cat):\r\n OUT = ['Error: IN[1] parámetro; IN[0] categoría o IN[4]=True con selección.']\r\nelse:\r\n n = 0\r\n errs = []\r\n try:\r\n elems = _elements(cat, use_sel)\r\n except Exception as ex:\r\n OUT = ['Error categoría/selección: ' + _exc_str(ex)]\r\n elems = None\r\n if elems is not None:\r\n TransactionManager.Instance.EnsureInTransaction(doc)\r\n try:\r\n for el in elems:\r\n if el is None or el.Category is None:\r\n continue\r\n p = el.LookupParameter(pname)\r\n if p is None or p.IsReadOnly or p.StorageType != StorageType.String:\r\n continue\r\n cur = p.AsString()\r\n if cur is None:\r\n continue\r\n if find_s not in cur:\r\n continue\r\n newv = cur.replace(find_s, repl_s)\r\n try:\r\n p.Set(newv)\r\n n += 1\r\n except Exception as ex:\r\n errs.append(_exc_str(ex))\r\n finally:\r\n TransactionManager.Instance.TransactionTaskDone()\r\n OUT = [n, 'elementos modificados'] + (errs[:5] if errs else [])\r\n\r\n# --- RÜM: mensaje de cierre (URL en rum_platform_url.py) ---\r\ntry:\r\n import sys as _rum_sys\r\n _rum_root = r'c:\\RUM_Platform\\RUM_Tools\\Dynamo_Routines'\r\n if _rum_root not in _rum_sys.path:\r\n _rum_sys.path.insert(0, _rum_root)\r\n import rum_finalize as _rum_fin\r\n OUT = _rum_fin.apply(OUT)\r\nexcept Exception:\r\n pass\r\n", "Engine": "CPython3", "VariableInputPorts": true, "Id": "ab280503bf644d20871a18c411f5c133", "NodeType": "PythonScriptNode", "Inputs": [ { "Id": "a59272d965714bb3869966fb316cfdac", "Name": "IN[0]", "Description": "IN[0] Categoría", "UsingDefaultValue": false, "Level": 2, "UseLevels": false, "KeepListStructure": false }, { "Id": "4c1856d1d8604f56874b335c641f019a", "Name": "IN[1]", "Description": "IN[1] Parámetro", "UsingDefaultValue": false, "Level": 2, "UseLevels": false, "KeepListStructure": false }, { "Id": "92aba7039a02412da18e7b53c1ee3e1b", "Name": "IN[2]", "Description": "IN[2] Buscar", "UsingDefaultValue": false, "Level": 2, "UseLevels": false, "KeepListStructure": false }, { "Id": "0b2525da26ed413ca419ee7d229880b5", "Name": "IN[3]", "Description": "IN[3] Reemplazo", "UsingDefaultValue": false, "Level": 2, "UseLevels": false, "KeepListStructure": false }, { "Id": "bbef974c1d964089ae7eb73970b6ec99", "Name": "IN[4]", "Description": "IN[4] Solo selección True/False", "UsingDefaultValue": false, "Level": 2, "UseLevels": false, "KeepListStructure": false } ], "Outputs": [ { "Id": "7c03f4780b0f461ea40732b23ff8c013", "Name": "OUT", "Description": "Result of the python script", "UsingDefaultValue": false, "Level": 2, "UseLevels": false, "KeepListStructure": false } ], "Replication": "Disabled", "Description": "Runs an embedded Python script." } ], "Connectors": [ { "Start": "4d56745c9ca048ae9a50e4bb0a2a0e3d", "End": "a59272d965714bb3869966fb316cfdac", "Id": "54805ef4fcc545668fea7d4168e6cb96", "IsHidden": "False" }, { "Start": "7907b472cc7a4963975d600fb5d0abbc", "End": "4c1856d1d8604f56874b335c641f019a", "Id": "5398077720614440bc01c3659011c578", "IsHidden": "False" }, { "Start": "b1a7c7d9182a4ad98e15c1efa2d20c00", "End": "92aba7039a02412da18e7b53c1ee3e1b", "Id": "f8887309c5454553b223bee81617ad26", "IsHidden": "False" }, { "Start": "c1fbcbeb74214bdf98e769192e5f6259", "End": "0b2525da26ed413ca419ee7d229880b5", "Id": "1cba8fe6f11a4ad8b3592f89a37658ab", "IsHidden": "False" }, { "Start": "4d54d06387e94f3887d0e00cb5b79e1b", "End": "bbef974c1d964089ae7eb73970b6ec99", "Id": "e085eeec5ed548b5bba916614fb8aab3", "IsHidden": "False" } ], "Dependencies": [], "NodeLibraryDependencies": [], "EnableLegacyPolyCurveBehavior": true, "Thumbnail": "", "GraphDocumentationURL": null, "ExtensionWorkspaceData": [ { "ExtensionGuid": "28992e1d-abb9-417f-8b1b-05e053bee670", "Name": "Properties", "Version": "3.3", "Data": {} }, { "ExtensionGuid": "DFBD9CC0-DB40-457A-939E-8C8555555A9D", "Name": "Generative Design", "Version": "8.2", "Data": {} } ], "Author": "RÜM", "Linting": { "activeLinter": "None", "activeLinterId": "7b75fb44-43fd-4631-a878-29f4d5d8399a", "warningCount": 0, "errorCount": 0 }, "Bindings": [], "View": { "Dynamo": { "ScaleFactor": 1, "HasRunWithoutCrash": false, "IsVisibleInDynamoLibrary": true, "Version": "3.3.0.6316", "RunType": "Manual", "RunPeriod": "1000" }, "Camera": { "Name": "_Background Preview", "EyeX": 0, "EyeY": 0, "EyeZ": 10, "LookX": 0, "LookY": 0, "LookZ": 0, "UpX": 0, "UpY": 1, "UpZ": 0 }, "ConnectorPins": [], "NodeViews": [ { "Id": "fffd25f1e67640b1a35a98d32d6655de", "Name": "IN[0]", "IsSetAsInput": false, "IsSetAsOutput": false, "Excluded": false, "ShowGeometry": true, "X": 40, "Y": 220 }, { "Id": "4ce44eab9ee44fe29aceab8e90a556f3", "Name": "IN[1]", "IsSetAsInput": false, "IsSetAsOutput": false, "Excluded": false, "ShowGeometry": true, "X": 240, "Y": 220 }, { "Id": "2709dc8469a94765939167b3a3a58a40", "Name": "IN[2]", "IsSetAsInput": false, "IsSetAsOutput": false, "Excluded": false, "ShowGeometry": true, "X": 440, "Y": 220 }, { "Id": "4861b311ea1749ce889a06dc692e8569", "Name": "IN[3]", "IsSetAsInput": false, "IsSetAsOutput": false, "Excluded": false, "ShowGeometry": true, "X": 640, "Y": 220 }, { "Id": "03f4a29c1cba45b391bee70fa1a34fc7", "Name": "IN[4]", "IsSetAsInput": false, "IsSetAsOutput": false, "Excluded": false, "ShowGeometry": true, "X": 840, "Y": 220 }, { "Id": "ab280503bf644d20871a18c411f5c133", "Name": "RUM_26_FindReplaceParameter", "IsSetAsInput": false, "IsSetAsOutput": false, "Excluded": false, "ShowGeometry": true, "X": 1120, "Y": 360 } ], "Annotations": [], "X": 0, "Y": 0, "Zoom": 0.75 } }