RIR Lock 3D views

Hi

I’m trying to lock 3D views. I haven’t been able to find any OOTB components so trying with Python. Any ideas why I am getting an error:

Runtime error (TypeErrorException): iteration over non-sequence of type View3D

Traceback:
line 24, in script

import rhinoscriptsyntax as rs

import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)

clr.AddReference("RevitAPI")
import Autodesk

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

doc = DocumentManager.Instance.CurrentDBDocument
views = x
toggle = lock

TransactionManager.Instance.EnsureInTransaction(doc)
for view in views:
	if toggle == True:
		view.Unlock()
	else:
		view.SaveOrientationAndLock()
TransactionManager.Instance.TransactionTaskDone()

Does ‘x’ have list access?

Your script is using Dynamo API.

In order to make it work on Rhino.Inside.Revit you need to change it a bit.

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

clr.AddReference('RhinoInside.Revit')
from RhinoInside.Revit import Revit

doc = Revit.ActiveDBDocument

with Transaction(doc, "Lock Views") as t:
    t.Start()
    for view in views:
        if lock == False:
            view.Unlock()
        elif view.IsLocked == False:
            view.SaveOrientationAndLock()
    t.Commit()

This is my GH file.
As @devin_jernigan said ‘views’ should have list acces.

1 Like

@kike One issue with this is that when used in conjunction with ‘Add 3D view’ it causes problems when the settings change and tracking is set to Reconstruct.

For example, if I create a view, lock the views and then modify the views I get an error saying that the view is locked. Ideally what would happen is that if the view is locked AND tracking is set to Reconstruct, the view is unlocked first and then updated.

OR alternatively, locking is built-in the ‘Add 3D view’ component.

Don’t you expect that locking a view prevents it from being modified?

I mean if we ignore locking state in Add View whats the point of locking the view?

Please share an screenshot of your Grasshopper document.
This will help me to understand better how you are connecting the components.

@kike yes sort of but let me explain…

If I created a view manually and locked it, I would expect that the lock operation is the dominate control. However, if I create a view with RIR and lock it downstream, I would expect that the view create is the dominant control.

I guess it comes down to separate transactions and their sequence. The way that I have it as two separate transactions means that once the view is locked, I can’t re-run the script easily. What I would need to do is collect all the views, filter them out, unlock them and then re-run the original script.

Although looking at it again, even if the views are locked, views are still output from the add 3d view component, so I can undo the lock after they are created. But it is still a bit awkward.

I guess if we could combine it into the same transaction, i.e. with Add 3D view, this would simplify the workflow. Just a thought…