Re: Newbie question about Python syntax

2019-08-26 Thread Paul St George

On 25/08/2019 02:39, Cameron Simpson wrote:

On 24Aug2019 21:52, Paul St George  wrote:

[snip]>
Aside from "map" being a poor name (it is also a builtin Python 
function), it seems that one creates one of these to control how some 
rendering process is done.


The class reference page you originally cites then specifies the meaning 
of the various attributes you might set on one of these objects.


Cheers,
Cameron Simpson 


Thanks Cameron. As this list has a low noise to signal ratio I cannot 
thank you enough here.


I could have stayed where I belong in Blender Artists, or similar, but 
those lists tend to just offer solutions and as Douglas Adams almost 
said knowledge without understanding is almost meaningless. Here I have 
gained enough understanding (perhaps not to yet make sufficient sense in 
what I say) but to transfer knowledge from solving one problem to 
possibly solving many.


Thank you for your patience and tolerance,

Dr Paul St George
--
http://www.paulstgeorge.com
http://www.devices-of-wonder.com


--
https://mail.python.org/mailman/listinfo/python-list


Re: Newbie question about Python syntax

2019-08-24 Thread Cameron Simpson

On 24Aug2019 21:52, Paul St George  wrote:

Have you not got one of these handed to you from something?

Or are you right at the outside with some "opaque" blender handle or 
something? (Disclaimer: I've never used Blender.)


Thank you once again.
If I understand your question, I am right outside. By this I mean I 
have not created anything with Python. I have made the Blender model 
with the UI and am trying to use Python to read the values for the 
settings used. This has worked for all settings except this Map Value 
Node.


Hmm. So you have a CompositorNodeMapValue instance? If that is the case 
you should be able to inspect it as previously described.


However, it looks like this is something you construct in order to do 
some task. A little web searching turns up this stackexchange post:


 
https://blender.stackexchange.com/questions/42579/render-depth-map-to-image-with-python-script/42667

and some example code from an unrelated project:

 
https://github.com/panmari/stanford-shapenet-renderer/blob/master/render_blender.py


From the stackexchange post:


   map = tree.nodes.new(type="CompositorNodeMapValue")
   # Size is chosen kind of arbitrarily, try out until you're satisfied 
   # with resulting depth map.

   map.size = [0.08]
   map.use_min = True
   map.min = [0]
   map.use_max = True
   map.max = [255]

"tree" is "bpy.context.scene.node_tree".

Aside from "map" being a poor name (it is also a builtin Python 
function), it seems that one creates one of these to control how some 
rendering process is done.


The class reference page you originally cites then specifies the meaning 
of the various attributes you might set on one of these objects.


Cheers,
Cameron Simpson 
--
https://mail.python.org/mailman/listinfo/python-list


Re: Newbie question about Python syntax

2019-08-24 Thread Barry
Have you tried asking on a blender user mailing list for help with this problem?

It seems that someone familiar with blender and its python interface should be 
able to help get you going.

Barry

> On 24 Aug 2019, at 20:52, Paul St George  wrote:
> 
>> On 24/08/2019 01:23, Cameron Simpson wrote:
>>> On 23Aug2019 13:49, Paul St George  wrote:
>>> Context:
>>> I am using Python to interrogate the value of some thing in Blender (just 
>>> as someone else might want to use Python to look at an email in a Mail 
>>> program or an image in Photoshop).
>>> 
>>> Assumptions:
>>> So, I want to look at the attribute of an instance of a class called 
>>> CompositorNodeMapValue. The code in the Python tutorial seems to be for 
>>> creating an instance of a class, but I assume Blender (in my case) has 
>>> already created the instance that I want to interrogate.
>> That would be the expectation. And to interrogate it, you need that instance 
>> to hand in a variable.
>>> Question:
>>> If this is so, should I find the code to get a list of the instances that 
>>> have been made (maybe using inspect?) and then, when I have its name, the 
>>> attributes of the one that interests me?
>> Have you not got one of these handed to you from something?
>> Or are you right at the outside with some "opaque" blender handle or 
>> something? (Disclaimer: I've never used Blender.)
> 
> Thank you once again.
> If I understand your question, I am right outside. By this I mean I have not 
> created anything with Python. I have made the Blender model with the UI and 
> am trying to use Python to read the values for the settings used. This has 
> worked for all settings except this Map Value Node.
> 
>> You can inspect objects with the inspect module. You can also be more 
>> direct. Given an object "o", you can do an assortment of things:
> 
> Before I do any of the following, I assume I need to use something like:
> 
> import struct
> class CompositorNodeMapValue(o):
> 
> I have tried this. Nothing happens. Not even an error. It's like waiting for 
> Godot.
> 
> I am guessing I am in the wrong namespace.
> 
> I don't know whether it is relevant, but I tried plain
> dir()
> and
> dir(struct)
> 
> They each returned a list and neither list had mention of 
> CompositorNodeMapValue
> 
> If I do something like:
> o = CompositorNodeMapValue()
> I get:
> NameError: name 'CompositorNodeMapValue' is not defined
> 
>> dir(o) gets a list of its attribute names.
>> help(o) prints out the docstring, somewhat rendered.
>> o.__dict__ is usually a dict mapping attribute names to their values.
>> type(o) gets you its type, so "print(type(o))" or "print(type(o).__name__)" 
>> can be handy.
>> A crude probe function (untested):
>>  def probe(o):
>>print(o)
>>for attr, value in sorted(o.__dict__.items()):
>>  print(" ", attr, type(value).__name__, value)
>> Enjoy,
>> Cameron Simpson  (formerly c...@zip.com.au)
>> "Are we alpinists, or are we tourists" followed by "tourists! tourists!"
>>- Kobus Barnard  in rec.climbing,
>>  on things he's heard firsthand
> 
> 
> -- 
> https://mail.python.org/mailman/listinfo/python-list

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Newbie question about Python syntax

2019-08-24 Thread Paul St George

On 24/08/2019 01:23, Cameron Simpson wrote:

On 23Aug2019 13:49, Paul St George  wrote:

Context:
I am using Python to interrogate the value of some thing in Blender 
(just as someone else might want to use Python to look at an email in 
a Mail program or an image in Photoshop).


Assumptions:
So, I want to look at the attribute of an instance of a class called 
CompositorNodeMapValue. The code in the Python tutorial seems to be 
for creating an instance of a class, but I assume Blender (in my case) 
has already created the instance that I want to interrogate.


That would be the expectation. And to interrogate it, you need that 
instance to hand in a variable.



Question:
If this is so, should I find the code to get a list of the instances 
that have been made (maybe using inspect?) and then, when I have its 
name, the attributes of the one that interests me?


Have you not got one of these handed to you from something?

Or are you right at the outside with some "opaque" blender handle or 
something? (Disclaimer: I've never used Blender.)


Thank you once again.
If I understand your question, I am right outside. By this I mean I have 
not created anything with Python. I have made the Blender model with the 
UI and am trying to use Python to read the values for the settings used. 
This has worked for all settings except this Map Value Node.




You can inspect objects with the inspect module. You can also be more 
direct. Given an object "o", you can do an assortment of things:


Before I do any of the following, I assume I need to use something like:

import struct
class CompositorNodeMapValue(o):

I have tried this. Nothing happens. Not even an error. It's like waiting 
for Godot.


I am guessing I am in the wrong namespace.

I don't know whether it is relevant, but I tried plain
dir()
and
dir(struct)

They each returned a list and neither list had mention of 
CompositorNodeMapValue


If I do something like:
o = CompositorNodeMapValue()
I get:
NameError: name 'CompositorNodeMapValue' is not defined



dir(o) gets a list of its attribute names.

help(o) prints out the docstring, somewhat rendered.

o.__dict__ is usually a dict mapping attribute names to their values.

type(o) gets you its type, so "print(type(o))" or 
"print(type(o).__name__)" can be handy.


A crude probe function (untested):

  def probe(o):
    print(o)
    for attr, value in sorted(o.__dict__.items()):
  print(" ", attr, type(value).__name__, value)

Enjoy,
Cameron Simpson  (formerly c...@zip.com.au)

"Are we alpinists, or are we tourists" followed by "tourists! tourists!"
    - Kobus Barnard  in rec.climbing,
  on things he's heard firsthand



--
https://mail.python.org/mailman/listinfo/python-list


Re: Newbie question about Python syntax

2019-08-23 Thread Cameron Simpson

On 23Aug2019 13:49, Paul St George  wrote:

Context:
I am using Python to interrogate the value of some thing in Blender 
(just as someone else might want to use Python to look at an email in 
a Mail program or an image in Photoshop).


Assumptions:
So, I want to look at the attribute of an instance of a class called 
CompositorNodeMapValue. The code in the Python tutorial seems to be 
for creating an instance of a class, but I assume Blender (in my case) 
has already created the instance that I want to interrogate.


That would be the expectation. And to interrogate it, you need that 
instance to hand in a variable.



Question:
If this is so, should I find the code to get a list of the instances 
that have been made (maybe using inspect?) and then, when I have its 
name, the attributes of the one that interests me?


Have you not got one of these handed to you from something?

Or are you right at the outside with some "opaque" blender handle or 
something? (Disclaimer: I've never used Blender.)


You can inspect objects with the inspect module. You can also be more 
direct. Given an object "o", you can do an assortment of things:


dir(o) gets a list of its attribute names.

help(o) prints out the docstring, somewhat rendered.

o.__dict__ is usually a dict mapping attribute names to their values.

type(o) gets you its type, so "print(type(o))" or 
"print(type(o).__name__)" can be handy.


A crude probe function (untested):

 def probe(o):
   print(o)
   for attr, value in sorted(o.__dict__.items()):
 print(" ", attr, type(value).__name__, value)

Enjoy,
Cameron Simpson  (formerly c...@zip.com.au)

"Are we alpinists, or are we tourists" followed by "tourists! tourists!"
   - Kobus Barnard  in rec.climbing,
 on things he's heard firsthand
--
https://mail.python.org/mailman/listinfo/python-list


Re: Newbie question about Python syntax

2019-08-23 Thread Paul St George

On 22/08/2019 23:21, Kyle Stanley wrote:
[snip]


The tutorial that Terry was referring to was the one on docs.python.org,
here's a couple of links for the sections he was referring to:

Full section on classes: https://docs.python.org/3/tutorial/classes.html

Section on instantiating objects from classes:
https://docs.python.org/3/tutorial/classes.html#class-objects


[snip]



Aha, thank you all.
Here then, is my first problem.

Context:
I am using Python to interrogate the value of some thing in Blender 
(just as someone else might want to use Python to look at an email in a 
Mail program or an image in Photoshop).


Assumptions:
So, I want to look at the attribute of an instance of a class called 
CompositorNodeMapValue. The code in the Python tutorial seems to be for 
creating an instance of a class, but I assume Blender (in my case) has 
already created the instance that I want to interrogate.


Question:
If this is so, should I find the code to get a list of the instances 
that have been made (maybe using inspect?) and then, when I have its 
name, the attributes of the one that interests me?


Or shall I go into the garden to eat worms?

--
https://mail.python.org/mailman/listinfo/python-list


Re: Newbie question about Python syntax

2019-08-22 Thread Kyle Stanley
> You are right, but it is even worse than you think. I do not have a
tutorial so I have no examples to understand.

The tutorial that Terry was referring to was the one on docs.python.org,
here's a couple of links for the sections he was referring to:

Full section on classes: https://docs.python.org/3/tutorial/classes.html

Section on instantiating objects from classes:
https://docs.python.org/3/tutorial/classes.html#class-objects

On Thu, Aug 22, 2019 at 4:40 PM Paul St George 
wrote:

> On 22/08/2019 20:02, Terry Reedy wrote:
> > On 8/22/2019 3:34 AM, Paul St George wrote:
> >> I have the Python API for the Map Value Node here:
> >> <
> https://docs.blender.org/api/current/bpy.types.CompositorNodeMapValue.html>.
>
> >>
> >>
> >> All well and good. Now I just want to write a simple line of code such
> >> as:
> >>
> >> import bpy
> >>
> >> ...
> >>
> >>  >>>print(bpy.types.CompositorNodeMapValue.max[0])
> >>
> >> If this works, I will do something similar for max, min, offset and
> >> then size.
> >
> >  From this and your other responses, you seem to not understand some of
> > the concepts explained in the tutorial, in particular class and class
> > instance.  Perhaps you should reread the appropriate section(s), and if
> > you don't understand any of the examples, ask about them here.  We are
> > familiar with those, but not with CompositorNodeMapValue.
> >
> >
> Terry,
> You are right, but it is even worse than you think. I do not have a
> tutorial so I have no examples to understand.
>
> Reading Cameron et al, I have broken the problem down into:
> do something (probably using the word self) that _gives_ me an instance
> of CompositorNodeMapValue.
>
> Then when I done that,
> look at some of the attributes (.max, .min, .offset, .size) of the
> instance.
>
> Paul
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Newbie question about Python syntax

2019-08-22 Thread Paul St George

On 22/08/2019 20:02, Terry Reedy wrote:

On 8/22/2019 3:34 AM, Paul St George wrote:
I have the Python API for the Map Value Node here: 
. 



All well and good. Now I just want to write a simple line of code such 
as:


import bpy

...

 >>>print(bpy.types.CompositorNodeMapValue.max[0])

If this works, I will do something similar for max, min, offset and 
then size.


 From this and your other responses, you seem to not understand some of 
the concepts explained in the tutorial, in particular class and class 
instance.  Perhaps you should reread the appropriate section(s), and if 
you don't understand any of the examples, ask about them here.  We are 
familiar with those, but not with CompositorNodeMapValue.




Terry,
You are right, but it is even worse than you think. I do not have a 
tutorial so I have no examples to understand.


Reading Cameron et al, I have broken the problem down into:
do something (probably using the word self) that _gives_ me an instance 
of CompositorNodeMapValue.


Then when I done that,
look at some of the attributes (.max, .min, .offset, .size) of the instance.

Paul

--
https://mail.python.org/mailman/listinfo/python-list


Re: Newbie question about Python syntax

2019-08-22 Thread Terry Reedy

On 8/22/2019 3:34 AM, Paul St George wrote:
I have the Python API for the Map Value Node here: 
. 



All well and good. Now I just want to write a simple line of code such as:

import bpy

...

 >>>print(bpy.types.CompositorNodeMapValue.max[0])

If this works, I will do something similar for max, min, offset and then 
size.


From this and your other responses, you seem to not undertstand some of 
the concepts explained in the tutorial, in particular class and class 
instance.  Perhaps you should reread the appropriate section(s), and if 
you don't understand any of the examples, ask about them here.  We are 
familiar with those, but not with CompositorNodeMapValue.



--
Terry Jan Reedy

--
https://mail.python.org/mailman/listinfo/python-list


Re: Newbie question about Python syntax

2019-08-22 Thread Chris Angelico
On Thu, Aug 22, 2019 at 9:20 PM Paul St George  wrote:
>
> On 22/08/2019 11:49, Cameron Simpson wrote:
> > On 22Aug2019 09:34, Paul St George  wrote:
> >> I have the Python API for the Map Value Node here:
> >> .
> >>
> >>
> >> All well and good. Now I just want to write a simple line of code such
> >> as:
> >>
> >> import bpy
> > print(bpy.types.CompositorNodeMapValue.max[0])
> > [...]
> >> AttributeError: type object 'CompositorNodeMapValue' has no attribute
> >> 'max'
> >
> > CompositorNodeMapValue is a class. All the attributes described are for
> > instances of the class. So you need to do something that _gives_ you an
> > instance of CompositorNodeMapValue. That instance should have a .max array.
> >
> > Cheers,
> > Cameron Simpson 
>
> Gulp. Thank you. I did ask for a pointer but perhaps I need a roadmap.
>
> I have tried to do something that gives me an instance of
> CompositorNodeMapValue. I don't think I should humiliate myself further
> by sharing my attempts so could you please show me what the code should
> look like.
>

Don't think of it as humiliating yourself - you're asking for fairly
specific advice, so showing your code is the best way to get that sort
of advice. We don't bite :)

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Newbie question about Python syntax

2019-08-22 Thread Paul St George

On 22/08/2019 11:49, Cameron Simpson wrote:

On 22Aug2019 09:34, Paul St George  wrote:
I have the Python API for the Map Value Node here: 
. 



All well and good. Now I just want to write a simple line of code such 
as:


import bpy

print(bpy.types.CompositorNodeMapValue.max[0])

[...]
AttributeError: type object 'CompositorNodeMapValue' has no attribute 
'max'


CompositorNodeMapValue is a class. All the attributes described are for 
instances of the class. So you need to do something that _gives_ you an 
instance of CompositorNodeMapValue. That instance should have a .max array.


Cheers,
Cameron Simpson 


Gulp. Thank you. I did ask for a pointer but perhaps I need a roadmap.

I have tried to do something that gives me an instance of 
CompositorNodeMapValue. I don't think I should humiliate myself further 
by sharing my attempts so could you please show me what the code should 
look like.


--
https://mail.python.org/mailman/listinfo/python-list


Re: Newbie question about Python syntax

2019-08-22 Thread Cameron Simpson

On 22Aug2019 09:34, Paul St George  wrote:

I have the Python API for the Map Value Node here: 
.

All well and good. Now I just want to write a simple line of code such as:

import bpy

print(bpy.types.CompositorNodeMapValue.max[0])

[...]
AttributeError: type object 'CompositorNodeMapValue' has no attribute 
'max'


CompositorNodeMapValue is a class. All the attributes described are for 
instances of the class. So you need to do something that _gives_ you an 
instance of CompositorNodeMapValue. That instance should have a .max 
array.


Cheers,
Cameron Simpson 
--
https://mail.python.org/mailman/listinfo/python-list


Newbie question about Python syntax

2019-08-22 Thread Paul St George
I have the Python API for the Map Value Node here: 
.


All well and good. Now I just want to write a simple line of code such as:

import bpy

...

>>>print(bpy.types.CompositorNodeMapValue.max[0])

If this works, I will do something similar for max, min, offset and then 
size.


I know my embarrassingly feeble attempt is wrong because the console 
tells me:

AttributeError: type object 'CompositorNodeMapValue' has no attribute 'max'

Could anyone (please) point me in the right direction?

Thanks,
Paul
--
https://mail.python.org/mailman/listinfo/python-list