{ "Uuid": "84b8d5621a674470bda3d166848239f4", "IsCustomNode": false, "Description": "", "Name": "06_parameters_from_excel", "ElementResolver": { "ResolutionMap": {} }, "Inputs": [], "Outputs": [], "Nodes": [ { "ConcreteType": "PythonNodeModels.PythonNode, PythonNodeModels", "Code": "# -*- coding: utf-8 -*-\r\n# 06 — Escribir parámetros en elementos que coinciden con otro parámetro.\r\n#\r\n# IN[0] : tabla (lista de listas) desde Data.ImportExcel (.xlsx + nombre de hoja).\r\n# Cabeceras: Category, MatchParam, MatchValue, TargetParam, TargetValue\r\n# Category = nombre BuiltInCategory sin prefijo (ej. Walls, Doors) o OST_Walls\r\n#\r\n# Salida: elementos modificados y errores.\r\n#\r\n# IronPython (Dynamo clásico) y CPython 3 (Revit 2025+). Probar en copia de proyecto.\r\n\r\nimport sys\r\n\r\nimport clr\r\nclr.AddReference('RevitAPI')\r\nclr.AddReference('RevitServices')\r\nfrom Autodesk.Revit.DB import (\r\n FilteredElementCollector, BuiltInCategory, StorageType,\r\n)\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 _normalize_table(data):\r\n rows = _to_py_list(data)\r\n return [_to_py_list(r) for r in rows]\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 _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\ndef _bic(cat_str):\r\n s = _ustr(cat_str)\r\n if s.startswith('OST_'):\r\n name = s\r\n else:\r\n name = 'OST_' + s.replace(' ', '')\r\n try:\r\n return getattr(BuiltInCategory, name)\r\n except Exception:\r\n return None\r\n\r\n\r\ndef _find_param(el, pname):\r\n p = el.LookupParameter(pname)\r\n if p is not None and not p.IsReadOnly:\r\n return p\r\n return None\r\n\r\n\r\ndef _set_param(p, val):\r\n if p.StorageType == StorageType.String:\r\n p.Set(_ustr(val))\r\n elif p.StorageType == StorageType.Double:\r\n p.Set(float(val))\r\n elif p.StorageType == StorageType.Integer:\r\n p.Set(int(float(val)))\r\n else:\r\n p.SetValueString(_ustr(val))\r\n\r\n\r\n_ports = _dynamo_in_ports()\r\nrows = _normalize_table(_ports[0]) if len(_ports) > 0 else []\r\n\r\nif not rows or len(rows) < 2:\r\n OUT = ['Error: tabla vacía. Conecta Data.ImportExcel (.xlsx) a IN[0].']\r\nelse:\r\n h = _hdr(rows[0])\r\n need = ['Category', 'MatchParam', 'MatchValue', 'TargetParam', 'TargetValue']\r\n if any(x not in h for x in need):\r\n OUT = ['Error: faltan columnas ' + ', '.join(need)]\r\n else:\r\n changed = []\r\n errors = []\r\n TransactionManager.Instance.EnsureInTransaction(doc)\r\n try:\r\n for r in rows[1:]:\r\n cat_s = _cell(r, h, 'Category')\r\n mp = _cell(r, h, 'MatchParam')\r\n mv = _cell(r, h, 'MatchValue')\r\n tp = _cell(r, h, 'TargetParam')\r\n tv = _cell(r, h, 'TargetValue')\r\n if not cat_s or not mp or mv is None or not tp or tv is None:\r\n continue\r\n bic = _bic(cat_s)\r\n if bic is None:\r\n errors.append('Categoría desconocida: ' + cat_s)\r\n continue\r\n col = FilteredElementCollector(doc).OfCategory(bic).WhereElementIsNotElementType().ToElements()\r\n for el in col:\r\n p_m = _find_param(el, mp)\r\n if p_m is None:\r\n continue\r\n cur = p_m.AsString()\r\n if cur is None:\r\n cur = p_m.AsValueString()\r\n if cur is None:\r\n continue\r\n if _ustr(cur) != _ustr(mv):\r\n continue\r\n p_t = _find_param(el, tp)\r\n if p_t is None:\r\n errors.append('Sin parámetro destino en id ' + _ustr(el.Id.IntegerValue))\r\n continue\r\n try:\r\n _set_param(p_t, tv)\r\n changed.append(el)\r\n except Exception as ex:\r\n errors.append('Set {0}: {1}'.format(el.Id.IntegerValue, _exc_str(ex)))\r\n finally:\r\n TransactionManager.Instance.TransactionTaskDone()\r\n OUT = changed + (['ERRORES:'] + errors if errors 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": "5cb1c4c35b7f406881cc03f4ef73b596", "NodeType": "PythonScriptNode", "Inputs": [ { "Id": "0988c85296a445c083d55341309a2cb9", "Name": "IN[0]", "Description": "Tabla Data.ImportExcel", "UsingDefaultValue": false, "Level": 2, "UseLevels": false, "KeepListStructure": false } ], "Outputs": [ { "Id": "c203568e34c24a90b993f0a9ab5a513d", "Name": "OUT", "Description": "Result of the python script", "UsingDefaultValue": false, "Level": 2, "UseLevels": false, "KeepListStructure": false } ], "Replication": "Disabled", "Description": "Runs an embedded Python script." }, { "ConcreteType": "CoreNodeModels.Input.Filename, CoreNodeModels", "Id": "4fc50df273ac4336b0ab985f2fcccaa1", "NodeType": "ExtensionNode", "Inputs": [], "Outputs": [ { "Id": "7fc837dcedbc4eaa890140e6245d23cb", "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\\\\06_parameters_from_excel\\\\template_parameters_demostracion.xlsx", "InputValue": ".\\\\template_parameters_demostracion.xlsx" }, { "ConcreteType": "Dynamo.Graph.Nodes.ZeroTouch.DSFunction, DynamoCore", "Id": "f1e258fbbe074e3c80a3e180798c977a", "NodeType": "FunctionNode", "Inputs": [ { "Id": "436e61b43c11405e8be26b9b7c0c6127", "Name": "file", "Description": "var", "UsingDefaultValue": false, "Level": 2, "UseLevels": false, "KeepListStructure": false }, { "Id": "19e895aece0b455e9e05f5e11789a962", "Name": "sheetName", "Description": "string", "UsingDefaultValue": false, "Level": 2, "UseLevels": false, "KeepListStructure": false }, { "Id": "20d4b41d5dd14692a56f5cb99e5fab59", "Name": "readAsStrings", "Description": "bool", "UsingDefaultValue": true, "Level": 2, "UseLevels": false, "KeepListStructure": false }, { "Id": "193673566e274fea80acfa95fdffa56a", "Name": "showExcel", "Description": "bool", "UsingDefaultValue": true, "Level": 2, "UseLevels": false, "KeepListStructure": false } ], "Outputs": [ { "Id": "0a723b9bb9f54174863fb3b5fc50f431", "Name": "var[][]", "Description": "var[][]", "UsingDefaultValue": false, "Level": 2, "UseLevels": false, "KeepListStructure": false } ], "FunctionSignature": "DSOffice.Data.ImportExcel@var,string,bool,bool", "Replication": "Auto", "Description": "Data.ImportExcel (file: var, sheetName: string, readAsStrings: bool = false, showExcel: bool = true): var[][]" }, { "ConcreteType": "CoreNodeModels.Input.StringInput, CoreNodeModels", "Id": "ae640d406bdc44838874b74d74705c6d", "NodeType": "StringInputNode", "Inputs": [], "Outputs": [ { "Id": "8c96f5c446fd492682cc629bf4407065", "Name": "", "Description": "String", "UsingDefaultValue": false, "Level": 2, "UseLevels": false, "KeepListStructure": false } ], "Replication": "Disabled", "Description": "Creates a string", "InputValue": "Parameters" }, { "ConcreteType": "CoreNodeModels.Input.FileObject, CoreNodeModels", "Id": "2d32acc88424482b877afb1f20a6ee55", "NodeType": "ExtensionNode", "Inputs": [ { "Id": "1cf4f019abc64f3e905409f864b27a18", "Name": "path", "Description": "Path to the file.", "UsingDefaultValue": false, "Level": 2, "UseLevels": false, "KeepListStructure": false } ], "Outputs": [ { "Id": "662b272abe824554a74b6b8bc1dfe7f2", "Name": "file", "Description": "File object", "UsingDefaultValue": false, "Level": 2, "UseLevels": false, "KeepListStructure": false } ], "Replication": "Disabled", "Description": "Creates a file object from the given path" } ], "Connectors": [ { "Start": "7fc837dcedbc4eaa890140e6245d23cb", "End": "1cf4f019abc64f3e905409f864b27a18", "Id": "66e80ea4381942818981e404ef51cf36", "IsHidden": "False" }, { "Start": "662b272abe824554a74b6b8bc1dfe7f2", "End": "436e61b43c11405e8be26b9b7c0c6127", "Id": "d95020f693b748d0a980bd8f733cc42e", "IsHidden": "False" }, { "Start": "0a723b9bb9f54174863fb3b5fc50f431", "End": "0988c85296a445c083d55341309a2cb9", "Id": "ccb15a75d3b74e73ac531da8bb4007bb", "IsHidden": "False" }, { "Start": "8c96f5c446fd492682cc629bf4407065", "End": "19e895aece0b455e9e05f5e11789a962", "Id": "55416925f0364659904252940980e54d", "IsHidden": "False" } ], "Dependencies": [], "NodeLibraryDependencies": [ { "Name": "template_parameters_demostracion.xlsx", "ReferenceType": "External", "Nodes": [ "4fc50df273ac4336b0ab985f2fcccaa1" ] } ], "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": "", "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": "5cb1c4c35b7f406881cc03f4ef73b596", "Name": "RÜM 06 Parámetros", "IsSetAsInput": false, "IsSetAsOutput": false, "Excluded": false, "ShowGeometry": true, "X": 860, "Y": 400 }, { "Id": "4fc50df273ac4336b0ab985f2fcccaa1", "Name": "File Path (.xlsx)", "IsSetAsInput": false, "IsSetAsOutput": false, "Excluded": false, "ShowGeometry": true, "X": -20, "Y": 280 }, { "Id": "f1e258fbbe074e3c80a3e180798c977a", "Name": "Data.ImportExcel", "IsSetAsInput": false, "IsSetAsOutput": false, "Excluded": false, "ShowGeometry": true, "X": 520, "Y": 380 }, { "Id": "ae640d406bdc44838874b74d74705c6d", "Name": "Nombre hoja", "IsSetAsInput": false, "IsSetAsOutput": false, "Excluded": false, "ShowGeometry": true, "X": 120, "Y": 420 }, { "Id": "2d32acc88424482b877afb1f20a6ee55", "Name": "File From Path", "IsSetAsInput": false, "IsSetAsOutput": false, "Excluded": false, "ShowGeometry": true, "X": 280, "Y": 280 } ], "Annotations": [], "X": 0, "Y": 0, "Zoom": 0.75 } }