johnpierson / FETCH

FETCH is a Revit plugin that loads your Dynamo packages on Revit startup from a variety of locations.
BSD 3-Clause "New" or "Revised" License
10 stars 0 forks source link

Dynamo Process checker #1

Closed brencass closed 1 year ago

brencass commented 1 year ago

@johnpierson Probably worth adding a process checker to check if Dynamo is within memory. If dynamo is within memory it will probably error out when either deleting or add new packages.

EG. Dynamo could be loaded within another revit instance or even previously been loaded within that instance, and therefore will error out this addon because it cannot delete or install the new packages.

Run this method to apply a value within the globals parameter, then if the parameter is true it wont download packages but if false it will. Or modify this method to output a bool as part of a check.

image

You will need to add "using System.Diagnostics;" at the top of your code, and add a new Globals called IsDynamoInMemory.

    /// <summary>
    /// Gets all processes running on the machine then checks if they are "Revit" based. Then if it does find any it checks if Dynamo dll's are in memory.
    /// If yes it changes Global "IsDynamoInMemory" to True
    /// </summary>
            public static void CheckIfProcessContainDynamo()
    {
        List<bool> tempBoolList = new List<bool>();

        foreach (Process process in Process.GetProcessesByName("revit"))
        {
            foreach (ProcessModule module in process.Modules)
            {
                if (module.FileName.ToLower().Contains("dynamo"))
                {
                    tempBoolList.Add(true);
                }
            }
        }
        if (tempBoolList.Count() > 0)
        {
            Globals.IsDynamoInMemory = true;
        }
        else
        {
            Globals.IsDynamoInMemory = false;
        }
    }

Edit: I have changed "Process.GetProcesses()" to "Process.GetProcessesByName("revit")" and got rid of the IF statement from the attached code but is still showing in the image.

johnpierson commented 1 year ago

Ah that makes sense. Will end up adding that soon. One thing is, I would want to ensure that the Revit version matches the one I am checking it from. In the case of someone running 2022 and 2023

brencass commented 1 year ago

After the "foreach (Process process in Process.GetProcessesByName("revit"))" for the process and before it checks the modules you can add the below.

Then use this FilePath to see if it contains the VersionNumber from revit, if yes then it checks if Dynamo is running.

string fullPath = process.MainModule.FileName;

What is outputted from ProcessName(does not include Autodesk Revit 20XX) and the mainmodule FileName(includes version from file path): image

Code used for the above window popup: image

johnpierson commented 1 year ago

That makes sense to me! I could see this happening with multiple revit sessions open for sure. Will get that added!

On Mon, Sep 26, 2022 at 2:44 AM Brendan Cassidy @.***> wrote:

@johnpierson https://github.com/johnpierson Probably worth adding a process checker to check if Dynamo is in within memory. If dynamo is within memory it will stop you from being able to delete or add new packages.

[image: image] https://user-images.githubusercontent.com/14090637/192232632-be7a42c8-9984-4163-afb0-ad412574991f.png

You will need to add "using System.Diagnostics;" at the top of your code.

` ///

/// Gets all processes running on the machine then checks if they are "Revit" based. Then if it does find any it checks if Dynamo dll's are in memory. /// If yes it changes Global "IsDynamoInMemory" to True /// public static void CheckIfProcessContainDynamo() { List tempBoolList = new List();

    foreach (Process process in Process.GetProcesses())
    {
        if (process.ProcessName.ToLower().Contains("revit"))
        {
            foreach (ProcessModule module in process.Modules)
            {
                if (module.FileName.ToLower().Contains("dynamo"))
                {
                    tempBoolList.Add(true);
                }
            }
        }
    }
    if (tempBoolList.Count() > 0)
    {
        Globals.IsDynamoInMemory = true;
    }
    else
    {
        Globals.IsDynamoInMemory = false;
    }
}`

— Reply to this email directly, view it on GitHub https://github.com/johnpierson/FETCH/issues/1, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADYD5VB3CKATD6RQ4NYHLHDWAFO6RANCNFSM6AAAAAAQVR7BBQ . You are receiving this because you were mentioned.Message ID: @.***>