Find and delete certain material nodes

Find and delete certain material nodes

andreasVT5XR
Participant Participant
2,840 Views
13 Replies
Message 1 of 14

Find and delete certain material nodes

andreasVT5XR
Participant
Participant

Hello

 

I got an issue that bugs me a lot, and I seem not to be able to find a solution to it. 

 

I want through maxscript to be able to find certain material nodes, f.ex falloff node, and then delete.

To specify; When I delete a node I need the input of the falloff node - let's take color 1 and add that to whatever was the output of the falloff node. This is because I don't want break the material chain.

I know I can find every falloff node in scene with "getclassinstances falloff". But I have no clue on find the output of all of the falloff nodes. I want to find the output so I connect the input to the output. 

 

So basically what I am asking for - I need a script that deletes every falloff node in a scene and reconnect the nodes to whatever slot the fallof was connected to.

 

My knowledge to maxscript is a bit limited so I would really appericate some explanation rather than just an example. But I take what I get 😉

 

Thanks for all help. 

0 Likes
Accepted solutions (2)
2,841 Views
13 Replies
Replies (13)
Message 2 of 14

denisT.MaxDoctor
Advisor
Advisor
Accepted solution
fn deleteSmeNodes refs = 
(
	for k=1 to sme.GetNumViews() do
	(
		view = sme.getView k
		view.SetSelectedNodes refs
		view.DeleteSelection()
	)
)

fn removeFalloff delete:off = 
(
	txs = getClassInstances Falloff astrackviewpick:on
	for_del = #()
	for tx in txs do 
	(
		if tx.client != undefined do
		(
			map = if tx.anim.map1 != undefined then tx.anim.map1 else tx.anim.map2
			tx.client[tx.subnum].value = map
		)
		appendIfUnique for_del tx.anim
	)
	if delete do deleteSmeNodes for_del
	
	for_del
)

/********* run below code to execute: *********

offs = removeFalloff delete:on

*/
0 Likes
Message 3 of 14

andreasVT5XR
Participant
Participant

Thanks a lot. 

So obviously it works.  But I am not sure exactly how it works, and I really want to learn. 

Are you able to give me a quick explanation of this line: 

tx.client[tx.subnum].value = map

So client is getting the name of the map in front of the falloff? How do subnum and value work? 

0 Likes
Message 4 of 14

andreasVT5XR
Participant
Participant

Hi again @denisT.MaxDoctor 

So I thought I had tested this enough, but it seems to crash on me now. 

It works fine when the falloff is connected straight to the texmapdiffuse of a CoronaLegacy Material but if there is something in between, let's say a color_correction, it crashes.

Attached a printscreen of the basic setup of the material and a notepad with the error message.

ill paste it here as well. Any idea why?

Thanks again.

deleteSmeNodes()
removeFalloff()
-- Error occurred in anonymous codeblock; filename: D:\Dropbox (3D Estate team)\Prosjekter\Kunder\00_Scripts\01_SuperScript\02_Remove AO\Falloff.ms; position: 476; line: 23
-- Unable to convert: Map #5:Bitmap to type: Integer
-- MAXScript callstack:
-- thread data: threadID:23360
-- ------------------------------------------------------
-- [stack level: 0]
-- In tx loop; filename: D:\Dropbox (3D Estate team)\Prosjekter\Kunder\00_Scripts\01_SuperScript\02_Remove AO\Falloff.ms; position: 434; line: 20
-- Parameters:
-- tx: TrackViewPick:"Map: Map #6 ( Falloff )"
-- Locals:
-- map: Map #5:Bitmap
-- tx: TrackViewPick:"Map: Map #6 ( Falloff )"
-- Externals:
-- owner: undefined
-- for_del: Free:for_del : #()
-- ------------------------------------------------------
-- [stack level: 1]
-- called from removeFalloff(); filename: D:\Dropbox (3D Estate team)\Prosjekter\Kunder\00_Scripts\01_SuperScript\02_Remove AO\Falloff.ms; position: 477; line: 23
-- Parameters:
-- delete: true
-- Locals:
-- txs: #(TrackViewPick:"Map: Map #6 ( Falloff )", TrackViewPick:"reference")
-- for_del: #()
-- delete: true
-- Externals:
-- deleteSmeNodes: Global:deleteSmeNodes : deleteSmeNodes()
-- owner: undefined
-- ------------------------------------------------------
-- [stack level: 2]
-- called from top-level

 

0 Likes
Message 5 of 14

denisT.MaxDoctor
Advisor
Advisor

I need to see the falloff.ms file

0 Likes
Message 6 of 14

andreasVT5XR
Participant
Participant

