Open Source Platform
for interconnected virtual worlds

Content Scripting Python Change Mediaurl

From RexWiki

Contents

Preface

This page shows how to create a script which can be used for changing mediaurls.

To use this script:

  1. Make sure server is down
  2. Add the python class from below to "\rexserver\ScriptEngines\PythonScript\Samples" folder to a file named samplemediaurl.py
  3. Open "\rexserver\ScriptEngines\PythonScript\Samples\__init__.py" file and add samplemediaurl.py to the end of the list
  4. Start servers
  5. Create a texture with a mediaurl in it
  6. Create a prim and add the mediaurl texture to it
  7. To the same prim define "samplemediaurl.MediaUrlPrim" for it's Class Name.
  8. Add to Rex tab-> Data the correct parameter (see below Rex data for prim with mediaurl texture). Remember to press the Set button below the Data to set it.
  9. Stop editing the prim.
  10. Create a prim and define "samplemediaurl.MediaUrlChanger" for it's Class Name.
  11. Add to Rex tab-> Data the correct parameters (see below Rex data for prim which changes mediaurl when touched). Remember to press the Set button below the Data to set it.
  12. Stop editing the prim.
  13. Touch the prim you created last to change the url of the texture.

Rex data for prim with mediaurl texture

The following text is a sample for Rex tab->Data for the prim which has the mediaurl texture.

http://www.realxtend.org

Parameter descriptions line by line are as follows:

  • Line 1: The first shown url.


Rex data for prim which changes mediaurl when touched

The following text is a sample for Rex tab->Data for the prim which has the mediaurl texture.

bffcccb6-562a-4c71-9384-ed0074ad57c0
http://www.slashdot.org

Parameter descriptions line by line are as follows:

  • Line 1: UUID of the mediaurl prim
  • Line 2: New url.

To get the prim UUID you can go to View->Object List. Doubliclick your prim on the list or select it from the 3D view and then press the Copy UUID button in the Object List window.


Python script

The following python script should be added to a file named samplemediaurl.py.

import rxactor
import rxavatar
import sys
import clr

asm = clr.LoadAssemblyByName('OpenSim.Region.ScriptEngine.Common')
Vector3 = asm.OpenSim.Region.ScriptEngine.Common.LSL_Types.Vector3

class MediaUrlPrim(rxactor.Actor):
    def GetScriptClassName():
        return "samplemediaurl.MediaUrlPrim"

    def EventCreated(self):
        super(self.__class__,self).EventCreated()
        print "samplemediaurl.MediaUrl"
        self.rexSetTextureMediaURL(self.rexGetPrimFreeData())

    def SetNewMediaUrl(self,newurl):
        self.rexSetTextureMediaURL(newurl)


class MediaUrlChanger(rxactor.Actor):
    def GetScriptClassName():
        return "samplemediaurl.MediaUrlChanger"

    def EventCreated(self):
        super(self.__class__,self).EventCreated()
        print "samplemediaurl.MediaUrlChanger"
        self.MyMediaUrlPrim = None
        self.MyMediaUrl = ""
        self.RefreshData()

    def EventTouch(self,vAvatar):
        self.RefreshData()
        
        if(self.MyMediaUrlPrim != None):
            self.MyMediaUrlPrim.SetNewMediaUrl(self.MyMediaUrl)
        else:
            print "Target prim for mediaurl change not found"
        
        
    def RefreshData(self):
        myfreedata = self.rexGetPrimFreeData()
        paramlistlines = myfreedata.splitlines()
        
        templocalid = self.GetPrimLocalIdFromUUID(paramlistlines[0])
        self.MyMediaUrlPrim = self.MyWorld.GetActorByLocalID(str(templocalid))
        self.MyMediaUrl = paramlistlines[1]