[Python Questions] [7] manipulate japanese text( String, Re Module Quest )[ Post 20]

Hello every one,
I will ask here really simple questions you will may be think,
but I am not a familiar at all to programming.

In order to progress I fix myself simple tasks and I try, using the API, to write a simple script that do it

First task: create a primitive cube and assign it a color.


from Blender import *

me = Mesh.Primitives.Cube(2.0)   # create a new cube of size 2
sc = Scene.GetCurrent()          # get current scene
sc.objects.new(me,'Mesh')        # add a new mesh-type object to the scene
           
mat = Material.New('newMat')          # create a new Material called 'newMat'
print mat.rgbCol                      # print its rgb color triplet sequence
mat.rgbCol = [0.8, 0.2, 0.2]          # change its color
mat.setAlpha(0.2)                     # mat.alpha = 0.2 -- almost transparent
mat.emit = 0.7                        # equivalent to mat.setEmit(0.8)
mat.setName('colorA')                  # change its name
me.materials.append(mat)
Window.RedrawAll()    # update windows

What was wrong in it?
The Cube still have his default color.
I have no error message from the console.
???
I tried something with
me.setMaterials(mat)
not working.
Edit:
found one solution here
http://blenderartists.org/forum/showthread.php?t=161902&highlight=.materials.append(
the solution was
me.materials=[mat]

from Blender import *
from Blender import Noise
from Blender import Object

me = Mesh.Primitives.Cube(4.0)   # create a new cube of size 2
sc = Scene.GetCurrent()          # get current scene
sc.objects.new(me,'Mesh')        # add a new mesh-type object to the scene
           
mat= Material.New('newMat')          # create a new Material called 'newMat'
mat.rgbCol = [0.8, 0.2, 0.2]          # change its color
mat.setAlpha(0.2)                     # mat.alpha = 0.2 -- almost transparent
mat.emit = 0.7                        # equivalent to mat.setEmit(0.8)
mat.setName('colorA')                  # change its name
me.materials=[mat]
Window.RedrawAll()    # update windows

Hopping that will help more beginner then I.

The documentation herehttp://www.blender.org/documentation/249PythonDoc/Mesh.Mesh-class.html#materials

states that "The list that’s returned is not linked to the original mesh. mesh.materials.append(material) won’t do anything. Use mesh.materials += [material] instead. " Although this is odd, you have to use this:

me.materials += [mat]


Thank you sornen for your help, I will check this data immediately

Hello every one,
new question, about the ipo curve
I want to create a camera and to make it move using a curve.
Down in the code I let the mistake.
The Ipo for the camera are not about mouvement,
and the object curve wont want to be connected to the camera.
still the is Action ipo…
still testing…
I copied some part from here
http://blenderartists.org/forum/showthread.php?t=102510
am I in the right direction?

from Blender import *
from Blender import Camera
from Blender import Object
from Blender import Scene
from Blender import Ipo


#creation du cube

me = Mesh.Primitives.Cube(4.0)   # create a new cube of size 2
sc = Scene.GetCurrent()          # get current scene
sc.objects.new(me,'Mesh')        # add a new mesh-type object to the scene

#camera

cam = Camera.New('ortho')   # create new ortho camera data
cam.scale = 6.0             # set scale value for ortho view
ob=sc.objects.new(cam)   # add a new camera object from the data
sc.setCurrentCamera(ob)    # make this camera the active

#ipo

ipo = Ipo.New('Object','deplacement')  
cam.setIpo(ipo)
locx = ipo.addCurve('LocX')
locx.interpolation = Blender.IpoCurve.InterpTypes.LINEAR
locy = ipo.addCurve('LocY')
locy.interpolation = Blender.IpoCurve.InterpTypes.LINEAR
locz = ipo.addCurve('LocZ')
locz.interpolation = Blender.IpoCurve.InterpTypes.LINEAR



#materiel pour l'objet cube

mat= Material.New('newMat')          # create a new Material called 'newMat'
mat.rgbCol = [0.8, 1, 0.2]          # change its color
mat.setAlpha(0.2)                     # mat.alpha = 0.2 -- almost transparent
mat.emit = 0.7                        # equivalent to mat.setEmit(0.8)
mat.setName('colorA')                  # change its name
me.materials+=[mat]

