Repeat mit Blender

Repeat-Script 0.3 Documentation

Preface

I love that array-functions.

Installation

  1. Download the script repeat.py
  2. Copy the script in the scripts-directory of your Blender

Execute the script

Run the script from the 3d View’s Mesh->Objects menu.
Picture 1

Usage

This script give you the possiblity to copy one or many objects in different directions and with different values of the copy object. It save the settings in a file, for later usage.

Functions

Picture 2

1,2,3 - single values (Move, Rotation, Scale, X, Y, Z) 4 - fixing value section (single/sum) 5,6,7 - single values (Move, Rotation, Scale, X, Y, Z) 8 - sum of all single values (Move, Rotation, Scale, X, Y, Z) 8 - uniform scale of object 9 - number of copies in 1./2. and 3. dimension 10,11,12 - X,Y,Z values of 2. and 3. dimension 13 - total numbers of all copies 14 - reset all values to default 15 - type of resultobject(s) (full copy/instance) 16 - undo action 17 - action

Example

In that example we make a very simple greek temple.

  1. Add a new cube (shift + A)
    Screen4

  2. Modifiy the cube to a platform
    Screen5

  3. Set a cylinder in a corner of this platform (shift + a)
    Screen6

  4. Select the cylinder (right mouse button)

  5. Set value Y in single section row move to 5 and press OK-Button.
    Screen7

  6. Now you got a row of 10 pillars.
    Screen8

  7. Select the corner pillar-cylinders (shift + right mouse button)
    Screen9

  8. Press the Default-Button to reset.

  9. Set value X in single section row move to 5 and the number of copies to 8, then press OK-Button.
    ScreenA

  10. Now we have a C-like pillar-set.
    ScreenB

  11. Press the Default-Button to reset.

  12. To the last: set value Y in single section row move to 5 and the number of copies to 9, then press OK-Button.
    ScreenC

  13. Finished.
    Finishpicture

Planed Functions

Thanks

I’d like to say thanks some people, that support me in different ways.

Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
#!BPY

""" Registrationsinformationen fuer Blender-Menues
Name: 'Repeat'
Blender: 236
Group: 'Object'
Tip: 'Repeat objects'
"""
__author__ = "Thomas Buschhardt"
__url__ = ["Script Site,www.buschhardt.de/repeat"]
__version__ = "0.3 20050202"
__email__ = ["Thomas Buschhardt, thomas:buschhardt*de"]
__bpydoc__ = """\
This script implements object repeat functions in Blender.

Usage:

Select the objects you want to work on, run this script from the 3d View's Objects->Scripts menu.

You can control the move, rotation,size and number of copies global X,Y and Z axis.
There is a undo function and all settings a save to a file, for next time use.
To quit the script press 'ESC' or 'Q'.

Thanks goes to ideasman (Blender-Forum) for the instance copy code!
"""
##
# Hauptmodule einladen
##
import Blender

##
# globale Variablen
##
colDefault=(0,0,0,0,0,0,100.0,100.0,100.0,0,0,0,0,0,0,100.0,100.0,100.0,0,0,0,0,0,0,10,1,1,0,0,0,0)
colVar=[]
for i in colDefault:colVar.append(i)
#0-2 mov sng
#3-5 rot sng
#6-8 siz sng
#9-11 mov sum
#12-14 rot sum
#15-17 siz sum
#18-20 2 dim
#21-23 3 dim
#24-26 num 1/2/3 dim
#27-29 fix mov/rot/siz
#30 full/instance

colOriginal=[]
colKopie=[]
colSlider=[]
for i in range(4):colSlider.append(Blender.Draw.Create(0))

##
# Hilfsfunktionen
##
def kopieObjekt(Objekt,type=0):#0 full 1 instanz
  if type==0:
    Meshneu=Blender.NMesh.GetRawFromObject(Objekt.getName())
    objneu=Blender.NMesh.PutRaw(Meshneu)
    objneu.setLocation(Objekt.getLocation())
    objneu.setEuler(Objekt.getEuler())
  else:
    scn = Blender.Scene.getCurrent()
    type = Objekt.getType()
    objneu = Blender.Object.New(type)
    objneu.shareFrom(Objekt)
    scn.link(objneu)
    objneu.setMatrix(Objekt.getMatrix())
    # Copy other attributes.
    objneu.drawMode = Objekt.drawMode
    objneu.Layer = Objekt.Layer
    scn.update(1)
  return objneu

def speichere():
  dir=Blender.Get("datadir")
  if dir!=None:
    f=open(dir+"repeat03.ini","w")
    ergg=""
    for i in colVar:ergg+=str(i)+"\t"
    f.write(ergg)
    f.close()

