How to use bridge tool in Python script

On 16/08/2018 at 13:30, xxxxxxxx wrote:

To automate some of my modelling workflows, I am currently trying to execute some bridge commands via scripts. Specifically, I try to bridge two polygons. How can I do this with a python script? I have two objects and the selected polygons to bridge. I tried:

c4d.CallCommand(450000008) # Bridge
    tool()[c4d.MDATA_BRIDGE_OBJINDEX1] = doc.SearchObject("Test2")
    tool()[c4d.MDATA_BRIDGE_OBJINDEX2] = doc.SearchObject("Test")
    tool()[c4d.MDATA_BRIDGE_ELEMENT1] = 0
    tool()[c4d.MDATA_BRIDGE_ELEMENT2] = 0
    tool()[c4d.MDATA_BRIDGE_DELETE] = True
    tool()[c4d.MDATA_BRIDGE_ISO] = False
 
    c4d.CallButton(tool(), c4d.MDATA_APPLY)

But I had no luck so far. Honestly, I have no clue what MDATA_BRIDGE_OBJINDEX1 and MDATA_BRIDGE_ELEMENT1 really should be. There is also no real documentation how this should work.

On 20/08/2018 at 06:23, xxxxxxxx wrote:

Hi TraceCat, first of all, welcome in the plugincafe community!

Here is a quick example to demonstrate how to use the BridgeTool in PolygonMode. One important thing is that polygon has to be selected in order to do the correct operation.

import c4d
  
def main() :
    firstObj = doc.GetFirstObject()
    secondObj =  doc.GetFirstObject().GetNext()
    if not firstObj and not secondObj and not firstObj.CheckType(c4d.Opolygon) and not secondObj.CheckType(c4d.Opolygon) :
        return
  
    # Select the polygon
    polyId1 = 5
    polyId2 = 0
  
    sel1 = firstObj.GetPolygonS()
    sel2 = secondObj.GetPolygonS()
  
    sel1.DeselectAll()
    sel2.DeselectAll()
  
    sel1.Select(polyId1)
    sel2.Select(polyId2)
  
    # Use the command
    settings = c4d.BaseContainer()
    settings[c4d.MDATA_BRIDGE_ELEMENT1] = polyId1 # The polygon id for the first obj
    settings[c4d.MDATA_BRIDGE_ELEMENT2] = polyId2 # The polygon id for the second obj
  
    settings[c4d.MDATA_BRIDGE_OBJINDEX1] = firstObj # Define the first obj
    settings[c4d.MDATA_BRIDGE_OBJINDEX2] = secondObj # Defien the second obj
    c4d.utils.SendModelingCommand(command = c4d.ID_MODELING_BRIDGE_TOOL,
                                list = [firstObj, secondObj],
                                mode = c4d.MODELINGCOMMANDMODE_POLYGONSELECTION,
                                bc = settings,
                                doc = doc,
                                flags = c4d.MODELINGCOMMANDFLAGS_CREATEUNDO)
  
  
    c4d.EventAdd()
  
if __name__=='__main__':
    main()

Sadly there is no way to affect the order of the vertex. So you may end up with a result which is not what you expected.

If you have any question, please let me know.
Cheers,
Maxime!

On 21/08/2018 at 05:40, xxxxxxxx wrote:

Hi Maxime!

Thx for the warm welcome and of course the help! Just tested it and it works nice, at least for straigtforward bridging (as you mentioned the vertex order needs to fit). Thank you very much! This helps a lot!