Window.RedrawAll()    # update windows

You need to use


ob.setIpo(ipo)

instead of


cam.setIpo(ipo)

It didn’t work because you were trying to hook an IPO for objects to camera data.

First a great thank to you for Te

Yet
I understand I think but
I still don’t visualise the logic of the thing.
There is a hierarchy, a organization that I need to visualize…

I’d suggest looking at the ‘Outliner’ Window. It’ll show you the Hierarchy of your Scene. For instance, you’ll see that you have a Scene, and below that you have Objects, and each object can have different data linked to it ranging from the raw Mesh, Curve, or Lamp Data to Ipo Data and Constraints. It might help to clear up how the various data types in Blender are linked together and interact.

Compared to many other programs, Blender has a quite novel but powerful data structure.

You can find more about it here.

A brief explanation of library linking can be found here.

This will change quite a bit in Blender 2.5 with the introduction of RNA more here, but the basic principles of data reuse and linking will be the same.

Thank you FunkyWyrm and forTe,
I will print all this and have some good scons, and a stong cup of tea…
to help the intergration of the concepts.

I am trying something else,
I am trying to make wall with randomly disposed bricks on the y Axe.
The wall is built but without taking in concideration any randomnity on y axe.
Also
I have to make a indentation at
cube.setLocation (x,y,z)
if not it is not working
Why ?

Edit:
I see
y= Mathutils.Rand(0.0,10.0)
is just not in the Boucle

Will try

Edit2:
It is working!
The indentation problem disapeared
copy past problem I guess.

from Blender import *
from Blender import Camera
from Blender import Object
from Blender import Scene
from Blender import Noise

#valeur a utiliser /value to use later
a=0
b=0
c=5
x=0

z=0


while a<5:
        while b<c:
                
       
        
            me = Mesh.Primitives.Cube(2.0)   # create a new cube of size 2
            sc = Scene.GetCurrent()          # get current scene
            cube=sc.objects.new(me,'Mesh')        # add a new mesh-type object to the scen
            y= Noise.random()
            cube.setLocation (x,y,z)             #a random position is setteled
            Window.RedrawAll()               # update windows
            b=b+1
            x=x+2.25
                
                
        
        a=a+1
        b=0
        x=0
        z=z+2.25
      


Window.RedrawAll()    # update windows



Hello Every one,
I just post the sript in order for beginners to study a bit.


from Blender import *
from Blender import Camera
from Blender import Object
from Blender import Scene
from Blender import Noise
from Blender import Mathutils





#valeur a utiliser /value to use later
a=0
b=0
c=10
x=0

z=0


while a<10:
        while b<c:
                
       
        
            me = Mesh.Primitives.Cube(2.0)   # create a new cube of size 2
            sc = Scene.GetCurrent()          # get current scene
            cube=sc.objects.new(me,'Mesh')        # add a new mesh-type object to the scen
            y= Mathutils.Rand(0.0,2.0)
            t= Noise.random()
            t2= Noise.random()
            t3= Noise.random()
            cube.setLocation (x,y,z)             #a random position is setteled
            Window.RedrawAll()               # update windows
            b=b+1
            x=x+2.25
            
            #materiel pour l'objet cube/Material for the cube
            mat= Material.New('newMat')          # create a new Material called 'newMat'
            mat.rgbCol = [t,y,t2]          # change its color
            mat.setMode( "RayMirr")
            mat.setRayMirr(t3)                     # mat.alpha = 0.2 -- almost transparent
            #mat.emit = 0.7                        # equivalent to mat.setEmit(0.8)
            mat.setName('colorA')                  # change its name
            me.materials+=[mat]
                
                
        
        a=a+1
        b=0
        x=0
        z=z+2.25
      


Window.RedrawAll()    # update windows



Hello every one,
I am trying to do some fractal…
huge…and hard dream…
I saw some topics here and there
http://blenderartists.org/forum/showthread.php?t=100544
http://blenderartists.org/forum/showthread.php?p=813715
I read some introduction doc to Python and the use of python in Blender.

