Revit not regenerating view after creating parts


#1

Hello, I am experimenting with diving walls into parts using the amazing script create by Einar on this post:

The problem is, after a successful run of the scrip, Revit does not regenerate its view, so I can’t see or interact with the created parts using Revit.

image
But if I manually create parts from another element, it immediately updates the previous elements and then I can see the parts.

image

Is there a way to “refresh” the view and have the expected result in the script?

I am using Revit 2019.2 Thank a lot for the help!


#2

Hi @lucaspfmoreira

Add boolean input in python to refresh view.

Cheers!


#3

Thanks, for your Help, but I have tried that already!


#4

Looks like I just found the method on the Revit API.
it is the PartsVisibility option.

the new code is:

import clr

clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *

clr.AddReference('System')
from System.Collections.Generic import List

clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.GeometryConversion)
clr.ImportExtensions(Revit.Elements)

clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

doc = DocumentManager.Instance.CurrentDBDocument
uidoc=DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument
#Preparing input from dynamo to revit
wall = UnwrapElement(IN[0])
divisionLines = [l.ToRevitType(True) for l in IN[1]]
sketchPlane = UnwrapElement(IN[2])

#Create a list for the wall and the divisionLines
wallList = List[ElementId]()
wallList.Add(wall.Id)
intersectionElementsIds = List[ElementId]()
curveArray = List[Curve](divisionLines)

#All actions that make changes to the Revit database needs to be inside a Transaction
TransactionManager.Instance.EnsureInTransaction(doc)

if PartUtils.AreElementsValidForCreateParts(doc, wallList):
	createParts = PartUtils.CreateParts(doc, wallList)
	doc.Regenerate()

parts = PartUtils.GetAssociatedParts(doc, wall.Id, True, True)
partDivide = PartUtils.DivideParts(doc, parts, intersectionElementsIds, curveArray, sketchPlane.Id)

doc.ActiveView.PartsVisibility  = PartsVisibility.ShowPartsOnly;

uidoc.RefreshActiveView()

TransactionManager.Instance.TransactionTaskDone()


OUT = partDivide

That does the trick.