Kivy Python ThreeLineIconListItem - kivymd

I have created a list as described below. How can I handle interaction with each list item so that the selected book can be "reserved". I did not find any documentation about interactions with ThreeLineIconListItem based lists.
Any help is appreciated
for book in books:
self.ids.list.add_widget(IconLeftWidget(icon=icons[3])
)
self.ids.list.add_widget(ThreeLineIconListItem(text=f"{str(book[0])}",
secondary_text=f"{str(book[1])}",
tertiary_text=f"{str(book[2])}"
)
)

Firstly you should add the IconLeftWidget to ThreeLineIconListItem and then you can add
the ThreeLineIconListItem to your list.
for book in books:
my_icon_list = ThreeLineIconListItem(
text=f"{str(book[0])}",
secondary_text=f"{str(book[1])}",
tertiary_text=f"{str(book[2])}")
my_icon_list.add_widget(IconLeftWidget(icon=icons[3])
self.ids.list.add_widget(my_icon_list)

Related

Why does "ElementId(BuiltInCategory.OST_Walls)" fails within Revit API 2019?

I am trying to filter walls. For that I use
categories = List[ElementId]()
myId = ElementId(BuiltInCategory.OST_Walls)
categories.Add(myId)
..but this obviously doesn't return a valid ElementId, as when I print it, it has some negative value (and if I print "doc.GetElement(myId)", I get "None").
Then, indeed when creating the filter...
filter = ParameterFilterElement.Create(doc, "Walls filter", categories)
...I get an ArgumentException.
I'm using Revit 2019 (with pyRevit). As far as I remember, it used to work with Revit 2018, but I don't see any reason it shouldn't anymore. What am I missing?
Thanks a lot!
You can simply use the filtered element collector OfCategory Method.
E.g., check out The Building Coder hints on filtered element collector optimisation.
Apply an ElementCategoryFilter to the collector to get all the walls of the project. By using the following code you can filter any kind of category. I have tried this on Revit 2019.
FilteredElementCollector collector = new FilteredElementCollector(document);
ICollection<Element> walls = collector.OfCategory(BuiltInCategory.OST_Walls).ToElements();
I agree with #Mah Noor answer.
If you need to have a filter with multiple categories, you can use:
ElementCategoryFilter wallFilter = new ElementCategoryFilter(BuiltInCategory.OST_Walls);
ElementCategoryFilter windowFilter = new ElementCategoryFilter(BuiltInCategory.OST_Windows);
LogicalOrFilter wallAndWindowFilter = new LogicalOrFilter(wallFilter, windowFilter);
ICollection<Element> collection = new FilteredElementCollector(doc).WherePasses(wallAndWindowFilter);
Bonus tip, you may want to add .WhereElementIsNotElementType() or .WhereElementIsElementType() to your query.
Best regards
François

Modify selection to first element by Selection.SetElementIds

I'm having trouble writing a script that lets med select the first element in my selection. This is useful for me because i select my correct Air Terminal from a schedule (where I can see the similar air-flow which I want to use) and use the command Create Similar from the selection. The trouble is that this command does not work when multiple elements are selected. Therefore, I want the first object from the list.
This is the code which I'm trying:
from Autodesk.Revit.UI.Selection.Selection import SetElementIds
from System.Collections.Generic import List
uidoc = __revit__.ActiveUIDocument
doc = __revit__.ActiveUIDocument.Document
selection = [ doc.GetElement( elId ) for elId in __revit__.ActiveUIDocument.Selection.GetElementIds() ]
sel=[]
for i in selection:
sel.append(i.Id)
uidoc.Selection.SetElementIds(List[ElementId](sel[0]))
That will return the following error message:
Exception : Microsoft.Scripting.ArgumentTypeException: expected int, got ElementId
OK, then I'll try to replace
uidoc.Selection.SetElementIds(List[ElementId](sel[0]))
with
uidoc.Selection.SetElementIds(List[ElementId](sel[0].IntegerValue))
This seems to work, but selection is not modified
I am just starting to write RPS-scripts, but I'm hoping someone will show me what am I doing wrong here even if it is very obvious.
Thank you.
Kyrre
EDIT:
Thank you Jeremy, for solving this for me! The trick was to generate a List, not a python list. .Add method is what I did not get.
Final code if someone is interested:
from Autodesk.Revit.UI.Selection.Selection import SetElementIds
from System.Collections.Generic import List
from Autodesk.Revit.DB import ElementId
uidoc = __revit__.ActiveUIDocument
doc = __revit__.ActiveUIDocument.Document
selection = [ doc.GetElement( elId ) for elId in __revit__.ActiveUIDocument.Selection.GetElementIds() ]
sel=[]
for i in selection:
sel.append(i.Id)
ids=List[ElementId](1)
ids.Add(sel[0])
uidoc.Selection.SetElementIds(ids)
SetElementIds takes a .NET ICollection<ElementId> argument, as you can see from the Revit API documentation.
Your statement calls the .NET List constructor that expects an integrer argument specifying the number N of elements to allovate space for: List[ElementId](N).
sel[0] is an ElementId, not an integer, which causes the first error.
sel[0].IntegerValue is a (very large and semi-arbitrary) integer number, so that causes no error. However, you are still leaving the List empty, unpopulated.
You should initialise the List for one single element and add that:
ids = List[ElementId](1)
ids.Add(sel[0])

Orchard: In what table is the Blog post stored

I'm attempting to export data from an older Orchard db and am having problems finding which table the content of a blog post is stored. I've tried using a number of different 'Search all columns' spocs to search all tables and columns but am not finding text from the post itself.
If I have a blog post where the opening sentence is:
This sentence contains a unique word.
I would have expected at least one of the various 'Search all columns' examples to have turned up a table/column. But so far, none have.
thx
Orchard store data based on two tables, ContentItemRecord and ContentItemVersionRecord, which store meta data for content items like BlogPost, and these content items built from multiple parts, each part has it's table and the relation between the item and it's parts is based on Id (if not draftable) or ContentItemRecord_Id (if draftable) columns
if we take BlogPost type as example, which built from TitlePart, BodyPart, AutoroutePart and CommonPart, and you want to select all the data of post (id = 90), then you can find it's title in TitlePartRecord table (ContentItemRecord_Id = 90), and the body text of it in BodyPartRecord table with same relation as title part record, and the route part in AutorouteRecord table with same relation, and the common meta data in CommonPartRecord (Id = 90).
This is the way to extract data from Orchard database, hope this will help you.
Tnx to #mdameer...
and the related query of madmeer's answer is this:
SELECT * FROM dbo.default_Title_TitlePartRecord
inner join dbo.default_Orchard_Framework_ContentItemRecord on
dbo.default_Title_TitlePartRecord.ContentItemRecord_id=dbo.default_Orchard_Framework_ContentItemRecord.Id
inner join dbo.default_Common_BodyPartRecord on
dbo.default_Common_BodyPartRecord.ContentItemRecord_id=dbo.default_Orchard_Framework_ContentItemRecord.Id
where dbo.default_Title_TitlePartRecord.ContentItemRecord_id=90
and this is the rightsolution
Just in case it may be useful for others, the following is the actual SQL query used to migrate an Orchard instance to Umbraco. It is derived from the excellent answers by mdameerand and Iman Salehi:
SELECT t.Title, f.Data, b.Text FROM dbo.Title_TitlePartRecord t
inner join dbo.Orchard_Framework_ContentItemRecord f on
t.ContentItemRecord_id=f.Id
inner join dbo.Common_BodyPartRecord b on
b.ContentItemRecord_id=f.Id
AND b.Id = (
SELECT MAX(m2.Id)
FROM dbo.Common_BodyPartRecord m2
WHERE m2.ContentItemRecord_id = f.Id
)
AND t.Id = (
SELECT MAX(m2.Id)
FROM dbo.Title_TitlePartRecord m2
WHERE m2.ContentItemRecord_id = f.Id
)

Create a collection of item ids Revit API in Python

So I am trying to use a list of input strings to isolate them in a view using Revit API. I got this far, but I am getting stuck where I am trying to create a set that takes all elements in a view and removes ones that are created from input IDs. I am doing this to end up with a set of all elements except ones that i want to isolate.
dataEnteringNode = IN0
view = IN0
str_ids = IN1
doc = __doc__
collector = FilteredElementCollector(doc, view.Id)
for i in str_ids:
int_id = int(i)
id = ElementId(int_id)
element = doc.GetElement(id)
element_set = ElementSet()
element_set.Insert(element)
elements_to_hide = collector.WhereElementIsNotElementType().Excluding(element_set).ToElements()
#Assign your output to the OUT variable
OUT = elements_to_hide
I would greatly appreciate a help in solving this error. I am getting that "expected ICollection[ElementId], got set". I am guessing the problem lies in a Excluding filter where i need to create a collection of Ids to exclude but I dont know how. Thank you in advance. Thank you for help in advance!
The reason your code doesn't work is that ElementSet in the Revit API does not implement the ICollection<T> interface - just the IEnumerable<T>. So, to get your code working, you will need to create an ICollection<T> object from your set.
Try something like this:
# ...
from System.Collections.Generic import List
element_collection = List[ElementId](element_set)
elements_to_hide = collector.WhereElementIsNotElementType().Excluding(element_collection).ToElements()

Gorm find subset in HasMany

I have the following relation in which I want to search
class Order {
static hasMany = [articles:Article]
}
class Article {
}
In my search I select N articles and I want to find all Orders that contain all the N selected articles. So far I was only able to find all Orders that contain one of the selected Articles. It would be great if anyone can help me on this.
Order.executeQuery("select o from Order o join o.articles as a where a in (:articleList)", [articleList: articleList])

Resources