# PySegment.smart\_replace\_media fails if current media path includes a space

**URL:** <https://forum.logik.tv/t/pysegment-smart-replace-media-fails-if-current-media-path-includes-a-space/11673>\
**Category:** Flame Questions\
**Tags:** timeline, media-path\
**Created:** [November 1, 2024, 11:36pm UTC](https://forum.logik.tv/t/pysegment-smart-replace-media-fails-if-current-media-path-includes-a-space/11673 "2024-11-01T23:36:33Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![RobinScher](https://avatars.discourse-cdn.com/v4/letter/r/77aa72/32.png) [@RobinScher](https://forum.logik.tv/u/RobinScher)\
**Post date:** [November 1, 2024, 11:36pm UTC](https://forum.logik.tv/t/pysegment-smart-replace-media-fails-if-current-media-path-includes-a-space/11673/1 "2024-11-01T23:36:33Z")

</div>

Can someone help me determine if this is a Flame bug or if I’m doing something incorrectly:

I have a conformed sequence with source media where some of the original media paths have space characters in the filename. I am using custom Python code to rebuild this conformed sequence with different media I have exported previously. If I use `PySegment.smart_replace_media()`, I get an exception `RuntimeError: Invalid source clip`.

Note that if I just do a “Sequence Publish” export on the original sequence and configure it to re-import the exported media that way, it works as expected, with my exported media in the new copy of the sequence all aligned to where it is supposed to be.

Is this a bug in the `PySegment.smart_replace_media()` method in the Flame API? Am I doing something wrong? The original paths are coming from external sources, so it’s not a trivial matter to ensure they have to spaces in them before the work completes, and that’s something I’d rather not have to deal with, if possible.

Any help is appreciated. Thank you,  
-robin

---

<div class="post-metadata">

**Author:** ![philm](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.logik.tv/philm/32/9286_2.png) [@philm](https://forum.logik.tv/u/philm)\
**Post date:** [November 1, 2024, 11:39pm UTC](https://forum.logik.tv/t/pysegment-smart-replace-media-fails-if-current-media-path-includes-a-space/11673/2 "2024-11-01T23:39:55Z")

</div>

Fix the names  
If it’s coming from an external source and can be quarantined on the central storage, script a way to make hard links on the same file system with sanitized filenames.  
Keep a log of this conversion.  
Conform from the sanitized filenames.  
Program everything afterwards.

---

<div class="post-metadata">

**Author:** ![RobinScher](https://avatars.discourse-cdn.com/v4/letter/r/77aa72/32.png) [@RobinScher](https://forum.logik.tv/u/RobinScher)\
**Post date:** [November 1, 2024, 11:43pm UTC](https://forum.logik.tv/t/pysegment-smart-replace-media-fails-if-current-media-path-includes-a-space/11673/3 "2024-11-01T23:43:48Z")

</div>

You probably know how this will go, Phil, given the source of the media and the artists I am supporting…

I can certainly put that together as an option, but if this is a stupid bug in the Flame API itself, which clearly allows spaces in the names, I’d like to at least try to get Autodesk to fix it!

---

<div class="post-metadata">

**Author:** ![philm](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.logik.tv/philm/32/9286_2.png) [@philm](https://forum.logik.tv/u/philm)\
**Post date:** [November 1, 2024, 11:47pm UTC](https://forum.logik.tv/t/pysegment-smart-replace-media-fails-if-current-media-path-includes-a-space/11673/4 "2024-11-01T23:47:27Z")

</div>

I’d love to help Robin.

Meanwhile, if you want to report a bug, submit it as a support case, through the [manage.autodesk.com](http://manage.autodesk.com) site.

If you submit the python script here, there are several generous souls who will most likely fly in to the rescue with a different perspective.

Be brave brother.

Everything will work out.

---

<div class="post-metadata">

**Author:** ![philm](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.logik.tv/philm/32/9286_2.png) [@philm](https://forum.logik.tv/u/philm)\
**Post date:** [November 1, 2024, 11:57pm UTC](https://forum.logik.tv/t/pysegment-smart-replace-media-fails-if-current-media-path-includes-a-space/11673/5 "2024-11-01T23:57:41Z")

</div>

I just had a thought.  
I know:  
It’s pretty rare.

Have you read about ‘Smart Replace’ and how it works?

The capability is dependent on the existence of a sequence into which the output node (render node or write file node) can ‘Smart Replace’ the result.

Have one of the artists load a sequence, with the corresponding batch groups to a desktop.

If the output of a batch group is feeding a segment in that timeline then ‘Smart Replace’ will function as you anticipate.

If you are using Render Nodes, you can keep doing this.

If you are using Write File Nodes and openclip, you only need to do this once.

If you send those batch groups to another station, that does not have the timeline, ‘Smart Replace’ does not function.

You must have the corresponding timeline, and that can be disastrous because there is not currently an openclip equivalent of a timeline where you have version001 and version002, so two artists buggering about with the same timeline can result in irreconcilable forking.

I’m happy to videoconference and show you.

---

<div class="post-metadata">

**Author:** ![RobinScher](https://avatars.discourse-cdn.com/v4/letter/r/77aa72/32.png) [@RobinScher](https://forum.logik.tv/u/RobinScher)\
**Post date:** [November 1, 2024, 11:58pm UTC](https://forum.logik.tv/t/pysegment-smart-replace-media-fails-if-current-media-path-includes-a-space/11673/6 "2024-11-01T23:58:46Z")

</div>

FYI, you can recreate this in the Python console in Flame without a script. Just build a sequence with media that has spaces in it, import a clip with different media (without a space) and run something like this in the Python Console:

```auto
import flame
seq = flame.find_by_name("original_sequence")[0]
clip = flame.find_by_name("new_clip")[0]
segment = seq.versions[0].tracks[0].segments[0]
segment.smart_replace(clip)

```

---

<div class="post-metadata">

**Author:** ![RobinScher](https://avatars.discourse-cdn.com/v4/letter/r/77aa72/32.png) [@RobinScher](https://forum.logik.tv/u/RobinScher)\
**Post date:** [November 2, 2024, 12:00am UTC](https://forum.logik.tv/t/pysegment-smart-replace-media-fails-if-current-media-path-includes-a-space/11673/7 "2024-11-02T00:00:47Z")

</div>

Let me see what Autodesk says, but I may take you up on looking at your workaround next week. Thanks for your thoughts, Phil.

---

<div class="post-metadata">

**Author:** ![RobinScher](https://avatars.discourse-cdn.com/v4/letter/r/77aa72/32.png) [@RobinScher](https://forum.logik.tv/u/RobinScher)\
**Post date:** [November 2, 2024, 12:02am UTC](https://forum.logik.tv/t/pysegment-smart-replace-media-fails-if-current-media-path-includes-a-space/11673/8 "2024-11-02T00:02:16Z")

</div>

Also, in my case, the new replacement clip is an OpenClip, but the original sequence is conformed directly with the MOVs coming from the client (who is giving us the names with spaces).

---

<div class="post-metadata">

**Author:** ![philm](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.logik.tv/philm/32/9286_2.png) [@philm](https://forum.logik.tv/u/philm)\
**Post date:** [November 2, 2024, 12:06am UTC](https://forum.logik.tv/t/pysegment-smart-replace-media-fails-if-current-media-path-includes-a-space/11673/9 "2024-11-02T00:06:39Z")

</div>

In LOGIK-PROJEKT the write nodes automatically switch to Smart Replace after conform.  
I just teach people to turn them off when rendering v0002 or above, since the openclip segment is now injected into the timeline.  
Distributed batch groups just bump up the iteration/version so the timeline can be manipulated by script or by artist to load the latest version.  
Smart Replace is only used immediately after conform, to swap the published openclips with the required ‘comp’ openclips.  
My code is free and available if you want it:  
[LOGIK-PROJEKT](https://www.logik.tv/logikprojekt)

---

<div class="post-metadata">

**Author:** ![PhilippeJ](https://avatars.discourse-cdn.com/v4/letter/p/a5b964/32.png) [@PhilippeJ](https://forum.logik.tv/u/PhilippeJ)\
**Post date:** [November 2, 2024, 2:05pm UTC](https://forum.logik.tv/t/pysegment-smart-replace-media-fails-if-current-media-path-includes-a-space/11673/10 "2024-11-02T14:05:13Z")

</div>

> [@RobinScher](#):
>
> …u can recreate this in the Python console in Flame without a script. Just build a sequence with media that has spaces in it, import a clip with different media (without a space) and run something like this in the Python Console:import flameseq = flame.find\_by\_name(“original\_sequence”)[0]clip = flame.find\_by\_name(“new\_clip”)[0]segment = seq.versions[0].tracks[0].segments[0]segment.smart\_replace(clip)

The PySegment smart\_replace (which overwrite the sequence TimelineFX with the source clip TimelineFX) and the smart\_replace\_media (which keep the sequence TimelineFX) only accepts the source clip if it fit one of the two following condition:

- The source clip media has the same length as the media in the PySegment ( including head and tail ) or the source clip media is a virtual source ( 1 frame with infinite head and tail ).
- The source timecode at the start of the PySegment can be found somewhere in the source clip and there is enough media between that time and the end of the source clip to fill the PySegment.

---

<div class="post-metadata">

**Author:** ![RobinScher](https://avatars.discourse-cdn.com/v4/letter/r/77aa72/32.png) [@RobinScher](https://forum.logik.tv/u/RobinScher)\
**Post date:** [November 4, 2024, 4:44pm UTC](https://forum.logik.tv/t/pysegment-smart-replace-media-fails-if-current-media-path-includes-a-space/11673/11 "2024-11-04T16:44:09Z")

</div>

Thank you for that information, Philippe. I will double check those conditions in my clips and make sure it’s not something going weird there. Do you know if there is sample Python code for how to handle swapping a clip in a sequence if those conditions are not met?

Thanks,  
-robin

---

<div class="post-metadata">

**Author:** ![philm](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.logik.tv/philm/32/9286_2.png) [@philm](https://forum.logik.tv/u/philm)\
**Post date:** [November 4, 2024, 4:52pm UTC](https://forum.logik.tv/t/pysegment-smart-replace-media-fails-if-current-media-path-includes-a-space/11673/12 "2024-11-04T16:52:12Z")

</div>

[Replacing a Clip on the Timeline](https://help.autodesk.com/view/FLAME/2025/ENU/?guid=GUID-81BD0D04-D9C7-4068-B769-30FFC070A1A9)

---

<div class="post-metadata">

**Author:** ![RobinScher](https://avatars.discourse-cdn.com/v4/letter/r/77aa72/32.png) [@RobinScher](https://forum.logik.tv/u/RobinScher)\
**Post date:** [November 4, 2024, 8:03pm UTC](https://forum.logik.tv/t/pysegment-smart-replace-media-fails-if-current-media-path-includes-a-space/11673/13 "2024-11-04T20:03:51Z")

</div>

OK, with more testing it seems it is not the space that is the issue. I can’t reproduce that so there must be something else going on with that data itself I will have to look at. Thank you all for your help.

---

<div class="post-metadata">

**Author:** ![philm](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.logik.tv/philm/32/9286_2.png) [@philm](https://forum.logik.tv/u/philm)\
**Post date:** [November 14, 2024, 3:56am UTC](https://forum.logik.tv/t/pysegment-smart-replace-media-fails-if-current-media-path-includes-a-space/11673/14 "2024-11-14T03:56:42Z")

</div>

[Logik Live #140](https://www.youtube.com/live/FYNkebyiCEU?si=GbZhObhFJOaOKEIh)

This is how I use the ‘Smart Replace’ function.
