Skip to content

Instantly share code, notes, and snippets.

@ethanaeris
Last active June 26, 2022 11:40
Show Gist options
  • Select an option

  • Save ethanaeris/4952e9d34ce54e4cbc5fe22983538b52 to your computer and use it in GitHub Desktop.

Select an option

Save ethanaeris/4952e9d34ce54e4cbc5fe22983538b52 to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
# ##### 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# ##### END GPL LICENSE BLOCK #####
bl_info = {
"name": "fast_path",
"author": "Laurent Laget",
"version": (0, 5),
"blender": (2, 78, 5),
"location": "Add",
"description": "Create fast_path",
"warning": "",
"wiki_url": "",
"category": "Add",
}
import bpy
def main(context):
for ob in context.scene.objects:
print(ob)
#Declaration of variables
forwardaxe = 'TRACK_NEGATIVE_Y'
upaxe = 'UP_Z'
def pathcreation(forwardaxe,upaxe):
#Get duration
duration = bpy.context.scene.frame_end
#Get the name of the selected object and add a follow path constrain to it
objectname = bpy.context.active_object
bpy.ops.object.constraint_add(type='FOLLOW_PATH')
# Add a curve object , name it, delete vertices and make it ready for shift + right click draw
bpy.ops.curve.primitive_nurbs_path_add()
bpy.context.object.name = "Path"
pathname= bpy.context.active_object
bpy.ops.object.editmode_toggle()
bpy.ops.curve.delete(type='VERT')
#Go back to object mode , set origin and reselect the selected object , push the name of the path in the follow path constraint and animate it
bpy.ops.object.editmode_toggle()
bpy.ops.object.origin_set(type='ORIGIN_GEOMETRY')
bpy.context.scene.objects.active = objectname
bpy.context.object.constraints["Follow Path"].target = pathname
bpy.context.object.constraints["Follow Path"].use_curve_follow = True
#Test if the selected object is different from a camera, and set variables accordingly
if objectname.type != 'CAMERA':
forwardaxe = 'TRACK_NEGATIVE_Y'
upaxe = 'UP_Z'
else:
forwardaxe = 'TRACK_NEGATIVE_Z'
upaxe = 'UP_Y'
#Get specific orientations
bpy.context.object.constraints["Follow Path"].forward_axis = forwardaxe
bpy.context.object.constraints["Follow Path"].up_axis = upaxe
override={'constraint':objectname.constraints["Follow Path"]}
bpy.ops.constraint.followpath_path_animate(override,constraint='Follow Path')
#reselect the path
bpy.context.scene.objects.active = pathname
bpy.context.object.data.path_duration = duration
bpy.ops.object.editmode_toggle()
objectname.location[0] = 0
objectname.location[1] = 0
objectname.location[2] = 0
objectname.rotation_euler[0] = 0
objectname.rotation_euler[1] = 0
objectname.rotation_euler[2] = 0
#Class fastpath
class fastpath(bpy.types.Operator):
"""Create a path for the selected object"""
bl_idname = "object.fastpath"
bl_label = "fastpath"
bl_options = {'REGISTER', 'UNDO'}
def invoke(self, context, event):
pathcreation(forwardaxe,upaxe)
return {'FINISHED'}
addon_keymaps = []
def menu_item(self, context):
self.layout.operator(fastpath.bl_idname, text="fastpath", icon="PLUGIN")
def register():
bpy.utils.register_module(__name__)
bpy.types.INFO_MT_curve_add.append(menu_item)
global addon_keymaps
wm = bpy.context.window_manager
km = wm.keyconfigs.addon.keymaps.new(name = "3D View", space_type = "VIEW_3D")
kmi = km.keymap_items.new(fastpath.bl_idname, 'LEFTMOUSE', 'DOUBLE_CLICK', ctrl=True)
addon_keymaps.append(km)
def unregister():
bpy.utils.unregister_module(__name__)
bpy.types.INFO_MT_curve_add.remove(menu_item)
global addon_keymaps
wm = bpy.context.window_manager
for km in addon_keymaps:
for kmi in km.keymap_items:
km.keymap_items.remove(kmi)
wm.keyconfigs.addon.keymaps.remove(km)
addon_keymaps.clear()
if __name__ == "__main__":
register()
@ethanaeris
Copy link
Copy Markdown
Author

ethanaeris commented May 25, 2017

Installation:

  1. Start Blender and open User Preferences. Click on the addons tab
  2. Click "install from file" , then choose downloaded zip.
  3. Check the addon to activate, then save user preferences.

How to use:
Select any objet and press Ctrl+double left mouse button
or press shift + A -> curve ->fastpath
Draw your path with shift + click

The script will change the forward and up axis if the object is a camera !

@antonvdh
Copy link
Copy Markdown

Is there an update for version blender 3.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment