Skip to content

Instantly share code, notes, and snippets.

@chuongmep
Last active April 14, 2022 16:26
Show Gist options
  • Save chuongmep/aec31589838dc023038b2fc5744df98c to your computer and use it in GitHub Desktop.
Save chuongmep/aec31589838dc023038b2fc5744df98c to your computer and use it in GitHub Desktop.
public void Action()
{
StringBuilder sb = new StringBuilder();
IList<Element> elements = new FilteredElementCollector(DB.Doc).OfClass(typeof(RevitLinkType)).ToElements();
foreach (Element element in elements)
{
sb.AppendLine(GetExtFileRefPath(element));
}
MessageBox.Show(sb.ToString());
}
string GetExtFileRefPath(Element item)
{
IDictionary<ExternalResourceType,ExternalResourceReference> resourceReferences = item.GetExternalResourceReferences();
foreach (KeyValuePair<ExternalResourceType,ExternalResourceReference> valuePair in resourceReferences)
{
var path = valuePair.Value.InSessionPath;
return path;
}
return string.Empty;
}
# Load the Python Standard and DesignScript Libraries
import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
# Import DocumentManager and TransactionManager
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
paths = []
def GetExtFileRefPath(item):
try :
dirRefs = item.GetExternalResourceReferences()
for i,v in enumerate(dirRefs):
return v.Value.InSessionPath
except Exception as e: return e.ToString()
doc = DocumentManager.Instance.CurrentDBDocument
items = FilteredElementCollector(doc).OfClass(RevitLinkType).ToElements()
OUT = [GetExtFileRefPath(x) for x in items]
import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
def GetExtFileRefPath(item):
try: return ModelPathUtils.ConvertModelPathToUserVisiblePath(item.GetExternalFileReference().GetAbsolutePath())
except: return None
items = UnwrapElement(IN[0])
if isinstance(IN[0], list): OUT = [GetExtFileRefPath(x) for x in items]
else: OUT = GetExtFileRefPath(items)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment