Last active
December 12, 2023 16:12
-
-
Save chuongmep/43d496597ca21068100c24aff603355b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 2, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"from dataclasses import dataclass\n", | |
"from typing import List, Optional\n", | |
"\n", | |
"@dataclass\n", | |
"class Parameter:\n", | |
" Name: str\n", | |
" TypeName: str\n", | |
" TypeRank: int\n", | |
" DefaultValue: Optional[object]\n", | |
" Description: str\n", | |
"\n", | |
"@dataclass\n", | |
"class Camera:\n", | |
" Name: str\n", | |
" EyeX: float\n", | |
" EyeY: float\n", | |
" EyeZ: float\n", | |
" LookX: float\n", | |
" LookY: float\n", | |
" LookZ: float\n", | |
" UpX: float\n", | |
" UpY: float\n", | |
" UpZ: float\n", | |
"\n", | |
"@dataclass\n", | |
"class Connector:\n", | |
" Start: str\n", | |
" End: str\n", | |
" Id: str\n", | |
" IsHidden: str\n", | |
"\n", | |
"@dataclass\n", | |
"class Dynamo:\n", | |
" ScaleFactor: float\n", | |
" HasRunWithoutCrash: bool\n", | |
" IsVisibleInDynamoLibrary: bool\n", | |
" Version: str\n", | |
" RunType: str\n", | |
" RunPeriod: str\n", | |
"\n", | |
"@dataclass\n", | |
"class ElementResolver:\n", | |
" ResolutionMap: Optional[object]\n", | |
"\n", | |
"@dataclass\n", | |
"class Input:\n", | |
" Id: str\n", | |
" Name: str\n", | |
" Description: str\n", | |
" UsingDefaultValue: bool\n", | |
" Level: int\n", | |
" UseLevels: bool\n", | |
" KeepListStructure: bool\n", | |
"\n", | |
"@dataclass\n", | |
"class Node:\n", | |
" ConcreteType: str\n", | |
" NodeType: str\n", | |
" Parameter: Parameter\n", | |
" Id: str\n", | |
" Inputs: List[Input]\n", | |
" Outputs: List['Output']\n", | |
" Replication: str\n", | |
" Description: str\n", | |
" ElementResolver: Optional[object]\n", | |
" Symbol: str\n", | |
"\n", | |
"@dataclass\n", | |
"class NodeView:\n", | |
" Name: str\n", | |
" ShowGeometry: bool\n", | |
" Id: str\n", | |
" IsSetAsInput: bool\n", | |
" IsSetAsOutput: bool\n", | |
" Excluded: bool\n", | |
" X: float\n", | |
" Y: float\n", | |
"\n", | |
"@dataclass\n", | |
"class Output:\n", | |
" Id: str\n", | |
" Name: str\n", | |
" Description: str\n", | |
" UsingDefaultValue: bool\n", | |
" Level: int\n", | |
" UseLevels: bool\n", | |
" KeepListStructure: bool\n", | |
"\n", | |
"@dataclass\n", | |
"class ResolutionMap:\n", | |
" pass\n", | |
"\n", | |
"@dataclass\n", | |
"class Root:\n", | |
" Uuid: str\n", | |
" IsCustomNode: bool\n", | |
" Category: str\n", | |
" Description: str\n", | |
" Name: str\n", | |
" ElementResolver: ElementResolver\n", | |
" Inputs: List[object]\n", | |
" Outputs: List[object]\n", | |
" Nodes: List[Node]\n", | |
" Connectors: List[Connector]\n", | |
" Dependencies: List[object]\n", | |
" NodeLibraryDependencies: List[object]\n", | |
" Author: str\n", | |
" Bindings: List[object]\n", | |
" View: 'View'\n", | |
"\n", | |
"@dataclass\n", | |
"class View:\n", | |
" Dynamo: Dynamo\n", | |
" Camera: Camera\n", | |
" ConnectorPins: List[object]\n", | |
" NodeViews: List[NodeView]\n", | |
" Annotations: List[object]\n", | |
" X: float\n", | |
" Y: float\n", | |
" Zoom: float\n" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 55, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"Totle number of dyf files: 3\n" | |
] | |
} | |
], | |
"source": [ | |
"import json\n", | |
"def read_dyf_file(file_path):\n", | |
" with open(file_path, 'r') as file:\n", | |
" dyf_data = json.load(file)\n", | |
" return dyf_data\n", | |
"\n", | |
"dir = r'C:\\Users\\chuongho\\AppData\\Roaming\\Dynamo\\Dynamo Core\\2.17\\definitions'\n", | |
"# read all dyf files\n", | |
"import os\n", | |
"dyf_files = [os.path.join(dir, f) for f in os.listdir(dir) if f.endswith('.dyf')]\n", | |
"print(\"Totle number of dyf files: \", len(dyf_files))\n", | |
"# read dyf data\n", | |
"dyf_data = [read_dyf_file(f) for f in dyf_files]\n" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 91, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/html": [ | |
"<div>\n", | |
"<style scoped>\n", | |
" .dataframe tbody tr th:only-of-type {\n", | |
" vertical-align: middle;\n", | |
" }\n", | |
"\n", | |
" .dataframe tbody tr th {\n", | |
" vertical-align: top;\n", | |
" }\n", | |
"\n", | |
" .dataframe thead th {\n", | |
" text-align: right;\n", | |
" }\n", | |
"</style>\n", | |
"<table border=\"1\" class=\"dataframe\">\n", | |
" <thead>\n", | |
" <tr style=\"text-align: right;\">\n", | |
" <th></th>\n", | |
" <th>Uuid</th>\n", | |
" <th>Name</th>\n", | |
" <th>NewName</th>\n", | |
" <th>Category</th>\n", | |
" <th>Description</th>\n", | |
" </tr>\n", | |
" </thead>\n", | |
" <tbody>\n", | |
" <tr>\n", | |
" <th>0</th>\n", | |
" <td>259a19cf-76e0-48a9-944a-dddab7735601</td>\n", | |
" <td>PackageName New Name</td>\n", | |
" <td>PackageName New Name</td>\n", | |
" <td>Package.String.Function</td>\n", | |
" <td>Hello, this is a node</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>0</th>\n", | |
" <td>259a19cf-76e0-48a9-944a-dddab7735603</td>\n", | |
" <td>PackageName Three</td>\n", | |
" <td>PackageName Three</td>\n", | |
" <td>Package.String.Function</td>\n", | |
" <td>Hello, this is a node</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>0</th>\n", | |
" <td>259a19cf-76e0-48a9-944a-dddab7735602</td>\n", | |
" <td>PackageName Two</td>\n", | |
" <td>PackageName Two</td>\n", | |
" <td>Package.String.Function</td>\n", | |
" <td>Hello, this is a node</td>\n", | |
" </tr>\n", | |
" </tbody>\n", | |
"</table>\n", | |
"</div>" | |
], | |
"text/plain": [ | |
" Uuid Name \\\n", | |
"0 259a19cf-76e0-48a9-944a-dddab7735601 PackageName New Name \n", | |
"0 259a19cf-76e0-48a9-944a-dddab7735603 PackageName Three \n", | |
"0 259a19cf-76e0-48a9-944a-dddab7735602 PackageName Two \n", | |
"\n", | |
" NewName Category Description \n", | |
"0 PackageName New Name Package.String.Function Hello, this is a node \n", | |
"0 PackageName Three Package.String.Function Hello, this is a node \n", | |
"0 PackageName Two Package.String.Function Hello, this is a node " | |
] | |
}, | |
"execution_count": 91, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"# create data to save excel\n", | |
"import pandas as pd\n", | |
"## save to excel with columns: Name,Category, Description\n", | |
"df = pd.DataFrame(columns=['Name', 'Category', 'Description'])\n", | |
"for dyf in dyf_data:\n", | |
" uuid = dyf['Uuid']\n", | |
" name = dyf['Name']\n", | |
" new_name = dyf['Name']\n", | |
" category = dyf['Category']\n", | |
" description = dyf['Description']\n", | |
" df = pd.concat([df, pd.DataFrame([[uuid,name,new_name, category, description]], columns=['Uuid','Name','NewName', 'Category', 'Description'])])\n", | |
"df = pd.DataFrame(df)\n", | |
"# reorder columns : uuid, name,new_name, category, description\n", | |
"df = df[['Uuid','Name','NewName', 'Category', 'Description']]\n", | |
"df" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 92, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"# save to excel\n", | |
"df.to_excel('rename-name.xlsx', index=False)\n" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 93, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/html": [ | |
"<div>\n", | |
"<style scoped>\n", | |
" .dataframe tbody tr th:only-of-type {\n", | |
" vertical-align: middle;\n", | |
" }\n", | |
"\n", | |
" .dataframe tbody tr th {\n", | |
" vertical-align: top;\n", | |
" }\n", | |
"\n", | |
" .dataframe thead th {\n", | |
" text-align: right;\n", | |
" }\n", | |
"</style>\n", | |
"<table border=\"1\" class=\"dataframe\">\n", | |
" <thead>\n", | |
" <tr style=\"text-align: right;\">\n", | |
" <th></th>\n", | |
" <th>Uuid</th>\n", | |
" <th>Name</th>\n", | |
" <th>NewName</th>\n", | |
" <th>Category</th>\n", | |
" <th>Description</th>\n", | |
" </tr>\n", | |
" </thead>\n", | |
" <tbody>\n", | |
" <tr>\n", | |
" <th>0</th>\n", | |
" <td>259a19cf-76e0-48a9-944a-dddab7735601</td>\n", | |
" <td>PackageName New Name</td>\n", | |
" <td>PackageName New Name</td>\n", | |
" <td>Package.String.Function</td>\n", | |
" <td>Hello, this is a node</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>1</th>\n", | |
" <td>259a19cf-76e0-48a9-944a-dddab7735603</td>\n", | |
" <td>PackageName Three</td>\n", | |
" <td>PackageName Three</td>\n", | |
" <td>Package.String.Function</td>\n", | |
" <td>Hello, this is a node</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>2</th>\n", | |
" <td>259a19cf-76e0-48a9-944a-dddab7735602</td>\n", | |
" <td>PackageName Two</td>\n", | |
" <td>PackageName Two</td>\n", | |
" <td>Package.String.Function</td>\n", | |
" <td>Hello, this is a node</td>\n", | |
" </tr>\n", | |
" </tbody>\n", | |
"</table>\n", | |
"</div>" | |
], | |
"text/plain": [ | |
" Uuid Name \\\n", | |
"0 259a19cf-76e0-48a9-944a-dddab7735601 PackageName New Name \n", | |
"1 259a19cf-76e0-48a9-944a-dddab7735603 PackageName Three \n", | |
"2 259a19cf-76e0-48a9-944a-dddab7735602 PackageName Two \n", | |
"\n", | |
" NewName Category Description \n", | |
"0 PackageName New Name Package.String.Function Hello, this is a node \n", | |
"1 PackageName Three Package.String.Function Hello, this is a node \n", | |
"2 PackageName Two Package.String.Function Hello, this is a node " | |
] | |
}, | |
"execution_count": 93, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"# load excel to rename name\n", | |
"import pandas as pd\n", | |
"df = pd.read_excel('rename-name.xlsx')\n", | |
"df" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 94, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/html": [ | |
"<div>\n", | |
"<style scoped>\n", | |
" .dataframe tbody tr th:only-of-type {\n", | |
" vertical-align: middle;\n", | |
" }\n", | |
"\n", | |
" .dataframe tbody tr th {\n", | |
" vertical-align: top;\n", | |
" }\n", | |
"\n", | |
" .dataframe thead th {\n", | |
" text-align: right;\n", | |
" }\n", | |
"</style>\n", | |
"<table border=\"1\" class=\"dataframe\">\n", | |
" <thead>\n", | |
" <tr style=\"text-align: right;\">\n", | |
" <th></th>\n", | |
" <th>Uuid</th>\n", | |
" <th>Name</th>\n", | |
" <th>NewName</th>\n", | |
" <th>Category</th>\n", | |
" <th>Description</th>\n", | |
" </tr>\n", | |
" </thead>\n", | |
" <tbody>\n", | |
" <tr>\n", | |
" <th>0</th>\n", | |
" <td>259a19cf-76e0-48a9-944a-dddab7735601</td>\n", | |
" <td>PackageName New Name</td>\n", | |
" <td>PackageName New Name NEW</td>\n", | |
" <td>Package.String.Function</td>\n", | |
" <td>Hello, this is a node</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>1</th>\n", | |
" <td>259a19cf-76e0-48a9-944a-dddab7735603</td>\n", | |
" <td>PackageName Three</td>\n", | |
" <td>PackageName Three NEW</td>\n", | |
" <td>Package.String.Function</td>\n", | |
" <td>Hello, this is a node</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>2</th>\n", | |
" <td>259a19cf-76e0-48a9-944a-dddab7735602</td>\n", | |
" <td>PackageName Two</td>\n", | |
" <td>PackageName Two NEW</td>\n", | |
" <td>Package.String.Function</td>\n", | |
" <td>Hello, this is a node</td>\n", | |
" </tr>\n", | |
" </tbody>\n", | |
"</table>\n", | |
"</div>" | |
], | |
"text/plain": [ | |
" Uuid Name \\\n", | |
"0 259a19cf-76e0-48a9-944a-dddab7735601 PackageName New Name \n", | |
"1 259a19cf-76e0-48a9-944a-dddab7735603 PackageName Three \n", | |
"2 259a19cf-76e0-48a9-944a-dddab7735602 PackageName Two \n", | |
"\n", | |
" NewName Category Description \n", | |
"0 PackageName New Name NEW Package.String.Function Hello, this is a node \n", | |
"1 PackageName Three NEW Package.String.Function Hello, this is a node \n", | |
"2 PackageName Two NEW Package.String.Function Hello, this is a node " | |
] | |
}, | |
"execution_count": 94, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"# try rename add NEW to NEWNAME , just test\n", | |
"df['NewName'] = df['NewName'].apply(lambda x: x + ' NEW')\n", | |
"df.to_excel('rename-name.xlsx', index=False)\n", | |
"df" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 95, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"Total number of dyf files: 3\n", | |
"PackageName New Name\n", | |
"Update uuid for PackageName New Name to PackageName New Name NEW\n", | |
"PackageName Three\n", | |
"Update uuid for PackageName Three to PackageName Three NEW\n", | |
"PackageName Two\n", | |
"Update uuid for PackageName Two to PackageName Two NEW\n", | |
"[{'Uuid': '259a19cf-76e0-48a9-944a-dddab7735601', 'IsCustomNode': True, 'Category': 'Package.String.Function', 'Description': 'Hello, this is a node', 'Name': 'PackageName New Name NEW', 'ElementResolver': {'ResolutionMap': {}}, 'Inputs': [], 'Outputs': [], 'Nodes': [{'ConcreteType': 'Dynamo.Graph.Nodes.CustomNodes.Symbol, DynamoCore', 'NodeType': 'InputNode', 'Parameter': {'Name': 'str', 'TypeName': 'var', 'TypeRank': -1, 'DefaultValue': None, 'Description': ''}, 'Id': 'cc963489b2184430b19bbdb9974851e2', 'Inputs': [], 'Outputs': [{'Id': '51116c5d551d4184b045ee58eaf76f26', 'Name': '', 'Description': 'Input Data', 'UsingDefaultValue': False, 'Level': 2, 'UseLevels': False, 'KeepListStructure': False}], 'Replication': 'Disabled', 'Description': 'A function parameter, use with custom nodes.\\r\\n\\r\\nYou can specify the type and default value for parameter. E.g.,\\r\\n\\r\\ninput : var[]..[]\\r\\nvalue : bool = false'}, {'ConcreteType': 'Dynamo.Graph.Nodes.CustomNodes.Output, DynamoCore', 'NodeType': 'OutputNode', 'ElementResolver': None, 'Symbol': 'data', 'Id': '69ca036f4bc6424b9ba7bf271cd7b862', 'Inputs': [{'Id': '882c0988ab9e40bcba8629c46e3de14a', 'Name': '', 'Description': 'Output Data', 'UsingDefaultValue': False, 'Level': 2, 'UseLevels': False, 'KeepListStructure': False}], 'Outputs': [], 'Replication': 'Disabled', 'Description': 'A function output, use with custom nodes'}, {'ConcreteType': 'CoreNodeModels.FromObject, CoreNodeModels', 'NodeType': 'ExtensionNode', 'Id': '7d40e8e4798c4137a9a1e12ce4871ea9', 'Inputs': [{'Id': 'ba583b75d3b14da7b2d3fc1c545241bb', 'Name': 'object', 'Description': 'Object to be serialized', 'UsingDefaultValue': False, 'Level': 2, 'UseLevels': False, 'KeepListStructure': False}], 'Outputs': [{'Id': 'fe1c32af6e1042afb797d5db7138a667', 'Name': 'string', 'Description': 'String representation of the object', 'UsingDefaultValue': False, 'Level': 2, 'UseLevels': False, 'KeepListStructure': False}], 'Replication': 'Disabled', 'Description': 'Converts an object to a string representation'}], 'Connectors': [{'Start': '51116c5d551d4184b045ee58eaf76f26', 'End': 'ba583b75d3b14da7b2d3fc1c545241bb', 'Id': '9e5522f8f4f84afd84078979b816c77b', 'IsHidden': 'False'}, {'Start': 'fe1c32af6e1042afb797d5db7138a667', 'End': '882c0988ab9e40bcba8629c46e3de14a', 'Id': '1e1baab5a47745a0a5d196d67a78d618', 'IsHidden': 'False'}], 'Dependencies': [], 'NodeLibraryDependencies': [], 'Author': 'None provided', 'Bindings': [], 'View': {'Dynamo': {'ScaleFactor': 1.0, 'HasRunWithoutCrash': False, 'IsVisibleInDynamoLibrary': True, 'Version': '2.17.3.4871', 'RunType': 'Manual', 'RunPeriod': '1000'}, 'Camera': {'Name': '_Background Preview', 'EyeX': -17.0, 'EyeY': 24.0, 'EyeZ': 50.0, 'LookX': 12.0, 'LookY': -13.0, 'LookZ': -58.0, 'UpX': 0.0, 'UpY': 1.0, 'UpZ': 0.0}, 'ConnectorPins': [], 'NodeViews': [{'Name': 'Input', 'ShowGeometry': True, 'Id': 'cc963489b2184430b19bbdb9974851e2', 'IsSetAsInput': False, 'IsSetAsOutput': False, 'Excluded': False, 'X': 100.0, 'Y': 200.0}, {'Name': 'Output', 'ShowGeometry': True, 'Id': '69ca036f4bc6424b9ba7bf271cd7b862', 'IsSetAsInput': False, 'IsSetAsOutput': False, 'Excluded': False, 'X': 546.0, 'Y': 211.0}, {'Name': 'String from Object', 'ShowGeometry': True, 'Id': '7d40e8e4798c4137a9a1e12ce4871ea9', 'IsSetAsInput': False, 'IsSetAsOutput': False, 'Excluded': False, 'X': 296.0, 'Y': 201.0}], 'Annotations': [], 'X': -23.0, 'Y': 8.0, 'Zoom': 1.0}}, {'Uuid': '259a19cf-76e0-48a9-944a-dddab7735603', 'IsCustomNode': True, 'Category': 'Package.String.Function', 'Description': 'Hello, this is a node', 'Name': 'PackageName Three NEW', 'ElementResolver': {'ResolutionMap': {}}, 'Inputs': [], 'Outputs': [], 'Nodes': [{'ConcreteType': 'Dynamo.Graph.Nodes.CustomNodes.Symbol, DynamoCore', 'NodeType': 'InputNode', 'Parameter': {'Name': 'str', 'TypeName': 'var', 'TypeRank': -1, 'DefaultValue': None, 'Description': ''}, 'Id': 'cc963489b2184430b19bbdb9974851e2', 'Inputs': [], 'Outputs': [{'Id': '51116c5d551d4184b045ee58eaf76f26', 'Name': '', 'Description': 'Input Data', 'UsingDefaultValue': False, 'Level': 2, 'UseLevels': False, 'KeepListStructure': False}], 'Replication': 'Disabled', 'Description': 'A function parameter, use with custom nodes.\\r\\n\\r\\nYou can specify the type and default value for parameter. E.g.,\\r\\n\\r\\ninput : var[]..[]\\r\\nvalue : bool = false'}, {'ConcreteType': 'Dynamo.Graph.Nodes.CustomNodes.Output, DynamoCore', 'NodeType': 'OutputNode', 'ElementResolver': None, 'Symbol': 'data', 'Id': '69ca036f4bc6424b9ba7bf271cd7b862', 'Inputs': [{'Id': '882c0988ab9e40bcba8629c46e3de14a', 'Name': '', 'Description': 'Output Data', 'UsingDefaultValue': False, 'Level': 2, 'UseLevels': False, 'KeepListStructure': False}], 'Outputs': [], 'Replication': 'Disabled', 'Description': 'A function output, use with custom nodes'}, {'ConcreteType': 'CoreNodeModels.FromObject, CoreNodeModels', 'NodeType': 'ExtensionNode', 'Id': '7d40e8e4798c4137a9a1e12ce4871ea9', 'Inputs': [{'Id': 'ba583b75d3b14da7b2d3fc1c545241bb', 'Name': 'object', 'Description': 'Object to be serialized', 'UsingDefaultValue': False, 'Level': 2, 'UseLevels': False, 'KeepListStructure': False}], 'Outputs': [{'Id': 'fe1c32af6e1042afb797d5db7138a667', 'Name': 'string', 'Description': 'String representation of the object', 'UsingDefaultValue': False, 'Level': 2, 'UseLevels': False, 'KeepListStructure': False}], 'Replication': 'Disabled', 'Description': 'Converts an object to a string representation'}], 'Connectors': [{'Start': '51116c5d551d4184b045ee58eaf76f26', 'End': 'ba583b75d3b14da7b2d3fc1c545241bb', 'Id': '9e5522f8f4f84afd84078979b816c77b', 'IsHidden': 'False'}, {'Start': 'fe1c32af6e1042afb797d5db7138a667', 'End': '882c0988ab9e40bcba8629c46e3de14a', 'Id': '1e1baab5a47745a0a5d196d67a78d618', 'IsHidden': 'False'}], 'Dependencies': [], 'NodeLibraryDependencies': [], 'Author': 'None provided', 'Bindings': [], 'View': {'Dynamo': {'ScaleFactor': 1.0, 'HasRunWithoutCrash': False, 'IsVisibleInDynamoLibrary': True, 'Version': '2.17.3.4871', 'RunType': 'Manual', 'RunPeriod': '1000'}, 'Camera': {'Name': '_Background Preview', 'EyeX': -17.0, 'EyeY': 24.0, 'EyeZ': 50.0, 'LookX': 12.0, 'LookY': -13.0, 'LookZ': -58.0, 'UpX': 0.0, 'UpY': 1.0, 'UpZ': 0.0}, 'ConnectorPins': [], 'NodeViews': [{'Name': 'Input', 'ShowGeometry': True, 'Id': 'cc963489b2184430b19bbdb9974851e2', 'IsSetAsInput': False, 'IsSetAsOutput': False, 'Excluded': False, 'X': 100.0, 'Y': 200.0}, {'Name': 'Output', 'ShowGeometry': True, 'Id': '69ca036f4bc6424b9ba7bf271cd7b862', 'IsSetAsInput': False, 'IsSetAsOutput': False, 'Excluded': False, 'X': 546.0, 'Y': 211.0}, {'Name': 'String from Object', 'ShowGeometry': True, 'Id': '7d40e8e4798c4137a9a1e12ce4871ea9', 'IsSetAsInput': False, 'IsSetAsOutput': False, 'Excluded': False, 'X': 296.0, 'Y': 201.0}], 'Annotations': [], 'X': -23.0, 'Y': 8.0, 'Zoom': 1.0}}, {'Uuid': '259a19cf-76e0-48a9-944a-dddab7735602', 'IsCustomNode': True, 'Category': 'Package.String.Function', 'Description': 'Hello, this is a node', 'Name': 'PackageName Two NEW', 'ElementResolver': {'ResolutionMap': {}}, 'Inputs': [], 'Outputs': [], 'Nodes': [{'ConcreteType': 'Dynamo.Graph.Nodes.CustomNodes.Symbol, DynamoCore', 'NodeType': 'InputNode', 'Parameter': {'Name': 'str', 'TypeName': 'var', 'TypeRank': -1, 'DefaultValue': None, 'Description': ''}, 'Id': 'cc963489b2184430b19bbdb9974851e2', 'Inputs': [], 'Outputs': [{'Id': '51116c5d551d4184b045ee58eaf76f26', 'Name': '', 'Description': 'Input Data', 'UsingDefaultValue': False, 'Level': 2, 'UseLevels': False, 'KeepListStructure': False}], 'Replication': 'Disabled', 'Description': 'A function parameter, use with custom nodes.\\r\\n\\r\\nYou can specify the type and default value for parameter. E.g.,\\r\\n\\r\\ninput : var[]..[]\\r\\nvalue : bool = false'}, {'ConcreteType': 'Dynamo.Graph.Nodes.CustomNodes.Output, DynamoCore', 'NodeType': 'OutputNode', 'ElementResolver': None, 'Symbol': 'data', 'Id': '69ca036f4bc6424b9ba7bf271cd7b862', 'Inputs': [{'Id': '882c0988ab9e40bcba8629c46e3de14a', 'Name': '', 'Description': 'Output Data', 'UsingDefaultValue': False, 'Level': 2, 'UseLevels': False, 'KeepListStructure': False}], 'Outputs': [], 'Replication': 'Disabled', 'Description': 'A function output, use with custom nodes'}, {'ConcreteType': 'CoreNodeModels.FromObject, CoreNodeModels', 'NodeType': 'ExtensionNode', 'Id': '7d40e8e4798c4137a9a1e12ce4871ea9', 'Inputs': [{'Id': 'ba583b75d3b14da7b2d3fc1c545241bb', 'Name': 'object', 'Description': 'Object to be serialized', 'UsingDefaultValue': False, 'Level': 2, 'UseLevels': False, 'KeepListStructure': False}], 'Outputs': [{'Id': 'fe1c32af6e1042afb797d5db7138a667', 'Name': 'string', 'Description': 'String representation of the object', 'UsingDefaultValue': False, 'Level': 2, 'UseLevels': False, 'KeepListStructure': False}], 'Replication': 'Disabled', 'Description': 'Converts an object to a string representation'}], 'Connectors': [{'Start': '51116c5d551d4184b045ee58eaf76f26', 'End': 'ba583b75d3b14da7b2d3fc1c545241bb', 'Id': '9e5522f8f4f84afd84078979b816c77b', 'IsHidden': 'False'}, {'Start': 'fe1c32af6e1042afb797d5db7138a667', 'End': '882c0988ab9e40bcba8629c46e3de14a', 'Id': '1e1baab5a47745a0a5d196d67a78d618', 'IsHidden': 'False'}], 'Dependencies': [], 'NodeLibraryDependencies': [], 'Author': 'None provided', 'Bindings': [], 'View': {'Dynamo': {'ScaleFactor': 1.0, 'HasRunWithoutCrash': False, 'IsVisibleInDynamoLibrary': True, 'Version': '2.17.3.4871', 'RunType': 'Manual', 'RunPeriod': '1000'}, 'Camera': {'Name': '_Background Preview', 'EyeX': -17.0, 'EyeY': 24.0, 'EyeZ': 50.0, 'LookX': 12.0, 'LookY': -13.0, 'LookZ': -58.0, 'UpX': 0.0, 'UpY': 1.0, 'UpZ': 0.0}, 'ConnectorPins': [], 'NodeViews': [{'Name': 'Input', 'ShowGeometry': True, 'Id': 'cc963489b2184430b19bbdb9974851e2', 'IsSetAsInput': False, 'IsSetAsOutput': False, 'Excluded': False, 'X': 100.0, 'Y': 200.0}, {'Name': 'Output', 'ShowGeometry': True, 'Id': '69ca036f4bc6424b9ba7bf271cd7b862', 'IsSetAsInput': False, 'IsSetAsOutput': False, 'Excluded': False, 'X': 546.0, 'Y': 211.0}, {'Name': 'String from Object', 'ShowGeometry': True, 'Id': '7d40e8e4798c4137a9a1e12ce4871ea9', 'IsSetAsInput': False, 'IsSetAsOutput': False, 'Excluded': False, 'X': 296.0, 'Y': 201.0}], 'Annotations': [], 'X': -23.0, 'Y': 8.0, 'Zoom': 1.0}}]\n" | |
] | |
} | |
], | |
"source": [ | |
"import json\n", | |
"import os\n", | |
"import pandas as pd\n", | |
"\n", | |
"def read_dyf_file(file_path):\n", | |
" with open(file_path, 'r') as file:\n", | |
" dyf_data = json.load(file)\n", | |
" return dyf_data\n", | |
"\n", | |
"# Directory containing dyf files\n", | |
"dir = r'C:\\Users\\chuongho\\AppData\\Roaming\\Dynamo\\Dynamo Core\\2.17\\definitions'\n", | |
"\n", | |
"# Read all dyf files\n", | |
"dyf_files = [os.path.join(dir, f) for f in os.listdir(dir) if f.endswith('.dyf')]\n", | |
"print(\"Total number of dyf files: \", len(dyf_files))\n", | |
"\n", | |
"# Read dyf data\n", | |
"dyf_data = [read_dyf_file(f) for f in dyf_files]\n", | |
"\n", | |
"# Load Excel file\n", | |
"excel_file_name = 'rename-name.xlsx'\n", | |
"df = pd.read_excel(excel_file_name)\n", | |
"\n", | |
"# Create a mapping of uuid to new names\n", | |
"uuid_mapping = dict(zip(df['Uuid'], df['NewName']))\n", | |
"# Update 'Uuid' field inside each dyf file\n", | |
"for dyf in dyf_data:\n", | |
" uuid = dyf.get('Uuid', '')\n", | |
" new_name = uuid_mapping.get(uuid, '')\n", | |
" name = dyf['Name']\n", | |
" print(name)\n", | |
" if new_name:\n", | |
" print(f\"Update uuid for {dyf['Name']} to {new_name}\")\n", | |
" dyf['Name'] = new_name\n", | |
" else:\n", | |
" print(f\"Uuid not found for {dyf['Name']}\")\n", | |
"\n", | |
" #Optionally, you can save the modified dyf_data back to the original .dyf file\n", | |
" #with open(os.path.join(dir, f\"{new_name}.dyf\"), 'w') as file:\n", | |
" #json.dump(dyf, file, indent=4)\n", | |
"\n", | |
"# Print or further process the updated dyf_data\n", | |
"print(dyf_data)\n" | |
] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 3", | |
"language": "python", | |
"name": "python3" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython3", | |
"version": "3.11.5" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment