0

So I have this code where I try to find if two meshes intersect or not:

import maya.cmds as cmds import pymel.core as pmc mesh_list = pmc.ls(type="mesh") char_transform = pmc.listRelatives(mesh_list,parent=True) def vtxPose(mesh): return pmc.general.PyNode(mesh).getPoints() transform_list = iter(char_transform) next_one = next(transform_list) for one in transform_list: cmds.polyCBoolOp(one, next_one, op=3, n="intersection") vtx_list = vtxPose("intersection") if len(vtx_list) > 0: cmds.undo() print("intersection found") else: cmds.undo() print("no intersection found") 

Anyways, when I execute it Maya gives this error:

# Error: TypeError: file <maya console> line 14: Object pSphere1 is invalid # 

I can't find the problem(i'm not very experienced in coding especially in Maya:( ) I also thought about doing the same thing with OpenMaya's MFnMesh::allIntersections() but thought that learning how to use that one can be time consuming.

So, if you could tell me my code's problem that'd be cool;)

Thanks in advance

4
  • but i have an error on importing maya, it says no module named maya.cmds then how do you import it, can you tell it's version? so i will try to find answer. Commented Nov 2, 2021 at 13:28
  • Hi @vkv-onfire. I think you misunderstood something:) Maya is a 3D software and you can call maya.cmds only in Maya's script editor. If you call it in Maya it should not cause any problems. Commented Nov 2, 2021 at 13:33
  • yah, i just go to cmd and typed pip install maya, it installed successfully so i think that you are using that package. Commented Nov 2, 2021 at 13:35
  • @vkv-onfire I've never used 'maya' package outside the software itself so idk. Most likely it's what I'm using Commented Nov 2, 2021 at 14:10

1 Answer 1

2

The problem seems to be that you mix pymel and maya.cmds. If you change the cmds.polyCBoolOp() to pmc.polyCBoolOp() it should work, or if you want to use cmds, you can convert the pymel objects to string.

Sign up to request clarification or add additional context in comments.

3 Comments

Thank you for responding @haggi krey ! That was actually the problem. Also, do you work with OpenMaya ? If so can you please tell me how to use MFnMesh::allIntersections()? That seems more reliable than what I do here. The problem is that I don't need to use all the flags required for this method but I also don't know which ones I need. I just want to know if my mesh intersects with another mesh or not. If you could help that'd be great! Thanks in advance:)
Not sure if allIntersections will do the job. If I understand you correctly, then you need to know if your objects intersect. What allIntersection() does is to trace a ray and find all points on a mesh where the ray hits the mesh what is a bit different.
Yep, I know:D I think it still can help. Anyway , I think I understood how to use it. Thank you for your time!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.