Dynamo Script do not run on other computers

Greetings to all, We’ve been developing a couple of python scripts and now we are facing troubles when spreading the routines among the company users. Somehow they can not run them by using the companies computers but It works on others devices such as our laptops at home. Does any have some insights of what might be the root cause of this?

Cheers and thanks in advance

Can’t help you troubleshoot without the warnings and code, but namespace collision and deployment failures come to mind.

3 Likes

Thanks for your prompt reply,
We’ve even tested the following small piece of code and did not succeed at all. Dynamo doesn’t through any warnings. Indeed, the user interface switch to the typical gray color and allows to pick a box. The issue comes afterwards as we don’t visualize the modifications that are suppose to get done.

import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
from Autodesk.Revit.DB.Structure import *
clr.AddReference('RevitAPIUI')
from Autodesk.Revit.UI import *
clr.AddReference('System')
from System.Collections.Generic import List
clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.GeometryConversion)
clr.ImportExtensions(Revit.Elements)
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

def cropView(p1, p2, p3, p4, clist,view):
    clist.append(Line.CreateBound(p1, p2))
    clist.append(Line.CreateBound(p2, p3))
    clist.append(Line.CreateBound(p3, p4))
    clist.append(Line.CreateBound(p4, p1))
    cl1=CurveLoop.Create(clist)
    crsm=view.GetCropRegionShapeManager()
    if crsm.IsCropRegionShapeValid(cl1):
        return crsm.SetCropShape(cl1)
        view.CropBoxActive=True
        view.CropBoxVisible = True
doc = DocumentManager.Instance.CurrentDBDocument
uidoc=DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument
view= doc.ActiveView
cropbox=view.CropBox
pickedbox=uidoc.Selection.PickBox(Selection.PickBoxStyle.Enclosing,"select view crop region")

if pickedbox.Min.X > pickedbox.Max.X:
    mmin=XYZ(pickedbox.Max.X,pickedbox.Min.Y,100)
    mmax=XYZ(pickedbox.Min.X,pickedbox.Max.Y,100)
    pickedbox.Min=mmin
    pickedbox.Max=mmax

if pickedbox.Min.Y > pickedbox.Max.Y:
    mmin=XYZ(pickedbox.Min.X,pickedbox.Max.Y,100)
    mmax=XYZ(pickedbox.Max.X,pickedbox.Min.Y,100)
    pickedbox.Min=mmin
    pickedbox.Max=mmax

tr=Transaction(doc,"cropbox")
tr.Start()
clist=[]
p1=XYZ(pickedbox.Min.X,pickedbox.Min.Y,100)
p2=XYZ(pickedbox.Min.X,pickedbox.Max.Y,100)
p3=XYZ(pickedbox.Max.X,pickedbox.Max.Y,100)
p4=XYZ(pickedbox.Max.X,pickedbox.Min.Y,100)
cropView(p1, p2, p3, p4, clist,view)
tr.Commit()

Hmmm… I don’t have access to Dynamo or even a PC at the moment… what are you attempting to do with the code after running the pick box?

Try taking the ‘cropView’ code out of the definition and run it line by line, outputting as needed. May be that there is a debugging issue that the definition is suppressing.

Hi Jacob!,
basically annotating multi-rebars that are visible in the current view and then aligning the tags to the cropbox’s frames to avoid overlaps between them. It end up being a 1800 code line as the approach depends on whether it is being deployed on a elevation view or floor plan. So we’ve even tried out copying the small cropview code task into a word document and then pasting all at once onto our colleagues python script nodes, which didn´t succeed as well.

Right, the next thing might be pasting and running the code line by line. I’m not quite sure what do you mean by the definition on “…debugging issue that the definition is suppressing”. Would you be kind of providing some context.

Best regards
Miguel G.

Because you are calling a definition you may be accidentally suppressing a warning or returning a value which is null by design. Removing the code from inside the definition might expose an empty list or a null or something which because you only have a single output of the definition so your ‘failure point’ may be masked.

1 Like

I have not tested this script, but I notice at least 2 errors

see FIX comments below

import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
from Autodesk.Revit.DB.Structure import *
clr.AddReference('RevitAPIUI')
from Autodesk.Revit.UI import *
# FIX 1
# missing NameSpace
from Autodesk.Revit.UI.Selection import PickBoxStyle
# END FIX 1
clr.AddReference('System')
from System.Collections.Generic import List
clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.GeometryConversion)
clr.ImportExtensions(Revit.Elements)
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

def cropView(p1, p2, p3, p4, clist,view):
    clist.append(Line.CreateBound(p1, p2))
    clist.append(Line.CreateBound(p2, p3))
    clist.append(Line.CreateBound(p3, p4))
    clist.append(Line.CreateBound(p4, p1))
    cl1=CurveLoop.Create(clist)
    crsm=view.GetCropRegionShapeManager()
    if crsm.IsCropRegionShapeValid(cl1):
        return crsm.SetCropShape(cl1)
        view.CropBoxActive=True
        view.CropBoxVisible = True
doc = DocumentManager.Instance.CurrentDBDocument
uidoc=DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument
view= doc.ActiveView
cropbox=view.CropBox
# FIX 1bis
#pickedbox=uidoc.Selection.PickBox(Selection.PickBoxStyle.Enclosing,"select view crop region")
pickedbox=uidoc.Selection.PickBox(PickBoxStyle.Enclosing,"select view crop region")

if pickedbox.Min.X > pickedbox.Max.X:
    mmin=XYZ(pickedbox.Max.X,pickedbox.Min.Y,100)
    mmax=XYZ(pickedbox.Min.X,pickedbox.Max.Y,100)
    pickedbox.Min=mmin
    pickedbox.Max=mmax

if pickedbox.Min.Y > pickedbox.Max.Y:
    mmin=XYZ(pickedbox.Min.X,pickedbox.Max.Y,100)
    mmax=XYZ(pickedbox.Max.X,pickedbox.Min.Y,100)
    pickedbox.Min=mmin
    pickedbox.Max=mmax

# FIX 2
# If you want use Revit Transaction you need Force Close Dynamo Transaction (Transaction Group)
TransactionManager.Instance.ForceCloseTransaction()
# END FIX 2
tr=Transaction(doc,"cropbox")
tr.Start()
clist=[]
p1=XYZ(pickedbox.Min.X,pickedbox.Min.Y,100)
p2=XYZ(pickedbox.Min.X,pickedbox.Max.Y,100)
p3=XYZ(pickedbox.Max.X,pickedbox.Max.Y,100)
p4=XYZ(pickedbox.Max.X,pickedbox.Min.Y,100)
cropView(p1, p2, p3, p4, clist,view)
tr.Commit()
1 Like

Greeting to you all, we went for compiling the code in visual studio and it turn out that was not working on other devices as well. Then we went for unblocking the .dll and .addin file on their property settings and it run appropriately.

2unblock

I’ll let my colleagues to replicate this on dynamo script by Monday and keep you updated by then. Thanks for spotting some code mistakes, I´ll be aware of them!
Cheers