Python troubles :(


(LethalSideP) #1

Hey there people. This probably seems really simple to you python folk out there - unfortunately I’m teaching myself python, so i can only go so far.

My problem is to do with an idea for a script that I’ve been sitting on for a while now. I’ll give more details once I’ve got it working/have taught myself enough python to do so.

Anyway, the problem. I’m trying to duplicate objects through this script (as in either shift-d or alt-d within Blender - try them to find out the difference between them if you’re not sure). Is there a way to do either of these within python aside from creating a loop which duplicates faces, materials, UVs, vertex colours etc (let’s face it - that would be long and very boring, and probably fail anyway!).

So…any ideas?

Also, can anyone tell me how to get values from a button in a Blender gui (you know, one you create with a script)? I’ve tried that trick where you put variable.val inside the button declaration, but it keeps raising an error with the .val - python doesn’t seem to have a clue about it. Blender 2.23, python 2.0.1.

Comments? Flames? Posts saying what an idiot I am? Any of these would be helpful! Thanks guys!

LethalSideParting


(theeth) #2

if you really want to do intensive GUI control, I can send you the GUI class I did for Dynamica. It will eventually be released as a developers tool, but I haven’t had time to make proper documentation, and I’m currently making an editor so it’s easier to create interface.

if you like the old fashion way better, just remember that the variables you used to store the GUI button’s value has to be created with the Create() function in Blender.Draw like this:


value = Blender.Draw.Create(1.000)

value.val would hold the numerical value.

also, to answer your object copying question, well, you can only really do that with mesh objects, and even then, it could be hard to create the same sort of link as with Alt-D. To just copy the mesh data, you should use the deepcopy() function in the copy python module. You can use it that way:


from copy import deepcopy

List1 = [1, 2, 3, 4]
List2_ref = List1
List2_copy = deepcopy(List1)

List1.pop()

print List2_ref
print List2_copy

List2_ref is only a reference to List1, if you modify it, so is List2_ref. List2_copy on the other side, is a deep copy of List1, as it contains absolutely no reference to the object copied.

That works the same for all Python mutable object (List, Dictionnary, Instance).

Martin


(Schlops) #3

On the problem with the button: What’s the error message?? Maybe you didn’t tell python that it’s a global variable, so if but is your button, put the following in your gui-function:

global but

(LethalSideP) #4

That worked absolutely great, you two. Thanks a million :slight_smile: . Once I’ve got the script working in a rudimentary way, I’ll release details of it here at Elysiun. Its (provisional) name is Ballistix, though that may change.

And as for that GUI class you mentioned, theeth, it’d be great if you could send me that, if only so I could try it out :smiley: - creating things the hard way takes such a long time - but you don’t have to if you don’t want to. If you still want to work on it or keep it under wraps or anything then that’s fine. My script doesn’t really do anything that’s REALLY GUI intensive - most of the work is behind the scenes, especially with IPOs, and I’m handling that fine at the moment. My email address is [email protected] . Now, I know that nothing (except Blender!) is free these days, so if you like once my exams are done (June 14th onwards) I could help you write the documentation for it using my experiences with this script, or translate it into French, as a sort of ‘thank you’. Let me know if you’re interested.

And that global thing has helped a lot, too. I’d gathered from looking at all the various scripts around (that’s how I’m teaching myself!) that you had to define variables globally if you wanted to use them across different procedures, but my methodology was still a little shaky. No more! 8)

Thanks a million, guys. Keep in touch. :wink:

LethalSideParting


(theeth) #5

I’ll send you my Editor script tonight. It’s not finish yet, but it should show you enough of the full power of my module. Then, if you want to use it, I could send you the short “how to” file.

Martin


(LethalSideP) #6

Just a thought I had whilst programming last night. For that alt-d problem we were having, could I do something like

Object1.Object.data=Object2.Object.data

or something similar? It would certainly save a lot of hastle…and since the two objects are being linked to the same object data block, updates in one would affect the other…right? Any comments anyone?

And by the way, theeth - that GUI script is amazing :o ! I was expecting something pretty good, considering it was coming from you :wink: , but not THAT good! Once the code is finalised for that, it’s absolutely going to blow this community away! GUIs are never going to look the same again. If you ever want any help with that script (testing, writing, translating, you name it), then I’ll be all too glad to help with something like that!

Cheers guys,
LethalSideParting


(theeth) #7

You can’t do that, the data property is read-only.

And by the way, theeth - that GUI script is amazing :o ! I was expecting something pretty good, considering it was coming from you :wink: , but not THAT good! Once the code is finalised for that, it’s absolutely going to blow this community away! GUIs are never going to look the same again. If you ever want any help with that script (testing, writing, translating, you name it), then I’ll be all too glad to help with something like that!

Thanks, I’m glad you liked it. I should have the GuiC_Editor more advanced some time next week, I’ll ship it to you.

Martin


(LethalSideP) #8

Yeah, I tried that thing out I mentioned last night. Why did they make it read-only? It strikes me as a bit of a daft thing to do - if they’d left it open, some of the resulting community scripting would’ve been fantastic…

And what really annoys me is the fact that the user can actually do this user in Blender themself (try going to edit buttons and using the drop down menu to change the mesh link). If the user can perform the operation in Blender, then why not the scripts as well??? Very annoying… :x That would’ve worked really well in my script, as well…

Oh well :frowning: . No point crying over spilt milk, as we say. What’s done is done. I’m off to finish coding version 1.0 of ballistix. I’ll let you all know when it’s done!

LethalSideParting


(theeth) #9

Actually, that falls in the same line of thought as having the matrix property read-only. It ensures that only correct data will be put it this field.

Martin