Author Topic: Face group selection  (Read 121 times)

Chemistry

  • Newbie
  • *
  • Posts: 8
    • View Profile
Face group selection
« on: February 10, 2018, 09:11:56 PM »
How can I use MMAPI to select a facegroup without having to do it manually? I'm reading everything and can't figure it out. Thanks!

MagWeb

  • Administrator
  • Hero Member
  • *****
  • Posts: 1271
    • View Profile
Re: Face group selection
« Reply #1 on: February 11, 2018, 09:30:27 AM »
You need to identify the target's group(s) ID(s) somewhere in your code when it is selected via

groups_list = mm.list_selected_groups(remote) 

Now knowing the target's ID(s) you can select them via

mm.selection.select_facegroups(remote, [2,45])

("2" and "45" have to be in group_list)

Code: [Select]
import mmapi
from mmRemote import *
import mm

remote = mmRemote()
remote.connect()

mm.selection.select_all(remote) # some selection needed
groups_list = mm.list_selected_groups(remote) # lists all available FaceGroups IDs in the selection. Here e.g.: [2, 4, 5, 7, 9, 15, 45, 58, 68, 108, 110, 111, 112, 122, 151]
mm.selection.select_facegroups(remote, [2,45]) # selects using IDs "2" and "45" as an example
# alternatives:
# mm.selection.select_facegroups(remote, [groups_list[0],groups_list[6]]) # selects same result but based on the list's position
# mm.selection.select_facegroups(remote, groups_list) # selects all groups in the list (which is All in this example)

remote.shutdown()
I'm just a user as you are. Being no Autodesk employee: I do not know where this road will lead to, nor do I claim to've all stuff got right.

Chemistry

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Face group selection
« Reply #2 on: February 11, 2018, 10:46:17 AM »
MagWeb,

This is amazing and exactly what I was looking for. You rock!

One more question for you about the MMAPI:

In the demo Transform_obj it takes a cylinder object and moves it to a selected facegroup, is it possible to do this with an stl file instead of a .obj? If not, is there a way to convert an .stl into a .obj using MMAPI?

I had one idea using RMS' meshconvert but can't quite figure out how to make it do the job from inside python, and think there is probably an easier way.

Thank you!


MagWeb

  • Administrator
  • Hero Member
  • *****
  • Posts: 1271
    • View Profile
Re: Face group selection
« Reply #3 on: February 11, 2018, 11:39:14 AM »
No problem,

Assuming there's some "something.stl" at the given location (example_dir = os.getcwd()) change line 16:
part_filename = os.path.join( examples_dir, "cylinder.obj" )
to
part_filename = os.path.join( examples_dir, "something.stl" )
I'm just a user as you are. Being no Autodesk employee: I do not know where this road will lead to, nor do I claim to've all stuff got right.

Chemistry

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Face group selection
« Reply #4 on: February 11, 2018, 12:15:50 PM »
It worked perfectly. Thanks MagWeb!