Open multiple .rvt files and create generic {3D} View

Hi @MartinSpence

You are my hero - together with @Mark.Ackerley :metal:t4:

It’s working like I imagined and quite smooth as well.

Here is the solution, where I take a bunch of .rvt files open them, add a 3D view and save them as detached from the central file with the suffix “_detached”.

if isinstance(IN[0], list):
	files = IN[0]
else:
	files = [IN[0]]

NewName = "_detached"

options = OpenOptions()
options.DetachFromCentralOption = DetachFromCentralOption.DetachAndPreserveWorksets

worksharingOptions = WorksharingSaveAsOptions()
worksharingOptions.SaveAsCentral = True

SaveOptions = SaveAsOptions()
SaveOptions.SetWorksharingOptions(worksharingOptions)

for file in files:
	modelpath = FilePath(file)
	newdoc = app.OpenDocumentFile(modelpath,options)

	collector = FilteredElementCollector(newdoc)
	viewTypeColl = collector.OfClass(ViewFamilyType)
	for i in viewTypeColl:
		if i.ViewFamily == ViewFamily.ThreeDimensional:
			viewType = i
		else:
			continue
	
	newfile = file[:-4] + NewName + ".rvt"

	TransactionManager.Instance.EnsureInTransaction(newdoc)

	view = View3D.CreateIsometric(newdoc, viewType.Id)
	#view.Name = viewName
	TransactionManager.Instance.ForceCloseTransaction()
	
	newdoc.SaveAs(newfile,SaveOptions)
	newdoc.Close(True)

OUT = 0

So I’m going to mark this as the solution, but all credit is to Martin and Mark - thank you again :sunglasses:

5 Likes