What is laking me the most is the thinking process.
for example,
http://cubemine.com/2006/02/fractal-sculpture-1-light-blue/
nice work…
I just don’t know how the looping is written in the python script, hard to figure for this one.
Is this Just array??

There are many different methods of making fractals. The overarching methods are iteration and recursion.

Iteration is just looping of course, and for instance you can plot the mandelbrot set using iteration and the escape time algorithm. There’s also just deriving an equation and plugging in points for that (its helpful if they’re differential equations that can be solved using Euler’s or Runge-Kutta or some other iterative solver).

Recursion on the other hand, is a little bit different. Things like the Sierpinski triangle are recursive. The one you’ve linked to with the spheres looks recursive. The basic method is you make a function and give it an initial point, it then generates the basic fractal for each of those given points. At each of those generated points, you then once again generate the fractal, and for each point generated from that one you do the same, and so on and so on. So in pseudo-code:


def genFractal(point):
     # Terminating condition

     # Logic to generate points of fractal

     points = [...the newly generated points]
     for pt in points:
          genFractal(pt)

     return

Would sort of be the way you’d go. There’s also things called strange attractors which fit into that general category of artistic fractals (although not the strict definition of self-repetitious structures).

Hello tsurubaso,

I’m glad you liked my blue fractal. :slight_smile:
I’ve been meaning to do some more of those but time/inspiration is lacking.

Anyway, maybe I’ll do a tutorial on this later but, for now, I’ve uploaded the original .blend with the generating script included:
http://uploads.cubemine.com/BlenderArtists/Fractal1-A.blend

ForTe, you got it right: the method I used is a recursive one. The first call is special as it generates three identical branches. Then the rest of the calls just creates two more smaller branches and another bigger one, all rotated by a fixed angle.

The rest of the code deals with two things:
-giving a different color for each sphere, according to its level in the recursion.
-assigning a different mesh to each sphere, according to its size.

This last one was needed because the triangle count would be too high otherwise.

To generate the fractal, select the 4 meshes that will be used and run the script. It’s old and probably there is some new API I could use, but works. I hope you find it useful. :slight_smile:

Cheers,
-Ratow

forTe
thanks for the infos…
I will give some skons, café and time to work, and properly google all the things you point out in your post.

have you tried the algo from
http://blenderartists.org/forum/showthread.php?p=813715

tried to run it and get an error index out of range ?

do you have to add a new object before running ?

are you going to come bakc with some algo to make fractals shapes

would be interesting to see and try results if you are sharing it !

thanks for any help

Here again
Thanks to Ratow and forTe for the precious help.
RickyBlender I didn’t try the algo you were pointing me out,
It is quite difficule.
I will have more time to see some theory tomorrow…
perhaps…
here is what I made so fare…
This is WIP.
I am not “satisfait”(satisfied) by it but any ways,
good to see for beginners.


See down for scripts

i get error on exe

line 66 indentation error

and may be on all other mini loop too ?

don’t know can you check
you should use tab instead of space easeir to follow code

i’m surprise that we don’t get more on fractals on forum
it’s a strange world but interesting
i just saw a NOVA sepcail last week on this and it’s inmpressive where you can find theses

Thanks

RickyBlender,
thanks to tell for this prob.
Will be ok now,
I change it a bite.




from Blender import *
from Blender import Mathutils


d=0
h=0



