Apply Function Multiple Times

Hi,

I’m trying to duplicate an element multiple times, but I just couldn’t wrap my head around the while function and the way functions can be applied in code blocks.

I tried transferring a function into a variable and then calling it from within the while loop, but that doesn’t seem like it’s working. Anyone has any suggestions or knows what I’m doing wrong?

duplicate%20multiple

Can you show which output you were expecting?

Also, are you insistent on a designscript solution or would python be ok?

If design script is your weapon of choice then I can recommend the literature uploaded in this post:

I was expecting the output from the multiple duplicate functions that I was trying to apply. Instead I got null.

Honestly, neither designscript nor python are very comfortable weapons for me as of yet. But I just tried to dive into it without understanding everything because the LoopWhile node didn’t seem to give me what I want.

The documentation for designscript is not very thorough for beginners, and there isn’t a lot of examples.

What i was looking for was more along the lines of a crude sketch of your inputs and the outputs from that I can reverse engineer a python script that performs the desired objective :slight_smile:

The reason I ask like this is that I cannot from your upload tell what you’re trying to do :slight_smile:

Ah I see, I thought it was clear. I made a rough sketch, let me know if that clears things up or if it’s still not clear.
I’ll also copy here the contents of the duplicate element node that I have in case it’s needed.

#Copyright (c) mostafa el ayoubi
#Node-mode 2016 elayoub.mostafa@gmail.com

import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
import Autodesk

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

from System.Collections.Generic import*

doc = DocumentManager.Instance.CurrentDBDocument

if isinstance(IN[0],list):
	views = UnwrapElement(IN[0])
else:
	views = [UnwrapElement(IN[0])]

ids = [view.Id for view in views]

elementlist = List[ElementId](ids)

TransactionManager.Instance.EnsureInTransaction(doc)
for view in views:

	copyid = ElementTransformUtils.CopyElements(doc, elementlist, doc, Transform.Identity, CopyPasteOptions())
	newview = [doc.GetElement(id) for id in copyid]

TransactionManager.Instance.TransactionTaskDone()

OUT = newview

2 Likes

While they are very useful to learn, I am not sure you need to use a loop here… list.ofrepeateditems to create a list of the floor element, into the element.duplicate node should work.

That said, if you’re open to learning some python or design script then you should keep at it.

2 Likes

Ah that’s a neat trick! I didn’t know you could repeat the same element in a list.

Thanks for the encouragement. Any comments on what I did wrong in the script in my first screenshot, as a general concept?

Oh, and why does it output only one element? Any simple way to collect all the outputs?
(it works fine by duplicating the required number of times, it just shows only one output for some reason)

Generally for the type of function you are making a while loop is not the best method, this is more used when there are some “if’s” in your condition.

A “for” loop would be more efficient.

Secondly the name “element” is reserved so this cannot be bound.
You are not returning a variable so this will not return anything.
don’t think you can assign a “value” by using “dop(flr)” , I’ll see if I can make a working example later.

1 Like

Oh, I see, that makes sense. I have to learn to apply the most appropriate flow method for the function.
Thanks for the pointers!

Try and use List.Map instead, with your list of repeated items in “list”:
image

2 Likes