How to import dwf file to revit

How to import dwf file to revit

silent_joe
Participant Participant
15,768 Views
11 Replies
Message 1 of 12

How to import dwf file to revit

silent_joe
Participant
Participant

just like navigating to the "Insert" tab and select "DWF Markup", I want to link dwf file by codes.

I wrote these codes, but nothing happens when Running. Is there anything wrong in DWFImportOptions' parameter? list_ViewSheet is a view sheet list of revit.

 

DWFImportOptions ops = new DWFImportOptions(list_ViewSheet.Select(o => o.Id).ToList());
using (Transaction ts = new Transaction(doc, "插入DWF校审文件"))
{
ts.Start();
doc.Link(filePath, ops);
ts.Commit();
}

0 Likes
15,769 Views
11 Replies
Replies (11)
Message 2 of 12

jeremy_tammik
Alumni
Alumni

I suggest that you research the best practices and optimal workflow in the manual end user interface before trying to address this task programmatically.

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes
Message 3 of 12

silent_joe
Participant
Participant

Thanks for your reply. 

I have read the content about Link DWF Markups.

https://help.autodesk.com/view/RVT/2020/ENU/?guid=GUID-CE67846D-C533-46DF-A702-7ECF2BB67DC8

But I'm still confused on how to construct a new instance of DWFImportOptions.

If I use DWFImportOptions(DWFImportOptions)  overload, how can i get a copy of the import options?