#creation of the first cube creation du premier cube
#cube 0
sc = Scene.GetCurrent()         
me = Mesh.Primitives.Cube(2.0)   
cube=sc.objects.new(me,'Mesh')       
cube.setLocation (0.0,0.0,0.0)             
while h<6:
    x=0
    y=0
    z=0
    g=2.0
    t1=0.0
    t2=0.0
    t3=0.0
    a=Mathutils.Rand(-5.0,5.0)
    b=Mathutils.Rand(-5.0,5.0)
    c=Mathutils.Rand(-5.0,5.0)
    while d<19:
        x=x+a
        y=y+b
        z=z+c
        f1=Mathutils.Rand(0.00,0.15)
        f2=Mathutils.Rand(0.00,0.15)
        f3=Mathutils.Rand(0.00,0.15)
        g=g-0.1
        
        me = Mesh.Primitives.Cube(g)
        cube=sc.objects.new(me,'Mesh')
        cube.setLocation (x,y,z)
        mat= Material.New('newMat')
        mat.rgbCol = [t1,t2,t3]
        me.materials+=[mat]
        
        me = Mesh.Primitives.Cube(g)
        cube=sc.objects.new(me,'Mesh')
        cube.setLocation (-x,y,z)
        mat= Material.New('newMat')
        mat.rgbCol = [t1,t2,t3]
        me.materials+=[mat]
        
        me = Mesh.Primitives.Cube(g)
        cube=sc.objects.new(me,'Mesh')
        cube.setLocation (-x,-y,z)
        mat= Material.New('newMat')
        mat.rgbCol = [t1,t2,t3]
        me.materials+=[mat]

        me = Mesh.Primitives.Cube(g)
        cube=sc.objects.new(me,'Mesh')
        cube.setLocation (-x,-y,-z)
        mat= Material.New('newMat')
        mat.rgbCol = [t1,t2,t3]
        me.materials+=[mat]
        
        me = Mesh.Primitives.Cube(g)
        cube=sc.objects.new(me,'Mesh')
        cube.setLocation (x,-y,-z)
        mat= Material.New('newMat')
        mat.rgbCol = [t1,t2,t3]
        me.materials+=[mat]

        me = Mesh.Primitives.Cube(g)
        cube=sc.objects.new(me,'Mesh')
        cube.setLocation (x,y,-z)
        mat= Material.New('newMat')
        mat.rgbCol = [t1,t2,t3]
        me.materials+=[mat]
        
        me = Mesh.Primitives.Cube(g)
        cube=sc.objects.new(me,'Mesh')
        cube.setLocation (x,-y,z)
        mat= Material.New('newMat')
        mat.rgbCol = [t1,t2,t3]
        me.materials+=[mat]
        
        me = Mesh.Primitives.Cube(g)
        cube=sc.objects.new(me,'Mesh')
        cube.setLocation (-x,y,-z)
        mat= Material.New('newMat')
        mat.rgbCol = [t1,t2,t3]
        me.materials+=[mat]
        a=a/1.22
        b=b/1.22
        c=c/1.22
        t1=t1+f1
        t2=t2+f2
        t3=t3+f3
        d=d+1
        Window.RedrawAll()
    h=h+1
    d=0
    Window.RedrawAll()
Window.RedrawAll()



Also made some google research about Mandelbrot set

some intro pages


http://www.ddewey.net/mandelbrot/
http://aleph0.clarku.edu/~djoyce/julia/julia.html

some python references
http://www.blendpolis.de/viewtopic.php?t=20778
http://www.eddaardvark.co.uk/python_patterns/mandj.html


http://29a.ch/2009/5/12/rendering-the-mandelbrot-set-using-python-and-opengl-glsl

ok here are some scripts,
can we call that fractals I don’t know.
But it is fun…




