Hello,
We resurrected a project. There are imported .dwg. how can i find out the path of it? or is this information lost?
can i when i import a .dwg “store” anywhere the path ?
https://thebuildingcoder.typepad.com/blog/about-the-author.html#5.23
Hello,
We resurrected a project. There are imported .dwg. how can i find out the path of it? or is this information lost?
can i when i import a .dwg “store” anywhere the path ?
https://thebuildingcoder.typepad.com/blog/about-the-author.html#5.23
Have a look here: TransmissionData Class
thats just quick done for .rvt does it work for .dwg?
def unload_revit_links(location_path):
# Convert the location string to a ModelPath
location = ModelPathUtils.ConvertUserVisiblePathToModelPath(location_path)
# Access transmission data in the given Revit file
trans_data = TransmissionData.ReadTransmissionData(location)
if trans_data:
# Collect all (immediate) external references in the model
external_references = trans_data.GetAllExternalFileReferenceIds()
# Find every reference that is a link
for ref_id in external_references:
ext_ref = trans_data.GetLastSavedReferenceData(ref_id)
if ext_ref.ExternalFileReferenceType == ExternalFileReferenceType.RevitLink:
# We do not want to change either the path or the path-type
# We only want the links to be unloaded (should_load = False)
trans_data.SetDesiredReferenceData(ref_id, ext_ref.GetPath(), ext_ref.PathType, False)
# Make sure the IsTransmitted property is set
trans_data.IsTransmitted = True
# Modified transmission data must be saved back to the model
TransmissionData.WriteTransmissionData(location, trans_data)
else:
TaskDialog.Show("Unload Links", "The document does not have any transmission data")
# Example usage
location_path = "C:\\path\\to\\your\\revitfile.rvt"
unload_revit_links(location_path)
You are filtering to only Revit links with this line: if ext_ref.ExternalFileReferenceType == ExternalFileReferenceType.RevitLink:
Likely if you remove that or perform a separate action for the CADLink enumeration you’ll get what you are after.
Try this - filters out dud links (Invalid
or NotFound
)
import clr
import sys
clr.AddReference("RevitServices")
from RevitServices.Persistence import DocumentManager
clr.AddReference("RevitAPI")
from Autodesk.Revit.DB import (
CADLinkType,
FilteredElementCollector,
LinkedFileStatus,
ModelPathUtils,
)
def get_abs_path(cad_link_type):
lfs = cad_link_type.GetExternalFileReference().GetLinkedFileStatus()
if all([lfs != LinkedFileStatus.Invalid, lfs != LinkedFileStatus.NotFound]):
return ModelPathUtils.ConvertModelPathToUserVisiblePath(
cad_link_type.GetExternalFileReference().GetAbsolutePath()
)
doc = DocumentManager.Instance.CurrentDBDocument
cad_links = FilteredElementCollector(doc).OfClass(CADLinkType).ToElements()
cad_files = list(filter(None, map(get_abs_path, cad_links)))
OUT = cad_files
there is some trouble, i tested also for linked .dwg but the same error.
the links finaly work
Change the function to handle the errors
def get_abs_path(cad_link_type):
try:
cad_path = ModelPathUtils.ConvertModelPathToUserVisiblePath(
cad_link_type.GetExternalFileReference().GetAbsolutePath()
)
return cad_path
except:
return "No link path found for Element {}".format(cad_link_type.Name)
Swap Id for Name of the last line of the function - see how that goes
sorry i can`t follow…
Hi,
if the file was imported instead of linked, I think there is no way to find the path.
Redo a DWG export of a view with this one
the issue is we resurract a project after 3 Years. There are imported .dwgs. So i hoped that the path is stored anywhere…
a imported .dwg is like a drop in the ocean.
Ah I missed that you were using imports. The path was lost as soon as the user hit ‘insert’ in the dialog box.
This is yet another reason why I don’t recommend using imports. Ever. pretty much never a better idea than linking when you’re in a project environment.
so i can`t find any history about it. A Journal or backup file to snoop.
Pretty sure not.
Best bet is a Journal, and those aren’t usually kept around for 3 years. If they are, finding the right journal, and the right import instance is an equal nightmare.
If you can’t find the old project directory (ouch) or archive (double ouch) then you’re likely better off doing an export of the import instances to make new DWG files (as @c.poupin noted), and tracing/editing those to get a suitable DWG back.
Change cad_link_type.Name
to cad_link_type.Id