Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pderendinger-everse/668e4fbd49239af5edb005728936e711 to your computer and use it in GitHub Desktop.
Save pderendinger-everse/668e4fbd49239af5edb005728936e711 to your computer and use it in GitHub Desktop.
ChatGPT-Geometry generator
{
"Uuid": "2493b807-0c2e-48d4-8838-e6c9b55015ed",
"IsCustomNode": false,
"Description": "",
"Name": "ChatGPT-Geometry generator",
"ElementResolver": {
"ResolutionMap": {
"Cuboid": {
"Key": "Autodesk.DesignScript.Geometry.Cuboid",
"Value": "ProtoGeometry.dll"
},
"Vector": {
"Key": "Autodesk.DesignScript.Geometry.Vector",
"Value": "ProtoGeometry.dll"
}
}
},
"Inputs": [],
"Outputs": [],
"Nodes": [
{
"ConcreteType": "PythonNodeModels.PythonNode, PythonNodeModels",
"NodeType": "PythonScriptNode",
"Code": "import sys\r\nimport clr\r\nimport math\r\nclr.AddReference('ProtoGeometry')\r\nfrom Autodesk.DesignScript.Geometry import *\r\n# Add paths to system libraries\r\nsys.path.append(r'C:\\Python310\\Lib')\r\nimport urllib.request\r\nimport json\r\n\r\n# set the OpenAI API key\r\nOPENAI_API_KEY =\"YOUR-API-KEY\"\r\nprompt = \"you are bot which provides python scripts to create dynamo geometries for Dynamo BIM 2.X\"\r\n\r\nprompt += \"\\n Do not include any Revit references.\"\r\nprompt += \"Add any reference library needed\"\r\nprompt += \"\\n I only need the script body\"\r\nprompt += \"\\n Don’t add any explanation. \"\r\nprompt += \"Use the simplest option available\"\r\nprompt += \"\\n Set the resulting geometry to the variable OUT. \"\r\nprompt += \"\\n For the following task\" \r\nprompt += IN[0] \r\n\r\n# set the API endpoint URL\r\nurl = \"https://api.openai.com/v1/chat/completions\"\r\n\r\n# set the headers for the request\r\nheaders = {\r\n \"Content-Type\": \"application/json\",\r\n \"Authorization\": \"Bearer \" + OPENAI_API_KEY,\r\n}\r\n\r\n# set the payload data for the request\r\ndata = {\r\n \"model\": \"gpt-4\",\r\n \"messages\": [{\"role\": \"user\", \"content\": prompt}],\r\n \"temperature\": 0.1\r\n}\r\n\r\n# encode the payload data as JSON\r\njson_data = json.dumps(data).encode('utf-8')\r\n\r\n# create a request object\r\nrequest = urllib.request.Request(url, json_data, headers)\r\n\r\n# send the request and get the response\r\nresponse = urllib.request.urlopen(request)\r\n\r\n# decode the response data from JSON\r\nresponse_data = json.loads(response.read().decode('utf-8'))\r\n\r\ncode = response_data[\"choices\"][0][\"message\"][\"content\"]\r\n# print the response data\r\nOUT = code\r\n",
"Engine": "CPython3",
"VariableInputPorts": true,
"Id": "ff5d69eaa9d94e6fbab00c9e91dbd65a",
"Inputs": [
{
"Id": "0cce67f3829f4706998944a86205e9a9",
"Name": "IN[0]",
"Description": "Input #0",
"UsingDefaultValue": false,
"Level": 2,
"UseLevels": false,
"KeepListStructure": false
}
],
"Outputs": [
{
"Id": "22e4f55c8f1f40b7ad6e6240feac61bf",
"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": "Dynamo.Graph.Nodes.CodeBlockNodeModel, DynamoCore",
"NodeType": "CodeBlockNode",
"Code": "\"create a cuboid of 3 by 4 meters and 3 meters height,\ncutting it with a cuboid of 2.9 by 3.9 meters by 4 meters height\";",
"Id": "5b05f7e039734540bf3c295b086611a4",
"Inputs": [],
"Outputs": [
{
"Id": "9ddef231d34447ed98459eebd8e6c65b",
"Name": "",
"Description": "Value of expression at line 1",
"UsingDefaultValue": false,
"Level": 2,
"UseLevels": false,
"KeepListStructure": false
}
],
"Replication": "Disabled",
"Description": "Allows for DesignScript code to be authored directly"
},
{
"ConcreteType": "PythonNodeModels.PythonStringNode, PythonNodeModels",
"Engine": "CPython3",
"VariableInputPorts": true,
"NodeType": "ExtensionNode",
"Id": "9813a279973e4bceb9ca21d7ee1a8587",
"Inputs": [
{
"Id": "b49eed307671483fbfed1ee2624daea4",
"Name": "script",
"Description": "Python script to run.",
"UsingDefaultValue": false,
"Level": 2,
"UseLevels": false,
"KeepListStructure": false
},
{
"Id": "79d8ef9fdc5f4ef5b2d7f8a12947533a",
"Name": "IN[0]",
"Description": "Input #0",
"UsingDefaultValue": false,
"Level": 2,
"UseLevels": false,
"KeepListStructure": false
}
],
"Outputs": [
{
"Id": "e78594fe98da4baebb3abdacc2e11014",
"Name": "OUT",
"Description": "Result of the python script",
"UsingDefaultValue": false,
"Level": 2,
"UseLevels": false,
"KeepListStructure": false
}
],
"Replication": "Disabled",
"Description": "Runs a Python script from a string."
}
],
"Connectors": [
{
"Start": "22e4f55c8f1f40b7ad6e6240feac61bf",
"End": "b49eed307671483fbfed1ee2624daea4",
"Id": "e057cd81eb9840a3acdfae906f3a748a",
"IsHidden": "False"
},
{
"Start": "9ddef231d34447ed98459eebd8e6c65b",
"End": "0cce67f3829f4706998944a86205e9a9",
"Id": "076679b4ea93421f94cf1f99aab5e86a",
"IsHidden": "False"
}
],
"Dependencies": [],
"NodeLibraryDependencies": [],
"Thumbnail": "",
"GraphDocumentationURL": null,
"ExtensionWorkspaceData": [
{
"ExtensionGuid": "28992e1d-abb9-417f-8b1b-05e053bee670",
"Name": "Properties",
"Version": "2.13",
"Data": {}
},
{
"ExtensionGuid": "DFBD9CC0-DB40-457A-939E-8C8555555A9D",
"Name": "Generative Design",
"Version": "2.0",
"Data": {}
}
],
"Author": "",
"Linting": {
"activeLinter": "None",
"activeLinterId": "7b75fb44-43fd-4631-a878-29f4d5d8399a",
"warningCount": 0,
"errorCount": 0
},
"Bindings": [],
"View": {
"Dynamo": {
"ScaleFactor": 1.0,
"HasRunWithoutCrash": true,
"IsVisibleInDynamoLibrary": true,
"Version": "2.13.1.3887",
"RunType": "Manual",
"RunPeriod": "1000"
},
"Camera": {
"Name": "Background Preview",
"EyeX": -5.198580265045166,
"EyeY": 5.0964016914367676,
"EyeZ": -3.9728837013244629,
"LookX": 7.8705239295959473,
"LookY": -7.3257088661193848,
"LookZ": 4.8589005470275879,
"UpX": 0.37301415205001831,
"UpY": 0.89879387617111206,
"UpZ": 0.2302825003862381
},
"ConnectorPins": [],
"NodeViews": [
{
"Name": "Python Script",
"ShowGeometry": true,
"Id": "ff5d69eaa9d94e6fbab00c9e91dbd65a",
"IsSetAsInput": false,
"IsSetAsOutput": false,
"Excluded": false,
"X": 570.590326611191,
"Y": 824.602168595983
},
{
"Name": "Code Block",
"ShowGeometry": true,
"Id": "5b05f7e039734540bf3c295b086611a4",
"IsSetAsInput": false,
"IsSetAsOutput": false,
"Excluded": false,
"X": -486.05698871687832,
"Y": 1058.5515261182713
},
{
"Name": "Python Script From String",
"ShowGeometry": true,
"Id": "9813a279973e4bceb9ca21d7ee1a8587",
"IsSetAsInput": false,
"IsSetAsOutput": false,
"Excluded": false,
"X": 909.51838367518587,
"Y": 787.03960609573039
}
],
"Annotations": [],
"X": 716.40994618393574,
"Y": -643.47636845638954,
"Zoom": 1.130842140625
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment