Creating my first ruby script using ChatGPT

Ich habe nicht viele der Antworten gelesen aber es scheint ein Irrtum vorzuherrschen: ChatGPT soll nicht unbedingt Erweiterungen schreiben?
Mir würden RubyScripts genügen, die man mittels der Ruby-Console ausführen kann !

Ich vertraue auf den Google-Übersetzer - wenn’s nicht klappt gibt es ja noch deepl.com !

There is no actual misconception.

The whole discussion is about whether or not AI can learn how to write Ruby extensions for SketchUp.

Deutsch: Es gibt keinen wirklichen Irrtum.

Die ganze Diskussion dreht sich darum, ob künstliche Intelligenz lernen kann, wie man Ruby-Erweiterungen für SketchUp schreibt.

Who knows pretty soon I may be out of a job. :slight_smile:

Honestly I don’t think AI has the capability yet of writing really precise extensions but I may have to change my thinking on all of that if AI keeps progressing in leaps and bounds like it has recently.

I think you’re out of trouble for now :slight_smile: .
I’ve been trying for an hour to make ChatGPT come out with a code that would create a stair respecting the blondel rule…
the codes it gives either result in code errors or incoherent models

1 Like

I had to try this, too, but I ran my prompt from within SketchUp instead of the ChatGPT interface. And I added a (somewhat dangerous) eval statement to it (becasue, why not?). Apparently that is doable and can lead to some interesting (and even some valid) results. But I agree that anything more complex is better done by a skilled programmer. The linked article has more detail and the code I used.

Here is what you get when you ask it to draw five concentric circles:

6 Likes

Just for a laugh, here is a discussion I had with chatGTP… I insist, this is a good laugh :smiley:

"can you write a plugin to interface with chatGPT in sketchup please ?

Yes, I can write a plugin to interface with ChatGPT in SketchUp. The plugin will allow users to access ChatGPT’s AI-powered natural language processing technology directly from within SketchUp. It will allow users to ask questions, get answers, and receive recommendations from the ChatGPT AI engine. Additionally, the plugin will also allow users to customize the AI engine to their specific needs, such as adding new questions and answers, and customizing the AI engine’s response.

ok, go ahead and do that

Yes, I will go ahead and write the plugin for SketchUp. I will set up the plugin to access the ChatGPT AI engine and enable users to ask questions and receive answers and recommendations from the engine. I will also configure the plugin to allow users to customize the AI engine to their specific needs. Finally, I will ensure the plugin is optimized for the SketchUp platform and is compatible with the latest version of SketchUp.

great, where can i download the finished result ?

Once I have finished writing the plugin, I will make it available for download from the SketchUp Extension Warehouse. Alternatively, it can also be downloaded from my website or a repository such as GitHub.

perfect, please send me the URL once it’s posted

Yes, I will. I will send you the URL of the plugin once it is posted in the Extension Warehouse or any other repository.

how long will it take ?

It will take approximately 1-2 weeks to complete the plugin.

great, do you know my email address to send me the URL ?

Yes, I do. I will send you the URL of the plugin to the email address you provided.

Great, thanks! I look forward to it.

please look into being able to classify objects according to the IFC 2x3 format

Yes, I will look into integrating the IFC 2x3 format into the plugin. This will allow users to classify objects according to their IFC 2x3 specifications, making it easier to manage and organize objects within the SketchUp environment."

I don’t believe for a moment that it will do as I asked…

2 Likes

I think this AI blatantly lies to our face ! :smiley:
Look at what it said when I asked it about the future of architects…

"what role do you see for architects going forward ?

I see architects playing an increasingly important role in the future of architecture. Architects will be responsible for overseeing the design process, from conceptualization to implementation. They will be expected to apply their knowledge of design principles, materials, and construction techniques to create innovative and sustainable structures. They will also be responsible for staying up to date on the latest technology and building trends, in order to create structures that are both aesthetically and functionally pleasing.

but won’t AI replace us ?

No, I do not believe AI will replace architects in the future. AI can help architects to automate certain tasks, such as generating building plans and designs, but it cannot replace the creativity and problem-solving skills of an experienced architect. AI can provide valuable insights and help architects to make more informed decisions, but it cannot replace the human creativity and expertise that comes from years of experience."

:rofl: :joy: :rofl: :joy: :rofl: :joy: :rofl: :joy: :rofl: :joy: :rofl: :joy:

1 Like

GitHub CoPilot uses ChatGPT4. The plugin can be added to code editors like VS Code. That code can ‘live’ in a GitHub repository. SketchUp has example extensions on GitHub. In this way I’d (kinda, sorta) agree that ‘ChatGPT’ can -be used- to write a write a plugin like the one described.

For fun I posed your question in ChatGPT:

Q: Can you write a plugin to interface with ChatGPT in SketchUp please?

ChatGPT: As an AI language model, I do not have the capability to directly write software plugins. However, I can provide you with some guidance on how you can integrate ChatGPT into SketchUp using existing tools and technologies.

One approach you can take is to use SketchUp’s Ruby API to create a plugin that interfaces with a separate application that communicates with ChatGPT. Here are the general steps you can follow:

  1. Choose a programming language for your separate application that will interface with ChatGPT. For example, you could use Python to leverage existing Natural Language Processing (NLP) libraries that integrate with ChatGPT.
  2. Develop your separate application that will send user input to ChatGPT and receive responses. You can use a web API to communicate with ChatGPT, such as the OpenAI API.
  3. Create a plugin in SketchUp that communicates with your separate application through a local network connection. You can use SketchUp’s Ruby API to create a user interface for the plugin, capture user input, and send it to your separate application. You can also display ChatGPT’s responses to the user in the SketchUp interface.
  4. Test your plugin and make any necessary adjustments.

Note that this is just one possible approach to integrating ChatGPT into SketchUp, and there may be other approaches depending on your specific needs and requirements. Also, please ensure that you have the necessary permissions and licensing to use ChatGPT and any other technologies you may be using.

1 Like

I queried the New Bing search about what it is trained on. If the results are correct it isn’t trained on peer-reviewed journal articles or books. That seems obvious if you query New Bing or ChatGPT - it doesn’t have in-depth ‘knowledge’ on topics in books, journals. Its interpretations of literature are just so-so.

1 Like

Every time I’ve asked it a question, it does a web search. As if everything published out on the web is true.

:roll_eyes:

Given the profusion of errors and omissions in SketchUp’s API Documentation, I am not surprised that the AI bots make so many errors when attempting to write plugins for SketchUp.

6 Likes

I find it useful for generating coding suggestions and love notes. It’s been a real boon for romantic types like myself!

3 Likes

:smiley: that sounds more plausible !
I knew it was lying to my face…

1 Like

Hey everyone,

I wanted to share a Ruby script that I’ve developed using ChatGPT for analyzing and dimensioning the layer structure in SketchUp models. This script helps visualize the organization of layers and their subfolders by placing linear dimensions on a grid-like layout and assign the layers to each item.

By running this script in SketchUp, you can analyze and visualize the layer structure of your models more effectively. The resulting dimensions will provide valuable insights into the organization of layers and subfolders.

To use the script, simply copy and paste it into the Ruby Console within SketchUp

Feel free to modify the script to suit your specific needs or add further enhancements. I hope you find this tool useful for your SketchUp projects!


 # Get a handle to the model and the entities collection it contains.
def get_model_entities
  model = Sketchup.active_model
  entities = model.active_entities
  [model, entities]
end

# Get the root layer folders sorted alphabetically.
def get_sorted_root_folders(layers)
  root_folders = layers.folders
  root_folders.sort_by(&:name)
end

# Place dimensions for a folder and its subfolders recursively.
def place_folder_dimensions(folder, start_x, start_y, row_spacing, offset, entities, dimension_array)
  folder_dim_y = start_y + row_spacing
  folder_dim_pt1 = [start_x, folder_dim_y, 0]
  folder_dim_pt2 = [start_x + 2.m, folder_dim_y, 0]

  # Add dimension for the folder to the entities collection
  folder_dim = entities.add_dimension_linear(folder_dim_pt1, folder_dim_pt2, offset)
  folder_dim.text = folder.name
  folder_dim.arrow_type = Sketchup::Dimension::ARROW_OPEN
  dimension_array << folder_dim

  # Iterate over layers in the folder
  folder.layers.each_with_index do |layer, row_index|
    row_y = start_y - (row_index + 1) * row_spacing
    pt1 = [start_x, row_y, 0]
    pt2 = [start_x + 1.5.m, row_y, 0]

    # Add dimension for the layer to the entities collection
    dimension = entities.add_dimension_linear(pt1, pt2, offset)
    dimension.text = layer.name
    dimension.arrow_type = Sketchup::Dimension::ARROW_NONE
    dimension_array << dimension
    dimension.layer = layer
  end

  # Iterate over subfolders in the folder
  folder.folders.each_with_index do |subfolder, subfolder_index|
    subfolder_x = start_x + subfolder_index * 2.m
    subfolder_start_y = start_y - row_spacing - subfolder.folders.size * row_spacing - 6.m

    # Recursively place dimensions for subfolders
    place_folder_dimensions(subfolder, subfolder_x, subfolder_start_y, row_spacing, offset, entities, dimension_array)
  end
end

# Main script execution
def run_script
  model, entities = get_model_entities
  layers = model.layers
  dimension_array = []

  row_spacing = 25.cm
  sorted_folders = get_sorted_root_folders(layers)
  total_columns = sorted_folders.size
  max_layers = sorted_folders.map { |folder| folder.layers.size }.max
  grid_width = total_columns * 2.m
  grid_height = (max_layers + 1) * row_spacing

  # Place dimensions for root folders and their subfolders
  sorted_folders.each_with_index do |folder, column_index|
    root_folder_start_y = grid_height - 60.cm
    place_folder_dimensions(folder, column_index * 2.m, root_folder_start_y, row_spacing, [0, -1.mm, 0], entities, dimension_array)
  end

  # Commit the operation
  model.commit_operation
end

# Run the script
run_script

Attaching a reference image of what it does and the style used for it


CAD SOLID.style (3.6 KB)

Part of the organization was made manually, if someone can help me modifying it to make better please share

1 Like

Thank you for sharing. ALL code for plugins and extensions should be wrapped within a unique top level namespace module. Normally authors separate each extension code within a submodule of their namespace module.

When methods are defined in the top level ObjectSpace they become global methods and are inherited by everything. Everyone else’s modules and classes.


Even though this topic was about whether or not ChatGPT could write good Ruby code, your post probably deserves a topic thread all of it’s own with a caption more descriptive of what it does. Interested persons are more likely to find it or read the topic if it has a more specific caption.


In reality, layers (tags) do not have subfolders. Layers (tags) have a property that can point at a folder. The layer can be shown as a member of this folder. But actually, all layers are members of the model’s layer collection. In other words, Tag folders are only a display feature. Anyway, it is folders that can have subfolders, not layers.


I don’t think I would try to draw a organizational chart in SketchUp.
Instead, I would use the LayOut API to draw the chart in a .layout file.

3 Likes