Issues calling ksconvert from Python

Hi Agustin.
I’m writing a script in Python that executes from within Blender.
I’ve crafted a call to the os using (assuming you might be familiar with Python) “os.system(blah blah blah)” command, where blahx3 is a string that emulates calling ksconvert with the appropriate parameters.
I’ve got the string correct and it works in a Windows command window.
In the Python case though, no window pops ups and I get a sterr message “Couldn’t set1024x768 OpenGL video mode: OpenGL not available”.
Do you have ANY idea how I can resolve this? Between Blender, Python, OpenGL, SDL and Windows, it’s hard to even know who to go to or where to start… :o My best guess is that I’m running into some kind of context problem since the command is originating from within the Python environment inside Blender. ugh.

edit: I just looked at the hex of ksconvert.exe and saw a string ‘this program cannot be run from DOS mode’. Am I sh*t out of luck?
Maybe I can craft, save, and execute a batch file…peuw!

Maybe this is a good time to bug you for a cleaner executable :slight_smile:

Oops. I’m still traveling abroad, but as soon as I return a properly functioning “dgconvert” is among my top priorities. Just a bit more patience! :nod:

Sent from my iPhone using Tapatalk

I don’t know if this will help at all but this is the script for my convertor

[code]#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=…DocumentsbatchImage1.ico
#AutoIt3Wrapper_Res_requestedExecutionLevel=asInvoker
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
AutoItSetOption(“TrayIconDebug”, 1);0-off
;TraySetState(2)
;combi box fix $CBS_DROPDOWNLIST)
#include <String.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <ComboConstants.au3>
#include <GUIListBox.au3>
#include <ProgressConstants.au3>
Opt(“GUIOnEventMode”, 1);We need this otherwise our GUI will not be OnEvent Mode.

