{ "Uuid": "a2a5f284-0059-4e78-9b43-f3880ed17830", "IsCustomNode": false, "Description": "", "Name": "03_rename_views_pattern", "ElementResolver": { "ResolutionMap": {} }, "Inputs": [], "Outputs": [], "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": [], "Nodes": [ { "ConcreteType": "CoreNodeModels.Input.Filename, CoreNodeModels", "Id": "5789bd237e1465a94d26b2f4918136f8", "NodeType": "ExtensionNode", "Inputs": [], "Outputs": [ { "Id": "ddbdc610a7b2229f9a5fa2199a5cb0e1", "Name": "", "Description": "File Path", "UsingDefaultValue": false, "Level": 2, "UseLevels": false, "KeepListStructure": false } ], "Replication": "Disabled", "Description": "Allows you to select a file on the system and returns its file path", "HintPath": "C:\\RUM_Platform\\RUM_Tools\\Dynamo_Routines\\03_rename_views_pattern\\template_rename_views.csv", "InputValue": ".\\template_rename_views.csv" }, { "ConcreteType": "CoreNodeModels.Input.StringInput, CoreNodeModels", "Id": "8796cee74fadaa88bcb1a556098f69e3", "NodeType": "StringInputNode", "Inputs": [], "Outputs": [ { "Id": "373500c2cd6ccdcb22d89aa1fd87e129", "Name": "", "Description": "String", "UsingDefaultValue": false, "Level": 2, "UseLevels": false, "KeepListStructure": false } ], "Replication": "Disabled", "Description": "Creates a string", "InputValue": "" }, { "ConcreteType": "CoreNodeModels.Input.StringInput, CoreNodeModels", "Id": "6341f638087c1dfd711da8eda1b6dcd8", "NodeType": "StringInputNode", "Inputs": [], "Outputs": [ { "Id": "a7988e211f35a95017dd7a21bed7c397", "Name": "", "Description": "String", "UsingDefaultValue": false, "Level": 2, "UseLevels": false, "KeepListStructure": false } ], "Replication": "Disabled", "Description": "Creates a string", "InputValue": "" }, { "ConcreteType": "PythonNodeModels.PythonNode, PythonNodeModels", "Code": "# -*- coding: utf-8 -*-\r\n# 03 — Renombrar vistas según tabla o prefijo/sufijo.\r\n#\r\n# Modo A (tabla): IN[0] = lista de listas o ruta .csv con cabeceras ViewNameOld, ViewNameNew\r\n# Modo B: IN[0] vacío o sin tabla válida; IN[1] = prefijo actual (str), IN[2] = nuevo prefijo (str)\r\n#\r\n# Salida: lista de vistas renombradas y errores.\r\n\r\nimport sys\r\nimport csv\r\nimport os\r\n\r\nimport clr\r\nclr.AddReference('RevitAPI')\r\nclr.AddReference('RevitServices')\r\nfrom Autodesk.Revit.DB import FilteredElementCollector, View\r\nfrom RevitServices.Persistence import DocumentManager\r\nfrom RevitServices.Transactions import TransactionManager\r\n\r\ndoc = DocumentManager.Instance.CurrentDBDocument\r\n_PY3 = sys.version_info[0] >= 3\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 _table_rows_from_in0(raw):\r\n if raw is None:\r\n return []\r\n if isinstance(raw, (list, tuple)) and len(raw) > 0:\r\n if isinstance(raw[0], (list, tuple)):\r\n return [list(r) for r in raw]\r\n sp = _ustr(raw)\r\n if not sp or not os.path.isfile(sp) or not sp.lower().endswith('.csv'):\r\n return []\r\n out = []\r\n try:\r\n if _PY3:\r\n fobj = open(sp, 'r', encoding='utf-8-sig', newline='')\r\n else:\r\n import codecs\r\n fobj = codecs.open(sp, 'r', 'utf-8-sig')\r\n try:\r\n for row in csv.reader(fobj):\r\n out.append(list(row))\r\n finally:\r\n fobj.close()\r\n except Exception:\r\n return []\r\n return out\r\n\r\n\r\ndef _hdr(row):\r\n d = {}\r\n for i, x in enumerate(row):\r\n if x is None:\r\n continue\r\n name = _ustr(x)\r\n if len(name) > 0 and ord(name[0]) == 0xFEFF:\r\n name = name[1:].lstrip()\r\n if name:\r\n d[name] = i\r\n return d\r\n\r\n\r\ndef _cell(row, h, k):\r\n if k not in h:\r\n return None\r\n i = h[k]\r\n if i >= len(row):\r\n return None\r\n v = row[i]\r\n if v is None:\r\n return None\r\n return _ustr(v)\r\n\r\n\r\n_ports = _dynamo_in_ports()\r\ntable = _table_rows_from_in0(_ports[0]) if len(_ports) > 0 else []\r\nviews = {_ustr(v.Name): v for v in FilteredElementCollector(doc).OfClass(View).ToElements() if not v.IsTemplate}\r\nrenamed = []\r\nerrors = []\r\n\r\nuse_table = (\r\n isinstance(table, list)\r\n and len(table) >= 2\r\n and 'ViewNameOld' in _hdr(table[0])\r\n and 'ViewNameNew' in _hdr(table[0])\r\n)\r\nuse_prefix = (\r\n not use_table\r\n and len(_ports) > 2\r\n and _ustr(_ports[1])\r\n and _ustr(_ports[2])\r\n)\r\n\r\nif use_table:\r\n h = _hdr(table[0])\r\n TransactionManager.Instance.EnsureInTransaction(doc)\r\n try:\r\n for r in table[1:]:\r\n old = _cell(r, h, 'ViewNameOld')\r\n new = _cell(r, h, 'ViewNameNew')\r\n if not old or not new:\r\n continue\r\n if old not in views:\r\n errors.append('No existe vista: ' + old)\r\n continue\r\n v = views[old]\r\n try:\r\n v.Name = new\r\n renamed.append(v)\r\n views[new] = views.pop(old)\r\n except Exception as ex:\r\n errors.append('{0}: {1}'.format(old, _exc_str(ex)))\r\n finally:\r\n TransactionManager.Instance.TransactionTaskDone()\r\nelif use_prefix:\r\n old_p = _ustr(_ports[1])\r\n new_p = _ustr(_ports[2])\r\n TransactionManager.Instance.EnsureInTransaction(doc)\r\n try:\r\n for nm, v in list(views.items()):\r\n if nm.startswith(old_p):\r\n new_name = new_p + nm[len(old_p):]\r\n try:\r\n v.Name = new_name\r\n renamed.append(v)\r\n except Exception as ex:\r\n errors.append('{0}: {1}'.format(nm, _exc_str(ex)))\r\n finally:\r\n TransactionManager.Instance.TransactionTaskDone()\r\nelse:\r\n errors.append('Usa CSV/tabla IN[0] con ViewNameOld/ViewNameNew o IN[1]=prefijo viejo e IN[2]=prefijo nuevo.')\r\n\r\nOUT = renamed + (['ERRORES:'] + errors if errors else [])\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": "2a19ab2ea7fd87d78defa9153534160c", "NodeType": "PythonScriptNode", "Inputs": [ { "Id": "5c1fdef0d682f4316020c7ad0d0b338b", "Name": "IN[0]", "Description": "IN[0] CSV/tabla ViewNameOld/New o vacío", "UsingDefaultValue": false, "Level": 2, "UseLevels": false, "KeepListStructure": false }, { "Id": "59720984b4de24aca8c13d2c3db9eccc", "Name": "IN[1]", "Description": "IN[1] prefijo viejo", "UsingDefaultValue": false, "Level": 2, "UseLevels": false, "KeepListStructure": false }, { "Id": "f6f3ca1fb74cfc57295e0c61aaee1705", "Name": "IN[2]", "Description": "IN[2] prefijo nuevo", "UsingDefaultValue": false, "Level": 2, "UseLevels": false, "KeepListStructure": false } ], "Outputs": [ { "Id": "e70a74610af55cd9383671c4f1787c31", "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": "ddbdc610a7b2229f9a5fa2199a5cb0e1", "End": "5c1fdef0d682f4316020c7ad0d0b338b", "Id": "d7e8321a724671cd9af56b136eeeaa17", "IsHidden": "False" }, { "Start": "373500c2cd6ccdcb22d89aa1fd87e129", "End": "59720984b4de24aca8c13d2c3db9eccc", "Id": "c19b6e5b7a615cbececa2766a6b5a66b", "IsHidden": "False" }, { "Start": "a7988e211f35a95017dd7a21bed7c397", "End": "f6f3ca1fb74cfc57295e0c61aaee1705", "Id": "759c1c13a216f370e9b520e43f7747b0", "IsHidden": "False" } ], "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": [], "Annotations": [], "X": 0, "Y": 0, "Zoom": 0.75, "NodeViews": [ { "Id": "5789bd237e1465a94d26b2f4918136f8", "Name": "IN[0] CSV", "IsSetAsInput": false, "IsSetAsOutput": false, "Excluded": false, "ShowGeometry": true, "X": 40, "Y": 300 }, { "Id": "8796cee74fadaa88bcb1a556098f69e3", "Name": "IN[1]", "IsSetAsInput": false, "IsSetAsOutput": false, "Excluded": false, "ShowGeometry": true, "X": 40, "Y": 440 }, { "Id": "6341f638087c1dfd711da8eda1b6dcd8", "Name": "IN[2]", "IsSetAsInput": false, "IsSetAsOutput": false, "Excluded": false, "ShowGeometry": true, "X": 240, "Y": 440 }, { "Id": "2a19ab2ea7fd87d78defa9153534160c", "Name": "RÜM 03 Renombrar vistas", "IsSetAsInput": false, "IsSetAsOutput": false, "Excluded": false, "ShowGeometry": true, "X": 520, "Y": 320 } ] } }