def lese():
  dir=Blender.Get("datadir")
  if dir!=None:
    try:
      f=open(dir+"repeat03.ini","r")
      ergg=f.read()
      f.close()
      numb=-1
      zwischen=""
      for i in ergg:
        if i=="\t":
          numb+=1
          colVar[numb]=eval(zwischen)
          zwischen=""
        else:zwischen+=i
    except:pass

def holeFloat(Initialwert,Bezeichnung="",noneg=0):
  if noneg==0:
    result = Blender.Draw.PupFloatInput(Bezeichnung,Initialwert,-10000,10000,100,1)
  else:
    result = Blender.Draw.PupFloatInput(Bezeichnung,Initialwert,0,10000,100,1)
  if result != None:return result
  else:return Initialwert

def holeInt(Initialwert,Bezeichnung=""):
  result = Blender.Draw.PupIntInput(Bezeichnung,Initialwert,1,10000)
  if result != None:return result
  else:return Initialwert

def rahmen(text,xmin,xmax,ymin,ymax,xtext):
  Blender.BGL.glColor3f(0,0,0)
  Blender.BGL.glRasterPos2i(xmin+3,ymax-3)
  Blender.Draw.Text(text)
  Blender.BGL.glBegin(Blender.BGL.GL_LINE_STRIP)
  Blender.BGL.glVertex2i(xmin,ymax)
  Blender.BGL.glVertex2i(xmin,ymin)
  Blender.BGL.glVertex2i(xmax,ymin)
  Blender.BGL.glVertex2i(xmax,ymax)
  Blender.BGL.glVertex2i(xtext,ymax)
  Blender.BGL.glEnd()
  return

def tx(posx,posy,text,farbe=0):
  Blender.BGL.glColor3f(farbe,farbe,farbe)
  Blender.BGL.glRasterPos2i(posx,posy)
  Blender.Draw.Text(text)
  return

##
# grafische Oberflaeche
##
def fenster():
  global colSlider

###Labels and Graphics
  all_tx=(30,167,"X",80,167,"Y",130,167,"Z",282,167,"X",332,167,"Y",382,167,"Z",160,167,"fix: 0-single  1-all",
  10,55,"1.Dim.",10,35,"2.Dim.",10,15,"3.Dim.",130,55,"X",180,55,"Y",230,55,"Z",270,70,"0-Fullcopy    1-Instance")

  for i in range(0,len(all_tx),3):
    tx(all_tx[i],all_tx[i+1],all_tx[i+2])
  tx(270,85,"Repeat 0.3 by Thomas Buschhardt",1)

  rahmen("Operation",5,470,100,185,100)
  rahmen("",265,470,5,90,470)
  rahmen("Dimensions",5,260,5,90,80)
###Buttons Sliders
  for i in range(3):
    for j in range(3):
      Blender.Draw.PushButton(str(colVar[j+i*3]),i*3+j+1,j*50+10,50-i*20+95,45,15)
      Blender.Draw.PushButton(str(colVar[j+i*3+9]),i*3+j+10,j*50+265,50-i*20+95,45,15)

  all_but=("Uniform",102,415,105,50,"Default",100,270,10,73,"Undo",101,348,10,72)
  for i in range(0,len(all_but),5):Blender.Draw.PushButton(str(all_but[i]),all_but[i+1],all_but[i+2],all_but[i+3],all_but[i+4],15)

  all_but=(colVar[18],19,110,32,colVar[19],20,160,32,colVar[20],21,210,32,colVar[21],22,110,12,colVar[22],23,160,12,colVar[23],24,210,12,colVar[24],25,55,52,colVar[25],26,55,32,colVar[26],27,55,12)
  for i in range(0,len(all_but),4):Blender.Draw.PushButton(str(all_but[i]),all_but[i+1],all_but[i+2],all_but[i+3],45,15)

  colSlider[0]=Blender.Draw.Slider("Move",28,160,145,100,15,colVar[27],0,1)
  colSlider[1]=Blender.Draw.Slider("Rotate",29,160,125,100,15,colVar[28],0,1)
  colSlider[2]=Blender.Draw.Slider("Scale",30,160,105,100,15,colVar[29],0,1)
  colSlider[3]=Blender.Draw.Slider("Objecttype",31,270,50,150,15,colVar[30],0,1,1)

  Blender.Draw.PushButton("OK",103,425,10,40,35)
  Blender.Draw.String("Total Number:",0,110,70,145,15,str(colVar[24]*colVar[25]*colVar[26]),100)
  Blender.Draw.Redraw(1)

##
# Auswerten von allgemeinen Ereignissen
##
def allg_ereignis(erg,wert):
  if erg==Blender.Draw.ESCKEY or erg==Blender.Draw.QKEY:Blender.Draw.Exit()

