Python to get scripts usage informations in your company

Hi all,
I am developing a workflow in order to monitor and track the scripts usage from all of the offices of the company where I am working for, here in Italy. I think it will be really useful to see how many times the scripts are used, from who and when.

In the next months you could create some dashboards to analyze those data, maybe combined with other data sets and do your “data analysis” and observations.

The code started from the @john_pierson one, then I’ll added a couple of things.

PS
We are currently using still Dynamo 1.3 and obviously I know it could be done in better ways, but I’ve just started coding like 10 days ago :space_invader: and this code it’s working for me at the moment. If there are improvements you think I could include, please feel free to tell me :pray:

Stop talking, here is the code: :sunglasses:

# ---------------------------------------------------------------------- CREDITS

"""

GET FILE, USER AND DATE INFORMATIONS

"""

__author__ = "Ernesto Pellegrino - pellegrinoernesto@gmail.com"

__twitter__ = "@aitenlabs"

__linkedin__ = "linkedin.com/in/pellegrinoernesto/"

__version__ = '1.0.0'

"""

This code started from the John Pierson (twitter @60secondrevit) one in order to obtain the dynamo workspace name.

I've added the username, the date and the time informations.

Please note that the date and time outputs might vary based on your own PC settings.

"""

# ---------------------------------------------------------------------- IMPORTS & REFERENCES

import clr

clr.AddReference('DynamoRevitDS')

import Dynamo

clr.AddReference('DSCoreNodes')

import DSCore

from DSCore import *

clr.AddReference("RevitServices")

from RevitServices.Persistence import DocumentManager

# ---------------------------------------------------------------------- DATA

# access to the current Dynamo instance and workspace

dynamoRevit = Dynamo.Applications.DynamoRevit()

currentWorkspace = dynamoRevit.RevitDynamoModel.CurrentWorkspace

dynamoFileName = currentWorkspace.FileName

# get the user

app = DocumentManager.Instance.CurrentUIApplication.Application

userName = app.Username

# get the current date and time

Now = DSCore.DateTime.Now

Day = DSCore.DateTime.DayOfWeek(Now)

Date = Now.ToString()[:10]

Time = Now.ToString()[11:16]

# ---------------------------------------------------------------------- OUTPUT

# output the username, the Dynamo Workspace name, the date & time

OUT = userName, dynamoFileName, Day, Date, Time



This is the custom node you can use
aitenlabs.GetUserAndWorkspaceInformations.dyf (11.8 KB)

6 Likes

Good job! :slight_smile:

1 Like

@Ernesto_Pellegrino
Here is something similar from a previous discussion.
Sending emails

1 Like

@Ernesto_Pellegrino have a look at the code on the below link. It was some python code started by @john_pierson which i updated to allow it to work for dynamo 1.3 and 2.0.

You could use the dynamo version it is getting to output that as part of the usage info :slight_smile:

Also if your scripts are generally used by revit it may be worthwhile getting the revit version/build and revit file info(file size, name and link info) to get the full extent of usage information?

3 Likes

Interesting…
I’d focus on which project used it rather than which user used the script. So I’m pulling project number & project name parameters as well to generate script use per project. here is the code for that…

collector = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_ProjectInformation).ToElements()
projectnumber=collector[0].get_Parameter(BuiltInParameter.PROJECT_NUMBER).AsString()
projectname=collector[0].get_Parameter(BuiltInParameter.PROJECT_NAME).AsString()

and for the username, I’m not using Revit Username, I’m using the username from OS.

2 Likes

Well done @jalshu, thanks for sharing!