Place View on same location

Hello Dynamo Community!

I have a View placed on a sheet:

I would like to replace the view with another one, which should be placed at the same location.

Placing a view on the sheet works fine with Viewport.Create from Rhythm:

And i also found a node to move a viewport to the same location as another one, works fine too, with Viewport.SetLocationBasedOnOther from Rhythm:

To put this all together i would need to get the viewport of the view. It doesn´t work with View.GetViewport from SteamNodes :slightly_frowning_face:

One solution would be to get all viewports on the sheet and then filter the one i need. I often have many views on a sheet and i really don`t know how i could filter the viewports.

For this easy example it would work like this:

So why is the GetViewport node not working and is there any other method to get the viewport?
Would be really happy for any advice!Thank you very much in advance :slightly_smiling_face:

Regards, Gerhard

This should do it:

(Note: make sure your crop regions are the same. I suggest using a scope box if the views are meant to be the same. Example = Multi level buildings)

Example:

Graph:

1 Like

Hello John!

Thanks for your reply, thats exactly the intended use for my script.

In your and mine example we only have one viewport, but i have plans with many views and i don`t want to filter the viewports to get the one that should be the template viewport.

So i wanted to know if there is an easy way to get the viewport from a specific view.

I think that the viewport list and the view list wont have the same order, so i cant filter by a mask…

Get a view’s viewport? (I might add this to Rhythm too)

Like this?

Here is the Python:

import clr

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

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

doc = DocumentManager.Instance.CurrentDBDocument
uidoc=DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument

def GetViewport(view):
	return filter(lambda v: v.ViewId.IntegerValue.Equals(view.Id.IntegerValue),FilteredElementCollector(doc).OfClass(Viewport))

#Preparing input from dynamo to revit
view = UnwrapElement(IN[0])

# return the results
if isinstance(IN[0], list): OUT = [GetViewport(x) for x in view]
else: OUT = GetViewport(view)
3 Likes

:heart_eyes:

wonderful! Thanks John! :grinning:

Any idea why the SteamNode is not working? Code:

#python nodes in dynamo 1.0
#proposed by Julien Benoit @jbenoit44 
#http://aecuandme.wordpress.com/
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

sheets = []
for i in IN[0]:
	sheets.append(UnwrapElement(i))

# Start Transaction
TransactionManager.Instance.EnsureInTransaction(doc)

vplist=[]
for v in sheets:
	vp=[]
	a=v.GetAllViewports()
	for i in a:
		b=doc.GetElement(i)
		vp.append(b)
	vplist.append(vp)
			

# End Transaction
TransactionManager.Instance.TransactionTaskDone()

OUT=vplist

So after testing this in a larger script it does not work, the new view is placed somewhere else:

I place the view after setting the cropbox. So it should work because the views are equal!?

Edit:

Tried to add a END/START-Transaction to be shure the cropbox is applied.

It works but now i have a litte offset, any ideas what could be the reason?

Hi Gerhard,

I had the exact same issue a while back.
a bit of a hacky solution since i bet there is a reason for this offset, but:

I removed the offset by doing this:


I am sure there is a better way to do this, but this resolved my issue so i havent looked into it further :slight_smile:

I added this LocationBasedOnOther node at the end, but it does not work, still the same offset. I even tried it with End/Start-Transaction nodes.

But if i run a standalone version it works perfect:

I´ll keep trying to find a solution…interresting that it works for you MVE1112.

If i use an existing copy of the planview it works.

So the problem has to be at creating an placing a Planview in one Dynamo session…

I have found the reason for the offset, it`s because the viewports are not equal in size.

There are many elements that affect the viewport (grids, section lines, 2D-Elements,…), so these viewport location nodes are not reliable, at least not for my workflow.

It would be much more reliable if the location of the views would be set by the cropbox and not the viewport, because the cropboxes are always equal!

I will try to get the location of the cropbox on the sheet and move by vector or something like this.

For example, see how a section line affects the viewport:

Hello,

There are many problems with locating viewports on sheets.

I don’t know exactly what you want to do but see the link below.
Maybe another way, but it might help you!

I have resolved this by turning off ALL annotation categories, get crop box, then turn back on, move the viewpoint as required. It’s a pain, but it works.

1 Like

Thanks for your replies!

What i want to do is to move one view to another one by using the cropboxes as reference instead of the viewports.

I would need this node but it does´nt work :confused:

I tried to make a vektor from one cropbox to the other one and then move by vector, but it does´nt work like this…