If I use DWFImportOptions(IList(ElementId) overload, is the list in revit sheet views, how can i know which are the right sheet views to be as parameter?

 
0 Likes
Message 4 of 12

silent_joe
Participant
Participant
I'm still Waiting for the answer. Any one can help me ?
0 Likes
Message 5 of 12

jeremy_tammik
Alumni
Alumni

What exact steps do you take in the manual user interface? Which views do you specify there? I would assume that you can do the same in the API. If you have a situation that works in the UI and not in the API, please try to create and share a complete minimal reproducible case for us to discuss:

  

https://thebuildingcoder.typepad.com/blog/about-the-author.html#1b

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes
Message 6 of 12

RPTHOMAS108
Mentor
Mentor

Last time I remember using this in the UI (years ago) the mark-ups in the dwf/x are linked to specific views in Revit because the dwf/x was generated from within Revit to begin with (so it knows what sheet is being marked up when it is marked up elsewhere). Therefore you just have to specify the sheets containing the mark ups you want to import from the dwf/x. If those same sheets don't have mark-up in the dwf/x then you get blank. If those sheets were not exported to the dwf/x in the first place (to then mark-up) then you perhaps get ArgumentException.

 

So two questions really:

Did the dwf/x come from the Revit file you are now trying to import the mark-up into?

Did the sheet ids you are specifying in Revit have mark-up information added to their equivalents in the dwf/x since they were exported?

 

Last time I used it, if you export a sheet showing an element and then cloud the element in design review then it imports the cloud not the clouded element.

 

Export dwf/x from Revit >  mark-up > import mark-up to Revit (that's the workflow).

Export dwf/x from elsewhere (e.g. AutoCad) > mark-up > import mark-up to Revit (that probably isn't going to work).

Message 7 of 12

silent_joe
Participant
Participant

First, in Revit ,I export three viewsheets to dwfx ,

silent_joe_0-1644995504747.png

then ,I open the dwfx file with design review, mark up two sheets, J0-1 and J0-2。

finally, I import the dwfx to Revit. In UI, there will show a dialog to match viewsheets.

silent_joe_1-1644996060592.png

But in codes, the dwfx can't be imported.

this is my codes:

string filePath = @"C:\Users\7109\Desktop\项目1.dwfx";

List<Autodesk.Revit.DB.ViewSheet> list_ViewSheet = new FilteredElementCollector(doc).OfClass(typeof(ViewSheet)).Cast<ViewSheet>().ToList();

using (Transaction ts = new Transaction(doc, "插入DWF校审文件"))

{

DWFImportOptions ops = new DWFImportOptions(list_ViewSheet.Select(o => o.Id).ToList());

//DWFImportOptions ops = new DWFImportOptions(list_ViewSheet.Where(o=>o.SheetNumber!= "J0-3").Select(o => o.Id).ToList());

ts.Start();
doc.Link(filePath, ops);
ts.Commit();
}

 

To make it clear, I did this test:

If i mark up three sheets, but only import two sheetviews of them as param , the codes won't works.

If i mark up two sheets, but import three sheetviews as param,the codes won't works.

If i mark up all three sheets, and import just the three sheetviews as param, the codes works.

In UI, it works in all conditions, even if I only markup two of three sheets.

 

0 Likes
Message 8 of 12

jeremy_tammik
Alumni
Alumni

Well, it sounds as if you have a pretty well defined little problem there. Does the RVT file contain the three views and a macro to manipulate them? Is the DWF that you import included? Can you provide a complete, minimal, totally self-contained single-click reproducible case? If so, I'll pass it on to the development team and ask them for advice:

 

https://thebuildingcoder.typepad.com/blog/about-the-author.html#1b

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes
Message 9 of 12

silent_joe
Participant
Participant

Thanks for your reply @jeremy_tammik 

this is my project and dwfx files:

项目1.rvt has three sheetviews, and includes macro;

项目1.dwfx is marked up with two sheets;

项目2.dwfx is marked up with all three sheets;

The two dwfxs are all exported by 项目1.rvt.

 

Looking forward to your reply and give my sincerely thanks to you!

0 Likes
Message 10 of 12

jeremy_tammik
Alumni
Alumni

Dear Silent Joe,

 

Thank you for your report and sample material.

 

I logged the issue REVIT-188516 [API problem importing DWF file with view sheets] with our development team for this on your behalf as it requires further exploration and possibly a modification to our software. Please make a note of this number for future reference.

 

You are welcome to request an update on the status of this issue or to provide additional information on it at any time quoting this change request number.

 

This issue is important to me. What can I do to help?

 

This issue needs to be assessed by our engineering team and prioritised against all other outstanding change requests. Any information that you can provide to influence this assessment will help. Please provide the following where possible:

 

  • Impact on your application and/or your development.
  • The number of users affected.
  • The potential revenue impact to you.
  • The potential revenue impact to Autodesk.
  • Realistic timescale over which a fix would help you.
  • In the case of a request for a new feature or a feature enhancement, please also provide detailed Use cases for the workflows that this change would address.

 

This information is extremely important. Our engineering team have limited resources, and so must focus their efforts on the highest impact items. We do understand that this will cause you delays and affect your development planning, and we appreciate your cooperation and patience.

 

Best regards,

 

Jeremy

 

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes
Message 11 of 12

jeremy_tammik
Alumni
Alumni

Dear Silent Joe,

 

Thank you for your patience.

 

The development team analysed your issue REVIT-188516 [API problem importing DWF file with view sheets] and report:

 

Reproduced this situation.

 

It was caused by different view name in Revit and DWF.

 

In the DWF file, the view name is "图纸: J0-1 - 未命名", that is "图表: J0-1 - 未命名".

 

In the attached RVT file, the name should be "Sheet: J01 - 未命名".

 

This mismatch causes the import failure.

 

I confirmed that Revit API works well, including DWFImportOptions and Document.Link().

 

A new exported DWF file can be imported into the Revit doc successfully.

 

In the new exported DWF file, the view name is "Sheet: J01 - 未命名", exactly the same with view name in the attached RVT file.

 

No code changes needed.

 

Best regards,

 

Jeremy

 

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes
Message 12 of 12

c.poupin
Advocate
Advocate

Hi, 

I founded a workaround parsing the manifest.xml in the dwfx (it's a zip archive)


 here the python code (with Dynamo)

 

Edit list of Sheets (Ids) must be ordered by Title Name

 

 

# Load the Python Standard and DesignScript Libraries
import clr
import re
import sys
import System
pyEngineName = sys.implementation.name 
from System.Collections.Generic import List

clr.AddReference('RevitAPI')
import Autodesk
import Autodesk.Revit.DB as DB

clr.AddReference('System.Windows.Forms')
import System.Windows.Forms
from System.Windows.Forms import OpenFileDialog, DialogResult

clr.AddReference('RevitAPIUI')
from Autodesk.Revit.UI import TaskDialog, TaskDialogIcon

clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Transactions import TransactionManager
from RevitServices.Persistence import DocumentManager
doc = DocumentManager.Instance.CurrentDBDocument

import zipfile
import xml.etree.ElementTree as ET
		
def get_xml_namespace(xmlelement):
	m = re.match(r'\{.*\}', xmlelement.tag)
	return m.group(0) if m else ''

lst_annotids = []		

openFileDialog  = OpenFileDialog()	
openFileDialog.Filter = "Dwfx files (*.dwfx)|*.dwfx|All files (*.*)|*.*"
openFileDialog.RestoreDirectory = True
openFileDialog.Title = "Select dwfx file"
#
if openFileDialog.ShowDialog() == DialogResult.OK:
	list_ViewSheet = List[DB.ViewSheet](DB.FilteredElementCollector(doc).OfClass(DB.ViewSheet).ToElements())
	sheetViewIds = List[DB.ElementId]()
	filePath = openFileDialog.FileName
	import_dwfx = System.IO.Path.GetFileName(filePath)
	# Start Read dwfx file with zipfile
	lst_no_associate_views = []
	with zipfile.ZipFile(filePath, mode="r") as archive: 
		for info in archive.infolist():
			if info.filename.endswith("manifest.xml"):
				# Read and parse the Xml content
				xmlcontent = archive.read(info.filename)
				root = ET.fromstring(xmlcontent)
				xml_namespace = get_xml_namespace(root)
				allSection = root.findall(".//{}Section".format(xml_namespace))
				for sectionNode in allSection:
					#
					full_title =  sectionNode.get("title")
					if full_title is not None :
						#
						allressource = sectionNode.findall(".//{}Resource".format(xml_namespace))
						for ressourceNode in allressource:
							role =  ressourceNode.get("role")
							if "markup object" in role:
								# find the good sheet with Title property
								filter_title = System.Predicate[System.Object](lambda v : v.Title == full_title)
								viewRvt = list_ViewSheet.Find(filter_title)
								if viewRvt is not None:
									sheetViewIds.Add(viewRvt.Id)
									view_ids_founded = True
									break
								else:
									lst_no_associate_views.append(full_title)
	# sort by Title Name (same UI revit)
	sheetViewIds = sorted(sheetViewIds, key = lambda xId : doc.GetElement(xId).Title)
	sheetViewIds = List[ElementId](sheetViewIds)
	print(sheetViewIds)
	print(lst_no_associate_views)
	# create a warning if dwfx has no associated views
	if len(lst_no_associate_views) > 0:
		# reset sheetViewIds
		sheetViewIds = List[DB.ElementId]()
		dialog = TaskDialog("Erreur Views")
		dialog.MainInstruction = "Unassociated views, delete views (or rename correctly from Revit Sheets) below on the dwfx, save, then restart"
		dialog.MainContent = "View to Delete or Rename on dwfx :\n\n-{}".format("-\n".join(lst_no_associate_views))
		dialog.MainIcon  = TaskDialogIcon.TaskDialogIconWarning
		#
		if pyEngineName == "ironpython":
			dialog.Show()
		else:
			# unfortunately, the Show() method does not work with PythonNet2.5/CPython3 (overload issue).
			from System.Reflection import BindingFlags
			arguments = []
			clr.GetClrType(dialog.GetType()).InvokeMember("Show", BindingFlags.InvokeMethod , None, dialog, arguments)
	#
				
	if len(sheetViewIds) > 0:
		# Import dwfx and get annotation element IDs
		TransactionManager.Instance.EnsureInTransaction(doc)
		ops = DB.DWFImportOptions(sheetViewIds)
		lst_annotids = doc.Link(filePath, ops)
		TransactionManager.Instance.TransactionTaskDone()
		doc.Regenerate()
	# get some information
	lstAnnot = [doc.GetElement(xId) for xId in lst_annotids]
	lstAnnot = [[doc.GetElement(x.OwnerViewId),x.get_Parameter(DB.BuiltInParameter.MARKUPS_LABEL).AsString()] for x in lstAnnot]

 

 

dynamo_screenshot.png

 

for a little more explanation, I wrote an article on my blog

Cyril POUPIN

EESignature


0 Likes