index global moho error

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

Moderators: Víctor Paredes, Belgarath, slowtiger

Post Reply
User avatar
davoodice2
Posts: 381
Joined: Tue Jun 15, 2021 1:14 pm

index global moho error

Post by davoodice2 »

any body can help?

Code: Select all

-- **************************************************
-- Provide Moho with the name of this script object
-- **************************************************

ScriptName = "daaaaaaaa"

-- **************************************************
-- General information about this script
-- **************************************************

daaaaaaaa = {}

function daaaaaaaa:Name()
	return 'daaaaaaaa'
end

function daaaaaaaa:Version()
	return '1.0'
end

function daaaaaaaa:UILabel()
	return 'daaaaaaaa'
end

function daaaaaaaa:Creator()
	return 'daaaaaaaa'
end

function daaaaaaaa:Description()
	return ''
end


-- **************************************************
-- Is Relevant / Is Enabled
-- **************************************************

function daaaaaaaa:IsRelevant(moho)
	return true
end

function daaaaaaaa:IsEnabled(moho)
	return true
end

-- **************************************************
-- Recurring Values
-- **************************************************

daaaaaaaa.name_textControl = 'Default'
daaaaaaaa.Lock_var = false
daaaaaaaa.labelCheck_var = true
daaaaaaaa.shyCheck_var = false

-- **************************************************
-- Keyboard/Mouse Control
-- **************************************************

function daaaaaaaa:OnMouseDown(moho, mouseEvent)
	
end

-- **************************************************
-- popupDialog1Dialog
-- **************************************************

local popupDialog1Dialog = {}

popupDialog1Dialog.CHANGE = MOHO.MSG_BASE
popupDialog1Dialog.LOCK = MOHO.MSG_BASE + 1
popupDialog1Dialog.LABEL = MOHO.MSG_BASE + 2
popupDialog1Dialog.SHY = MOHO.MSG_BASE + 3

function popupDialog1Dialog:new()
	local d = LM.GUI.SimpleDialog('', popupDialog1Dialog)
	local l = d:GetLayout()

	l:PushH()
		d.boneName = LM.GUI.TextControl(100, 'Name', d.CHANGE, LM.GUI.FIELD_TEXT, 'Rename:')
		l:AddChild(d.boneName, LM.GUI.ALIGN_LEFT, 0)

		d.lockBone = LM.GUI.CheckBox('Lock', d.LOCK)
		l:AddChild(d.lockBone, LM.GUI.ALIGN_LEFT, 7)

		d.colorMenu = LM.GUI.DynamicText('color:', 0)
		l:AddChild(d.colorMenu, LM.GUI.ALIGN_LEFT, 0)

		d.menu1Menu = LM.GUI.Menu('plain')
		d.menu1Menu_popup = LM.GUI.PopupMenu(120, true)
		d.menu1Menu_popup:SetMenu(d.menu1Menu)
		d.menu1Menu:AddItem('plain', 0, 0)
		l:AddChild(d.menu1Menu_popup, LM.GUI.ALIGN_LEFT, 0)

		d.labelCheck = LM.GUI.CheckBox('Label', d.LABEL)
		l:AddChild(d.labelCheck, LM.GUI.ALIGN_LEFT, 0)

		d.shyCheck = LM.GUI.CheckBox('Shy', d.SHY)
		l:AddChild(d.shyCheck, LM.GUI.ALIGN_LEFT, 0)
	l:Pop()
	return d
end

function popupDialog1Dialog:UpdateWidgets(moho)
	self.boneName:SetValue(daaaaaaaa.name_textControl)
	self.lockBone:SetValue(daaaaaaaa.Lock_var)
	self.labelCheck:SetValue(daaaaaaaa.labelCheck_var)
	self.shyCheck:SetValue(daaaaaaaa.shyCheck_var)
end

function popupDialog1Dialog:OnOK(moho)
	daaaaaaaa.name_textControl = self.boneName:Value()
	daaaaaaaa.Lock_var = self.lockBone:Value()
	daaaaaaaa.labelCheck_var = self.labelCheck:Value()
	daaaaaaaa.shyCheck_var = self.shyCheck:Value()
end

function popupDialog1Dialog:HandleMessage(msg)
	if msg == self.CHANGE then
		print('Message CHANGE received')
	elseif msg == self.LOCK then
		print('Message LOCK received')
	elseif msg == self.LABEL then
		print('Message LABEL received')
	elseif msg == self.SHY then
		print(moho.layer)
	else
		
	end
end


-- **************************************************
-- Tool Panel Layout
-- **************************************************

function daaaaaaaa:DoLayout(moho, layout)
	self.dlog = popupDialog1Dialog:new()
	self.popupDialog1Popup = LM.GUI.PopupDialog('Popup Dialog 1', false, 0)
	self.popupDialog1Popup:SetDialog(self.dlog)
	layout:AddChild(self.popupDialog1Popup, LM.GUI.ALIGN_LEFT, 0)
