Swap Objects (Modeling Cities)

I have been working on some city scenes using ezuals CityBlock script, the built in Blender scripts scatter and drop and clone_array. As one final touch to my clusters of buildings I would like to select building objects and swap the objects positions with other selected objects.

Does anyone know of a script that swaps object positions to move objects to the location of a opposite selected objects orientation?

Thanks in advance.

JA_forreal

Like this one ?


#!BPY

"""
Name: 'Swap Object's Matrix'
Blender: 237
Group: 'Object'
Tooltip: 'Swap the matrix of the two selected object '
"""

__author__ = "jms"
__url__ = ("blender", "elysiun","Inverse Objetc's Location script homepage, http://http://jmsoler.free.fr/didacticiel/blender/tutor/cpl_invobjloc.htm",)
__version__ = "0.01"
__bpydoc__ = """\
Usage: Select two objects and call the script . 
Notes: two objects must be selected at least .
"""

# --------------------------------------------------------------------------
# Inverse Objetc's Location (c) jmsoler 26/07/2005
# --------------------------------------------------------------------------
# ***** BEGIN GPL LICENSE BLOCK *****
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
#
# ***** END GPL LICENCE BLOCK *****
# -------------------------------------------------------------------------- 

import Blender
from Blender import Object
try:
  O=Object.GetSelected()
  mat=O[1].getMatrix() 
  O[1].setMatrix(O[0].getMatrix()) 
  O[0].setMatrix(mat)
  Blender.Redraw()
except:
	print "two objects must be selected at leat "


	

Perhaps useful too :

#!BPY

"""
Name: 'Move Object to a symmetric location '
Blender: 237
Group: 'Object'
Tooltip: 'Move the second selected object to a symmetric location according to the location of the first one'
"""

__author__ = "JMS"
__url__ = ("blender", "elysiun","Move object to a symmetric location  script homepage, http://http://jmsoler.free.fr/didacticiel/blender/tutor/cpl_movobjsymm.htm",)
__version__ = "0.01"
__bpydoc__ = """ Move the second selected object to a symmetric location according to the location of the first one .
Usage: Select two objects and call the script with shortkey 'alt-p' on the text window or with the scripts menu/Object .
Notes: two objects must be selected at least , but only the two first ones are used .
"""

# --------------------------------------------------------------------------
#  Move Object to Symmetric location (c) jmsoler 26/07/2005
# --------------------------------------------------------------------------
# ***** BEGIN GPL LICENSE BLOCK *****
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
#
# ***** END GPL LICENCE BLOCK *****
# --------------------------------------------------------------------------

import Blender
from Blender import Object, Mathutils

try:
  O=Object.GetSelected()
  P=[0.0,0.0,0.0]
  for n in [0,1,2]:
    P[n]=O[0].matrix[3][n]-(O[1].matrix[3][n]-O[0].matrix[3][n])
  mat= Mathutils.Matrix(O[1].matrix[0][:],
               O[1].matrix[1][:],
               O[1].matrix[2][:],
               [P[0],P[1],P[2],1.0])    
  O[1].setMatrix(mat)
  Blender.Redraw()
except:
  print "At least two objects must be selected ."
     

Thanks! Is any way to increase the number of selected object groups that can be swaped beyond just two objects?

It would be nice if the applications of all of the scripts that I’m using could be merged into one set of tools as one powerful object translation script.

A try .

In this script the first object of the the half list is swaped with the first object of with the second half .

if list contains 2 elements, it swaps the first one and second one.
if the list has 4 elements, it swaps the first with the third one

#!BPY

"""
Name: 'Swap Objetc's Location'
Blender: 237
Group: 'Object'
Tooltip: 'Swap the location of the two selected object'
"""

__author__ = "Authors Name"
__url__ = ("blender", "elysiun","Inverse Objetc's Location script homepage, http://http://jmsoler.free.fr/didacticiel/blender/tutor/cpl_invobjloc.htm",)
__version__ = "0.02"
__bpydoc__ = """\ 
In this script, the first object of the the half list is swaped with the first object of with the second half .

If the  objects list contains 2 elements, the script  swaps the first one and second one.  if the list  owns 4  elements, it swaps the first with the third one and so on .
Usage: Select two objects or more but the number must always be even (pair)  and call the script . 
Notes: two objects must be selected at least .
"""

# --------------------------------------------------------------------------
# Inverse Objetc's Location (c) jmsoler 26/07/2005
# --------------------------------------------------------------------------
# ***** BEGIN GPL LICENSE BLOCK *****
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
#
# ***** END GPL LICENCE BLOCK *****
# -------------------------------------------------------------------------- 

import Blender
from Blender import Object, Mathutils
try:
  O=Object.GetSelected()
  n2=len(O)/2
  for n in range(0,n2):
     mat=O[n].getMatrix() 
     O[n].setMatrix(O[n+n2].getMatrix()) 
     O[n+n2].setMatrix(mat)
  Blender.Redraw()
except:
	print "two objects must be selected at least "

You could also go first-last, second-one before last, and on, but since the order is not related to the order of selection (except for the fact that the active object is first), I think it would probably be a bit confusing regardless for any number other than 2.

Martin

Perfect! I used the CityBlock script and the clone_array scripts to generate and populate my city. Then I applied the scatter and drop script only on the selected objects with the settings “randomize and scatter -selected objects” locations-X/Y and uniform size- Z selected. Then I turned off the uniform size button and randomized the buildings to my liking hitting the scatter button. Finally I looked at my city and selected building objects that I wanted to relocate and applied the Swap script. Perfection. And endless possiblities to tweak a 3d city. This process works on plant and rock clusters also.

Thanks!

I hope that this helps out other Blender users.

Blend on!

Ok a new script :
http://cobalt3d.free.fr//didacticiel/blender/tutor/images/python/swapobjectlocation/nswapobjectloc01.jpg
http://jmsoler.free.fr/didacticiel/blender/tutor/cpl_invobjloc.htm#Parobjetconnectes
Not yet translated (sorry, my english is not fluent) but there is a file to test :
http://cobalt3d.free.fr//didacticiel/blender/tutor/images/python/swapobjectlocation/swapobjectloc.blend

There is two parts : the firts to select the object and the second to swap .

Great! This is a good way to pinpoint all of the obects that you want to swap.

Maybe I should start a new thread for this next question. But I think that it’s connected to the topic.

Is there a script that deflects selected objects from each other so that no objects overlap? I thought that I had seen a python script like this for Blender. If there is a script that deflects objects in this manner please provide a link if you can.

I have noticed that some groups of building objects are overlapping as I generate them. This seems to be the last step to take to clean everything up.

I hope that Ezual reads this thread as the various scripts that were used for this city building process compliment each other greatly. Maybe these scripts can be of help in his efforts on the Beast project.

Blend on!

http://jmsoler.free.fr/didacticiel/blender/tutor/cpl_invobjloc.htm#Parobjetconnectes