Get version of RHI, RHP

Hi there,

I would like to compare the version of an installed plug-in (Python scripts, compiled into an RHI with the RhinoScriptCompiler) against that of an RHI that is sitting on my hard disk, but hasn’t been installed. Is this possible?

The only solution I have come up with is to use the file creation times, but checking the actual version string would be tidier, I reckon. Python’s distutils LooseVersion works nicely with the version string extracted from the plug-in’s path.

I opened the RHP (extracted from the RHI Zip) in a text editor, and found some human readable strings. However, the version (e.g. ‘1.0.5912.29706’) is not one of them.

Thank you for your thoughts.

Axa

I think, if you rename the file to have the .DLL extension, you can use properties (right-click) then go to Version tab to see the version.

Thanks for this, menno. Got the DLL props through the right-click menu, but the version shown is ‘1.0.0.0’. This is different to the version in the install path, which is ‘1.0.5912.29706’.

Regards

Axa

Sorry, then I don’t know…

So I have half an answer. The four numbers of the version string (e.g. ‘1.0.5912.29706’ are stored as short ints (2 bytes) in the RHP.

You can search for the string ‘Module’, and seek back by 74 characters. This is the first of four pairs of two bytes that you can convert to integers which give you the full Rhino plug-in version number.

I need to test this on more plug-ins to seek if the seek is always exactly 74 chars.

Have a very good weekend

Regards

Axa

How about this:

Assembly assembly = Assembly.LoadFrom("MyAssembly.dll");
Version ver = assembly.GetName().Version;

Thanks, Dale. Can this be done in Python? I can’t find the Assembly class anywhere.

This ‘should’ work in Python:

import System
assembly = 'C:\Program Files\Rhinoceros 5 (64-bit)\System\RhinoCommon.dll'
version = System.Reflection.Assembly.LoadFile(assembly).GetName().Version.ToString();
print version

No luck with this:

Message: The module was expected to contain an assembly manifest. (Exception from HRESULT: 0x80131018)

But thank you for this tip. I didn’t know about this System.Reflection.Assembly thing. Very interesting.

Parsing the version from the RHP as I described above does work well:

        with open(rhp_path, 'rb') as fh:
            data = fh.read()
            found = data.find('Module')
            if found == -1:
                print("Error: Could not determine version of '{p}' from DLL.".format(
                        p=rhp_path))
                return False

            fh.seek(found)
            fh.seek(-74,1)

            chars = fh.read(8)

        pairs = []
        for i in range(0, len(chars), 2):
            pairs.append(chars[i+1] + chars[i])

        hex = [ i.encode("hex") for i in pairs ]
        ints = [ int(i, 16) for i in hex ]

        ver_str = '.'.join(["{i}".format(i=i) for i in ints ])

I know the topic is old, but maybe someone will use this answer.

rhp is a zip, so just change extension from rhp to zip and extract content. Inside folder .rsrc you will find a text file version.txt with all the data you want including the VALUE “Assembly Version”