end
I get error here
elseif msg == self.SHY then
print(moho.layer)
خیام اگر ز باده مستی خوش باش
با ماهرخی اگر نشستی خوش باش
چون عاقبت کار جهان نیستی است
انگار که نیستی چو هستی خوش باش
User avatar
synthsin75
Posts: 9979
Joined: Mon Jan 14, 2008 11:20 pm
Location: Oklahoma
Contact:

Re: index global moho error

Post by synthsin75 »

You cannot access moho in a function that doesn't have moho as an argument. Passing moho as an argument requires the calling function to have access to moho as well.
User avatar
SimplSam
Posts: 1048
Joined: Thu Mar 13, 2014 5:09 pm
Location: London, UK
Contact:

Re: index global moho error

Post by SimplSam »

There are 2 definitions for HandleMessage.

1) Tool: HandleMessage(moho, view, msg)

2) Button: HandleMessage(msg)

You appear to be using a Tool script - so should be able to use HandleMessage(moho, view, msg)

Additionally - you can't print moho.layer - as it is an object.
Moho 14.1 » Win 11 Pro 64GB » NVIDIA GTX 1080ti 11GB
Moho 14.1 » Mac mini 2012 8GB » macOS 10.15 Catalina
Tube: SimplSam


Sam
User avatar
davoodice2
Posts: 381
Joined: Tue Jun 15, 2021 1:14 pm

Re: index global moho error

Post by davoodice2 »

SimplSam wrote: Thu Sep 09, 2021 7:34 pm There are 2 definitions for HandleMessage.

1) Tool: HandleMessage(moho, view, msg)

2) Button: HandleMessage(msg)

You appear to be using a Tool script - so should be able to use HandleMessage(moho, view, msg)

Additionally - you can't print moho.layer - as it is an object.
I use moho in arg in handlemessage. But i get same error.
Yes sure i put that print just for test
خیام اگر ز باده مستی خوش باش
با ماهرخی اگر نشستی خوش باش
چون عاقبت کار جهان نیستی است
انگار که نیستی چو هستی خوش باش
User avatar
davoodice2
Posts: 381
Joined: Tue Jun 15, 2021 1:14 pm

Re: index global moho error

Post by davoodice2 »

synthsin75 wrote: Thu Sep 09, 2021 7:13 pm You cannot access moho in a function that doesn't have moho as an argument. Passing moho as an argument requires the calling function to have access to moho as well.
Please correct my code wes. I do some things but error exist still.
خیام اگر ز باده مستی خوش باش
با ماهرخی اگر نشستی خوش باش
چون عاقبت کار جهان نیستی است
انگار که نیستی چو هستی خوش باش
User avatar
synthsin75
Posts: 9979
Joined: Mon Jan 14, 2008 11:20 pm
Location: Oklahoma
Contact:

Re: index global moho error

Post by synthsin75 »

There's no easy way to do what you're asking. A SimpleDialog can't pass moho to its UpdateWidgets, HandleMessage, etc. functions. You can pass moho by defining d.moho = moho, but you can't then use that to do self.moho.layer without Moho crashing. This seems to be because that self.moho is an instance, not a reference to the actual ScriptInterface. This means that you need to define every individual object you may need to access. In your case, d.layer = moho.layer will allow you to print(self.layer:Name()) in your HandleMessage. The problem with this is that self.layer is only initialized when the DoLayout is invoked, and cannot be updated until it is reinvoked. So if you change layers, that self.layer will not be the currently layer. It's the layer that was selected the last time the tool's options were invoked. This only happens naturally when you switch between different layer types.

So you have to jump through a lot of hoops to get Moho to do this. Far too much for me to explain here, but you can look at how I handle this in my Switch Icons tools for ideas.
User avatar
davoodice2
Posts: 381
Joined: Tue Jun 15, 2021 1:14 pm

Re: index global moho error

Post by davoodice2 »

Thanks wes.i will try .
I succeed to combine bone select tool and bone transform tool. Also i added tween machine to keytools script.
Now i want compress some options into popup menu to add more options. In this case i want add tween machine to bone transform. But i need more room in tool bar.
خیام اگر ز باده مستی خوش باش
با ماهرخی اگر نشستی خوش باش
چون عاقبت کار جهان نیستی است
انگار که نیستی چو هستی خوش باش
User avatar
davoodice2
Posts: 381
Joined: Tue Jun 15, 2021 1:14 pm

Re: index global moho error

Post by davoodice2 »

