[Bf-python] option to choose executable instead of raising error inside function

flavio soares qazav3.0 at gmail.com
Tue Oct 15 20:05:11 CEST 2013


Alright! Thanks, that's probably it! =)


2013/10/15 Bastien Montagne <montagne29 at wanadoo.fr>

>  Eh, it’s like any file, right? Just have a look around in other addons,
> many of them handle files…
>
> I would point you to official ui_translate addon, for example, but it has
> some extra complexity you do not need… Just note that simply adding
> "subtype='FILE_PATH'" parameter to a string prop definition will turn it
> into a file-selector one in the UI… ;)
>
>
> On 15/10/2013 19:38, flavio soares wrote:
>
>  Hi, Bastien,
>
>  Thanks for the link. I'll try to mess with it, but I think the addon part
> is ok. The problem is really calling a window to choose the executable and
> storing it in a variable.
>
>
> 2013/10/15 Bastien Montagne <montagne29 at wanadoo.fr>
>
>>  Hi Flavio,
>>
>> Think you are looking for AddonPreferences ?
>>
>> http://www.blender.org/documentation/blender_python_api_2_69_1/bpy.types.AddonPreferences.html
>>
>> Bastien
>>
>>
>> On 15/10/2013 19:03, flavio soares wrote:
>>
>>     Hi,
>>
>>  I'm doing an exporter to ardour and it runs an external ffmpeg. I'm
>> wondering if there is a way of letting user point to a local ffmpeg
>> executable in case it is not recognized by "which". The idea is to replace
>> the RuntimeError with something like:
>>
>> with open(self.filepath) as file:
>>             ffCommand = self.filepath
>>
>>  but this only works inside classes.
>>
>>
>>
>>  Relevant code is below:
>>
>>  this is the main class:
>>
>> class ExportArdour(bpy.types.Operator, ExportHelper):
>>     """Export audio timeline (including audios from videos) to Ardour"""
>>     bl_idname = "export.ardour"
>>     bl_label = "Export to Ardour"
>>     filename_ext = ".ardour"
>>     filter_glob = StringProperty(default="*.ardour", options={'HIDDEN'})
>>
>>     @classmethod
>>     def poll(cls, context):
>>         if bpy.context.sequences:
>>             return context.sequences is not None
>>
>>     def execute(self, context):
>>         scene = bpy.context.scene
>>         startFrame = scene.frame_start
>>         endFrame = scene.frame_end
>>         fps, timecode = checkFPS()
>>
>>         system = bpy.context.user_preferences.system
>>         audioRate = int(system.audio_sample_rate.split("_")[1])
>>
>>         audiosFolderPath, ardourFile = os.path.split(self.filepath)
>>         ardourBasename = os.path.splitext(ardourFile)[0]
>>         audiosFolder = audiosFolderPath + os.sep + "Audios_for_" +
>> ardourBasename
>>
>>         Session = createXML(startFrame, endFrame, fps, timecode,
>> audioRate,
>>                             ardourBasename, audiosFolder)
>>
>>         runFFMPEG(sources, audioRate, audiosFolder)
>>         writeXML(self.filepath, Session)
>>
>>         return {'FINISHED'}
>>
>>
>>  ..........that calls this function (notice the RunTime error):
>>
>> def runFFMPEG(sources, audioRate, outputFolder):
>>     if which('ffmpeg') is not None:
>>         if (os.name == "nt"):
>>             ffCommand = ffmpegPath + os.sep + "ffmpeg.exe"
>>         else:
>>             ffCommand = "ffmpeg"
>>     else:
>>         raise RuntimeError("You don\'t seem to have FFMPEG installed on
>> your system. \
>>                             Please install it and re-run the Ardour
>> exporter.")
>>
>>     if (os.path.exists(outputFolder) is False):
>>         os.mkdir(outputFolder)
>>
>>     for source in sources:
>>         basename, ext = os.path.splitext(source['name'])
>>
>>         input = source['origin']
>>         if (input.startswith("//")):
>>             input = input.replace("//", "")
>>
>>         output = outputFolder + os.sep + basename + ".wav"
>>
>>         # Due to spaces, the command entries (ffCommand, input and
>> output) have
>>         # to be read as strings by the call command, thus the escapings
>> below
>>         callFFMPEG = "\"%s\" -i \"%s\" -y -vn -ar %i -ac 1 \"%s\"" \
>>                      % (ffCommand, input, audioRate, output)
>>         call(callFFMPEG, shell=True)
>>
>>     return {'FINISHED'}
>>
>>
>>
>> thanks.
>>
>>  flavio
>>
>>
>>  _______________________________________________
>> Bf-python mailing listBf-python at blender.orghttp://lists.blender.org/mailman/listinfo/bf-python
>>
>>
>> _______________________________________________
>> Bf-python mailing list
>> Bf-python at blender.org
>> http://lists.blender.org/mailman/listinfo/bf-python
>>
>>
>
>
> _______________________________________________
> Bf-python mailing listBf-python at blender.orghttp://lists.blender.org/mailman/listinfo/bf-python
>
>
> _______________________________________________
> Bf-python mailing list
> Bf-python at blender.org
> http://lists.blender.org/mailman/listinfo/bf-python
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.blender.org/pipermail/bf-python/attachments/20131015/fcc11a07/attachment.html>


More information about the Bf-python mailing list