How to copy element from view to another view?


#1

I use method ElementTransformUtils.CopyElements Method (View, ICollection(ElementId), View, Transform, CopyPasteOptions) to copy some 2D element from one view to another. it’s error like picture below “document expected…” Maybe it don’t understand my method, we have another method to copy element from document to another document : ElementTransformUtils.CopyElements Method (Document, ICollection(ElementId), Document, Transform, CopyPasteOptions). But i just only want to copy element from view to view, don’t want to copy from document to document. Anyone has idea ?? Thanks.Untitled


#2

Still need a solution for this.

Thanks


#3

Still need a solution for this.

Thanks


#4


#5

Hi ORGANON,

How could I change it if I want it just for one element? It works for a list of elements, but doen’t for just one.

 

THks


#6

Hi ORGANON, Thank you for your help. So we need ElementIds collection and 5 arguments for that method : Transform and CopyPasteOptions will be set null.

Thank you.


#7

Manel,

You need to check your list count. I had the same problem and wasn’t sure why, here’s my workaround. (There are probably much better ways which some proper Python programmer could tell you as I’m no expert with python. ps. I haven’t handled null inputs, but that 's easy):

c = o

try:
c = len(IN[0])
except:
c = 1

if c > 1:

#Do something with a list

else:

#Do something with one item

 


#8

Hi Daniel,
With the new forum I can’t see your python script properly


#9

Yeah… Not sure that would compile! Haha!

c = 0

try:
c = len(IN[0])
except:
c = 1

if c > 1:
do something to list…
else:
do something to item…

That’s the basic principle I’ve used, but I use C# and only been using Python for a little while just for Dynamo. Like I said before, there’s probably many ways to do this better, this is my workaround. One thing I did notice the other day to be aware of is if you are using strings as input, doing len(IN[0]) with one item in list will return the length of the input strings characters, so use isinstance method to check for string inputs, if it is a string then assume that the list length is 1.


#10

Thks Daniel,

The thing is I’m not good with python, so I understand your point, but I don’t know how to change the pyton script in order to use it with an item or a list.

c = 0
try:
c = len(IN[0])
except:
c = 1
if c > 1:
c = ElementTransformUtils.CopyElements(view1,elementsId,view2,None,None)
else:
do something to item… (What should I change to do that?)

Thks


#11

Hi Manel, This works for me.


#12

Thks Daniel,
It works perfectly


#13