synthsin75 wrote: Thu Sep 09, 2021 9:54 pm There's no easy way to do what you're asking. A SimpleDialog can't pass moho to its UpdateWidgets, HandleMessage, etc. functions. You can pass moho by defining d.moho = moho, but you can't then use that to do self.moho.layer without Moho crashing. This seems to be because that self.moho is an instance, not a reference to the actual ScriptInterface. This means that you need to define every individual object you may need to access. In your case, d.layer = moho.layer will allow you to print(self.layer:Name()) in your HandleMessage. The problem with this is that self.layer is only initialized when the DoLayout is invoked, and cannot be updated until it is reinvoked. So if you change layers, that self.layer will not be the currently layer. It's the layer that was selected the last time the tool's options were invoked. This only happens naturally when you switch between different layer types.

So you have to jump through a lot of hoops to get Moho to do this. Far too much for me to explain here, but you can look at how I handle this in my Switch Icons tools for ideas.
Is this possible that i connect shy checkbox to a variable in other function?
Chage shy 》 change var ■■ change var》 change layer.
خیام اگر ز باده مستی خوش باش
با ماهرخی اگر نشستی خوش باش
چون عاقبت کار جهان نیستی است
انگار که نیستی چو هستی خوش باش
User avatar
SimplSam
Posts: 1048
Joined: Thu Mar 13, 2014 5:09 pm
Location: London, UK
Contact:

Re: index global moho error

Post by SimplSam »

OK. I will revert my answer.

You would use for the main toolbar:

Code: Select all

daaaaaaaa:HandleMessage(moho, view, msg)
for the popup - you need to use:

Code: Select all

popupDialog1Dialog:HandleMessage(msg)
Moho 14.1 » Win 11 Pro 64GB » NVIDIA GTX 1080ti 11GB
Moho 14.1 » Mac mini 2012 8GB » macOS 10.15 Catalina
Tube: SimplSam


Sam
User avatar
SimplSam
Posts: 1048
Joined: Thu Mar 13, 2014 5:09 pm
Location: London, UK
Contact:

Re: index global moho error

Post by SimplSam »

davoodice2 wrote: Thu Sep 09, 2021 10:06 pm Thanks wes.i will try .
I succeed to combine bone select tool and bone transform tool. Also i added tween machine to keytools script.
Now i want compress some options into popup menu to add more options. In this case i want add tween machine to bone transform. But i need more room in tool bar.
By the time you have finished embedding one tool inside another, I don't think you are actually making the usage/process any more efficient.

I understand combining multiple tools to optimize their use, but you could end up with a less streamlined workflow, an inability to keyboard shortcut / macro tools and non-modular monolithic spaghetti code - if you over do it.
Moho 14.1 » Win 11 Pro 64GB » NVIDIA GTX 1080ti 11GB
Moho 14.1 » Mac mini 2012 8GB » macOS 10.15 Catalina
Tube: SimplSam


Sam
User avatar
davoodice2
Posts: 381
Joined: Tue Jun 15, 2021 1:14 pm

Re: index global moho error

Post by davoodice2 »

Thanks. But that way get same error too.
In my work flow of animating switching tools is boring.
I came from maya to moho. I like make moho work flow much faster .
خیام اگر ز باده مستی خوش باش
با ماهرخی اگر نشستی خوش باش
چون عاقبت کار جهان نیستی است
انگار که نیستی چو هستی خوش باش
User avatar
synthsin75
Posts: 9979
Joined: Mon Jan 14, 2008 11:20 pm
Location: Oklahoma
Contact:

Re: index global moho error

Post by synthsin75 »

davoodice2 wrote: Thu Sep 09, 2021 10:06 pm Also i added tween machine to keytools script.
Have you posted that one yet? I might have missed it.
davoodice2 wrote: Thu Sep 09, 2021 10:10 pm Is this possible that i connect shy checkbox to a variable in other function?
Chage shy 》 change var ■■ change var》 change layer.
I don't quite follow, but I think so. You can have the shy checkbox msg be global to the script, like daaaaaaaa.SHY = MOHO.MSG_BASE + 3 instead of popupDialog1Dialog.SHY = MOHO.MSG_BASE + 3. Then the tool options HandleMessage, that does have access to moho, will read it when it's invoked. Then it's just a matter of if the tool option HandleMessage is invoked when you need it to be (which in this case might be when the popupMenu is closed, I don't remember exactly). If you try to call the tool option HandleMessage from the popup dialog HandleMessage, it won't get moho.
Last edited by synthsin75 on Fri Sep 10, 2021 5:48 pm, edited 1 time in total.
User avatar
davoodice2
Posts: 381
Joined: Tue Jun 15, 2021 1:14 pm

Re: index global moho error

Post by davoodice2 »

synthsin75 wrote: Fri Sep 10, 2021 12:45 am Have you posted that one yet? I might have missed it.


no.but after more test in real project I will post that.
خیام اگر ز باده مستی خوش باش
با ماهرخی اگر نشستی خوش باش
چون عاقبت کار جهان نیستی است
انگار که نیستی چو هستی خوش باش
Post Reply