On 21/06/2018 at 03:48, xxxxxxxx wrote:
Hi pgrooff.
Actually, STITCHANDSEW have a different implementation compared to other ModelingCommand.
First of all, you need to pass a document and the first object.
Then additionally in MDATA_STITCHANDSEW_BC1, you have to set point id you actually want to stitch
Here is the structure of this container (which is currently not documented).
bc[0] = count of points you want to stitch for the first selection
bc[10 to 9999] = point ID
bc[10000] = count of points you want to stitch for the second selection
bc[10010 and more] = point ID
Points will be connected in the same order you fill the BaseContainer.
For example bc[10] = 10 and bc[10010] = 20, you will connect the point ID 10 from the first obj to the point ID 20 of the second obj (which can be the same than the first object).
So here an example which connects selected points.
import c4d
def GetPointIdSelected(obj) :
if not obj:
return
ptIds = list()
ptCnt = obj.GetPointCount()
bs = obj.GetPointS()
for index, selected in enumerate(bs.GetAll(ptCnt)) :
if not selected:
continue
ptIds.append(index)
return ptIds
def main() :
obj1 = doc.SearchObject("Cube")
obj2 = doc.SearchObject("Cube.1")
l1 = GetPointIdSelected(obj1)
l2 = GetPointIdSelected(obj2)
con = c4d.BaseContainer()
con[0] = len(l1) # cnt of ptn selected in first object
con[10000] = len(l2) # cnt of ptn selected in second object
# assign pt ID for first object and make sure to not overwrite con[10000]
for i in xrange(min(len(l1), 9989)) :
con[10+i] = l1[i]
# assign pt ID for second object
for i in xrange(len(l2)) :
con[10010+i] = l2[i]
bc = c4d.BaseContainer()
bc.SetLink(c4d.MDATA_STITCHANDSEW_OBJINDEX1, obj1)
bc.SetLink(c4d.MDATA_STITCHANDSEW_OBJINDEX2, obj2)
bc.SetData(c4d.MDATA_STITCHANDSEW_SHIFT, True)
bc.SetContainer(c4d.MDATA_STITCHANDSEW_BC1, con)
# Make sure to define [obj1] and doc
c4d.utils.SendModelingCommand(c4d.ID_MODELING_STITCHANDSEW_TOOL, [obj1], c4d.MODELINGCOMMANDMODE_EDGESELECTION, bc, doc=doc)
c4d.EventAdd()
if __name__=='__main__':
main()
Cheers,
Maxime