Python Command to render vray - python

Making a small script to write out .vrscenes for me, however I'm a little stick with getting them to render.
I'm using the pymel render command, which seems to call the maya software renderer rather than vray itself ignoring all the rendersettings I have set. Anyone know if there is an alternative command?
Thanks, sorry if this has been asked before!
script as follows;
frames = 100
split = 1
location = "/Users/adamcheshire/Desktop/testing/testScene"
# Create a list of render frames evenly split
framesToRender = frames/split
listToRender = []
start = 1
end = framesToRender
for i in range(0, split):
listToRender.append([start, end])
start += framesToRender
end += framesToRender
# Make sure final element == to frames
listToRender[-1] = [listToRender[-1][0], frames]
# init vrscene mode
vray = pm.ls('vraySettings')[0]
DRG = pm.ls('defaultRenderGlobals')[0]
vray.vrscene_render_on.set(0)
vray.vrscene_on.set(1)
DRG.animation.set(1)
vray.animBatchOnly.set(0)
# Set and Render
for i in range(0, len(listToRender)):
DRG.startFrame.set(listToRender[i][0])
DRG.endFrame.set(listToRender[i][1])
vray.vrscene_filename.set(location+"_s"+str(listToRender[i][0])+"_e"+str(listToRender[i][1])+".vrscene")
pm.render()
#pm.batchRender()

i think it's something like:
pm.vrend()

Related

Process 100 of feature classes through script and feature class name to end of each output

NOTE: Work constraints I must use python 2.7 (I know - eyeroll) and standard modules. I'm still learning python.
I have about 100 tiled 'area of interest' polygons in a geodatabase that need to be processed through my script. My script has been tested on individual tiles & works great. I need advice how to iterate this process so I don't have to run one at a time. (I don't want to iterate ALL 100 at once in case something fails - I just want to make a list or something to run about 10-15 at a time). I also need to add the tile name that I am processing to each feature class that I output.
So far I have tried using fnmatch.fnmatch which errors because it does not like a list. I changed syntax to parenthesis which did NOT error but did NOT print anything.
I figure once that naming piece is done, running the process in the for loop should work. Please help with advice what I am doing wrong or if there is a better way - thanks!
This is just a snippet of the full process:
tilename = 'T0104'
HIFLD_fc = os.path.join(work_dir, 'fc_clipped_lo' + tilename)
HIFLD_fc1 = os.path.join(work_dir, 'fc1_hifldstr_lo' + tilename)
HIFLD_fc2 = os.path.join(work_dir, 'fc2_non_ex_lo' + tilename)
HIFLD_fc3 = os.path.join(work_dir, 'fc3_no_wilder_lo' + tilename)
arcpy.env.workspace = (env_dir)
fcs = arcpy.ListFeatureClasses()
tile_list = ('AK1004', 'AK1005')
for tile in fcs:
filename, ext = os.path.splitext(tile)
if fnmatch.fnmatch(tile, tile_list):
print(tile)
arcpy.Clip_analysis(HIFLD_fc, bufferOut2, HIFLD_fc1, "")
print('HIFLD clipped for analysis')
arcpy.Clip_analysis(HIFLD_fc, env_mask, HIFLD_masked_rds, "")
print('HIFLD clipped by envelopes and excluded from analysis')
arcpy.Clip_analysis(HIFLD_masked_rds, wild_mask, HIFLD_excluded, "")
print('HIFLD clipped by wilderness mask and excluded from analysis')
arcpy.MakeFeatureLayer_management(HIFLD_fc1, 'hifld_lyr')
arcpy.SelectLayerByLocation_management('hifld_lyr', "COMPLETELY_WITHIN", bufferOut1, "", "NEW_SELECTION", "INVERT")
if arcpy.GetCount_management('hifld_lyr') > 0:
arcpy.CopyFeatures_management('hifld_lyr', HIFLD_fc2)
print('HIFLD split features deleted fc2')
else:
pass

Python consumes excessive memory, doesn't complete run even given adequate memory

