Select control on second rig - python

I am trying to transfer controls from one rig to another.
I think I have most of it figured out but I'm getting a bit stuck.
I have a function that I am feeding, the duplicated control that I want to attach as well as the list of controls from the original rig that I need to find to move the control to.
My issue is that I keep getting this error:
Error: ValueError: file line 132: More than one object matches name: Index_2_L_ctrl
I searched through everything and I'm pretty sure that there is only one thing named each, but I can't figure out how to list any additional items named the same way. Or better yet to get rid of them.
Here is my function; let me know if anything is unclear I will try to clarify:
def spltString(wtlf, arr):
ndp = wtlf
print ndp
dlb = difflib.get_close_matches(ndp, arr)
fil = dlb[0]
cmds.pointConstraint(ndp, dlb[0])

Try passing in the long names of the controls you want, rather than the short names. That will disambiguate different copies of Index_2_L_ctrl
You can find all of the copies of the control like this:
controls = cmds.ls('Index_2_L_ctrl', long = True)
the results will be object names with the complete hierarchy prepended, like
|skeleton|pelvis|spine1|spine2|chest|r_arm|r_forearm
or whatever. cmds.ls() with the long=True flag will convert short names to long ones for you.
It's a good habit to use long names most of the time precisely because of the problems you're having.

Related

Copying and reorganizing data from one table to another in sqlite3 with python

Here's my issue. I have a bunch of data organized like this:
(bad_table)
Name.......Thing...... Count
Dave........Houses.......1
Bob..........Cars............2
Jeff...........Boats..........1
Bob..........Houses.......1
Dave........Kids............3
Jeff..........Cars............3
And I’d like to have it organized like this:
(good_table)
Name.....Houses.......Boats.....Cars
Dave...........1................0.............0
Bob.............1................0.............2
Jeff..............0................1.............3
This is simplified; I’d actually like to make a table with hundreds of Things/Columns, but you get the idea.
My approach has been to create a good_table with columns for Name, Houses, Boats, Cars, and rows for Dave, Bob and Jeff, but with no other values filled in.
Then for each Name, I would create a list of tuples (I think) from the original bad_table by saying, for example
Items = cur.execute(“SELECT Thing, Count FROM bad_table WHERE Name = Dave”)
Which gives me an “Items” that looks like [(‘Houses’, 1), (‘Boats’, 0), (‘Cars’, 0), (‘Kids’, 3)].
Then I would say,
For item in Items:
Thing = item[0]
Count = item[1]
cur.execute(“INSERT INTO good_table ? = ? WHERE Name = Dave”, (Thing, Count))
Which should, I would think, in the first instance translate to
“INSERT INTO good_table Houses = 1 WHERE Name = Dave”
This doesn’t produce any errors when I run it, but it also doesn’t actually insert anything into my good_table.
I’ve also tried running it with
(“UPDATE good_table SET ? = ? WHERE Name = Dave”, (Name, Count))
in case the problem was that sqlite3 was treating the ‘None’ values in the (to my mind) empty columns as already filled in. But, that didn’t work either.
If you can’t tell, I’m pretty new to all of this (python, SQL, etc.) and rely a lot on trial-and-error (along with, of course, a very thorough reading of the documentation).
The potential sources of my problem that I can think of are:
1) Not every “Thing” from the bad_table corresponds to a column in the good_table (e.g. “Kids”). I would hope that sqlite would simply skip over my attempts to “INSERT INTO” the good_table data that won’t fit there, but I don’t know that.
2) More likely, though, is that I’m formatting something wrong, or leaving out a comma or a set of curly braces or something where I need them. Which is why I’ve come to you good people for advice.
It doesn’t seem like what I’m trying to do should be very complicated, but I’m completely stumped and I’d really appreciate it if anyone can point out where I’ve gone wrong or suggest a better approach.

Instancing maya objects with a sequential suffix, object name string not seen by cmds.instance

