Hi everyone,
I’m trying to do a script to modify link file’s visibility with Dynamo. I saw with the new API in Revit 2024 that it’s possible ?
I try first with Rhythm package but I got blocked, so I try to do a python script with the new Revit class for LinkVisibility but I don’t know how to match the argument for View.GetLinkOverrides…
import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
clr.AddReference('System')
from System.Collections.Generic import List
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
uidoc = DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument
linkinstance = IN[0]
ViewType = []
for Views in linkinstance :
ViewType.append(View.GetLinkOverrides(Views))
OUT = linkinstance
Daan
July 26, 2023, 1:11pm
2
Hi @guillaume.trang ,
Could you share the API Page where you found that it’s possible in Revit 2024 to change the link visibiliy?
Hi,
it seems for now it’s limited to defining a linked view.
here an example to set a Linked View
Edit : code update for all PythonEngine
# Load the Python Standard and DesignScript Libraries
import sys
import clr
import System
from System.Collections.Generic import List
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
#import Revit API
clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *
import Autodesk.Revit.DB as DB
#import Revit APIUI namespace
clr.AddReference('RevitAPIUI')
from Autodesk.Revit.UI import *
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
clr.AddReference('System.Drawing')
clr.AddReference('System.Windows.Forms')
import System.Drawing
import System.Windows.Forms
from System.Drawing import *
from System.Windows.Forms import *
class Form28(Form):
def __init__(self, currentView):
self._currView = currentView
self._linktypes = FilteredElementCollector(doc).OfClass(DB.RevitLinkInstance).ToElements()
self._lstLinkViews = []
#
self.selectlinkTypeId = None
self.selectlinkView = None
self.lnkDoc = None
#
self.InitializeComponent()
def InitializeComponent(self):
self._comboBoxLinkType = System.Windows.Forms.ComboBox()
self._comboBoxLinkView = System.Windows.Forms.ComboBox()
self._buttonOK = System.Windows.Forms.Button()
self.SuspendLayout()
#
# comboBoxLinkType
#
self._comboBoxLinkType.Anchor = System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right
self._comboBoxLinkType.FormattingEnabled = True
self._comboBoxLinkType.Location = System.Drawing.Point(12, 36)
self._comboBoxLinkType.Name = "comboBoxLinkType"
self._comboBoxLinkType.Size = System.Drawing.Size(299, 21)
self._comboBoxLinkType.TabIndex = 0
self._comboBoxLinkType.Items.AddRange(System.Array[System.Object](self._linktypes))
self._comboBoxLinkType.DisplayMember = "Name"
self._comboBoxLinkType.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
self._comboBoxLinkType.SelectedIndexChanged += self.ComboBoxLinkTypeSelectedIndexChanged
#
# comboBoxLinkView
#
self._comboBoxLinkView.Anchor = System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right
self._comboBoxLinkView.FormattingEnabled = True
self._comboBoxLinkView.Location = System.Drawing.Point(12, 85)
self._comboBoxLinkView.Name = "comboBoxLinkView"
self._comboBoxLinkView.Size = System.Drawing.Size(299, 21)
self._comboBoxLinkView.TabIndex = 0
self._comboBoxLinkView.DisplayMember = "Name"
self._comboBoxLinkView.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
self._comboBoxLinkView.SelectedIndexChanged += self.ComboBoxLinkViewSelectedIndexChanged
#
# buttonOK
#
self._buttonOK.Anchor = System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right
self._buttonOK.Location = System.Drawing.Point(225, 138)
self._buttonOK.Name = "buttonOK"
self._buttonOK.Size = System.Drawing.Size(86, 29)
self._buttonOK.TabIndex = 1
self._buttonOK.Text = "OK"
self._buttonOK.UseVisualStyleBackColor = True
self._buttonOK.Click += self.ButtonOKClick
#
# Form28
#
self.ClientSize = System.Drawing.Size(323, 179)
self.Controls.Add(self._buttonOK)
self.Controls.Add(self._comboBoxLinkView)
self.Controls.Add(self._comboBoxLinkType)
self.Name = "Form28"
self.Text = "Form28"
self.ResumeLayout(False)
def ComboBoxLinkTypeSelectedIndexChanged(self, sender, e):
self.lnkDoc = sender.SelectedItem.GetLinkDocument()
filterV= System.Predicate[System.Object](lambda x : x.ViewType == self._currView.ViewType\
and x.GenLevel is not None\
and x.GenLevel.Name == self._currView.GenLevel.Name)
#
self._lstLinkViews = List[DB.Element](FilteredElementCollector(self.lnkDoc).OfClass(DB.View).ToElements()).FindAll(filterV)
self._comboBoxLinkView.Items.Clear()
self._comboBoxLinkView.Items.AddRange(System.Array[System.Object](list(self._lstLinkViews)))
self.selectlinkTypeId = sender.SelectedItem.GetTypeId()
def ButtonOKClick(self, sender, e):
self.Close()
self.Dispose()
def ComboBoxLinkViewSelectedIndexChanged(self, sender, e):
self.selectlinkView = sender.SelectedItem
activeView = doc.ActiveView
objForm = Form28(activeView)
objForm.ShowDialog()
#Do some action in a Transaction
TransactionManager.Instance.EnsureInTransaction(doc)
link_ovg = RevitLinkGraphicsSettings()
link_ovg.LinkVisibilityType = LinkVisibility.ByLinkView
link_ovg.LinkedViewId = objForm.selectlinkView.Id
activeView.SetLinkOverrides(objForm.selectlinkTypeId, link_ovg)
TransactionManager.Instance.TransactionTaskDone()
# check if the linked View is apply
link_ovg_check = activeView.GetLinkOverrides(objForm.selectlinkTypeId)
select_lnk_viewName = objForm.lnkDoc.GetElement(link_ovg_check.LinkedViewId ).Name
OUT = select_lnk_viewName
1 Like
Hi,
Thanks for your reply.
It is what I try to do, so I ran your python script but I got this error…
And when I click to continue, I don’t have anything in the second selection
I’m not with PC but for a CPython3 compatibility you need to cast the list ‘self._lstLinkViews’ into a .Net ‘List[DB.Element]’
I will update the code later if necessary
Hi,
code update for all PythonEngines in previous my post
Hi,
it seems for now it’s limited to defining a linked view.
here an example to set a Linked View
Edit : code update for all PythonEngine
# Load the Python Standard and DesignScript Libraries
import sys
import clr
import System
from System.Collections.Generic import List
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
#import Revit API
clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *
import Autodesk.Revit.DB as DB
#impor…
2 Likes