How to ungroup a shader node group

Within an operator that is run by clicking a button in the properties panel, how can I ungroup a shader node group within a given material?

I have tried literally everything. bpy.ops.node.group_ungroup is always context incorrect, even if I change the area ui_type first.

Driving me insane. Any help?

nvm, I misunderstood post maybe someone with coding experience can help!


are you sure there are no conflicts with shortcuts?
I used to have plenty of problems similar to this when upgrading through blender versions and importing older user settings

see if it works with default blender file
if it does, then you should consider starting a fresh config/keymap setup from scratch

1 Like

@Alumx Thanks for trying. I’ve posted this here before, but it’s just tumbleweeds every time.

I guess this is not possible.

-give a try, there are some smart fellas helping out if you’re lucky

-otherwise OpenVFX: The Blender Hub (discord), i got some python help there one time, altho the server grew a ton since that happened so you should be persistent and maybe @ directly someone who might help

-and lastly there’s , a lot of blender devs hang out there so you might get some help if they answer back (I never tried it much, its a bit over my expertise lol, but i lurk sometimes to see what’s going on)

ps: I’d recommend looking through some currently active addon developer (for example here) and maybe directing your question to them via any social media dm you happen to find

good luck! sorry I can’t help but if you persist you’ll find answers for sure :+1:

Well, I am slightly further along with this problem.

I’ve figured out how to call bpy.ops.node.group_ungroup() without the context incorrect problem.

The issue I have now is that I want to change the active material slot on an object while the script is running so that the correct material’s nodes are actually shown in the node editor.

I can make this change, but it doesn’t take effect until the script is stopped, so that’s no use to me.

Currently looking for a way to pause the script to allow Blender to update, and then resume it. Might end up being some overly complicated arrangement using timers.


call bpy.ops.node.group_ungroup() without the context incorrect problem

May I ask how? I am at the same point right now.

I’m afraid that I no longer have the code (as I abandoned this), however, if you search StackExchange for override context you will find some guidance.

Thank you for the tip (‘override’), that will come in in handy! I made a button inside the node editor for my script. -I just saw 21. January, now I realized this means jan. 2021. :grinning_face_with_smiling_eyes:

I needed my script to start from the 3D view, so a button in the node editor wasn’t an option for me.

What I ended up with was a modal timer. I change the viewport area to a node editor, and then have a timer that executes one step of what I want to do per interval (change active material, ungroup node group, change active material etc.). At the end I restore the viewport area to whatever it was originally.

I’ve no idea if that’s the best or only way to do it. It’s kind of hideous. But it does work.

Why not a timer. But isnt there something that your function reports ‘ready’ and then the next step starts, more in a ‘batch’ way?

I found this in someones script. The comment is very funny: “override = bpy.context.copy() #i don’t know what it does. without it it says the context is wrong”. :grin:
I am just throwing in patches of python, and most times it starts to work somehow, and maybe later I get why something does not work. It takes me soo long time to find, but when it does work, its like magic.
I’m struggeling with getting/finding a node_group by name (name startswith ‘text***’) 'inside a Material. I cant get it to work. something like: ‘for i in active material.node_groups.names.’
I can already select the nodegroup by name and ungroup it from script ( inside Node editor). But I need to find out the right name first.