[Python] How do I change sub-object level and polyselection?

[Python] How do I change sub-object level and polyselection?

Anonymous
Not applicable
1,922 Views
6 Replies
Message 1 of 7

[Python] How do I change sub-object level and polyselection?

Anonymous
Not applicable

Hi,

 

I am working on a script for generating gears. To extrude the 'teeth' I need to make a poly-dot-selection.

My issue is that I don't know and can't find a way to go into the polygon sub-object level. In MaxScript this is done with the simply by typing:

  subobjectLevel = 4
  $.EditablePoly.SetSelection #Face #{10}

 

 

I can't seem to find how exactly this is done using Max's Python API. Is there something like the dollar sign or SetSelection in Python?

 

Cheers.

0 Likes
Accepted solutions (1)
1,923 Views
6 Replies
Replies (6)
Message 2 of 7

Swordslayer
Advisor
Advisor

Either use the runtime maxscript engine and do it the same way as you'd do in maxscript, or if you use older max where pymxs isn't available, you have to do it the hard way, this could get you started:

 

 

import MaxPlus

EPOLY_INTERFACE_ID = MaxPlus.Interface_ID(0x092779, 0x634020)

sl = MaxPlus.SelectionManager.GetNodes()

for iNode in sl:
	baseInt = iNode.EvalWorldState().Getobj().GetInterface(EPOLY_INTERFACE_ID)
	help (MaxPlus.PolyObject__CastFrom(baseInt))

 

Anyway, the approach in your sample code isn't how one would do that in maxscript either, most of the time you'd want to avoid having the modifier panel active and use polyop methods instead. Or mesh methods, in case you were making a procedural primitive like Gear.

0 Likes
Message 3 of 7

Anonymous
Not applicable

Hi Swordslayer,

 

With your answer I found the SetSubSelState() method in Object so the sub-object level problem is solved. I am still having trouble finding how to do seemingly basic Max-functionalities in code. Like selecting polygons and accessing the Graphite modeling tools. Forgive me if this is a newbie remark to make, I am a modeler transitioning to more technical stuff and still learning about Max's Python API. Any way you can help me out or tell me if I'm overlooking something obvious here?

 

Thanks!

0 Likes
Message 4 of 7

Swordslayer
Advisor
Advisor

Still no idea why you'd want to use SetSubSelState at all, you don't (and shouldn't) have to do it the way user does it, entering subObject mode and selecting stuff will only make everything slower. As for graphite tools, they're tools that use the SDK, not tools that are part of the SDK, you'd either have to reimplement them yourself or call them via pymxs.

0 Likes
Message 5 of 7

Anonymous
Not applicable

How would you suggest to go about it then? ('it' being: making a simple gear)

Judging from your answers I seem to have a completely wrong mindset/approach.

 

To clarify why I try to do it this way: this project is an exam assignment for a basic scripting course where we learned maxscript and python (only basic though). We did simple exercises with maxscript that involved selecting faces to extrude and small scripts to alter geometry. I guess this is where the mindset comes from. I wanted to do it the way we did it with maxscript but then in Python.

0 Likes
Message 6 of 7

Swordslayer
Advisor
Advisor
Accepted solution

Ah, so someone's teaching that as a part of a course... oh well, sometimes it's better to be selftaught I guess. In the maxscript case you really really want to use methods that are made for that instead of mimicking what happens in the UI, in this case that would be polyop methods:

 

segs = 16

cylPoly = convertToPoly (Cylinder prefix:#gear sides:(2 * segs) radius:15 height:5) cylPoly.bevelType = 2 polyop.bevelFaces cylPoly (for face = 2 to 2 * segs by 2 collect face) 3 -1

When it comes to python, I'd just avoid MaxPlus as a beginner altogether and used pymxs instead:

 

mxs = pymxs.runtime
segs = 16

cylPoly = mxs.convertToPoly (mxs.Cylinder(prefix='Gear', sides=(2 * segs), radius=15, height=5))
cylPoly.bevelType = 2
mxs.polyop.bevelFaces(cylPoly, [face for face in xrange(2, 2 * segs + 1) if face % 2 == 0], 3, -1)
Message 7 of 7

Anonymous
Not applicable

Thanks, this helps a lot!

 

 

I was kind of stuck on MaxPlus thinking it was the base of the python API.

I think I'll have to throw away most of what I know and self-teach python as a whole, since all I know now is just keeping me stuck most of the time.

0 Likes