I have a question about string usage in lists in python for Maya. I am writing a script meant to take a selected object, then instance it 100 times with random translate, scale, and orient attributes. The script itself works and does what it's meant to, however I'm not being able to decipher how to instance the objects with the original object name, and then add a suffix that ends with "_instance#", where # assigns 1, 2, 3, etc. in order to the copies of the original mesh. This is where I'm at so far:
#Capture selected objects, sort into list
thing = MC.ls(sl=True)
print thing
#Create instances of objects
instanceObj = MC.instance(thing, name='thing' + '_instance#')
This returns a result that looks like "thing_instance1, thing_instance2".
Following this, I figured the single quote around the string for the object was causing it to just name it "thing", so I attempted to write it as follows
MC.instance(thing, name=thing + '_instance1'
I guess because instance uses a list, it's not accepting the second usage of the string as valid and returns a concatenate error. I've tried rewriting this a few times and the closest I get is with
instanceObj = MC.instance(thing)
which results in a list of (pCube1,2,3,4), but is lacking the suffix.
I'm not sure where to go from here to end up with a result where the instanced objects are named with the convention "pCube1_instance1, pCube1_instance2" etc.
Any assistance would be appreciated.
It is not clear if you want to use only one source object or more. In any case the
MC.ls(sl=True)
returns a list of strings. And concatenating a list and a string does not work. So use thing[0] or simply
MC.ls(sl=True)[0]
If you get errormessages, please always include the message in your question, it helps a lot to see what error appears.

using input as both an array and a string

I feel like there is a simple solution to this but I am kinda new.
stat_input= input("Hello Mr. Jenner, what are you interested in tracking today?")
I use an input like this which later is used to call upon data and uses that data to calculate statistics and produce histogram charts / normal distributions.
It works quite nicely. Here are some examples where it is used.
cur.execute('SELECT {} FROM statdata'.format(stat_input))
np.array(stat_input).astype(np.float)
sigma = math.sqrt(np.var(stat_input))
So if I type threemonthdata it will pull the array of data from my database and use it . Its great. However, I have one small problem
I understand that threemonthdata refers to an array. Since I am creating charts, I want to use the input as the title so the chart title identifies what data I am drawing and using (as a reference in the future)
ax.set_title('stat_input')
This doesn't work
ax.set_title(' + stat_input + ')
Nor does this. I want the title to say Threemonthdata. But if I input twomonthdata I want it to say twomonthdata and not give me the array of numbers.
Any ideas?
I have never played with psycopg's cursor class. But, from what I can read, it appears that this one does the job for you of turning your string in place into a list whose name is the same as the referring string.
Thus what about defining another viariable to store the string before it is overriden ? As follows
stat_input_title = stat_input.capitalize()
cur.execute('SELECT {} FROM statdata'.format(stat_input))
Henceforth, stat_input_title and stat_input can be used together withouh conflicting.
ax.set_title(stat_input_title)
It looks like the issue you are facing is that you are passing the set_title() a string 'stat_input', and not the variable stat_input. You likely simply need to use:
ax.set_title(stat_input)

I have a python tuple of namedtuples. Is there a way to access individual members other than by indexing or unpacking them?

I have a python 3.5 tuple where a typical structure of a data item is something like this.
item = (PosixPath('/mnt/dson/Music/iTunes/iTunes Music/funtoons.mp3'), tagtypes(txt=False, word=False, ebook=False, image=False, exe=False, iso=False, zip=False, raw=False, audio=True, music=True, photoshop=False, video=False, src=False, geek=False, pdf=False, appledouble=False, dot=False), fileinfo(size=13229145, datetime=1333848240.0))
This describes a common file on my Linux filesystem. If I want to know the size
of the given file, I can access it with something like this ---
item[2].size. Similarly, logic to grab the tags describing the file's contents would use code like --- item[1].music, etc..
It seems on the face of it, with each object being unique in the tuple
that if you wanted to access one of the members, you should be able to
drill down in the tuple and do something like item.fileinfo.size. All of
the information to select the correct item from the tuple is deducible
to the interpreter. However, if you do attempt something like
item.fileinfo.size you will get (almost expectedly) an attribute error.
I could create a namedtuple of namedtuples but that has a bit of a code smell to it.
I'm wondering if there is a more pythonic way to access the members of the tuple other than by indexing or unpacking. Is there some kind of
shorthand notation such that you convey to the interpreter which one of
the tuple's elements you must be referencing (because none of the other
options will fit the pattern)?
This is kind of a hard thing to explain and I'm famous for leaving out
critical parts. So if more info is needed by the first responders, please
let me know and I'll try and describe the idea more fully.
You really think doing this:
Item = namedtuple('Item', 'PosixPath tagtypes fileinfo')
item = Item(PosixPath('/mnt/dson/Music/iTunes/iTunes Music/funtoons.mp3'), tagtypes(txt=False, word=False, ebook=False, image=False, exe=False, iso=False, zip=False, raw=False, audio=True, music=True, photoshop=False, video=False, src=False, geek=False, pdf=False, appledouble=False, dot=False), fileinfo(size=13229145, datetime=1333848240.0))
is not worth it if it lets you do item.fileinfo.size AND item[2].size ? That's pretty clean. It avoids creating classes by hand and gives you all the functionality in a clear and concise manner. Seems like pretty good python to me.

