Delete collisions - PyMel


#1

Hi Everyone.

So I’m making a basic rain simulation script where the user can add objects from their scene to collide with the particles. I also want to add the functionality to remove collision objects - say they selected something by accident when making the collision objects and its now too late to just undo.

I’m really struggling to find a way to actually stop objects colliding. If anyone can offer any suggestions that’d be great.

I’m currently trying to delete the geoConnector node of the object that should no longer be a collision object but the nodes are listed as geoConnector1, geoConnector2 etc. and I don’t know how to get the geoConnector node from the currently selected object. If these seems like the right path to go down, any help on this matter would be awesome.

Just for clarity, I’m using Maya 2016.

Thanks
B


#2
import pymel.core as pm

sel = pm.selected()[0]

geoConnectorNodes = sel.getShape().message.listConnections(t='geoConnector')

edit: forum code formatting seems to be broken so here’s a gist .


#3

Thank you Pollos.

That’s almost what I’m after. Using your code I get:

nt.GeoConnector(u’geoConnector2’)

where I only want the ‘geoConnector2’ bit. I’ve tried the following

sel = pm.selected()[0]

geoConnectorNodes = sel.getShape().message.listConnections(t=‘geoConnector’)
for node in geoConnectorNodes:
if pm.nodeType(node) == ‘GeoConnector’:
pm.select(’’+node)

which works but I have to physically execute the pm.select(’’+node) part by right clicking on it and selecting execute from the menu. Any ideas why this might be the case? obviously as this will be part of a script it should execute when the function it is in is called right?

Thanks
B


#4

No need to loop through the geoConnectorNodes list. I think a shape will only ever have a single geoConnector node so looping through is uneccesary. And the t=‘geoConnector’ flag already filters the result of listConnections to only return nodes of type geoConnector.

The “nt.GeoConnector(u’geoConnector2’)” is a PyMel object. You shouldn’t have any issue simply doing pm.select(geoConnectorNodes).

Not exactly sure what you’re trying to do with the "+node. If you want the name of the node as a string you can use the name method:

geoConnectorNodes[0].name() will return a string with just the nodes name ‘geoConnector2’


#5

ahhh, Awesome. Got it working now. Thanks so much Pollos.

(the ‘’+node bit was my work around having not known about the name method. Why I didnt think there would be one, I don’t know…)

Thanks again!
B