Hi @denisT.MaxDoctor 

Thanks for the reply.

I think haven't done anything to your code posted above - but I have attached the code here.


0 Likes
Message 7 of 14

denisT.MaxDoctor
Advisor
Advisor
Accepted solution
fn deleteSmeNodes refs = 
(
	for k=1 to sme.GetNumViews() do
	(
		view = sme.getView k
		view.SetSelectedNodes refs
		view.DeleteSelection()
	)
)

fn findSubTextures target tex = 
(
	indexs = #{}
	for k=1 to getNumSubTexmaps target where (getSubTexmap target k == tex) do append indexs k 
	indexs
)

fn removeFalloff delete:off = 
(
	txs = getClassInstances Falloff astrackviewpick:on
	for_del = #()
	for tx in txs do 
	(
		tex = tx.anim
		map = if tex.map1 != undefined then tex.map1 else tex.map2
		if iskindof tx.client Material do --and map != undefined do
		(
			indexs = findSubTextures tx.client tex
			for i in indexs do setSubTexmap tx.client i map
		)
		appendIfUnique for_del tex
	)
	if delete do deleteSmeNodes for_del
	
	for_del
)


offs = removeFalloff delete:on
	

 

here is an improved version (PRO 😉)... works for your case but may need some testing to be sure

Message 8 of 14

denisT.MaxDoctor
Advisor
Advisor

@andreasVT5XR wrote:

I think haven't done anything to your code posted above - but I have attached the code here.


the Color_Correction texture map is a special case. It was interesting to know... Keep testing, there may be some other special cases.

0 Likes
Message 9 of 14

andreasVT5XR
Participant
Participant

Thank you so much @denisT.MaxDoctor 

I will test it and let you know how it works. So far I can't find any errors.

0 Likes
Message 10 of 14

andreasVT5XR
Participant
Participant

@denisT.MaxDoctor  Hi again. 

So I have tested it a bit - and it works great.

I have also tried to understand the code and how "astrackviewpick:on" works.

 

To me, it looks like I should be able to NOT delete the falloff node if it's connected directly to a texmapdiffuse. 

But I am not getting it to work and I am a bit lost on how to do it.

 

I want to delete and relink every falloff as we can now, but keep the falloffs that are directly connected to a texmapdiffuse.

From what I can see - I want to keep the falloffs that have tx.name == "texmapdiffuse".

Happy Holidays! 

 

0 Likes
Message 11 of 14

Gellvanni
Explorer
Explorer

Eu estou encantado com esse "plugin", toda vez que iria exportar do 3ds max para o blender o mapa de falloff acaba se perdendo, fazendo com que o blender não identificasse a textura. Agora, deletando todos os falloff, não preciso ajustar os matérias um a um no Blender. Agradeço por isso! 

 

 

 

 

 

"I am delighted with this "plugin", every time I would export from 3ds max to blender the falloff map ends up getting lost, causing blender not to identify the texture. Now, by deleting all the falloffs, I don't need to adjust the materials one by one in Blender. I am gratefull for that!"

Translated by Google
Traduzido por [@clacampos] através do Google Tradutor

0 Likes
Message 12 of 14

dqdwaresking
Community Visitor
Community Visitor

Here is a simple code to delete a certain type of node from selected nodes in SME. You can delete any type of node:

activeSelect = #()

fn delete_nodes_type nodeType =
(
-- local currentView = sme.GetView 1
local currentView = sme.GetView sme.activeView
local selectedNodes = currentView.GetSelectedNodes()
local newSelectedNodes = #()

for each_node in selectedNodes do
(
if isKindOf each_node.reference nodeType then
append newSelectedNodes each_node.reference
else
append activeSelect each_node.reference
)
currentView.SetSelectedNodes newSelectedNodes
currentView.DeleteSelection()
currentView.SetSelectedNodes activeSelect
)

delete_nodes_type CoronaColor
delete_nodes_type ColorMap
delete_nodes_type CoronaAO
delete_nodes_type ColorCorrection
delete_nodes_type Falloff
delete_nodes_type Output
delete_nodes_type CoronaNormal
delete_nodes_type CoronaTriplanar
delete_nodes_type Mix
delete_nodes_type CompositeTexturemap

0 Likes
Message 13 of 14

1652058350
Community Visitor
Community Visitor

Hi, please tell me how to delete dirt nodes,Thanks

0 Likes
Message 14 of 14

1652058350
Community Visitor
Community Visitor

嗨,请问,再删除中间节点时,它不会自动连接两端的节点。
而且对于污垢节点无效,

如果有时间期待您的回复

0 Likes