{ "Uuid": "31d68c31-4423-462a-8bcb-c7ca8013f09e", "IsCustomNode": false, "Description": "", "Name": "04_apply_view_templates", "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.StringInput, CoreNodeModels", "Id": "225a67626ea0df6d13c0421877412278", "NodeType": "StringInputNode", "Inputs": [], "Outputs": [ { "Id": "0b90f5b421c47b18394958a56dda187e", "Name": "", "Description": "String", "UsingDefaultValue": false, "Level": 2, "UseLevels": false, "KeepListStructure": false } ], "Replication": "Disabled", "Description": "Creates a string", "InputValue": "" }, { "ConcreteType": "CoreNodeModels.Input.Filename, CoreNodeModels", "Id": "1bba980b1978b97a26bc50c464c1ae7d", "NodeType": "ExtensionNode", "Inputs": [], "Outputs": [ { "Id": "0ed88c617a74e66a65c37e2588f2a667", "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\\04_apply_view_templates\\template_view_targets.csv", "InputValue": ".\\template_view_targets.csv" }, { "ConcreteType": "PythonNodeModels.PythonNode, PythonNodeModels", "Code": "# -*- coding: utf-8 -*-\r\n# 04 — Aplicar plantilla de vista a un conjunto de vistas por nombre.\r\n#\r\n# IN[0] : nombre exacto de la vista plantilla (View with IsTemplate=True)\r\n# IN[1] : lista de nombres (str), tabla con columna ViewName, ruta .csv con columna ViewName,\r\n# o un string con nombres separados por ; o ,\r\n#\r\n# Salida: vistas actualizadas / 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 _names_from_in1(raw):\r\n if raw is None:\r\n return []\r\n sp = _ustr(raw)\r\n if sp and os.path.isfile(sp) and sp.lower().endswith('.csv'):\r\n rows = []\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 rows.append(list(row))\r\n finally:\r\n fobj.close()\r\n except Exception:\r\n return []\r\n if len(rows) < 1:\r\n return []\r\n hdr = [_ustr(x) for x in rows[0]]\r\n if 'ViewName' not in hdr:\r\n return []\r\n idx = hdr.index('ViewName')\r\n out = []\r\n for r in rows[1:]:\r\n if idx < len(r) and r[idx] is not None:\r\n n = _ustr(r[idx])\r\n if n:\r\n out.append(n)\r\n return out\r\n if sp and (';' in sp or ',' in sp):\r\n parts = sp.replace(',', ';').split(';')\r\n return [p.strip() for p in parts if p.strip()]\r\n if isinstance(raw, list) and len(raw) > 0:\r\n if isinstance(raw[0], list):\r\n hdr = [_ustr(x) for x in raw[0]]\r\n if 'ViewName' in hdr:\r\n idx = hdr.index('ViewName')\r\n out = []\r\n for r in raw[1:]:\r\n if idx < len(r) and r[idx] is not None:\r\n n = _ustr(r[idx])\r\n if n:\r\n out.append(n)\r\n return out\r\n out = []\r\n for x in raw:\r\n if x is not None:\r\n n = _ustr(x)\r\n if n:\r\n out.append(n)\r\n return out\r\n return []\r\n\r\n\r\n_ports = _dynamo_in_ports()\r\ntpl_name = _ustr(_ports[0]) if len(_ports) > 0 else ''\r\ntargets_in = _ports[1] if len(_ports) > 1 else None\r\nnames = _names_from_in1(targets_in)\r\n\r\ntemplate = None\r\nfor v in FilteredElementCollector(doc).OfClass(View).ToElements():\r\n if v.IsTemplate and _ustr(v.Name) == tpl_name:\r\n template = v\r\n break\r\n\r\nif template is None:\r\n OUT = ['Error: no se encontró plantilla con nombre: ' + tpl_name]\r\nelif not names:\r\n OUT = ['Error: IN[1] sin nombres de vista (lista, CSV con ViewName, o texto con ;).']\r\nelse:\r\n by_name = {_ustr(v.Name): v for v in FilteredElementCollector(doc).OfClass(View).ToElements() if not v.IsTemplate}\r\n updated = []\r\n errors = []\r\n TransactionManager.Instance.EnsureInTransaction(doc)\r\n try:\r\n for nm in names:\r\n if nm not in by_name:\r\n errors.append('Vista no encontrada: ' + nm)\r\n continue\r\n v = by_name[nm]\r\n try:\r\n v.ViewTemplateId = template.Id\r\n updated.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\n OUT = updated + (['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": "b05f942dd9075ee555d45b3583dea3e8", "NodeType": "PythonScriptNode", "Inputs": [ { "Id": "839aa01fecb5fd0f68f0741737a7f5ed", "Name": "IN[0]", "Description": "IN[0] nombre plantilla", "UsingDefaultValue": false, "Level": 2, "UseLevels": false, "KeepListStructure": false }, { "Id": "52f047043926bc85c9b4c961ee67d91a", "Name": "IN[1]", "Description": "IN[1] CSV / lista / nombres con ;", "UsingDefaultValue": false, "Level": 2, "UseLevels": false, "KeepListStructure": false } ], "Outputs": [ { "Id": "94f36367294b186ea15db8edfdd7ee0b", "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": "0b90f5b421c47b18394958a56dda187e", "End": "839aa01fecb5fd0f68f0741737a7f5ed", "Id": "f84f4957400044a475ecc5e53c3c832e", "IsHidden": "False" }, { "Start": "0ed88c617a74e66a65c37e2588f2a667", "End": "52f047043926bc85c9b4c961ee67d91a", "Id": "50a88b4a505ffde3c1985570f0c64c5f", "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": "225a67626ea0df6d13c0421877412278", "Name": "IN[0] plantilla", "IsSetAsInput": false, "IsSetAsOutput": false, "Excluded": false, "ShowGeometry": true, "X": 40, "Y": 260 }, { "Id": "1bba980b1978b97a26bc50c464c1ae7d", "Name": "IN[1] vistas CSV", "IsSetAsInput": false, "IsSetAsOutput": false, "Excluded": false, "ShowGeometry": true, "X": 40, "Y": 380 }, { "Id": "b05f942dd9075ee555d45b3583dea3e8", "Name": "RÜM 04 Plantillas de vista", "IsSetAsInput": false, "IsSetAsOutput": false, "Excluded": false, "ShowGeometry": true, "X": 520, "Y": 300 } ] } }