How to weld two points to the last selected point?
-
Hello, currently this code welds two points in the middle, but i want it to weld to the last selected point, setting MDATA_WELD_TOPOINT to True doesn't help. How to solve this?
import c4d, sys # # M A I N # def main(): doc = c4d.documents.GetActiveDocument() settings = c4d.BaseContainer() settings[c4d.MDATA_WELD_TOPOINT] = True result = c4d.utils.SendModelingCommand( command=c4d.ID_MODELING_WELD_TOOL, list=[op], mode=c4d.MODELINGCOMMANDMODE_POINTSELECTION, bc=settings, doc=doc, flags=c4d.MODELINGCOMMANDFLAGS_CREATEUNDO) if not result: raise RuntimeError(f"Modelling command failed for {op}.") # Inform Cinema 4D that the document has been modified. c4d.EventAdd() # Execute main() if __name__=='__main__': main()
-
-
-
Hi @Gaal-Dornik ,
Sorry for the delayed answer.
The welding command was already comprehensively explained by Riccardo in this thread: ID_MODELING_WELD_TOO - Doesn't work [SOLVED].
In addition, the undo issue was discussed in the following thread: Problem on AddUndo and SendModellingCommand (Weld Tool)
As a compilation of both answers you can find the following code snippet (below) that welds currently selected points to the point with index pointIdx.
Cheers,
Iliaimport c4d def main(): doc = c4d.documents.GetActiveDocument() op = doc.GetActiveObject() pointIdx = 2 # FIXME: put here the index of the point you'd like to weld to' settings = c4d.BaseContainer() settings[c4d.MDATA_WELD_TOPOINT] = True settings[c4d.MDATA_WELD_POINTINDEX] = 2 settings[c4d.MDATA_WELD_OBJECTINDEX] = op doc.StartUndo() doc.AddUndo(c4d.UNDOTYPE_CHANGE, op) result = c4d.utils.SendModelingCommand( command=c4d.ID_MODELING_WELD_TOOL, list=[op], mode=c4d.MODELINGCOMMANDMODE_POINTSELECTION, bc=settings, doc=doc,) doc.EndUndo() c4d.EventAdd() if __name__=='__main__': main()
-
The problem with this code - it doesn't always work correctly. Sometimes it's not taking into account selection order - welds to the first selected point for example. Look at this preview.
import c4d def main(): doc = c4d.documents.GetActiveDocument() op = doc.GetActiveObject() lastPoint = op.GetPointS().GetLastElement() settings = c4d.BaseContainer() settings[c4d.MDATA_WELD_TOPOINT] = True settings[c4d.MDATA_WELD_POINTINDEX] = lastPoint settings[c4d.MDATA_WELD_OBJECTINDEX] = op doc.StartUndo() doc.AddUndo(c4d.UNDOTYPE_CHANGE, op) result = c4d.utils.SendModelingCommand( command=c4d.ID_MODELING_WELD_TOOL, list=[op], mode=c4d.MODELINGCOMMANDMODE_POINTSELECTION, bc=settings, doc=doc,) doc.EndUndo() c4d.EventAdd() if __name__=='__main__': main()
-
Considering this thread it looks like getting points selection order is not trivial task for c4d api.
-
Yes, you found the thread about point selection just right!