#Region ### START Koda GUI section ### Form=C:UsersnigeDesktopksconvertform.kxf
$Form1 = GUICreate(“DGConverter GUI”, 520, 569, -1, -1)
$Button1 = GUICtrlCreateButton("…", 128, 24, 35, 25)
$Label1 = GUICtrlCreateLabel(“Path to the DGConverter.exe”, 32, 20, 95, 34)
$PathInp = GUICtrlCreateInput("", 168, 24, 329, 21)
$Input2 = GUICtrlCreateInput("", 176, 60, 121, 21)
$Combo1 = GUICtrlCreateCombo(“tga”, 352, 60, 145, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))
GUICtrlSetData(-1, “tga|jpg|tiff|png|bmp|TGA|JPG|TIFF|PNG|BMP”)
$Label2 = GUICtrlCreateLabel(“Image set 1”, 32, 64, 59, 17)
$Label3 = GUICtrlCreateLabel(“000X”, 304, 60, 41, 17)
$Label4 = GUICtrlCreateLabel(“Image set 2”, 31, 90, 59, 17)
$ImgTwo = GUICtrlCreateInput("", 175, 90, 121, 21)
$Label5 = GUICtrlCreateLabel(“000X”, 303, 90, 41, 17)
$Combo2 = GUICtrlCreateCombo(“tga”, 351, 90, 145, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))
GUICtrlSetData(-1, “tga|jpg|tiff|png|bmp|TGA|JPG|TIFF|PNG|BMP”)
$Label6 = GUICtrlCreateLabel(“Image set 3”, 30, 120, 59, 17)
$Imgthree = GUICtrlCreateInput("", 174, 120, 121, 21)
$Label7 = GUICtrlCreateLabel(“000X”, 302, 120, 41, 17)
$Combo3 = GUICtrlCreateCombo(“tga”, 350, 120, 145, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))
GUICtrlSetData(-1, “tga|jpg|tiff|png|bmp|TGA|JPG|TIFF|PNG|BMP”)
$Label8 = GUICtrlCreateLabel(“Image set 4”, 32, 150, 59, 17)
$Imgfour = GUICtrlCreateInput("", 176, 150, 121, 21)
$Label9 = GUICtrlCreateLabel(“000X”, 304, 150, 41, 17)
$Combo4 = GUICtrlCreateCombo(“tga”, 352, 150, 145, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))
GUICtrlSetData(-1, “tga|jpg|tiff|png|bmp|TGA|JPG|TIFF|PNG|BMP”)
$Label10 = GUICtrlCreateLabel(“Image set 5”, 32, 180, 59, 17)
$ImgFive = GUICtrlCreateInput("", 175, 180, 121, 21)
$Label11 = GUICtrlCreateLabel(“000X”, 303, 180, 41, 25)
$Combo5 = GUICtrlCreateCombo(“tga”, 351, 180, 145, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))
GUICtrlSetData(-1, “tga|jpg|tiff|png|bmp|TGA|JPG|TIFF|PNG|BMP”)
$Button2 = GUICtrlCreateButton(“Convert!”, 424, 534, 80, 25)
$Button3 = GUICtrlCreateButton(“Save Image set”, 424, 210, 80, 25)
$Group1 = GUICtrlCreateGroup(“Help”, 8, 256, 257, 297)
$Edit2 = GUICtrlCreateEdit("", 16, 280, 233, 257, BitOR($ES_AUTOVSCROLL,$ES_AUTOHSCROLL,$ES_READONLY))
GUICtrlSetData(-1, StringFormat(“Select the path to the GConverter.exe.rnAdd you imageset, select the first image in thernset.rnChange image format if required.rnClick the save image set button.rnYou can add more imagesets by adding newrnsets,simply change the image fieldsrnand use the image set button to addrnqueue.rnClick the convert button.rnWait for conversion complete.”))
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Edit1 = GUICtrlCreateEdit("", 280, 238, 225, 289)
$imgbtn = GUICtrlCreateButton("…", 129, 60, 35, 25)
$imgbtn2 = GUICtrlCreateButton("…", 129, 90, 35, 25)
$imgbtn3 = GUICtrlCreateButton("…", 129, 120, 35, 25)
$imgbtn4 = GUICtrlCreateButton("…", 129, 150, 35, 25)
$imgbtn5 = GUICtrlCreateButton("…", 129, 180, 35, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

GUICtrlSetOnEvent($Button1, “ButtonFunction1”) ; The button’s function#include <ButtonConstants.au3>
GUICtrlSetOnEvent($Button3, “ButtonFunction2”) ; The button’s function
GUICtrlSetOnEvent($Button2, “ButtonFunction3”) ; The button’s function
GUICtrlSetOnEvent($imgbtn, “ButtonFunction4”) ; The button’s function
GUICtrlSetOnEvent($imgbtn2, “ButtonFunction5”) ; The button’s function
GUICtrlSetOnEvent($imgbtn3, “ButtonFunction6”) ; The button’s function
GUICtrlSetOnEvent($imgbtn4, “ButtonFunction7”) ; The button’s function
GUICtrlSetOnEvent($imgbtn5, “ButtonFunction8”) ; The button’s function
GUISetOnEvent($GUI_EVENT_CLOSE, “ExitGUI”) ; What function to call when we try close the GUI
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit

EndSwitch

WEnd
Func ButtonFunction1()
$savepath = FileSelectFolder(“Select DGConverter.exe location”, “”, 2)
GUICtrlSetData($PathInp, $savepath & “”)
;FileCopy(".binDGConverter.exe", $savepath &".")
;FileCopy(".binglew32.dll", $savepath &".")
;FileCopy(".binSDL.dll", $savepath &".")
EndFunc ;==>ButtonFunction1

Func ButtonFunction2()

$path = GUICtrlRead($PathInp)
$read1 = GUICtrlRead($Input2)
$read3 = GUICtrlRead($Combo1)
$read2 = GUICtrlRead($Edit1)
$read4 = GUICtrlRead($ImgTwo)
$read5 = GUICtrlRead($Combo2)
$read6 = GUICtrlRead($Imgthree)
$read7 = GUICtrlRead($Combo3)
$read8 = GUICtrlRead($Imgfour)
$read9 = GUICtrlRead($Combo4)
$read10 = GUICtrlRead($ImgFive)
$read11 = GUICtrlRead($Combo5)
If GUICtrlRead($PathInp) = “” Then
MsgBox(0, “Error”, “Enter a save path!”)
Return
EndIf
If GUICtrlRead($Input2) = “” Then
Local $Line1 = ‘‘
Else
Local $Line1 = ‘DGConverter ’ &’"’ & $read1 &’"’ & ’ ’ & $read3
EndIf
If GUICtrlRead($ImgTwo) = “” Then
Local $Line2 = ‘‘
Else
Local $Line2 = ‘DGConverter ’ &’"’ & $read4 &’"’ & ’ ’ & $read5
EndIf
If GUICtrlRead($Imgthree) = “” Then
Local $Line3 = ‘‘
Else
Local $Line3 = ‘DGConverter ’ &’"’ & $read6 &’"’ & ’ ’ & $read7
EndIf
If GUICtrlRead($Imgfour) = “” Then
Local $Line4 = ‘‘
Else
Local $Line4 = ‘DGConverter ’ &’"’ & $read8 &’"’ & ’ ’ & $read9
EndIf
If GUICtrlRead($ImgFive) = “” Then
Local $Line5 = ‘‘
Else
Local $Line5 = ‘DGConverter ’ &’"’ & $read10 &’"’ & ’ ’ & $read11
EndIf
$read2 = GUICtrlRead($Edit1)
If GUICtrlRead($Edit1) = “” Then
$text = $read2 &"cd " &$Path & @CRLF & $Line1 & @CRLF & $Line2 & @CRLF & $Line3 & @CRLF & $Line4 & @CRLF & $Line5
Else
$text = $read2 & @CRLF & $Line1 & @CRLF & $Line2 & @CRLF & $Line3 & @CRLF & $Line4 & @CRLF & $Line5
EndIf
GUICtrlSetData($Edit1, $text) ; Set the edit control to have our new data!
MsgBox(4096, “”, “Queue added”)
EndFunc ;==>ButtonFunction1

Func ButtonFunction3()
$path = GUICtrlRead($PathInp)
$read2 = GUICtrlRead($Edit1)
If GUICtrlRead($Edit1) = “” Then
MsgBox(0, “Error”, “no images stored”)
Return
EndIf
$file = FileOpen($path & “convert.bat”, 10) ; which is similar to 2 + 8 (erase + create dir)

FileWrite($file, $read2)
FileClose($file)
MsgBox(4096, "Bat file created:", $path  & "convert.bat")
If $file = -1 Then
	MsgBox(0, "Error", "Unable to open file.")

EndIf

FileClose($file)

ShellExecute($path & “convert.bat”)

Do
$process = ProcessExists(“cmd.exe”)
Until $process = 0 ; Until process is gone
MsgBox(0, “Complete”, “Conversion complete”)

EndFunc

Func ButtonFunction4()

Local $message = "Add a Image Set"

Local $var = FileOpenDialog($message, "" & "", "Images (*.tga;*.png;*.jpg;*.hdr;*.bmp;*.tiff)", 1 + 4)
If @error Then
	MsgBox(4096, "", "No File(s) chosen")
Else
	$var = StringReplace($var, "|", @CRLF)
	MsgBox(4096, "", "Selected image " & $var)
	Local $result = StringTrimRight($var, 8)

;MsgBox(0, “String without leftmost 3 characters is:”, $result)
GUICtrlSetData($Input2, $result)

	EndIf

EndFunc
Func ButtonFunction5()

Local $message = "Add a Image Set"

Local $var = FileOpenDialog($message, "" & "", "Images (*.tga;*.png;*jpg)", 1 + 4)
If @error Then
	MsgBox(4096, "", "No File(s) chosen")
Else
	$var = StringReplace($var, "|", @CRLF)
	MsgBox(4096, "", "Selected image " & $var)
	Local $result = StringTrimRight($var, 8)

;MsgBox(0, “String without leftmost 3 characters is:”, $result)
GUICtrlSetData($ImgTwo, $result)

	EndIf
EndFunc

Func ButtonFunction6()

Local $message = "Add a Image Set"

Local $var = FileOpenDialog($message, "" & "", "Images (*.tga;*.png;*jpg)", 1 + 4)
If @error Then
	MsgBox(4096, "", "No File(s) chosen")
Else
	$var = StringReplace($var, "|", @CRLF)
	MsgBox(4096, "", "Selected image " & $var)
	Local $result = StringTrimRight($var, 8)

;MsgBox(0, “String without leftmost 3 characters is:”, $result)
GUICtrlSetData($Imgthree, $result)

	EndIf

EndFunc
Func ButtonFunction7()

Local $message = "Add a Image Set"

Local $var = FileOpenDialog($message, "" & "", "Images (*.tga;*.png;*jpg)", 1 + 4)
If @error Then
	MsgBox(4096, "", "No File(s) chosen")
Else
	$var = StringReplace($var, "|", @CRLF)
	MsgBox(4096, "", "Selected image " & $var)
	Local $result = StringTrimRight($var, 8)

;MsgBox(0, “String without leftmost 3 characters is:”, $result)
GUICtrlSetData($Imgfour, $result)

	EndIf
EndFunc

Func ButtonFunction8()

Local $message = "Add a Image Set"

Local $var = FileOpenDialog($message, "" & "", "Images (*.tga;*.png;*jpg)", 1 + 4)
If @error Then
	MsgBox(4096, "", "No File(s) chosen")
Else
	$var = StringReplace($var, "|", @CRLF)
	MsgBox(4096, "", "Selected image " & $var)
	Local $result = StringTrimRight($var, 8)

;MsgBox(0, “String without leftmost 3 characters is:”, $result)
GUICtrlSetData($ImgFive, $result)

	EndIf

EndFunc
Func ExitGui()
$ExitDialog =MsgBox(36, “Are You Sure?”, “Are you sure you want to exit?”)
If $ExitDialog = 6 Then

Exit

Else
Return
EndIf
;Exit ; Exit the program
EndFunc ;==>ExitGui
[/code]

I’m taking a wild guess here but have you imported the opengl lib in your python script?

I tried importing bgl, opengl as presented inside blender. Right now it’s all guess work. I like to create, not play detective. It’s why I don’t program as much as I used to…programming seems to be more about banging away a things rather than planning them out anymore.