Hi is there usual way to clicking to select element to be listed to dynamo data?

i got to make dynamo which is to select wall and create automatically make custom curtain wall by dynamo.
and i found this code created by chat GPT but it doesn’t work at all.
can someone review its code?

import clr
clr.AddReference(“RevitAPI”)
from Autodesk.Revit.DB import *

clr.AddReference(“RevitServices”)
import RevitServices
from RevitServices.Persistence import DocumentManager

import csv

doc = DocumentManager.Instance.CurrentDBDocument

def select_element_by_view(sender, args):
try:
mouse_x = args.MousePoint.X
mouse_y = args.MousePoint.Y

    collector = FilteredElementCollector(doc, doc.ActiveView.Id)
    options = Options()
    options.View = doc.ActiveView
    result = collector.ToElementIdsAtPoint(XYZ(mouse_x, mouse_y, 0), options)

    if result:
        selected_element_id = result.FirstElementId
        selected_element = doc.GetElement(selected_element_id)
        
        # Define the path and filename for the output file
        output_path = "C:\\Temp\\"
        output_file = "selected_elements.csv"
        output_file_path = output_path + output_file

        # Create a list to store the element data
        element_data = [[selected_element.Id.ToString(), selected_element.Name]]
        
        # Write the element data to a CSV file
        with open(output_file_path, 'w', newline='') as csvfile:
            writer = csv.writer(csvfile)
            writer.writerows(element_data)

        print("Selected element data has been written to:", output_file_path)

except Exception as ex:
    print("Error:", ex)

Hook up the event handler to the RevitPythonShell events

RevitServices.EventHandler[simplemouseclickeventargs].Subscribe(select_element_by_view)

To unsubscribe the event handler when no longer needed, use the following line:

RevitServices.EventHandler[simplemouseclickeventargs].Unsubscribe(select_element_by_view)

Don’t use ChatGPT. Search the forum first, this isn’t a ‘do this for me’ forum.

This is not a surprise. Success rate is less than 5% even when asking for tasks in the help documentation that the tool was trained on.

Your solution is probably better found by googling “dynamo create custom curtain wall”
should you try one of the guides found, given it a good attempt and are still encountering issues.

That would be the time to post to this forum.

1 Like