Publish Coordinates Transactions

Howdy :cowboy_hat_face:,

I’m trying to use the PublishCoordinates Method to publish linked project locations that have the same name as the host file’s project location, but I’m having trouble with the transactions.

The method requires both a transaction and a LinkElementId, the issue is that opening a transaction in the current document will not allow you to interact with the linked file(and subsequently the LocationId), transactions cannot be opened in linked files, and opening the document in the background converts the LinkElementId to a normal ElementId because the linked file is now the active file.

Has anyone successfully used this method and, how so?
PublishCoordinates.dyn (14.4 KB)[ I’ve commented out my four failed attempts ]

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 = []

projSite = None
projLocName = None

ProLoc = UnwrapElement(IN[1])
orgin = XYZ(0, 0, 0)
projPos = ProLoc.get_ProjectPosition(orgin)
projLocName = ProLoc.Name

#Publish newloc 

#Modifying is forbidden because document has no open transaction#
"""for rvtLinkInstance in rvtLinkInstances:
	linkdoc = rvtLinkInstance.GetLinkDocument()
	message = "Project Location already Published"
	TransactionManager.Instance.ForceCloseTransaction()
	Linklocations = linkdoc.ProjectLocations
	for Linklocation in Linklocations:
		if Linklocation.Name == projLocName:
			try: 
				linkdoc.PublishCoordinates(LinkElementId(Linklocation.Id))
				message = "Project Location successfully published"
			except Exception as e: 
				message2 = "Could not publish project location due to: " + str(e)
		else: continue	
	result.append(message)"""

#Modifying is forbidden beacause document has no open transaction#
"""for rvtLinkInstance in rvtLinkInstances:
	linkdoc = rvtLinkInstance.GetLinkDocument()
	message = "Project Location already Published"
	TransactionManager.Instance.ForceCloseTransaction()
	Linklocations = linkdoc.ProjectLocations
	for Linklocation in Linklocations:
		if Linklocation.Name == projLocName:
			t = Transaction(doc, "Publish Project Location")
			t.Start()
			try: 
				linkdoc.PublishCoordinates(LinkElementId(Linklocation.Id))
				message = "Project Location successfully published"
				t.Commit()
			except Exception as e: 
				message = "Could not publish project location due to: " + str(e)
				t.RollBack() 
		else: continue	
	result.append(message)"""

#Transactions can only be used in primary documents#
"""for rvtLinkInstance in rvtLinkInstances:
	linkdoc = rvtLinkInstance.GetLinkDocument()
	message = "Project Location already Published"
	TransactionManager.Instance.ForceCloseTransaction()
	Linklocations = linkdoc.ProjectLocations
	for Linklocation in Linklocations:
		if Linklocation.Name == projLocName:
			t = Transaction(linkdoc, "Publish Project Location")
			t.Start()
			try: 
				linkdoc.PublishCoordinates(LinkElementId(Linklocation.Id))
				message = "Project Location successfully published"
				t.Commit()
			except Exception as e: 
				message = "Could not publish project location due to: " + str(e)
				t.RollBack() 
		else: continue 	
	result.append(message)"""

#LocationID does not contain valid linkinstance id (Due to Open and Unload from host)
"""for rvtLinkInstance in rvtLinkInstances:
	linkdoc = rvtLinkInstance.GetLinkDocument()
	linkdocpath = linkdoc.PathName
	message = "Project Location already Published"
	rvtlinktype = doc.GetElement(rvtLinkInstance.GetTypeId())
	TransactionManager.Instance.ForceCloseTransaction()
	rvtlinktype.Unload(None)	
	newdoc = app.OpenDocumentFile(linkdocpath)
	Linklocations = newdoc.ProjectLocations
	for Linklocation in Linklocations:
		if Linklocation.Name == projLocName:
			t = Transaction(newdoc, "Publish Project Location")
			t.Start()
			try: 
				newdoc.PublishCoordinates(LinkElementId(Linklocation.Id))
				message = "Project Location successfully published"
				t.Commit()
			except Exception as e: 
				message = "Could not publish project location due to: " + str(e)
				t.RollBack() 
		else: continue
	newdoc.Close()
	rvtlinktype.Reload() 	
	result.append(message)"""

#Final output
OUT = result
#Thanks @stilgotme for original code

Thanks

P.S. This is a continuation of my quest to automate creating shared coordinates with only ablsolute northing, easting and elevation values.

I think you need to be using doc.PublishCordinates(LinkElementId(LinkLocation.Id))

1 Like

No luck :confused:

Error/Exception code: “locationId does not contain a valid linkInstanceId. Parameter name: locationId”

I figured it out, my LinkedElementId constructor was missing an argument, which prevented it from creating LinkedElementID and LinkInstanceId properties that are essential in the publish coordinates method.


Before:

After:

Result:

So it is working now! :grinning:

Next Question: Does anyone know how to suppress the publish coordinates warnings?

1 Like

Hi Luke, i was wondering if you could share a working version of the DYN file.

I have been trying to repair the earlier version you had shared but am getting a an error from the GetLocation Input.

any help much appreciated.
Cheers
C

Hi,

You can use the Publish Coordinates node instead.
Publish Coordinates

thanks Alban, thats seems easier haha

whic version for 2019?

All versions of the Genius Loci package are compatible with Revit 2019.