Blender (jusqu'à 2.49)
Curseur 3D
Getting real-time location
(version française)
    Début   Index
previoust Saving a theme 
 Loading a picture Next
1/ Cursor real location.
    Automatic connection to the scene
2/ distance of a point from the 3D cursor

 

1/ Cursor real location.

This script is not really useful since you can get this location in the View Properties pannel that can be displayed through the View menu of  the 3D window. But it is essential to test the automatic connection to the scene methods and the order of retrieval of the empty name that will be used as 3D display.

Automatic connection to the scene method


sce=Blender.Scene.getCurrent()
if sce.getScriptLinks('Redraw')== None : 
    sce.addScriptLink('auto3dcursor.py','Redraw')
elif 'auto3dcursor.py' not in sce.getScriptLinks('Redraw'): 
    sce.addScriptLink('auto3dcursor.py','Redraw') 

 


 import Blender
p= Blender.Window.GetCursorPos()
EN="  %2s,%2s,%2s"%(round(p[0],2),
                       round(p[1],2),
                       round(p[2],2))
try:
  if Blender.x3dpos!=EN:
     print EN, Blender.x3dpos
     EP=Blender.Object.Get()
     print EP
     E=Blender.Object.Get(Blender.x3dpos)
     E.setLocation(p)
     E.setName(EN) 
     Blender.x3dpos=EN
     Blender.Redraw()

except:
     E=Blender.Object.New('Empty')
     sce=Blender.Scene.getCurrent()
     sce.link(E)
     Blender.x3dpos=EN
     E.setName(EN)
     print EN
     E.setLocation(p)
     E.setDrawMode(8)
     Blender.Redraw()

sce=Blender.Scene.getCurrent()
if sce.getScriptLinks('Redraw')== None : 
    sce.addScriptLink('auto3dcursor.py','Redraw')
elif 'auto3dcursor.py' not in sce.getScriptLinks('Redraw'): 
    sce.addScriptLink('auto3dcursor.py','Redraw') 

2/ Distance of a point from the 3D cursor
Download the script

Joined with the View Properties pannel and the Transform Properties pannel display,  the script should offer an efficient mesurement tool. 

Principal:

  1. Automatically creating an Empty and connecting it to the script.
    •  
  2. Mesuring the distance between the empty and the 3D cursor. 
    • To do so, we retrieve the 3D cursor location with the function : 
          Blender.Window.GetCursorPos() 
      and the one of the empty with the two lines : 
          E= Blender.Object.Get(Blender.x3dpos)
          p2=E.getLocation() 
  3. Tracing a line between these two reference elements :
    1. An old-established ability, only recently discovered : drawing directly in the 3D window . If we stick to a simple restriction : the script must be connected to an object and not to the scene. The rest passes through the openGL functions located in the BGL module.
  4. Giving the result under figures shape in the empty name.
    • This is a legerdemain since you must be able to retrieve the name of this object each time the display is renewed and there is a renewed display each time an object is moved in the scene. If the empty is moved, then it's name changes at each display redrawing.  Thus, you have to store it temporarily and be able to retrieve it at the next script call . Since the name space of the python is cancelled each time a script is ended the only place available is the Blender module itself.
  5. VERY IMPORTANT.
    1. Caution, if you copy the here below code as it stands, don't forget to rename the script in the wordprocessing window. Because, it connect itself automatically to the Empty but  it is waiting for a script named mesure.py 
#!BPY

"""
Name: 'Mesure on'
Blender: 232
Group: 'Misc'
Tooltip: 'Activate control of the length to the 3Dcursor'
"""
# ============================================
# jmsoler 26/10/2004, Blender artistic licence
# updated : 27/07/2005
# last update : 26/10/2006
# ============================================
import Blender

from Blender import BGL,Draw, Window
p=[0,0,0.0,0.0]
p2=[0,0,0.0,1.0]

viewMatrix = Window.GetPerspMatrix()
viewBuff = [viewMatrix[i][j] for i in xrange(4) for j in xrange(4)]
viewBuff = BGL.Buffer(BGL.GL_FLOAT, 16, viewBuff)

BGL.glLoadIdentity()
BGL.glMatrixMode(BGL.GL_PROJECTION)
BGL.glPushMatrix()
BGL.glLoadMatrixf(viewBuff)

try:
  p= Blender.Window.GetCursorPos()
  E= Blender.Object.Get(Blender.x3dpos)
  p2=E.getLocation() 
  E.setSize(-p2[0],-p2[1],-p2[2])

  BGL.glColor4f(1.0,0.5,0.0,1.0)
  BGL.glBegin(BGL.GL_LINES)
  BGL.glVertex3f(p[0],p[1],p[2])
  BGL.glVertex3f(p2[0],p2[1],p2[2])
  BGL.glEnd()

  BGL.glColor4f(1.0,1.0,1.0,1.0)

  EN=abs((p[0]-p2[0])*(p[0]-p2[0])+
                 (p[1]-p2[1])*(p[1]-p2[1])+
                       (p[2]-p2[2])*(p[2]-p2[2]))**0.5
  E.setName("  %s"%round(EN,4))
  Blender.x3dpos=E.getName()

except:
     E=Blender.Object.New('Empty')
     sce=Blender.Scene.getCurrent()
     sce.link(E)

NAME='mesure.py'

     if NAME not in [t.name for t in Blender.Text.Get()]:
        SCRIPTDIR = Blender.Get('scriptsdir')+Blender.sys.sep
        print SCRIPTDIR+NAME
        Blender.Text.Load(SCRIPTDIR+NAME)

     p= Blender.Window.GetCursorPos()
     p2= [1.0,1.0,1.0]
     E.setLocation(p2)
     E.setSize(p2)

     EN=abs((p[0]-p2[0])*(p[0]-p2[0])+
                   (p[1]-p2[1])*(p[1]-p2[1])+
                      (p[2]-p2[2])*(p[2]-p2[2]))**0.5
     E.setName("  %s"%round(EN,4))
     Blender.x3dpos=E.getName()
     E.setDrawMode(8)

     if sce.getScriptLinks('Redraw')== None : 
        sce.addScriptLink(NAME,'Redraw')
     elif 'mesure.py' not in sce.getScriptLinks('Redraw'): 
        sce.addScriptLink(NAME,'Redraw')

     BGL.glColor4f(1.0,0.5,0.0,1.0)
     BGL.glBegin(BGL.GL_LINES)
     BGL.glVertex3f(p[0],p[1],p[2])
     BGL.glVertex3f(p2[0],p2[1],p2[2])
     BGL.glEnd() 


 
previous Saving a theme 
  Loading a picture Next
To the  Top of the page

You can ask questions concerning this page on   :
 news://news.zoo-logique.org/3D.Blender


 

 

Les questions concernant cette page  peuvent être posées sur  :
news://news.zoo-logique.org/3D.Blender

Livre en français
Blender : apprenez, pratiquez, Créez, livre, Ed. Campus Press, coll. Starter Kit
Blender Starter Kit

Forum
FAQ
Lexique
Didacticiels
Compilations
Blender2KT
Débuter
Modelage
Blender python
Materiaux
Lumière
Animation
API python (eng)
Archives nzn
Statistiques
Doc flash Sculptris
Galerie Sculptris

mon site de démos sur youtube