Combine two lists together

Hi

I have a request where we have text notes to be able to jump to these. I have filtered them out per view, but i have two lists.

One is the ID and one is the text. Is there a way of combining these together?

Hi @jstillplowman

?

hi

i am looking to have the ID and the text word in one list.

ie

0 Wall opening with inner 2207600

hi, kind of but i want to keep the ID number “clickable” so it will take them to the text note.

the image shows the result im hoping.

It is possible, but it would require you to look at/edit the source code of Dynamo and create a new node.

thanks, i had a feeling it wasnt easy to do - will work with two lists for now

Combine your two lists using List.Create, then do a Transpose. That’s the closest you’ll get with OOTB Dynamo…

1 Like

@jstillplowman One possibility is to use winforms. I did a quick test, but was not able to make it work for more than one textnote.

If anybody know how to pass the id as a argument in the button.Click event I would be very happy if you tell me. (se commented out code for my trials). @Dimitar_Venkov maybe?

import clr
import System
clr.AddReference("System.Drawing")
clr.AddReference("System.Windows.Forms")

from System.Drawing import Point
from System.Windows.Forms import Application, Button, Form, Label

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
uidoc=DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument

txtNote = UnwrapElement(IN[0])

class TextNoteShower(Form):

	def __init__(self):
		self.Text = 'Text note finder'
		self.Width = 410

		n=1
		self.label = Label()
		self.label.Text = txtNote.Text
		self.label.Location = Point(50, 50*n)
		self.label.Height = 30
		self.label.Width = 200
		
		button = Button()
		button.Text = "Show in Revit"
		button.Width = 100
		button.Location = Point(260, 50*n)
				
		button.Click += self.buttonPressed
		#button.Click += lambda event, id=txtNote.Id: self.buttonPressed(event, id) 
		self.Controls.Add(self.label)
		self.Controls.Add(button)
		n=n+1
		
	def buttonPressed(self, sender, args):
		#uidoc.ShowElements(id)
		uidoc.ShowElements(txtNote.Id)


form = TextNoteShower()
Application.Run(form)

OUT = 0
1 Like

You’ve got a lot of options.

You can sub-class the button class and give it an id property that stores a reference to the element id.

Or if you have a matching list of buttons and ids, you could find the index of the button and get the appropriate id.

I would personally reuse the infrastructure provided by dynamo and sub-class the element type:

3 Likes

thank you so much all, this is brilliant!

it is a bit out my depth at the moment, do you have the code to share Dimitar?

Dimitar, you make it look too easy! How much more code do you need to make a ZeroTouch node from that? I will try and see what I can figure out, starting with the Wiki:

I’ll wrap it up in a node later today.

1 Like

thank you so much!

You’ll find below a very minimal ZT implementation of the above script:

using System;
using Revit.Elements;
using RVT = Autodesk.Revit.DB;

namespace Revit.Elements
{
    public class TextPreview : Element
    {
        public override RVT.Element InternalElement {get;}

        public override string ToString()
        {
            var t1 = (RVT.TextNote) InternalElement;
            return t1.Text;
        }

        public TextPreview(Element element)
        {
            RVT.Element e1 = element.InternalElement;
            InternalElement = e1;
            InternalElementId = e1.Id;
            InternalUniqueId = e1.UniqueId;
        }
    }
}

edit:
You’ll need to reference just three assemblies:

  • “DynamoServices.dll” from “C:\Program Files\Dynamo\Dynamo Core\1.2\DynamoServices.dll”

And then, once you build it, you’ll end up with a library, similar to this one, which I complied for Revit 2017 and Dynamo 1.2.

You can finally add the compiled library in Dynamo:

and have it available as a node:

3 Likes

Thank you very much for this Dimitar. However I’m not able to make it work…

  1. When I try to import the ready compiled library i get the (not very helpful) error “Failed to load library”. (Tested in Dynamo for Revit 1.2.0 and Revit 2017.1)

  2. When I try to compile the code in Sharp Develop i get the following error on line 11:

‘Revit.Elements.TextPreview.InternalElement.get’ must declare a body because it is not marked abstract or extern. Automatically implemented properties must define both get and set accessors. (CS0840) - C:\Users\eibre\Documents\SharpDevelop Projects\Revit-TextNote\Program.cs:11,10

I tried to add a body by editing line 11 to get { return null; } but then i recieved another error on line 23:

Property or indexer ‘Revit.Elements.Element.InternalElement’ cannot be assigned to – it is read only (CS0200) - C:\Users\eibre\Documents\SharpDevelop Projects\Revit-TextNote\Program.cs:23,13

When I browse the RevitNodes library Revit.Elements.Element Internal Element looks like this:

		public abstract Element InternalElement
		{
			get;
		}

So I guess the warnings make sense, since the method is abstract and does not have a set accessor.

I was using visual studio community. You can download it for free from here.

It seems that SharpDevelop can’t create auto-properties automatically, unlike VS. In that case, you should modify the code a bit and create the internal property manually:

using System;
using Revit.Elements;
using RVT = Autodesk.Revit.DB;

namespace Revit.Elements
{
    public class TextPreview : Element
    {
        private RVT.Element _InternalElement;
        public override RVT.Element InternalElement {get{return _InternalElement;} }

        public override string ToString()
        {
            var t1 = (RVT.TextNote) InternalElement;
            return t1.Text;
        }

        public TextPreview(Element element)
        {
            RVT.Element e1 = element.InternalElement;
            _InternalElement = e1;
            InternalElementId = e1.Id;
            InternalUniqueId = e1.UniqueId;
        }
    }
}

Also, in my effort to simplify the example, it seems I removed one assembly reference that is also needed for ZT. You’ll need to reference the “DynamoServices.dll” found in “C:\Program Files\Dynamo\Dynamo Core\1.2\DynamoServices.dll”

Just did a quick test in sharpDevelop and built the node again for Revit 2016 and Dynamo 1.1:

SharpDevelop should work fine for simpler nodes like this one, but the DynamoDS and DynamoRevit repositories are unfortunately built with visual studio. Therefore you might experience other unexpected problems if you use SD. :confused:

3 Likes

Hi @Einar_Raknes

dll file which @Dimitar_Venkov has provided works fine. I tested from my side. Make sure you “Unblock” dll file by right clicking it.

1 Like

Thank you again Dimitar, it works now. (And I have a much better understanding of subclassing and overriding). I do like the lightwheightness of Sharp Develop, but I will download VS in case I run into similar problems.