ksobon / MantisShrimp

A interop project for bridging the gap between Rhino/Grasshopper and Revit/Dynamo
37 stars 9 forks source link

Mantis Shrimp fails to load on Grasshopper side #10

Closed mostaphaRoudsari closed 9 years ago

mostaphaRoudsari commented 9 years ago

@ksobon I see that you have multiple paths for RhinoCommon but Hiram just showed me that it still fails on our systems here. Is there any reason that you don't use a method to find it instead of guessing? Function below should do it for you.

import os

def which(program):
        """
        Check for path. Modified from this link:
        http://stackoverflow.com/questions/377017/test-if-executable-exists-in-python
        """
        def is_exe(fpath):
            return os.path.isfile(fpath) and os.access(fpath, os.X_OK)

        fpath, fname = os.path.split(program)
        if fpath:
            if is_exe(program):
                return program
        else:
            for path in os.environ["PATH"].split(os.pathsep):
                path = path.strip('"')
                exe_file = os.path.join(path, program)
                if is_exe(exe_file):
                    return path, exe_file
        return None, None

print which ("Rhino.exe")
ksobon commented 9 years ago

Nah, I just didnt know any better way, plus I was considering making that be a user input. I will implement your function, that seems to be a good idea.

ksobon commented 9 years ago

So like I have mentioned in my email for some reason path to Rhino is not part of the os.environ["PATH"] which causes this function to return NULL when asked for "Rhino.exe". Also, the initial check of the home path os.access() is not returning the right path since that's the Revit folder for the Dynamo. I am not sure how to proceed with this, but I will keep looking at different solutions. In the meantime i included RhinoCommon.dll with Mantis Shrimp install in the "bin" folder and added a path to look there if all other fail. This ensures that you at least will always be able to get it to work. I understand that this might be a small violation of Rhino license, but I am out of options at this point, unless I want users to specify that path manually.

mostaphaRoudsari commented 9 years ago

@ksobon you are right. When you run the script from Grasshopper side it does add Rhino folder to path so you can find it but it is not happening on Revit side.

In the meantime i included RhinoCommon.dll with Mantis Shrimp install in the "bin" folder and added a path to look there if all other fail. This ensures that you at least will always be able to get it to work. 

I don't think it is a good idea. Violation is violation - there is no small or big for this in my book.

I think the best solution is to to save the folder in an ASCII file in user's MantisShrimp folder. You can either do it from Grasshopper side or add a new node on Dynamo side to SetRhinoPath. The code will try to find RhinoCommon based on your best guess and if it finds it then it will write it to the file in MS folder. In case it fails to find the path then it gives a warning to user to define the path using the same component and write it to the file. The file will look something like this: {"RhinoCommonFolder" : "WhateverPath"}

All the other components will look to this file to find the path and if the file doesn't exist then they give a warning to user to set the path using SetRhinoPath node.

ksobon commented 9 years ago

@mostaphaRoudsari I am not sure how you came up with this idea that redistributing RhinoCommon.dll is actually some sort of violation of Rhino's license. RhinoCommon is an open source project. It's perfectly fine to distribute it with Mantis Shrimp. Here's a link: ://github.com/mcneel/rhinocommon Are we good? :-)

mostaphaRoudsari commented 9 years ago

Ha! You are right. My bad! The license says that you can do it with no problem. Then you have already solved this issue. I'm closing this.