##
# Auswerten von Schalter-Ereignissen
##
def schalter_ereignis(erg):
  global colVar,colOriginal,colKopie
  if erg<4:# mov sng
    colVar[erg-1]=holeFloat(colVar[erg-1],"units")
    colVar[erg+8]=colVar[erg-1]*colVar[24]
  elif erg>3 and erg<7:# rot sng
    colVar[erg-1]=holeFloat(colVar[erg-1],"degree")
    colVar[erg+8]=colVar[erg-1]*colVar[24]
  elif erg>6 and erg<10:# siz sng
    colVar[erg-1]=holeFloat(colVar[erg-1],"percent",1)
    colVar[erg+8]=(colVar[erg-1]/100)**colVar[24]*100
  elif erg>9 and erg<13:# mov sum
    colVar[erg-1]=holeFloat(colVar[erg-1],"units")
    colVar[erg-10]=colVar[erg-1]/colVar[24]
  elif erg>12 and erg<16:# rot sum
    colVar[erg-1]=holeFloat(colVar[erg-1],"degree")
    colVar[erg-10]=colVar[erg-1]/colVar[24]
  elif erg>15 and erg<19:# siz sum
    colVar[erg-1]=holeFloat(colVar[erg-1],"percent",1)
    colVar[erg-10]=(colVar[erg-1]/100)**(1.0/colVar[24])*100
  elif erg>18 and erg<25:# 2 + 3 dim
    colVar[erg-1]=holeFloat(colVar[erg-1],"units")
  elif erg==25:# number 1 dim
    altwert=colVar[24]
    colVar[24]=holeInt(colVar[24])
    if altwert!=colVar[24]:
      for i in range(3):
        if colVar[27]==0:
          colVar[i+9]=colVar[i]*colVar[24]
        else:
          colVar[i]=colVar[i+9]/colVar[24]
        if colVar[28]==0:
          colVar[i+12]=colVar[i+3]*colVar[24]
        else:
          colVar[i+3]=colVar[i+12]/colVar[24]
        if colVar[29]==0:
          colVar[i+15]=(colVar[i+6]/100)**colVar[24]*100
        else:
          colVar[i+6]=(colVar[i+15]/100)**(1.0/colVar[24])*100
  elif erg>25 and erg<28:# number 2 + 3 dim
    colVar[erg-1]=holeInt(colVar[erg-1])
  elif erg>27 and erg<32:# fix mov/rot/siz objecttyp
    colVar[erg-1]=colSlider[erg-28].val
  elif erg==100:# default
    colVar=[]
    for i in colDefault:colVar.append(i)
  elif erg==101:# undo
    for i in colKopie:Blender.Scene.getCurrent().unlink(i)
    for i in colOriginal:i.select(1)
    colOriginal=[]
    colKopie=[]
    Blender.Redraw()
  elif erg==102:# uniform
    colVar[7]=colVar[6]
    colVar[8]=colVar[6]
    colVar[15]=(colVar[6]/100)**colVar[24]*100
    colVar[16]=colVar[15]
    colVar[17]=colVar[15]
  elif erg==103:# ok
    pi2=180/3.1415926
    colOriginal=[]
    colKopie=[]
    for obj in Blender.Object.GetSelected():
      erstkopie=0
      if obj.getType()=="Mesh":
        colOriginal.append(obj)
        objLoc=obj.getLocation()
        objRot=obj.getEuler()
        objScale=obj.getSize()
        for i in range(colVar[24]):
          for j in range(colVar[25]):
            for k in range(colVar[26]):
              ob=kopieObjekt(obj,colVar[30])
              if erstkopie==0:erstkopie=ob
              ob.setLocation(objLoc[0]+i*colVar[0]+j*colVar[18]+k*colVar[21],objLoc[1]+i*colVar[1]+j*colVar[19]+k*colVar[22],objLoc[2]+i*colVar[2]+j*colVar[20]+k*colVar[23])
              ob.setEuler(objRot[0]+i*(colVar[3]/pi2),objRot[1]+i*(colVar[4]/pi2),objRot[2]+i*(colVar[5]/pi2))
              ob.setSize(objScale[0]*(colVar[6]/100)**i,objScale[1]*(colVar[7]/100)**i,objScale[2]*(colVar[8]/100)**i)
              colKopie.append(ob)
      Blender.Scene.getCurrent().unlink(erstkopie)
    Blender.Redraw()
  speichere()

lese()

Blender.Draw.Register(fenster,allg_ereignis,schalter_ereignis)
6. März 2017 10:46:50
© 2017. Thomas Buschhardt. Some Rights Reserved. Alle hier genannten Marken sind Eigentum der jeweiligen Inhaber.