Clone bones

Moho allows users to write new tools and plugins. Discuss scripting ideas and problems here.

Moderators: Víctor Paredes, Belgarath, slowtiger

Post Reply
bogush_r
Posts: 6
Joined: Sat Jul 09, 2005 1:49 am

Clone bones

Post by bogush_r »

I wrote this script to compensate lack of copy/paste operations on bone objects. This script can duplicate selected bone with child bones. This is pre-alpha version with some restictions. For example, a bone can have more than one child bone, but only first children will be included in copy sequence (yet):

Code: Select all

P-+-A-+-B-+-C-
    \             
      +-a-+-b-

P has 2 children (A and a), but only P-A-B-C bones will be duplicated.

Another disadvantage is bones will be copied without keyframes.

I hope however, this tool can be useful. Anyway, all comments welcome.

http://bogush-r.narod.ru/moho/scripts/rb_clonebone.lua
Roman Bogush.
User avatar
genericdave
Posts: 4
Joined: Tue Aug 09, 2005 9:58 am

Post by genericdave »

Seems a bit strange that this isn't part of the main moho package. Oh well, I guess that's why scripting is so great.

Anyway I was looking at your script and it seems like it would be pretty easy to make it clone all the selected bone's children. You could probably change the RB_CloneBone:Run() function so that it loops through the id of every bone in the skeleton and checks to see if it's a child of the selected bone instead of using the GetFirstChildBone() method. Something like this:

Code: Select all

function RB_CloneBone:Run(moho)
	local skel = moho:Skeleton()
	local parId = skel:SelectedBoneID()
	if parId == -1 then
		MESSAGE = 'Select a bone first'
		RB_CloneBoneMsg:new(moho):DoModal()
		return
	end


	local dlog = RB_CloneBoneDialog:new(moho)
	if (dlog:DoModal() == LM.GUI.MSG_CANCEL) then
		return
	end
	

-- Enum all child bones
	PARENT= -1
	Clone(moho:Skeleton(), parId)
	local numBones = skel:CountBones()
	for x = 1, numBones, 1 do	
		if skel:IsBoneParent(x, parId) then
			Clone(moho:Skeleton(), x)
		end
	end
end
Although for some reason this copies the entire skeleton instead of just the children. Pretty good for my first crack at moho scripting though.
This signature is not clever by any means...
User avatar
Rai López
Posts: 2242
Joined: Sun Aug 08, 2004 1:41 pm
Location: Spain
Contact:

Post by Rai López »

WOW!!! :shock: ...VEEERY USEFULL!!! THANKS! :D

PS: I always wonder me too why I could not do that with the main moho package, yes...
Post Reply