from Blender import *
from Blender import Mathutils
d=0
h=0
sc = Scene.GetCurrent()         
me = Mesh.Primitives.Cube(2.0)   
cube=sc.objects.new(me,'Mesh')       
cube.setLocation (0.0,0.0,0.0)             
while h<7:
    x=0
    y=0
    z=0
    g=2.0
    t1=0.0
    t2=0.0
    t3=0.0
    a=Mathutils.Rand(-5.0,5.0)
    b=Mathutils.Rand(-5.0,5.0)
    c=Mathutils.Rand(-5.0,5.0)
    i=Mathutils.Rand(-1.0,1.0)
    j=Mathutils.Rand(-1.0,1.0)
    k=Mathutils.Rand(-1.0,1.0)
    while d<19:
        x=x+a
        y=y+b
        z=z+c
        f1=Mathutils.Rand(0.00,0.15)
        f2=Mathutils.Rand(0.00,0.15)
        f3=Mathutils.Rand(0.00,0.15)
        g=g-0.1
        
        me = Mesh.Primitives.Cube(g)
        cube=sc.objects.new(me,'Mesh')
        cube.setLocation (x,y,z)
        mat= Material.New('newMat')
        mat.rgbCol = [t1,t2,t3]
        me.materials+=[mat]
        
        me = Mesh.Primitives.Cube(g)
        cube=sc.objects.new(me,'Mesh')
        cube.setLocation (-x,y,z)
        mat= Material.New('newMat')
        mat.rgbCol = [t1,t2,t3]
        me.materials+=[mat]
        
        me = Mesh.Primitives.Cube(g)
        cube=sc.objects.new(me,'Mesh')
        cube.setLocation (-x,-y,z)
        mat= Material.New('newMat')
        mat.rgbCol = [t1,t2,t3]
        me.materials+=[mat]

        me = Mesh.Primitives.Cube(g)
        cube=sc.objects.new(me,'Mesh')
        cube.setLocation (-x,-y,-z)
        mat= Material.New('newMat')
        mat.rgbCol = [t1,t2,t3]
        me.materials+=[mat]
        
        me = Mesh.Primitives.Cube(g)
        cube=sc.objects.new(me,'Mesh')
        cube.setLocation (x,-y,-z)
        mat= Material.New('newMat')
        mat.rgbCol = [t1,t2,t3]
        me.materials+=[mat]

        me = Mesh.Primitives.Cube(g)
        cube=sc.objects.new(me,'Mesh')
        cube.setLocation (x,y,-z)
        mat= Material.New('newMat')
        mat.rgbCol = [t1,t2,t3]
        me.materials+=[mat]
        
        me = Mesh.Primitives.Cube(g)
        cube=sc.objects.new(me,'Mesh')
        cube.setLocation (x,-y,z)
        mat= Material.New('newMat')
        mat.rgbCol = [t1,t2,t3]
        me.materials+=[mat]
        
        me = Mesh.Primitives.Cube(g)
        cube=sc.objects.new(me,'Mesh')
        cube.setLocation (-x,y,-z)
        mat= Material.New('newMat')
        mat.rgbCol = [t1,t2,t3]
        me.materials+=[mat]
        
        a=(a-i)/2
        b=(b-j)/2
        c=(c-k)/2
        t1=t1+f1
        t2=t2+f2
        t3=t3+f3
        d=d+1
        Window.RedrawAll()
    h=h+1
    d=0
    Window.RedrawAll()
Window.RedrawAll()

a bite changed




from Blender import *
from Blender import Mathutils


d=0
h=0

