Hello,
I have been calling the SAP2000 API inside Grasshopper since Rhino 8 release. However, last week I started getting this error in my previously working components:
The API (comtypes library) is imported, and interestingly, if I set in Visual Studio Code .rhinocode/py39-rh8/python.exe as my Python interpreter, the scripts works.
I installed Rhino in October 2024 and the I have been working with that version. Because of this error I have updated Rhino this week to Version 8 SR16 and the error persists.
I don´t remember when I last updated windows, by it is Version 23H2.
Thanks. I checked for myself recently and I’m on 23H2 too - the troublesome update I mentioned is for 24H2.
Strange that it works in a Rhino’s Python 3 run-time, outside of Rhino. I’ve not used comtypes or SAP2000 I’m afraid. Others on the forum have experience of using COM though
Let’s see if this is a problem with the SAP module or not. Try running this script in the editor. It should print a series of PASS messages. This means the comtypes functionality is working so then the error might be related to the SAP module
#! python 3
# r: comtypes
import comtypes
import comtypes.client
helper = comtypes.client.CreateObject('Scripting.FileSystemObject')
print('PASS' if helper else 'FAIL')
helper = comtypes.client.CreateObject('Shell.Application')
print('PASS' if helper else 'FAIL')
helper = comtypes.client.CreateObject('WScript.Shell')
print('PASS' if helper else 'FAIL')
helper = comtypes.client.CreateObject('InternetExplorer.Application')
print('PASS' if helper else 'FAIL')
helper = comtypes.client.CreateObject('Msxml2.XMLHTTP')
print('PASS' if helper else 'FAIL')
helper = comtypes.client.CreateObject('WinHttp.WinHttpRequest.5.1')
print('PASS' if helper else 'FAIL')
helper = comtypes.client.CreateObject('WbemScripting.SWbemLocator')
print('PASS' if helper else 'FAIL')
helper = comtypes.client.CreateObject('WMPlayer.OCX')
print('PASS' if helper else 'FAIL')
helper = comtypes.client.CreateObject('Paint.Picture')
print('PASS' if helper else 'FAIL')
But the original script still does not work in GH (but it does in Visual Stufdio Code). It is worth mentioning that we just changed our SAP2000 licences from standalone to Cloud Sign in.
A colleague suggested doing the following and my script works in GH, when I open the Rhino icon to whcih I made the following changes:
" To start Rhino in .NET Framework once: Caution: only recommended if you have a plug-in that doesn’t run in .NET Core.
You can use SetDotNetRuntime command to set Rhino to run in a dotnet framework or dotnet core.
This is most probably related to dotnet core. It works in your vscode since it is running native python and is not dealing with the dotnet core runtime the way python in Rhino does.
Try it with dotnet framework and see if it works there