[How to] SketchUP and C# /.Net or WPF

Hello,

Is there an SDK to develop custom APIs for Skectchup / Ruby in C # in Visual Studio. This interests me a lot and I think there is a lot to do.
I am in SketchUp pro 2020 and Visual Studio pro 2019 (the last one)
Thank you for your answers

cordially

Patrick

I think @Neil_Burkholder has played with linking a WPF app to a SketchUp extension.

There are a few standalone C# libraries for manipulating SKP files, but I haven’t seen one for use within SketchUp application process.

C# also interests me.

I’ve never had the need to manipulate SKP files outside of SketchUp. I think I do remember seeing a C# wrapper for the C SDK, but have never used it. C# is my favorite language, and with WPF it is easy to design a very nice UI.

In this thread I did post some code where I had a WPF app communicating with SketchUp.

The problem with that approach is that the WPF app is a separate app, so clicking the SketchUp window hides the WPF window behind SketchUp (unlike the SketchUP HTMLDialog window which stays on top). I could set my WPF window to be ‘always on top’ but that is a real nuisance because it stays on top of other apps as well. I’m in the middle of doing a major update to my Building Creator extension, and I’m going back to all HTMLDialogs for the UI. There are still things I plan to use C# for such as generating xlsx spreadsheets. Ruby in SketchUp is limited when it comes to things like that. For that case I’ll probably write the C# app as a command line app that runs in the background.

Another reason I’m going to all HTMLDialogs, is because I still have my fingers crossed that SketchUp will someday implement docking HTMLDialogs as a first class citizen in SU.

You can change the parent of your wpf window to the sketchup window handle…Not sure if that works when they are separate processes though.

Also worth mentioning: wpf is windows only, while c# nowadays is multi platform.

C # is also my favorite language because it is a real object oriented language unlike C ++.
I just want to give a little clarification, I don’t need the C # language to manage skp files. I’m just trying to create a small, user-friendly dialog interface for use with sketchup.
Maybe i can use html code but i don’t know how to do that.
Sorry for my bad English and don’t hesitate to correct me if necessary.

I understood this. Thee is no embedded official C# API for SketchUp.

Yes, SketchUp has the Chromium Embedded Framework for UI::HtmlDialog class.
This means you may need to know HTML, Javascript and CSS to make HTML interfaces.

There were several attempts to make pure Ruby libraries that would auto generate the UI::HtmlDialogs.
The latest is:

This old one by ThomThom maps to the deprecated UI::WebDialog class. It hasn’t been updated to use the UI.HtmlDialog class (yet.)

Thanks, and yes i know HTML, CSS and javascript.

the “UI.select_directory” method works really well but is there a similar method to reach files like “select_file” (windows explorer?).
Or is there a source in C or a dll that I could use?
If necessary, I can do it in C - it’s easy - but then, how can I integrate it into my ruby code ?

Because it uses platform OS dialog interfaces. (On Windows the API uses "comdlg32.dll")

Yes, there is, and they are from the same OS libraries. They are exposed to the Ruby API via …

There a bit of a difference in their operation.

The UI::openpanel always returns a valid filepath (unless the user cancels the dialog). The openpanel also allows multiple filetype filters for the MS Windows platform.)

The UI::savepanel allows the suggestion of a filename and file extension, but the user can override these (including giving an incorrect file extension.) The user may also attempt to use invalid characters that are not allowed in path strings and filenames. (Ie, code defensively.) Also, the user can navigate away from your suggested directory path.
As with the other method, the user can cancel the dialog.

The results from these methods (and that of UI::inputbox) should always be checked for a false eval, and if so … exit the command. (Ie, take it as an indication the user wishes to cancel the task.)

Example:

def open_model_command
  filter = Sketchup.platform == :platform_win ? 'SketchUp Model|*.skp||' : '*.skp'
  filepath = UI.openpanel("Select model to load", ENV['HOME'], filter)
  return if !filepath # user cancelled !
  # Continue with task ...
  Sketchup.open_file(filepath)
end

Thanks, I’ll try that.
I just made a deposit on Github of my work so far
You can give it at : https://github.com/PB-BZH/external-loader-for-SketchUp.git