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.

Hi! I think there might be an issue with this node, or am I doing something wrong?


Hi,

Which version of Revit do you use ?
I will check this node.

Hi, thx for the quick answer! I am usind Revit 2021 and Dynamo 2.6… I am now looking at the python code, perhaps I need to have the coordinate system already created in the model, with the given name in order for the node to work? I think that is the problem, I am trying to create the coordinate system with the given name upon publishing coordinates (this is my usual workflow in Rvt)

Edit: My mistake, it works like a charm. You really need to have a site with the given name already created in the linked doc. So I would need to find a way to do that

Hi,

I edited the custom node to create the Project Location Name if it doesn’t already exist.

Try with this new version :

Replace the old node in C:\Users\%USERNAME%\AppData\Roaming\Dynamo\Dynamo Revit\2.6\packages\Genius Loci\dyf with the new one.

2 Likes

Wow, huge thanks for that! I just tried it, but I still think there might be an issue, I got a warning:

“Warning: IronPythonEvaluator.EvaluateIronPythonScript operation failed.
Traceback (most recent call last):
File “”, line 20, in
AttributeError: ‘NoneType’ object has no attribute ‘ProjectLocations’”

I think it gets the names of the coordinate systems in the wrong order:

Instances on the other hand are still with their location set to “Not Shared”

Hi @danail.momchilov,

I updated the node again to work in all cases.
You must have as many Project Location Names as there are linkinstances or a unique Project Location Name for all linkinstances.

Hi, @Alban_de_Chasteigner ! Thank you very much for trying to make this work, but unfortunattely there is still an issue - the node now creates the sites if they do not exist, but it changes instances’ locations. I tried it yesterday with the previous edit and all the links were moved to the wrong locations. I just tried your last update now and half of the links were immediately moved to wrong locations again, so I had to stop its run manually. You can see on the screenshot links already disappearing:

I have the same amount of instances and site names:

Edit: Perhaps two separate nodes would work better, the one for publishing coordinates like it was before and another one that only creates coordinate systems in linked files by their given name?

Hi Danail,

If I understand your workflow correctly, I don’t think it’s supported in Revit.
The Publish Coordinates node creates the sites if they do not exist and publish the current shared coordinates of the host model to the linked models.
Publish

If you have several sites in the host model, those that are not active are not taken into account.

1 Like

Hi, I only have one site in the host model:

But several different ones in the linked instances. Here’s my workflow:

The way your node worked previously was doing just that - publishing coordinates to an existing site within the link. The only thing missing was that you already needed to have these sites created in the linked file. So that’s what I was wondering how to automate :slight_smile:

Sorry to take so much of your time, I think I will just rollback to the initial version of your node and create the sites manually with the given names - it would take not more than an hour. Then publishing would work, I tried that already with a few instances only :slight_smile:

I now understand your workflow better.
I updated the custom node again. This time, I’m not creating a new project location, but duplicating the active project location from the linked model and setting a new name. The link should no longer move.
If you have time to experiment with this new behavior, that would be appreciated.

1 Like

Since I already created half of the sites back, would that be a problem? I mean if some of the sites exist, while others - not?