I’m trying to suppress the errors that arise when you automatically publish coordinates, via transaction failure handling options.
Python Script...
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
# Import DocumentManager and TransactionManager
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
# Import RevitAPI
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
# Import ToDSType(bool) extension method
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)
# Import ToProtoType, ToRevitType geometry conversion extension methods
clr.ImportExtensions(Revit.GeometryConversion)
# Import DSCore nodes in Dynamo
clr.AddReference('DSCoreNodes')
import DSCore
from DSCore import *
# Import python library
import sys
pyt_path = r'C:\Program Files (x86)\IronPython 2.7\Lib'
sys.path.append(pyt_path)
import os
import shutil
import math
# Import math library
from math import *
#Import Data and Time
from datetime import datetime
now = datetime.now()
#Import System Library
import System
from System.Collections.Generic import *
from System.IO import Directory, Path
doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application
#Preparing input from dynamo to revit
rvtLinkInstances = UnwrapElement(IN[0])
result = []
#Do some action in a Transaction
projSite = None
projLocName = None
ProLoc = UnwrapElement(IN[1])
orgin = XYZ(0, 0, 0)
projPos = ProLoc.get_ProjectPosition(orgin)
projLocName = ProLoc.Name
projPosEW = projPos.EastWest
projPosNS = projPos.NorthSouth
projPosEl = projPos.Elevation
projPosAngle = projPos.Angle
projSite = ProLoc.GetSiteLocation()
projSiteLat = projSite.Latitude
projSiteLong = projSite.Longitude
projSiteTimeZ = projSite.TimeZone
trigger = True
#TransactionManager.Instance.EnsureInTransaction(doc)
for rvtLinkInstance in rvtLinkInstances:
linkdoc = rvtLinkInstance.GetLinkDocument()
linkdocpath = linkdoc.PathName
message = "Project Location of specific name already exist"
message3 = "Project Location of specific name already exist"
rvtlinktype = doc.GetElement(rvtLinkInstance.GetTypeId())
TransactionManager.Instance.ForceCloseTransaction()
rvtlinktype.Unload(None)
newdoc = app.OpenDocumentFile(linkdocpath)
currentLinkLocation = newdoc.ActiveProjectLocation
Linklocations = newdoc.ProjectLocations
for Linklocation in Linklocations:
if Linklocation.Name == projLocName:
trigger = False
break
else: continue
if trigger:
t = Transaction(newdoc, "Create Project Location")
t.Start()
try:
newloc = currentLinkLocation.Duplicate(projLocName)
newloc.set_ProjectPosition(orgin,projPos)
newlocsite = newloc.GetSiteLocation()
newlocsite.Latitude = projSiteLat
newlocsite.Longitude = projSiteLong
newlocsite.TimeZone = projSiteTimeZ
#newloc = ProjectLocation.Create(newdoc, projSite.Id, projLocName)
message = "Project Location successfully duplicated/created"
t.Commit()
except Exception as e:
message = "Could not create project location due to: " + str(e)
t.RollBack()
newdoc.Close()
rvtlinktype.Reload()
result.append(message)
#Publish newloc
for rvtLinkInstance in rvtLinkInstances:
linkdoc = rvtLinkInstance.GetLinkDocument()
message2 = "Project Location already Published"
TransactionManager.Instance.ForceCloseTransaction()
Linklocations = linkdoc.ProjectLocations
for Linklocation in Linklocations:
if Linklocation.Name == projLocName:
t = Transaction(doc, "Publish Project Location")
fho = FailureHandlingOptions.SetDelayedMiniWarnings(True)
t.SetFailureHandlingOptions(fho)
t.Start()
try:
doc.PublishCoordinates(LinkElementId(rvtLinkInstance.Id,Linklocation.Id))
message2 = "Project Location successfully published"
t.Commit()
except Exception as e:
message2 = "Could not publish project location due to: " + str(e)
t.RollBack()
else: continue
result.append(message2)
#TransactionManager.Instance.TransactionTaskDone()
#Final output
debug = False
#debug = True#Comment to turn off
if debug:
OUT=['orgin: ', orgin, 'projPos: ' , projPos, 'projLocName: ', projLocName, 'projPosEW: ', projPosEW, 'projPosNS: ', projPosNS, 'projPosEl: ', projPosEl, 'projPosAngle: ', projPosAngle,'projSite: ', projSite, 'projSiteLat: ' , projSiteLat, 'projSiteLong: ' , projSiteLong, 'projSiteTimeZ: ', projSiteTimeZ, 'result: ', result]
else:
OUT = result
My issue is that I have no idea what the second argument for this method is, it isn’t listed on the SetDelayedMiniWarnings Method site.
Am I creating my FailureHandlingOptions object wrong? I am kinda confused on how this one works because there isn’t a constructor and I don’t know where to pull and existing one from.
Is there another way to automatically close this error dialog box?