I want to get this in a windows pop up.
Obvs labels are text… I’ve tried it as a link but seem to keep getting errors.
How do I do it?
I want to get this in a windows pop up.
Obvs labels are text… I’ve tried it as a link but seem to keep getting errors.
How do I do it?
I’m not sure I follow… do you want a popup where the users can trigger the 'Show in view" for a given element?
Yeah… Like you get in Dynamo, you can click on the green bit and it takes you to that element.
I want that, but in my windows pop ups.
Not sure that’s going to work with a windows popup, at least not easily… I recommend looking into the Revit Task Dialog tools as a starting point, as we know it can be done there:
EDIT This looks like it might be relevant to your query, just use show in view command instead of select command: c# - Selecting a Revit Element by the ID taken from WPF DataGrid - Stack Overflow
Hi,
there is an example here
Data-Shapes has that option in it I believe.
Yeah but that’d mean me reading through 1000000000000 lines of code… #IAmLazy
I have bespoke company pop ups so was wondering how to do it myself.
Would having your graph highlight the element in the view, work instead?
That would be awesome
ImportError: No module named _wpf<<
This seems to be a sticking point.
Which Python engine are you using ?
an option could be to use winform instead
Yes, I’ve been using winform for my pop-ups.
I added a LinkLabel … but then getting it to centre on something in Revit I’ve not worked out how to do yet.
I’m in Revit 21, so that’s Dyno 2.6.1
So I’ve tried this:
def linkLabel_LinkClicked(self, sender, e):
uidoc.ShowElements(???)
for ??? I have tried the AreaId and also the Area.
With the Id I get a warning it’s expecting an element not an integer.
With the Area I get a warning it’s expecting an element not an Area…
So an Area is not an Element?
an example with winform
import sys
import clr
import System
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 net library
from System.Collections.Generic import List
#import transactionManager and DocumentManager (RevitServices is specific to Dynamo)
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
uidoc = uiapp.ActiveUIDocument
app = uiapp.Application
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 FormResume(Form):
def __init__(self, lstElems):
self._lst_Elems = lstElems
self.InitializeComponent()
def InitializeComponent(self):
self._listView1 = System.Windows.Forms.ListView()
self._buttonQuit = System.Windows.Forms.Button()
self.SuspendLayout()
#
# listView1
x,y = 294, 379
self._listView1.Anchor = System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right
self._listView1.Location = System.Drawing.Point(13, 33)
listViewItem = []
for elem in self._lst_Elems:
item1 = System.Windows.Forms.ListViewItem(elem.Name)
item1.Tag = elem
listViewItem.append(item1)
self._columnHeader1 = System.Windows.Forms.ColumnHeader()
self._columnHeader1.Text = "Liste Elements"
self._listView1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
self._listView1.CheckBoxes = False
self._listView1.Columns.AddRange(System.Array[System.Windows.Forms.ColumnHeader]([self._columnHeader1]))
self._listView1.GridLines = True
self._listView1.Items.AddRange(System.Array[System.Windows.Forms.ListViewItem](listViewItem))
self._listView1.Size = System.Drawing.Size(x,y)
self._listView1.View = System.Windows.Forms.View.Details
self._columnHeader1.Width = x
self._listView1.ItemSelectionChanged += self.ListView1ItemSelectionChanged
#
# buttonQuit
#
self._buttonQuit.Anchor = System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right
self._buttonQuit.Location = System.Drawing.Point(226, 418)
self._buttonQuit.Name = "buttonQuit"
self._buttonQuit.Size = System.Drawing.Size(81, 30)
self._buttonQuit.TabIndex = 1
self._buttonQuit.Text = "Quit"
self._buttonQuit.UseVisualStyleBackColor = True
self._buttonQuit.Click += self.ButtonQuitClick
#
# FormListView29
#
self.ClientSize = System.Drawing.Size(319, 460)
self.Controls.Add(self._buttonQuit)
self.Controls.Add(self._listView1)
self.Name = "FormResume"
self.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Show
self.Text = "FormResume"
self.ResumeLayout(False)
def ButtonQuitClick(self, sender, e):
self.Close()
def ListView1ItemSelectionChanged(self, sender, e):
elem = e.Item.Tag
itemId = elem.Id
uidoc.ShowElements(elem)
uidoc.Selection.SetElementIds(List[ElementId]([itemId]))
objForm = FormResume(UnwrapElement(IN[0]))
objForm.Show()
ShowElements
works only with local Elements, for link Elements it’s better to use this method
You can use this code to highlight/select the elements.
import clr
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
from System.Collections.Generic import *
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
highlight = []
elements = UnwrapElement(IN[0])
elementsel = uidoc.Selection
result = []
for i in elements:
highlight.append(i.Id)
Icollection = List[ElementId](highlight)
elementsel.SetElementIds(Icollection)
result.append("Success")
OUT = result
Finally got back to this!
The Python node doesn’t like that import. Any idea why?
Edit: It seems fine with this tho:
from Autodesk.Revit.DB import ElementId
I don’t know why though.
Try reducing the scope of the import for the system.collections.generic namespace. Might be a namespace collision based on your version/environment.
I didn’t think I had that much…
import clr
clr.AddReference(“System.Windows.Forms”)
clr.AddReference(“System.Drawing”)
import System
from System.Windows.Forms import *
from System.Drawing import *
clr.AddReference(“RevitServices”)
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
from System.Collections.Generic import *
clr.AddReference(“RevitAPI”)
import Autodesk
from Autodesk.Revit.DB import *
I tried your code:
The bottom node is your code C+P exactly.
It worked fine for walls but I got errors for areas.
File “”, line 52, in InitializeComponent
AttributeError: Name<<<
Top python node is your code + I added
if hasattr(elem, ‘Name’) else " " <<
So then I got no errors for areas… but a blank form.
Then I changed “Name” to “Number” and it works for Areas but not walls.
I don’t really understand what it means by no name:
Can anyone explain?
Change the line to something which always exists…
ie: item1 = System.Windows.Forms.ListViewItem(str(elem.Id))
That works for both (and likely everything), but it may not be very descriptive to end users though. As perhaps a more useful alternative you could use a generated string. Something like this:
for elem in self._lst_Elems:
text = "Item #{0}: {1}".format(str(val),str(elem))
item1 = System.Windows.Forms.ListViewItem(text)
item1.Tag = elem
listViewItem.append(item1)
Can you explain what it means by name?
As you see I’ve named the area… So I’m guessing it’s not the identity data name.