Sketch Lines - Edit, Copy, Paste

Hello Dynamo Community,

I would like to get the sketch lines of a floor and copy it to another one.
Getting the lines is not a big deal:

In 2018 there was no method to edit the sketch lines, but how about today?

Thankful for any advice, thanks :slight_smile:

Kind regards

Doable if you are in Revit 2022. Are you?

yes I am :smiley:


I did my best searching APIDOCS for any information, but i can`t find anything usefull. You have any additional info for me? :slight_smile:

Looking at this is in my backlog… Which is large, ever expanding, and has to be triaged based on my day job, impact of solution, ask, time needed to implement, and the like. Maybe later tonight or if I boot up the work laptop over the weekend.

It might be easier to copy the entire floor to the new location/level since you are bulk grabbing the curves.

So I dug into this in conjunction with another thing which was easy. Figured “that’ll be a five minute fix now, super easy!” Well… I figured wrong.

This kinda works, fairly consistently in IronPython2.7. But not consistently in CPython, due to some really crazy stuff in the IFailuresPreprocessor Interface class, which is a requirement to get into when you edit a sketch (there are too many things which can fail for it to not have that extra check to prevent the copy if you’ve done something silly). But this mostly works. If the sketch edit fails you may find your system gets ‘stuck’ in sketch edit mode, which stinks as you can’t cancel the operation in the UI for some reason. Also you may find subsequent runs create a duplicate copy of the sketch lines producing an error… think this is a function of the custom class being poorly implemented on my part, or perhaps the sketch edit API really doesn’t like not being compiled at run time… again, this mostly works, but just in case you should sync often.

It currently only does one set of sketch lines to another; if you need more you will want to wrap it in a custom node or add a looping mechanism in the code.

As underwhelming as that may all sound, it’s really nice looking when it works. Go ahead and give it a go, and let me know how it works out.

Copy_sketch_lines_to_element_-_share_out.dyn.dyn (11.8 KB)


Hi Jacob…thats amazing :wink:

the lack of support (not completely) for Net interfaces with CPython/PythonNet is currently for me one of the main pain


Thank you very much @jacob.small

I´m happy to test it.

For now it does not work, but i can tell you why.

Using your code gives errors because of overlapping lines and crossing lines:


I get the exact same result when i copy the sketch lines from one floor to the other one:

sketch 2

So i think your code is not deleting the sketch lines from the target floor before pasting them, like i do it in revit:

sketch 3

That would require adding new stuff into the code base, which wasn’t my intent to build. In your case you want the exact same floor at the next level, why not copy the element with the desired shape and deleting the incorrect shape to that level instead of editing the incorrectly shaped one? Easily 10x more stable and reliable.

1 Like

I’m planning on raising this and a few other CPython things with the development team next week - feel free to DM me and I’ll add anything else you have to my list.

1 Like

Oh, then i don´t even know what the intended use of your code is, can you explain please?

It was a request of my coworkers to update sketchlines by the sketch lines of another floor. We are talking about a finished model with finished plans. Deleting a floor will mess up everything i guess (annotations, dimensioning, connections, etc…).

Some issues should be resolved with the upcoming release of PythonNet 3.0.

For the Interfaces it would seem that the instances remain in memory (not Disposable?) and this during the entire Revit session (because the CPython3 interpreter is active during the entire Revit session, once executed)


Add a few openings in slab B which are not in slab A. Run the code. Openings move from A to B.

As noted above and in the Python notes… there is a lot which will prevent execution. Of the infinite possible sets of lines being moved over, a sizable fraction of them will cause an error (anything crosses, anything not closed, anything touching except at an end point, etc.) Unfortunately type of error handling isn’t going to come easy enough that it instantly comes together on a Friday night in conjunction with the larger build out.

If the intent is to simply wipe the old sketch that could be added without as much work, but that is a larger update as removing elements will create it’s own issues in the code sequencing (I think an error may be returned if a sketch is empty even if a transaction is open… or at least that used to be the case the last time I hacked at this stuff pre sketch API).

I’ll see if it is a quick enough fix all the same at some point next week.

1 Like

OK, but i think this is currently not possible, because all sketch lines are moved and so is the outline of the slab which is then overlapping:

Yeah - slab A and B can’t have the same limits. I’ll look at this Monday, but I feel like a complete deletion would ruin more than it would help. Lol

1 Like

Ignoring the outline of the slab, so the sketch line loop with the largest area, would be exactly what i need too!

Copying all sketch lines if the limits are not equal will give the following result, what was expected.

and the other way round:

(these are the results of your code)

That was the intent. Might not be exactly your use case but it was pretty much perfect for the other case (where non-aligned floors wanted an aligned elevator shaft, copying the outline of the pit slab to every other level so the shaft wall could run continuously).

1 Like

Modified version here:
modify sketch to given lines - share out.dyn.dyn (22.2 KB)

Works like this:
First use: Copy lines to show overlapping making a non-issue.
Second use: Completely overwrite old sketch, making the new shape instead.
Third use: Moving sketch lines between non-parallel sketch planes… That wasn’t a part of the stated request but this is my free time and I had an need for this on a project back when I was practicing, so why not go crazy with it?

There are some limits, and be certain that the edited shape doesn’t lose any hosted elements (ie: doors in a wall that no longer touches the door’s insertion point) and other dependent elements (ie: I am not sure that there isn’t a situation where a model line somehow hosted open the sketch but outside the sketch itself could be removed - initial testing shows it is ok). I have provided the previous curves as well as a list of the actual model elements which were removed from the model as a ‘undoable check’ should there be a future need for debugging this.

Hope this squares you away. :slight_smile: