ElementTransformUtils.CopyElements Error

ElementTransformUtils.CopyElements Error

PaulCollins7972
Advocate Advocate
3,295 Views
11 Replies
Message 1 of 12

ElementTransformUtils.CopyElements Error

PaulCollins7972
Advocate
Advocate

Hi Everyone

 

I am trying to copy elements from one sheet to another which works ok until I try and copy lines

 

I am finding the elements to copy like this (for text)

 

'get text items
Dim Collector_Text As FilteredElementCollector = New FilteredElementCollector(doc, SourceView.Id)
Dim Filter_Text As ElementClassFilter = New ElementClassFilter(GetType(TextElement))
Dim FoundElements As ICollection(Of ElementId) = Collector_Text.WherePasses(Filter_Text).ToElementIds()

 

Then using

 

ElementTransformUtils.CopyElements(sourceView, ElementsToCopy, targetView, Transform, CopyPasteOptions)

 

So far so good. This works fine if I store the ids of text and generic annotations.

 

However if I add the ids of Lines, which I find like this 

 

'get line elements
Dim Collector_Lines As FilteredElementCollector = New FilteredElementCollector(doc, SourceView.Id).WherePasses(New ElementClassFilter(GetType(CurveElement)))
For Each e As Element In Collector_Lines
 FoundElements.Add(e.Id)
Next

 

then I get these errors:

 

Capture1.JPGCapture2.JPG

 

I have tried changing the active view to the target view but this makes no difference.

 

Anyone got any ideas?

 

Paul Collins

0 Likes
Accepted solutions (1)
3,296 Views
11 Replies
Replies (11)
Message 2 of 12

arnostlobel
Alumni
Alumni
Paul, I have our copy'n'paste expert looking into it. He will give me his assessment at the beginning of the next week. I will let you know what he would find.
Arnošt Löbel
0 Likes
Message 3 of 12

PaulCollins7972
Advocate
Advocate

Thanks Arnošt

0 Likes
Message 4 of 12

Revitalizer
Advisor
Advisor

Hi,

 

you need to read the documentation of ElementClassFilter.

"There is a small subset of Element subclasses in the API which are not supported by this filter."...

"Subclasses of Autodesk.Revit.DB.CurveElement"...

 

If you filter CurveElements, you may get both ModelCurves and DetailCurves and also the lines of existing Sketches, which are also some sort of ModelCurve.

 

The error message may reflect this fact since ModelCurves need a proper SketchPlane.

In your target document, these SketchPlanes are probably missing.

 

 

Revitalizer




Rudolf Honke
Software Developer
Mensch und Maschine





Message 5 of 12

arnostlobel
Alumni
Alumni

Paul,

 

I've got a word from our copy'n'paste expert, quote:

 

"Most plan views already have some sort of a work plane, so it ought to work as is. There might be something else at play. Difficult to tell without seeing what he’s really doing. Can we ask for a file? Or at least what sorts of view he’s copying from/to, so I can try to reproduce it"

 

So, my conclusion is: when you happen to copy curves from a view I'd assume the curves are on some work plane. And, since you want the curves to be copied to another view I'd also assume that the target view too has a work plane set. If you case is indeed as I have described but the copy operation still fails, my colleague would need to have more information so he could reproduce it.

 

Thanks

Arnošt Löbel
0 Likes
Message 6 of 12

PaulCollins7972
Advocate
Advocate

Arnošt

 

This is part of a routine to duplicate sheet views.

 

 

In my test I drew a single straight detail line on a sheet, along with a text element and a generic annotation symbol (e.g. a north point or scalebar).

 

I used my code sample in previous post to get the element id's and then attempted to copy/paste to the newly created sheet, to duplicate things that may have been added by a user.

 

Text and generic sysmbols copy OK, the detail line caused the error.

 

Example R2015 file attached.

 

Paul

0 Likes
Message 7 of 12

arnostlobel
Alumni
Alumni

Paul, the straight detail line you try to copy is on a sheet that contains a work plane. Now, in the new sheet you created and want to copy to, have you created a work plane there too? Because of you did not and if there is no default one either, curves could not be copied to the new sheet, for they need a work plane. Can you confirm? It is not obvious from your posted code snippet how did you get the target view.

Thank you

Arnošt Löbel
0 Likes
Message 8 of 12

PaulCollins7972
Advocate
Advocate

Arnošt, I created a new sheet but no work plane.

 

Can you give me a hint as to how to do that? I can find code in the API help for creating sketch planes and reference planes but not sure how to create a plane on a viewsheet.

 

Thanks, Paul

0 Likes
Message 9 of 12

PaulCollins7972
Advocate
Advocate

Found this on AEC Devblog which looks like it should do it, its for an older version of Revit though and some code is obseleted.

 

http://adndevblog.typepad.com/aec/2012/07/creating-active-work-plane-of-the-view-using-revit-api.htm...

 

Paul

0 Likes
Message 10 of 12

PaulCollins7972
Advocate
Advocate

Or maybe not.

 

I changed the code from the blog to Revit 2015 version as

 

'create a workplane in the new view
Dim plane As New Plane(newSheet.ViewDirection, newSheet.Origin)
Dim sp As SketchPlane = SketchPlane.Create(doc, plane)
newSheet.SketchPlane = sp
newSheet.ShowActiveWorkPlane()

 

but because the new view is a sheet view model lines are not allowed through the UI so not surprisingly got this error:

ErrorCapture.JPG

 

The blog suggests that this is how to create a working plane in a view, but not a sheet it seems.

 

Help appreciated!

 

Paul

0 Likes
Message 11 of 12

arnostlobel
Alumni
Alumni
Accepted solution

Paul,

 

I was actually going to suggest something similar to what you found. I've talked to some other developers in the office (those that are not on vacation yet!) and we came to a conclusion that a possible way is to create a detail curve in your target sheet view, which should trigger automatic adding of a reference plane. That's what we believe anyway. This workaround is also mentioned in the blog you found (at the very end.) I assume you'd add the curve in the same transaction in which you paste the elements from your source view. You can probably delete the curve too, but you need to stay in the same transaction, naturally. I would also call Regenerate after the curve was added. Give it a try and let me know if it worked. If it does not, I'll try digging deeper.

 

Have a nice weekend.

Arnošt Löbel
0 Likes
Message 12 of 12

PaulCollins7972
Advocate
Advocate

Arnošt

 

Excellent, thanks very much, it worked!

 

I created a temporary detail curve on my new sheet, stored the id's of text, lines, symbols etc on the existing sheet and then copied and pasted.

Finally I deleted the temporary detail line.

 

Paul

0 Likes