Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamo Process checker #1

Closed
brencass opened this issue Sep 26, 2022 · 3 comments
Closed

Dynamo Process checker #1

brencass opened this issue Sep 26, 2022 · 3 comments

Comments

@brencass
Copy link

brencass commented Sep 26, 2022

@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
Copy link
Owner

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
Copy link
Author

brencass commented Oct 5, 2022

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
Copy link
Owner

johnpierson commented Oct 11, 2022 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants