Notifications
Clear all

[Closed] SME script – variable fails?

Hello there

I’ve found on this forum a piece of code that should do exactly what I’m looking for: creating a new node view, and gather all scene materials in it. Sorry, I don’t remember who gave this, but here where I am:

for i = sme.GetNumViews() to 1 by -1 do sme.DeleteView i false -- deletes all SME node views
	sme_AIVview1 = sme.GetView (sme.CreateView "MyView") -- creates a new view
	for matAIV in sceneMaterials do 
	(
		sme_AIVview1.createNode matAIV [0,0] -- creates a material node for each scene material
	)

	actionMan.executeAction 369891408 "40060"  -- SME: Lay Out All

The problem is that when I run this, it always fails printing that my sme_AIVview1 variable is undefined … I even tried declaring it at the beginning of my script, but still the same. What big am I missing, please ?

Thanks in advance !

Regards.

4 Replies

OK, I thought I was about to become crazy, but finally found some dirty workaround:

	sme.Open()
	for i = sme.GetNumViews() to 1 by -1 do sme.DeleteView i false -- deletes all SME node views

	sme.CreateView "MyView" -- creates a new view
	sme.activeView = sme.GetViewByName "MyView"
	for matAIV in sceneMaterials do 
	(
		(sme.GetView 1).createNode matAIV [0,0] -- creates a material node for each scene material
	)
	actionMan.executeAction 369891408 "40060"  -- SME: Lay Out All
	sme.Close()
	sme.open()

That sounds stupid to me, being forced to first open SME, then close it, to finally reopen it to “refresh” it. That works like I want, but this workaround seems weird to me. Am I doing something wrong ?

Hello, that’s look it’s miss updating SME.
when you close and open it again it’s execute « update »
try to found how to update sme view

Work for me without any error…

Hello

You mean, the first script version works fine for you ? interesting … here it always fails, I assume it’s because the created view sme_AIVview1 doesn’t really exist unless SME has actually been opened first. It’s weird (but cool) if it works for you anyway, I’d be interested to know why

Thank you for taking some time to test btw.