Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

CopyElements

6 REPLIES 6
SOLVED
Reply
Message 1 of 7
Moshe-A
1004 Views, 6 Replies

CopyElements

Moshe-A
Mentor
Mentor

Hi Guys

 

I need an example of ElementTransformUtils.CopyElements() from one view to others

(even copying 1 element on the same view with XYZ offset does not work)

 

My goal is copying some custom detail items (i'm using version 2015)

 

thanks

 

 

 

0 Likes

CopyElements

Hi Guys

 

I need an example of ElementTransformUtils.CopyElements() from one view to others

(even copying 1 element on the same view with XYZ offset does not work)

 

My goal is copying some custom detail items (i'm using version 2015)

 

thanks

 

 

 

6 REPLIES 6
Message 2 of 7
FAIR59
in reply to: Moshe-A

FAIR59
Advisor
Advisor

For the code from your previous question, the last 2 parameters can't be null.

Copy to the "same place" in the second view: 

 

                    ElementTransformUtils.CopyElements(actView,selection.GetElementIds(),secondView,Transform.Identity,new CopyPasteOptions());

0 Likes

For the code from your previous question, the last 2 parameters can't be null.

Copy to the "same place" in the second view: 

 

                    ElementTransformUtils.CopyElements(actView,selection.GetElementIds(),secondView,Transform.Identity,new CopyPasteOptions());

Message 3 of 7
Moshe-A
in reply to: FAIR59

Moshe-A
Mentor
Mentor

FAIR59 hey,

 

Maybe i was not so clear...i have 2 detail items simple graphics arrows one should be pointing as project north and the other should be pointing to true north

 

my application insert them in the current view + add a spot coordinates for the project base (0,0,0) + execute a Rotate on the second arrow

than i'm getting these 3 objects and copy + paste them [copyElements()] to other views (which are selected from a dialog box)

this does not work. the code is running but no copy is made and i get no exception at all.

 

so what i tried yesterday is to run it like the objects are exist by preselecting them and them invoked the command and that worked

and the 2 last args were null. 

 

Does that means that Revit API does not like my creation objects or maybe at run time my added objects are not fully prepared to be copied?

untill my application comes to it's end.

 

thnaks

Moshe

 

 

 

 

 

 

 

 

 

 

 

 

 

0 Likes

FAIR59 hey,

 

Maybe i was not so clear...i have 2 detail items simple graphics arrows one should be pointing as project north and the other should be pointing to true north

 

my application insert them in the current view + add a spot coordinates for the project base (0,0,0) + execute a Rotate on the second arrow

than i'm getting these 3 objects and copy + paste them [copyElements()] to other views (which are selected from a dialog box)

this does not work. the code is running but no copy is made and i get no exception at all.

 

so what i tried yesterday is to run it like the objects are exist by preselecting them and them invoked the command and that worked

and the 2 last args were null. 

 

Does that means that Revit API does not like my creation objects or maybe at run time my added objects are not fully prepared to be copied?

untill my application comes to it's end.

 

thnaks

Moshe

 

 

 

 

 

 

 

 

 

 

 

 

 

Message 4 of 7
FAIR59
in reply to: Moshe-A

FAIR59
Advisor
Advisor

From your last description, I think the objects are indeed "not ready" to be copied.

The safest way to solve this,  is to commit the creation transaction and to start a new transaction for the copying.

 

An alternative is to issue a Document.Regenerate(), between the creation and the copying, that might also work.

0 Likes

From your last description, I think the objects are indeed "not ready" to be copied.

The safest way to solve this,  is to commit the creation transaction and to start a new transaction for the copying.

 

An alternative is to issue a Document.Regenerate(), between the creation and the copying, that might also work.

Message 5 of 7
Moshe-A
in reply to: FAIR59

Moshe-A
Mentor
Mentor

well, i am using TransactionGroup to combine all inner Transactions for one undo. from what you are saying i understand that this is my problem

but how do you explain that after inserting the second arrow i'm using ElementTransformUtils.RotateElement() to rotate it and it works?

ElementTransformUtils.CopyElements () is in the same class.

 

i did tried Documnet.Regenerate() before coping and it didn't  work.

 

the other option i have is to loop through all  my views of interest and insert my 3 objects at each, this will maintain one undo for the user

 

am i right?

 

thanks FAIR59

Moshe

 

0 Likes

well, i am using TransactionGroup to combine all inner Transactions for one undo. from what you are saying i understand that this is my problem

but how do you explain that after inserting the second arrow i'm using ElementTransformUtils.RotateElement() to rotate it and it works?

ElementTransformUtils.CopyElements () is in the same class.

 

i did tried Documnet.Regenerate() before coping and it didn't  work.

 

the other option i have is to loop through all  my views of interest and insert my 3 objects at each, this will maintain one undo for the user

 

am i right?

 

thanks FAIR59

Moshe

 

Message 6 of 7
FAIR59
in reply to: Moshe-A

FAIR59
Advisor
Advisor
Accepted solution

The need for a regeneration , or a separate transaction has come already multiple times, see http://thebuildingcoder.typepad.com/blog/about-the-author.html#5.33

 

I think that the position of an element, while creating it is "fluid", so you can rotate it in the same transaction. A copy of the element requires a "fixed" position to copy from, so the creation transaction must be finished.

 

If you are not happy with a transactiongroup, you can indeed create several instances in different views in one transaction.

The need for a regeneration , or a separate transaction has come already multiple times, see http://thebuildingcoder.typepad.com/blog/about-the-author.html#5.33

 

I think that the position of an element, while creating it is "fluid", so you can rotate it in the same transaction. A copy of the element requires a "fixed" position to copy from, so the creation transaction must be finished.

 

If you are not happy with a transactiongroup, you can indeed create several instances in different views in one transaction.

Message 7 of 7
Moshe-A
in reply to: FAIR59

Moshe-A
Mentor
Mentor

OK, Thank you very much

 

 

0 Likes

OK, Thank you very much

 

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report