I am writing a code for an information retrieval project, which reads Wikipedia pages in XML format from a file, processes the string (I've omitted this part for the sake of simplicity), tokenizes the strings and build positional indexes for the terms found on the pages. Then it saves the indexes to a file using pickle once, and then reads it from that file for the next usages for less processing time (I've included the code for that parts, but they're commented)
After that, I need to fill a 1572 * ~97000 matrix (1572 is the number of Wiki pages, and 97000 is the number of terms found in them. Like each Wiki page is a vector of words, and vectors[i][j] is, the number of occurrences of the i'th word of the word set in the j'th Wiki Page. (Again it's been simplified but it doesn't matter)
The problem is that it takes way too much memory to run the code, and even then, from a point between the 350th and 400th row of the matrix beyond, it doesn't proceed to run the code (it doesn't stop either). I thought the problem was with memory, because when its usage exceeded my 7.7GiB RAM and 1.7GiB swap, it stopped and printed:
Process finished with exit code 137 (interrupted by signal 9: SIGKILL)
But when I added a 6GiB memory by making a swap file for Python3.7 (using the script recommended here, the program didn't run out of memory, but instead got stuck when it had 7.7GiB RAM + 3.9GiB swap memory occupied) as I said, at a point between the 350th and 400th iteration of i in the loop at the bottom. Instead of Ubuntu 18.04,I tried it on Windows 10, the screen simply went black. I tried this on Windows 7, again to no avail.
Next I thought it was a PyCharm issue, so I ran the python file using the python3 file.py command, and it got stuck at the very point it had with PyCharm. I even used the numpy.float16 datatype to save memory, but it had no effect. I asked a colleague about their matrix dimensions, they were similar to mine, but they weren't having problems with it. Is it malware or a memory leak? Or is it something am I doing something wrong here?
import pickle
from hazm import *
from collections import defaultdict
import numpy as np
'''For each word there's one of these. it stores the word's frequency, and the positions it has occurred in on each wiki page'''
class Positional_Index:
def __init__(self):
self.freq = 0
self.title = defaultdict(list)
self.text = defaultdict(list)
'''Here I tokenize words and construct indexes for them'''
# tree = ET.parse('Wiki.xml')
# root = tree.getroot()
# index_dict = defaultdict(Positional_Index)
# all_content = root.findall('{http://www.mediawiki.org/xml/export-0.10/}page')
#
# for page_index, pg in enumerate(all_content):
# title = pg.find('{http://www.mediawiki.org/xml/export-0.10/}title').text
# txt = pg.find('{http://www.mediawiki.org/xml/export-0.10/}revision') \
# .find('{http://www.mediawiki.org/xml/export-0.10/}text').text
#
# title_arr = word_tokenize(title)
# txt_arr = word_tokenize(txt)
#
# for term_index, term in enumerate(title_arr):
# index_dict[term].freq += 1
# index_dict[term].title[page_index] += [term_index]
#
# for term_index, term in enumerate(txt_arr):
# index_dict[term].freq += 1
# index_dict[term].text[page_index] += [term_index]
#
# with open('texts/indices.txt', 'wb') as f:
# pickle.dump(index_dict, f)
with open('texts/indices.txt', 'rb') as file:
data = pickle.load(file)
'''Here I'm trying to keep the number of occurrences of each word on each page'''
page_count = 1572
vectors = np.array([[0 for j in range(len(data.keys()))] for i in range(page_count)], dtype=np.float16)
words = list(data.keys())
word_count = len(words)
const_log_of_d = np.log10(1572)
""" :( """
for i in range(page_count):
for j in range(word_count):
vectors[i][j] = (len(data[words[j]].title[i]) + len(data[words[j]].text[i]))
if i % 50 == 0:
print("i:", i)
Update : I tried this on a friend's computer, this time it killed the process at someplace between the 1350th-1400th iteration.

python + objectlistview + updatelist

I have an objectlistview. I remove a line from it and then I want to update the list without the removed line. I fill the list with data from a database. I tried repopulatelist, but then it seems to use the data that is already in the list.
I think I can solve it with clearAll (clearing the list) and then addobjects and add the database again. But it seems that it should be possible to just update the list. This is my code:
def deletemeas(self):
MAid = self.objectma.id
MAname = self.pagename
objectsRemList = self.tempmeasurements.GetCheckedObjects()
print 'objectremlist', objectsRemList
for measurement in objectsRemList:
print measurement
Measname = measurement.filename
Measid = database.Measurement.select(database.Measurement.q.filename == Measname)[0].id
deleteMeas = []
deleteMeas.append(MAid)
deleteMeas.append(Measid)
pub.sendMessage('DELETE_MEAS', Container(data=deleteMeas)) #to microanalyse controller
#here I get the latest information from the database what should be viewed in the objectlist self.tempmeasurements
MeasInListFromDB = list(database.Microanalysismeasurement.select(database.Microanalysismeasurement.q.microanalysisid == MAid))
print 'lijstmetingen:', MeasInListFromDB
#this doesn't work
self.tempmeasurements.RefreshObjects(MeasInListFromDB)
Ok, this was actually easier than I thought ...
I added this line:
self.tempmeasurements.RemoveObject(measurement)
So I first removed the data from my database table and then I just removed the line in my objectlistview.

Issue with python class in Kodi, trying to write a UI to replace Kodi generic menu with PYXBMCT

I'm quite new to python class's and have not really used them much so please feel free to point out any other errors except the one I point out.
What I'm trying to achieve is a new UI in Kodi using the pyxbmct module. I'm sending through a list of things (still yet to work out how I'm going to sort the split to next process with the modes but that's the next task)
My Lists are as such:
List = [['[COLOR darkgoldenrod][I]Search[/I][/COLOR]','',904,'http://icons.iconarchive.com/icons/icontexto/search/256/search-red-dark-icon.png','','',''],
['[COLOR darkgoldenrod][I]Menu Test[/I][/COLOR]','',905,'http://icons.iconarchive.com/icons/icontexto/search/256/search-red-dark-icon.png','','','']]
process.Window_Menu_Class(List)
Then obviously being sent through to the Window_Menu_Class() to attempt to display the name(s) in a List and also display a icon to the right but alternating depending on where you are focused in the List.
Code for Window_Menu_Class :-
import pyxbmct
List = []
class Window_Menu_Class():
fanart = 'http://www.wall321.com/thumbnails/detail/20121108/creepy%20video%20games%20castles%20diablo%20tristram%20creep%20diablo%20iii%20sanctuary%201920x1080%20wallpaper_www.wall321.com_92.jpg'
iconimage = ICON
power = 'http://herovision.x10host.com/fb_replays/power.png'
power_focus = 'http://herovision.x10host.com/fb_replays/power_focus.png'
text = '0xffffffff'
window_menu = pyxbmct.AddonDialogWindow('')
Background=pyxbmct.Image(fanart)
Icon=pyxbmct.Image('', aspectRatio=2)
button = pyxbmct.Button('', noFocusTexture=power,focusTexture=power_focus)
window_menu.setGeometry(1250, 650, 100, 50)
nameList = pyxbmct.addonwindow.List(_space=11,_itemTextYOffset=0,textColor=text)
window_menu.connect(button, window_menu.close)
window_menu.connect(pyxbmct.ACTION_NAV_BACK, window_menu.close)
window_menu.placeControl(Background, -5, 0, 110, 51)
window_menu.placeControl(nameList, 65, 1, 50, 20)
window_menu.placeControl(Icon, 30, 30, 60, 18)
name_list = []; url_list = []; mode_list = []; iconimage_list = []; fanart_list = []; desc_list = []; extra_list = []
def __init__(self,List):
self.Window_Menu(List)
def Window_Menu(self,List):
for item in List:
name = item[0]
url = item[1]
mode = item[2]
iconimage = item[3]
fanart = item[4]
desc = item[5]
extra = item[6]
if not name in self.name_list:
self.nameList.addItem(name);self.name_list.append(name);self.url_list.append(url);self.mode_list.append(mode);self.iconimage_list.append(iconimage);self.fanart_list.append(fanart);self.desc_list.append(desc);self.extra_list.append(extra)
self.create_window(name,url,mode,iconimage,fanart,desc,extra)
self.window_menu.doModal()
def create_window(self,name,url,mode,iconimage,fanart,desc,extra):
self.window_menu.setFocus(self.nameList)
self.window_menu.connectEventList(
[pyxbmct.ACTION_MOVE_DOWN,
pyxbmct.ACTION_MOVE_UP,
pyxbmct.ACTION_MOUSE_MOVE],
self.LIST_UPDATE(name,url,mode,iconimage,fanart,desc,extra))
def LIST_UPDATE(self,name,url,mode,iconimage,fanart,desc,extra):
if self.window_menu.getFocus() == self.nameList:
pos=self.nameList.getSelectedPosition()
Iconimg=self.iconimage_list[pos]
Fanart =self.fanart_list[pos]
self.Icon.setImage(Iconimg)
self.Background.setImage(Fanart)
but I receive the error -
File "C:\Users*\AppData\Roaming\Kodi\addons\plugin.video.sanctuary\lib\process.py", line 74, in LIST_UPDATE
if self.window_menu.getFocus() == self.nameList:
RuntimeError: Non-Existent Control 0
If I hash out the if self.window_menu.getFocus() == self.nameList: then it works but, it doesn't alter the image in the list when you move on to the next item, I have a working version but it was all done in one .py file and no need for class at all, however now I am trying to separate the code into different .py files i needed to create a class to contain all the info and give a starting point. Hope this is enough information and appreciate any feedback.
Your problem does not have a simple answer because you are doing it wrong at both Python level and PyXBMCt level (I'm the author of PyXBMCt, BTW).
First, I strongly recommend you to learn Python classes: how they are defined, how they are initialized, how they are used.
When you get that in order, then I strongly recommend to read PyXBMCt documentation which is now hosted here: http://romanvm.github.io/script.module.pyxbmct/ Look into the examples, including the example plugin, that show how to use PyXBMCt. For example, what is this window_menu.placeControl(Background, -5, 0, 110, 51)? PyXBMCt does not use pixels, it places controls in a grid with rows and columns and you need to set up the grid first.
Anyway, I recommend to start with Python stuff first.

How do I send NLTK plots to files?

I'm using NLTK to create dispersion plots and do a few other things. Trouble is, I have to manually close the window that creating a dispersion plot opens to get the code to continue running. How can I send the plot to a file and keep the script moving? I assume I'll have the same problem with other plots. I can see from the NLTK source that dispersion_plot already includes pylab.show() so maybe this isn't possible without writing my own plotting function?
Here's my code that stops at line 2 until I close the Python window that opens with the plot.
1 # do some analysis
2 disp_plot(days, key_terms)
3 diversity_table(days, "Day")
Here's the disp_plot function:
# dispersion plots for search terms
def disp_plot(texts, terms):
concat_text = ''.join(texts.values())
tokens = nltk.word_tokenize(concat_text)
text = nltk.Text(tokens)
text.dispersion_plot(terms)
I ran into the same problem and solved it by reassigning pylab.show to my own function. You might do something like this:
import pylab
counter = 0
def filename_generator():
global counter
to_return = 'myfig{0}.png'.format(counter)
counter += 1
return to_return
def my_show():
return pylab.savefig(filename_generator())
and change your disp_plot() to look like
def disp_plot(texts, terms):
concat_text = ''.join(texts.values())
tokens = nltk.word_tokenize(concat_text)
text = nltk.Text(tokens)
pylab_orig_show = pylab.show
pylab.show = my_show
text.dispersion_plot(terms)
pylab.show = pylab_orig_show
Some would argue about the global, but this is just a quick hack to get the library to do what you want.

Categories

Resources