Good day,
I'm very new to the Blender API.
Ultimately, I am trying to get the currently selected object. I know this is available bpy.context.selected_objects. However, I'm running my script from a python file and the context object is different. in my current context the selected_objects does not exist.
I've searched around and at most I've been able to find that you can edit in which context some operators are run by overriding their settings. But bpy.context.selected_objects is not an operator.
Perhaps there is a method or operator inside bpy.data which returns the selected object? I can't seem to find the part of the documentation which shows what attributes are exposed inside bpy.data https://docs.blender.org/api/current/search.html?q=bpy.data.&check_keywords=yes&area=default#
Thanks in advance.
As your running this from blender scripting possibly using bpy.context.active_object rather then bpy.context.selected_objects might work better.
There can be an active object when no objects are selected, here's more info on them: https://blender.stackexchange.com/questions/27396/whats-the-difference-among-object-active-object-and-selected-objects
It's also quite hard to tell what could be going on without more details on the internal functionings, so attaching code would be usefull.
Related
I currently have two files: control.py and list.py. list.py contains a list of objects that I want to access and edit in control.py. In the project I'm working on, I should be able to open multiple instances of control.py (essentially, open x number of terminals each running its own instance of control.py). I want to able to access the list in list.py from each instance of control.py. Each instance should be able to edit the list such that after editing, all the other instances should be able to see the edited list.
I've looked into the shelve module but it turns out that shelve doesn't support concurrent modification, so that won't work because i need each instance to simultaneously be able to read and edit the list.
The usual solution to this problem is known as "pubsub"; i.e., publish/subscribe. See https://en.wikipedia.org/wiki/Publish%E2%80%93subscribe_pattern for a primer on the topic. There is no way to do this using just the capabilities provided by the core Python libraries; at least not without writing a pubsub implementation using those capabilities.
However, I get the sense you are doing the programming equivalent of trying to use a hammer to drive a screw. That is, because a hammer is the only tool you know how to use every problem looks like a nail. Reframing the problem is likely to help you, and us, provide better solutions.
I am now working on a IDA plugin development. but I got some problem on this. I need your help .
Here is the situation:
I used the hexray plugin to get a decompiled function like this: c_func=idaapi.decompile(0x1234).
after getting c_func object, I want to manipulate on this object, like changing type of some lvars, and then obain the updated pseudo C-code. but I do not know how to do this. There is rarely few reference on this topic.
Could anyone help me on this?
Actually, what I want to do is just a simulation of "Set lvar Type" in pseudocode window of IDA . If a proper type is set for some lvars, the hex-ray decompiler will automatic change the pseudo-C code according to the new type.
I want to do this by calling SDK APIs.
Do something like this:
c=idaapi.decompile(func.startEA)
for v in c.lvars:
if name==v.name:
v.set_lvar_type(...) or v.set_final_lvar_type(...) or v.force_lvar_type(...)
See here: https://www.hex-rays.com/products/decompiler/manual/sdk/classlvar__t.shtml#a2963a6281d004d2868728ec8c8c04fd6
You can create t_info and use the deserialize function in order to set the type.
Good luck!
I'm using IPython qtconsole under windows 7, and when I first write a method name and type the bracket, a popup shows method parameters.
What is the way to display that popup explicitly, once it has disappeared? This is pretty common 'show method parameters' shortcut that I'm talking about, but I've failed to find the shortcut to it after an embarrassing amount of google searches.
In Spyder, try View - Panes - Object inspector. Then type the full name of the function.
I would highly recommend relying on the Python Library Reference rather than any in-IDE tools, at least for functions and classes that are in the standard library. For objects outside those libraries however... it looks like you can type object_name followed by a question mark, that is, object_name?, to get a list of informative details about the object. (Since everything is an object, this presumably includes functions.)
For your specific question, it looks, from the iPython docs, like the TAB key is what you're looking for, but somehow I doubt you haven't already tried that.
I find it hard to explain my problem as the problem is not within the code itself. If you need more input to understand the following better, please let me know.
I'm using ArcGIS to call a bunch of python scripts, one after another. The scripts use the same class by importing it, or inherit from it. To initialize the class I often use the same name. I have no idea how the communication between ArcGIS and python is implemented. But I noticed that my scripts are not always behaving like they should. I suppose that the reference to the object still exists (even though the script the object was created with has finished) when I call the second script.
First of all: How can I make sure my suspicion is true?
Secondly, if this is the case: is it a good idea to destroy all references to all objects using del or __del__? What is the best way to do this?
Trace tracing your code and walking through it with a debugger? Quickest way to tell if it's accessing correct code. Python Debugger
If you read the documentation, what you want to do is use a break point to make sure code reaches that point in code.
This is the syntax with the debugger.
b(reak) [[filename:]lineno | function[, condition]]
In my code I've connected to the WebView's load-finished event. The particular callback function takes a webview object and frame object as arguments. Then I tried executing get_dom_document() on the frame & the webview objects respectively. It seems this method doesn't exist for those objects...
PS: i started with the tips i got here http://www.gnu.org/software/pythonwebkit/
UPDATE (11-Sep-2010): I think the link I shared relates to a new & different project. Its not a solution per se. My bad!
it's definitely there.
and you can't just "take the tips from http://www.gnu.org/software/pythonwebkit/" you actually have to COMPILE THE CODE (reason: standard pywebkitgtk DOES NOT have W3C DOM accessor functions).
then take a look in pythonwebkit/pywebkitgtk/examples and run browser.py and you'll see what to do.
l.
i forgot to mention (and it wasn't on the documentation, which i've now updated): you specifically need to check out the "python_codegen" branch, otherwise you just end up with plain vanilla webkit. which is of absolutely no use to you.