- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I am attempting to automate VRED through the Web Interface as described in this Autodesk University tutorial:
http://au.autodesk.com/au-online/classes-on-demand/class-catalog/2015/vred/at10281#chapter=0
The tutorial uses the following python script to attach to the web interface:
import urllib
import socket
# Function to send a command to VRED and optionally return a response.
def sendVredCmd(cmd, replyNeeded):
reply = None
cmd = urllib.quote(cmd)
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(("localhost", 8888))
s.send("GET ")
if replyNeeded:
s.send("/pythoneval?value=")
else:
s.send("/python?value=")
s.send(cmd)
s.send(" HTTP/1.1\r\n\r\n")
if replyNeeded:
reply = s.recv(5000)
s.close()
return reply
I am trying to use this method, but access VRED using VB .net. Below is a simplified version of the code I have tried. Eventually I plan to have two way communication with VRED, but for now I am just attempting to send a simple print command.
Imports System.Text
Imports System.IO
Imports System.Net.Sockets
Public Class Main
Private Sub GoButton_Click(sender As Object, e As EventArgs) Handles GoButton.Click
Dim sResp As String = SendVREDCmd("print 'Test'", False) '"getActiveCameraNode().getWorldTransform()", True)
End Sub
Private Const sServiceSite As String = "http://localhost:8888"
Private Const sContentType = "application/x-www-form-urlencoded"
Private Function SendVREDCmd(sPython As String, bReply As Boolean) As String
' Create byte array
Dim sPostData As String
If bReply Then
sPostData = "/pythoneval?value="
Else
sPostData = "/python?value="
End If
sPostData &= sPython
Dim byteArray As Byte() = Encoding.ASCII.GetBytes(sPostData)
' Mothod #1 - Socket
Dim oClient As New TcpClient(System.Net.Sockets.AddressFamily.InterNetwork)
oClient.Connect("localhost", 8888)
oClient.SendBufferSize = byteArray.Length
Dim oNetStream As NetworkStream = oClient.GetStream()
oNetStream.Write(byteArray, 0, byteArray.Length)
oNetStream.Flush()
oNetStream.Close()
oClient.Close()
' Mothod # 2 - Web Request - Post
Dim oReqPost As Net.WebRequest = Net.WebRequest.Create(sServiceSite)
oReqPost.Method = "POST"
oReqPost.ContentLength = byteArray.Length
Dim oStream As Stream = oReqPost.GetRequestStream()
oStream.Write(byteArray, 0, byteArray.Length)
oStream.Close()
oStream = Nothing
' Mothod #3 - Web Request - Get
Dim oReqGet As Net.WebRequest = Net.WebRequest.Create(sServiceSite & sPostData)
oReqGet.Method = "GET"
oReqGet.ContentType = sContentType
Dim oResp As Net.WebResponse = oReqGet.GetResponse()
Return ""
End Function
End Class
All 3 of the methods failed. The first two fail silently. The third method actually executes the python "print" command twice (printing "Test" twice in the terminal window) and errors out giving "The underlying connection was closed: The connection was closed unexpectedly."
Does anybody have any experience using the Web Interface for executing python scripts? I know this isn't a .net forum but maybe someone has tried something other than python.
Thanks for any help you can provide.
Solved! Go to Solution.