How is possible to move the viewport title in Revit 2019 with Dynamo?

how is possible to move the viewport title in Revit 2019 with Dynamo?

It’s not possible unless in Revit 2022+

3 Likes

I do not believe it, must be a workaround trick that is not just a Revit API code

JT
Don’t know what to tell you :confused:

If you find a way (you wont) come back and let us know

4 Likes

I am trying with this from @john_pierson [Revit Can't Do That Part 2 - Design Tech Unraveled] (Revit Can't Do That Part 2 - Design Tech Unraveled) which deletes the viewports and place them again in same location than the originals but they appear with fantanstic fit to the vieport crop region.

I wrote in python from some C# code snippet shared in that link, hoping it would work but it does not in my case because the viewports are already deleted or something like that I understand in the warning.

let me know if you can do something from this, I think it is not completed

import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
# Import ToDSType(bool) extension method
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)
# Import geometry conversion extension methods
clr.ImportExtensions(Revit.GeometryConversion)
# Import DocumentManager and TransactionManager
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
from System.Collections.Generic import *
# Import RevitAPI
clr.AddReference("RevitAPI")
import Autodesk
from Autodesk.Revit.DB import *

doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application
uidoc=DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument


# Example usage:
viewports = UnwrapElement(IN[0])

def align_view_title(viewport):
    doc = DocumentManager.Instance.CurrentDBDocument
    internalViewportId = viewport.Id
    internalViewport = doc.GetElement(internalViewportId)
    
    originalBoxCenter = internalViewport.GetBoxCenter()
    sheetId = internalViewport.SheetId
    viewId = internalViewport.ViewId
    
    TransactionManager.Instance.ForceCloseTransaction()
    tGroup = TransactionGroup(doc, "Aligning Viewport")
    tGroup.Start()
    deleteOriginalViewport = Transaction(doc, "Deleting Original")
    deleteOriginalViewport.Start()
    doc.Delete(internalViewportId)
    deleteOriginalViewport.Commit()
    
    replaceViewport = Transaction(doc, "Placing Viewport with Aligned View Title")
    replaceViewport.Start()
    Autodesk.Revit.DB.Viewport.Create(doc, sheetId, viewId, originalBoxCenter)
    replaceViewport.Commit()
    
    tGroup.Assimilate()


# Call the align_view_title function for each viewport in the list
output = []
for viewport in viewports:
    align_view_title(viewport)
    output.append(viewport)

OUT = output

this is what I get

To quote your own too early for the API reply (sorry, couldn’t help myself):

The only way to workaround API not being present is generally hacks that abuse other features. In the case of view titles I’m not familiar with any myself, although John’s workflow looks interesting despite its many noted limits.

This works for me, but you wont be able to control the viewport title beyond where the placement puts it I think:

# Made by Gavin Crump
# Free for use
# BIM Guru, www.bimguru.com.au

# Boilerplate text
import clr

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

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

# Current doc/app/ui
doc = DocumentManager.Instance.CurrentDBDocument

# Define list/unwrap list functions
def uwlist(input):
    result = input if isinstance(input, list) else [input]
    return UnwrapElement(result)

# Preparing input from dynamo to revit
viewports_ex  = uwlist(IN[0])
viewports_new = []

vids = [vp.ViewId for vp in viewports_ex]
sids = [vp.SheetId for vp in viewports_ex]
bcts = [vp.GetBoxCenter() for vp in viewports_ex]

# Delete old viewports
TransactionManager.Instance.EnsureInTransaction(doc)

for vp in viewports_ex:
	doc.Delete(vp.Id)

TransactionManager.Instance.TransactionTaskDone()

# Make new viewports
TransactionManager.Instance.EnsureInTransaction(doc)

for v,s,b in zip(vids,sids,bcts):
	vp_new = Viewport.Create(doc,s,v,b)
	viewports_new.append(vp_new)

TransactionManager.Instance.TransactionTaskDone()

# Preparing output to Dynamo
OUT = viewports_new
4 Likes

because you return deleted object at OUT python node

a solution

import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
# Import ToDSType(bool) extension method
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)
# Import geometry conversion extension methods
clr.ImportExtensions(Revit.GeometryConversion)
# Import DocumentManager and TransactionManager
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
from System.Collections.Generic import *
# Import RevitAPI
clr.AddReference("RevitAPI")
import Autodesk
from Autodesk.Revit.DB import *

doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application
uidoc=DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument


# Example usage:
viewports = UnwrapElement(IN[0])

def align_view_title(viewport):
    doc = DocumentManager.Instance.CurrentDBDocument
    internalViewportId = viewport.Id
    internalViewport = doc.GetElement(internalViewportId)
    
    originalBoxCenter = internalViewport.GetBoxCenter()
    sheetId = internalViewport.SheetId
    viewId = internalViewport.ViewId
    
    TransactionManager.Instance.ForceCloseTransaction()
    tGroup = TransactionGroup(doc, "Aligning Viewport")
    tGroup.Start()
    deleteOriginalViewport = Transaction(doc, "Deleting Original")
    deleteOriginalViewport.Start()
    doc.Delete(internalViewportId)
    deleteOriginalViewport.Commit()
    
    replaceViewport = Transaction(doc, "Placing Viewport with Aligned View Title")
    replaceViewport.Start()
    newviewport = Autodesk.Revit.DB.Viewport.Create(doc, sheetId, viewId, originalBoxCenter)
    replaceViewport.Commit()
    
    tGroup.Assimilate()
    return newviewport


# Call the align_view_title function for each viewport in the list
output = []
for viewport in viewports:
    newviewport = align_view_title(viewport)
    output.append(newviewport)

OUT = output

or see the @GavinCrump solution

2 Likes

yeah better than nothing that a stone gives, in my case the viewport titles are in same place after running the script because I already placed the viewport with that Dynamo method, so I am thinking to try 2 things:

  1. change the viewport family instead, tweak with new parameters the location of the text and the awful line.

  2. try to get the element viewport title and move it by a vector in Dynamo but no clue about this, I tried to select model element but it selects the whole viewport, so it moves all at once, not only the title of the viewport.
    image

Yes 2 is due to the API limits I’d say. I believe the view title itself isnt a separate object until that change, it always returns the actual viewport itself until then.

based on the limitations, to solve this topic I would like to know how to swap the viewport title family and set instance parameters of the “Title” family loaded, I am not sure if it works with setparametervalueby name to the viewport type parameters and the instance parameters of the “Title” loaded. I am talking about this family

I do not know how to get access to this family embedded in the viewports titles set under the parameter “Title”, I can get the viewport type though

Definitely. It’s one of those things that can add a lot of functionality, but for my use case, I wasn’t comfortable enough with it to build out nodes for each action. As an end user, you’re essentially abusing the heck out of viewport size and its (coincidental) manipulation of the view title length and location.

2 Likes