Python wishes and help needed

I need some help to be able to finish Holomark2.

First two simple things:
Can you please add TextOut and Prompt soon?
It is not possible to copy text from the textbox and print is great for a lot of things but not for everything.

The other thing is that I cant figure out how to access stuff like this:

On Error Resume Next
	strComputer = "."
	Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
	Set colItems = objWMIService.ExecQuery("Select * from Win32_VideoController")
	On Error GoTo 0

Which I need to get system data like graphiccard, RAM, CPU, speeds and cores etc.

Here ya go. I just typed up some functions that do what you’re asking for so you don’t have to wait around for the functions to get added to rhinoscriptsyntax.

import Rhino
import clr
clr.AddReference("System.Management")
import System.Management

def video_information():
    select = "SELECT * FROM Win32_DisplayConfiguration"
    searcher = System.Management.ManagementObjectSearcher(select)
    lines = []
    for mgmtobj in searcher.Get():
        for prop in mgmtobj.Properties:
            lines.append("{0}: {1}".format(prop.Name,prop.Value))
    return "\n".join(lines)

def TextOut(text, title=None):
    Rhino.UI.Dialogs.ShowTextDialog(text, title)

def Prompt(prompt):
    Rhino.RhinoApp.CommandPrompt = prompt


info = video_information()
Prompt("video info")
TextOut(info, "Video Information")

BAERHUG!!

And how can I find info on all this? It is difficult to figure out what modules to import, and what they contain. I feel that when ever I need something you just pull another rabbit out of a magic hat. Could you point me in the right direction for that? :smile:

Duh, google of course :smiling_imp:

In reality, a lot of this just comes from experience of using these frameworks and knowing “what” I’m looking for. I usually use C# as part of my search since it is unique and tends to help me get at .NET specific information that I can parse and convert to python syntax. For the lines of script that you posted, I had no idea what they did but it did give me an idea to try a google search for

C# Win32_DisplayConfiguration

which pointed me in the direction of the ManagementObjectSearcher class in .NET.

1 Like

Steve, I get info from ShoreTel from your example… not what I expected…

-Pascal

BitsPerPel: 32
Caption: ShoreTel Desktop Sharing Accelerator
Description: ShoreTel Desktop Sharing Accelerator
DeviceName: ShoreTel Desktop Sharing Accelerator
DisplayFlags: 0
DisplayFrequency: 60
DitherType: None
DriverVersion: None
ICMIntent: None
ICMMethod: None
LogPixels: 120
PelsHeight: 768
PelsWidth: 1024
SettingID: ShoreTel Desktop Sharing Accelerator
SpecificationVersion: 1025

I haven’t dug into this beyond what Jorgen asked for. I was figuring he had some other code to parse what is returned in his old holomark since those are going to be the same values he gets back in RhinoScript.

Thanks a lot Steve!
I finally had time to update your script to get the details I want and this is what it currently returns:

Your Graphic Card Data:
-------------------------------

AdapterCompatibility: NVIDIA
VideoProcessor: GeForce GT 330M
AdapterRAM: 512.0
DriverVersion: 9.18.13.697

I changed it to search in Win32_VideoController, multiple times for detailed information. And this is what the code now looks like:

import Rhino
import clr
clr.AddReference("System.Management")
import System.Management
    
def video_information():
    select = "SELECT * FROM Win32_VideoController"
    arrInfo = System.Management.ManagementObjectSearcher(select)
    lines = []
    for strInfo in arrInfo.Get():
        lines.append("\nYour Graphic Card Data:\n-----------------------\n")
        for prop in strInfo.Properties:
            if prop.Name=="AdapterCompatibility":
                lines.append("{0}: {1}".format(prop.Name,prop.Value))
        for prop in strInfo.Properties:
            if prop.Name=="VideoProcessor":
                lines.append("{0}: {1}".format(prop.Name,prop.Value))
        for prop in strInfo.Properties:
            if prop.Name=="AdapterRAM":
                lines.append("{0}: {1}".format(prop.Name,(prop.Value)/1048576))
        for prop in strInfo.Properties:
            if prop.Name=="DriverVersion":
                lines.append("{0}: {1}".format(prop.Name,prop.Value))

    return "\n".join(lines)
    
def TextOut(text, title=None):
    Rhino.UI.Dialogs.ShowTextDialog(text, title)
    
def Prompt(prompt):
    Rhino.RhinoApp.CommandPrompt = prompt
    
    
info = video_information()
Prompt("video info")
TextOut(info, "Video Information")

Edit: I just removed a few “----” from the code so it would avoid the line break.
This Discourse should support wider text fields, as we need to cut and paste code in here, and not all code is as short as the width of this post.

Edit 2: @pascal can you test this code on your system please?

I edited your post to show how to post python scripts using discourse. Notice the backticks before and after the script block

You could shorten your video_information function by using the ‘in’ keyword

def video_information():
    select = "SELECT * FROM Win32_VideoController"
    arrInfo = System.Management.ManagementObjectSearcher(select)
    lines = []
    for strInfo in arrInfo.Get():
        lines.append("\nYour Graphic Card Data:\n-----------------------\n")
        names = "AdapterCompatibility", "VideoProcessor", "DriverVersion"
        for prop in strInfo.Properties:
            if prop.Name in names:
                lines.append("{0}: {1}".format(prop.Name,prop.Value))
            elif prop.Name=="AdapterRAM":
                lines.append("{0}: {1}".format(prop.Name,(prop.Value)/1048576))

    return "\n".join(lines)

Maybe that’s why you’re having so much display trauma on your computer; all of the graphics are being sent through your phone :wink:

P.S. I don’t really know why you get those strings printed out; I was just converting Jorgen’s code over to python/.NET syntax

Thanks, but how did you edit the post to show the script propperly?
I used the < / > feature?

EDIT: Oh… I see… I could just click the edit button my self and have a look :smile:
You added (three backticks)python before the script, and (three backticks) after.

I got similar info as Pascal, but that was with your script that searched in Win32_DisplayConfiguration instead of Win32_VideoController.

I like the short version, but the list is alphabetical, so to be able to get my preferred order I had to break it down. I could use fewer searches, but it looked tidier if I used one search for each… In the final version I will give the values to strings and then assemble the strings in the right order after. So this was just a hack.

And again, thanks a lot for the help!

Right, I can hear them perfectly.

-Pascal

1 Like

@stevebaer could you hook up these commands in Python please?

Rhino.ExeVersion
Rhino.ExeServiceRelease
Rhino.ExePlatform

These should work:

import Rhino

print Rhino.RhinoApp.ExeVersion
print Rhino.RhinoApp.ExeServiceRelease
print Rhino.Runtime.HostUtils.RunningOnWindows
print Rhino.Runtime.HostUtils.RunningOnOSX

–Mitch

Thanks Mitch!
And that also covered my next question, you mind reading wizard you! :wink:

You probably don’t need these now that Mitch showed you the RhinoCommon calls, but I’ll make sure these get added for a future service release. As far as ExePlatform, that would be implemented as

import System
def ExePlatform():
    "Returns the platform of the Rhino executable"
    if System.Environment.Is64BitProcess: return 1
    return 0

These additions will be in SR9 (we’re too close to shipping SR8 and it doesn’t seem like a “rush” item)

OK, thanks.
And workarounds are just as good for me now, so no worries about SR8.

Ah, I don’t know why I thought that “platform” was Mac/Windows… Doh… :dizzy_face:

Thanks Steve!

–Mitch