Creating dictionary from xlsx: TypeError: argument of type 'Book' is not iterable

I'm pretty new to Python (and the xlrd module), so my code is probably not nearly as compact as it could be. I'm just using it to analyse some data, so it's more important for me to get what I'm doing rather than for me to make the code as compact as possible (though I do hope to improve, so feel free to give me advice on the coding itself, provided you manage to explain it to a 'newbie' :p )
That being said, here's my issue:
Context
I have an xlsx file with data on errors that people made when translating a text. The first column contains a code for the error relative to the text (conceptual errors), the second column contains a code for the translator that made the error. I want to create a dictionary in which the keys are the conceptual error codes, and the values are lists of the different translators that made that conceptual error.
An short fragment from the xlsx (to give you an idea of the codes in the two columns):
1722_Z1_CF5 1722_HT_EV_Z1_F1
1722_Z1_CF1 1722_PE_AL_Z1_F1
1722_Z1_CF9 1722_PE_EVC_Z1_F1
1722_Z1_CF5 1722_PE_LH_Z1_F1
As you can see, the conceptual error '1722_Z1_CF5' has been made by 2 different people ('1722_HT_EV_Z1_F1' and '1722_PE_LH_Z1_F1). The dictionary for this fragment would look something like:
1722_Z1_CF5: 1722_HT_EV_Z1_F1, 1722_PE_LH_Z1_F1
1722_Z1_CF1: 1722_PE_AL_Z1_F1
1722_Z1_CF9: 1722_PE_EVC_Z1_F1
Code
The code below is what I tried to do to create the dictionary.
def TranslatorsPerError(sheet):
TotalConceptualErrors(sheet)
TranslatorsPerError = {}
for row_index in range(sheet.nrows):
if sheet.cell(row_index,0).value in ConceptualErrors and sheet.cell(row_index,0).value not in TranslatorsPerError:
TranslatorsPerError[str(sheet.cell(row_index,0).value)]=[str(sheet.cell(row_index,1).value),]
if sheet.cell(row_index,0).value in ConceptualErrors and sheet.cell(row_index,0).value in TranslatorsPerError:
TranslatorsPerError[str(sheet.cell(row_index,0).value)].append(str(sheet.cell(row_index,1).value))
return TranslatorsPerError
'TotalConceptualErrors' is a function I created that returns a list ('ConceptualErrors') of the conceptual error codes from the first column without duplicates (and it filters out some other information that was also present in the first column, that's why I needed to use this one first).
Problem
The problem is that this function keeps giving me an error: TypeError: argument of type 'Book' is not iterable
I know that problems with iterables can sometimes be solved by casting certain things into a different type, but I'm not sure how I should solve this one. I tried to use 'str()' for different elements, but that didn't solve the problem. Maybe it has something to do with my code, maybe with the nature of dictionaries or xlrd... (looking at the type 'book', my guess would be on the latter).
Any help or feedback on how to fix this would be greatly appreciated. If you need extra information to understand what's going on or what I'm looking for, please ask.
where is ConceptualErrors being set?

Categories

Resources