sc = Scene.GetCurrent()         
me = Mesh.Primitives.Cube(2.0)   
cube=sc.objects.new(me,'Mesh')       
cube.setLocation (0.0,0.0,0.0)             
while h<7:
    x=0
    y=0
    z=0
    g=2.0
    t1=0.0
    t2=0.0
    t3=0.0
    l=0.0
    m=0.0
    n=0.0
    a=Mathutils.Rand(-5.0,5.0)
    b=Mathutils.Rand(-5.0,5.0)
    c=Mathutils.Rand(-5.0,5.0)
    i=Mathutils.Rand(-1.0,1.0)
    j=Mathutils.Rand(-1.0,1.0)
    k=Mathutils.Rand(-1.0,1.0)
    while d<19:
        x=x+a
        y=y+b
        z=z+c
        f1=Mathutils.Rand(0.00,0.15)
        f2=Mathutils.Rand(0.00,0.15)
        f3=Mathutils.Rand(0.00,0.15)
        g=g-0.1
        
        me = Mesh.Primitives.Plane(g)
        cube=sc.objects.new(me,'Mesh')
        cube.setLocation (x,y,z)
        cube.setEuler(l,m,n)
        mat= Material.New('newMat')
        mat.rgbCol = [t1,t2,t3]
        me.materials+=[mat]
        
        me = Mesh.Primitives.Plane(g)
        cube=sc.objects.new(me,'Mesh')
        cube.setLocation (-x,y,z)
        cube.setEuler(l,m,n)
        mat= Material.New('newMat')
        mat.rgbCol = [t1,t2,t3]
        me.materials+=[mat]
        
        me = Mesh.Primitives.Plane(g)
        cube=sc.objects.new(me,'Mesh')
        cube.setLocation (-x,-y,z)
        cube.setEuler(l,m,n)
        mat= Material.New('newMat')
        mat.rgbCol = [t1,t2,t3]
        me.materials+=[mat]

        me = Mesh.Primitives.Plane(g)
        cube=sc.objects.new(me,'Mesh')
        cube.setLocation (-x,-y,-z)
        cube.setEuler(l,m,n)
        mat= Material.New('newMat')
        mat.rgbCol = [t1,t2,t3]
        me.materials+=[mat]
        
        me = Mesh.Primitives.Plane(g)
        cube=sc.objects.new(me,'Mesh')
        cube.setLocation (x,-y,-z)
        cube.setEuler(l,m,n)
        mat= Material.New('newMat')
        mat.rgbCol = [t1,t2,t3]
        me.materials+=[mat]

        me = Mesh.Primitives.Plane(g)
        cube=sc.objects.new(me,'Mesh')
        cube.setLocation (x,y,-z)
        cube.setEuler(l,m,n)
        mat= Material.New('newMat')
        mat.rgbCol = [t1,t2,t3]
        me.materials+=[mat]
        
        me = Mesh.Primitives.Plane(g)
        cube=sc.objects.new(me,'Mesh')
        cube.setLocation (x,-y,z)
        cube.setEuler(l,m,n)
        mat= Material.New('newMat')
        mat.rgbCol = [t1,t2,t3]
        me.materials+=[mat]
        
        me = Mesh.Primitives.Plane(g)
        cube=sc.objects.new(me,'Mesh')
        cube.setLocation (-x,y,-z)
        cube.setEuler(l,m,n)
        mat= Material.New('newMat')
        mat.rgbCol = [t1,t2,t3]
        me.materials+=[mat]
        
        a=(a-i)/2
        b=(b-j)/2
        c=(c-k)/2
        t1=t1+f1
        t2=t2+f2
        t3=t3+f3
        d=d+1
        l=l+0.025
        m=m+0.025
        n=n+0.025
        Window.RedrawAll()
    h=h+1
    d=0
    Window.RedrawAll()
Window.RedrawAll()



I will give later the complete code here is just about what I want to do.
The simplest way to insert Japanese text in Blender.
Is to load a Japanese font.
and after that load the text saved in UTF-8 in edit mode.
I am trying to do that…
without success.
Text3d have no load attribute
I used setFont() fonction that I found in a forum but no sign of it in the API.
setText only accept string but I was thinking we can use a path.
???

A bit lost,
will strongly appreciate any help.


from Blender import *


sc = Scene.GetCurrent()       

txt=Text.Load('H:/test.txt') # I have the text in this driver in simpletext format saved in UTF-8

txt3d = Text3d.New("MyText3d") 
ob = sc.objects.new(txt3d)   
myfont= Text3d.Font.Load('C:/WINDOWS/Fonts/MSMINCHO.TTC')
txt3d.setFont(myfont)
txt3d.setWidth(1)
txt3d.setExtrudeDepth(0.1)
txt3d.setExtrudeBevelDepth(0.05)
#txt3d.setText(txt)



The answer was given by TK of Blender.jp assuming that the simple text file is (UTF-8 ) Is on the driver H.



from Blender import *
from Blender import Mathutils




sc = Scene.GetCurrent()       

txt = open('H:/test.txt').read() # c'est ici que ça change

txt3d = Text3d.New("MyText3d") 
ob = sc.objects.new(txt3d)   
myfont= Text3d.Font.Load('C:/WINDOWS/Fonts/MSMINCHO.TTC')
txt3d.setFont(myfont)
txt3d.setWidth(1)
txt3d.setExtrudeDepth(0.1)
txt3d.setExtrudeBevelDepth(0.05)
txt3d.setText(txt)

remains a small concern, a sort of cube appears,
I’ve always manually removed it.
:slight_smile: