@ferdinand My English isn't very good, sorry about that. What I mean is that when I am in edit mode and select points/edges/polygons, create a null object, and then switch back to object mode, if I want to undo, it would be more 'user-friendly' if I could return to the previous edit mode instead of object mode
It's good to know that calling doc.SetMode(c4d.Mmodel) is non-undoable; I struggled with this for a while
Posts made by kangddan
-
RE: How to Undo Switching Between Modes?
-
RE: How to Undo Switching Between Modes?
@ferdinand Thank you for letting me know that switching between modes is irreversible! My initial thought was that when I generate an empty object in edit mode, if I undo the action, I could return to edit mode. Thanks again for your explanation
-
How to Undo Switching Between Modes?
Hello all, my script needs to work in point, edge, and polygon modes (edit modes). At the end of the script, I will switch it back to model mode, but I'm not sure how to undo the mode switching. When I run the code in point mode, I can't return to point mode when undoing
import c4d def main(): sel = doc.GetActiveObjects(c4d.GETACTIVEOBJECTFLAGS_CHILDREN) if not sel or not doc.IsEditMode(): return # edit mode doc.StartUndo() for obj in sel: doc.SetSelection(obj, c4d.SELECTION_SUB) joint = c4d.BaseObject(c4d.Ojoint) doc.AddUndo( c4d.UNDOTYPE_NEWOBJ, joint) doc.InsertObject(joint, None, obj, True) doc.SetSelection(joint, c4d.SELECTION_ADD) ... doc.SetMode(c4d.Mmodel) # set model mode doc.EndUndo() c4d.EventAdd() if __name__ == '__main__': main()
-
How to Use Button Properties in an XPresso Python Node?
I hope to do something by clicking the update button on the Python node. I’m not sure if this is possible
-
RE: Calling the button to create an object cannot add it to the undo queue
Thank you @m_adam It seems that the best approach is to manually create a null object and calculate its correct rotation matrix through certain methods to achieve the same effect. Once again, thank you for your code; it has been very useful to me!
-
Calling the button to create an object cannot add it to the undo queue
Hello everyone, when creating a splineIK tag, I dynamically call c4d.CallButton to create an IkHandle. At this point, an empty object is generated. I am now able to correctly retrieve it, but I can't add it to the undo queue. Since c4d.CallButton has no return value, I retrieve the empty object from the current scene each time I create an IkHandle. I'm not sure if there's a more proper way to do this
import c4d def createJoints(jointCount): jntList = [] for i in range(jointCount): jnt = c4d.BaseObject(c4d.Ojoint) jnt.SetName('splineIK_{}'.format(i)) doc.InsertObject(jnt) doc.AddUndo(c4d.UNDOTYPE_NEW, jnt) jntList.append(jnt) if i > 0: jnt.InsertUnder(jntList[i-1]) return jntList def getAllNulls(): return [obj for obj in doc.GetObjects() if obj.GetType() == c4d.Onull] def addSplineTag(startJnt, endJnt, spline): tag = c4d.BaseTag(1019862) doc.AddUndo(c4d.UNDOTYPE_NEW, tag) startJnt.InsertTag(tag) tag[c4d.ID_CA_IKSPLINE_TAG_TYPE] = 2 tag[c4d.ID_CA_IKSPLINE_TAG_TWIST_TYPE] = 1 tag[c4d.ID_CA_IKSPLINE_TAG_SPLINE] = spline tag[c4d.ID_CA_IKSPLINE_TAG_END] = endJnt splineIkHandles = [] for i in range(spline.GetPointCount()): c4d.CallButton(tag, c4d.ID_CA_IKSPLINE_HANDLE_ADD) c4d.CallButton(tag, c4d.ID_CA_IKSPLINE_HANDLE_CREATE) null = getAllNulls()[0] doc.AddUndo(c4d.UNDOTYPE_NEW, null) # add undo splineIkHandles.append(null) return splineIkHandles def createSplineIK(jointCount=10): sel = doc.GetSelection() if not sel: return spline = sel[0] if sel[0].CheckType(c4d.Ospline) else None if spline is None: return doc.StartUndo() # --------------------------------- jnts = createJoints(jointCount) splineIkHandles = addSplineTag(jnts[0], jnts[-1], spline) for i in splineIkHandles: print(i.GetName()) # --------------------------------- doc.EndUndo() c4d.EventAdd() if __name__ == '__main__': createSplineIK(jointCount=10)
-
RE: Adding a Morph Deformer Causes Pose Morph Tag to Stop Working
Thank u @i_mazlov
I appreciate you pointing me in the right direction. I will try to understand the workings behind the posemorph tag! -
RE: Adding a Morph Deformer Causes Pose Morph Tag to Stop Working
Hello everyone, I seem to have found a solution. You just need to go to the Falloff option in Morph and add a default parameter
data = c4d.FieldList() morph[c4d.FIELDS] = data
This way, the PoseMorph tag becomes effective. I still don't understand why this is necessary, as I can't find any python related content about the Morph deformer:(
-
Adding a Morph Deformer Causes Pose Morph Tag to Stop Working
Hello all, I've noticed that my Pose Morph tag stops working after I add a Morph Deformer. It seems that I can't replicate the manual process of adding the Morph Deformer. What might I be doing wrong?
The main function of the code is to copy the selected object, then add a pose morph, and set the target to the selected object. The reason for adding the Morph Deformer is that I can offset issues with priority lag. However, in the code, once I add the Morph Deformer, the Pose Morph stops workingimport c4d def copyObj(obj): _copyObj = obj.GetClone(); doc.AddUndo(c4d.UNDOTYPE_NEW, _copyObj) _copyObj.SetName('{}_copy'.format(obj.GetName())) _copyObj[c4d.ID_BASEOBJECT_VISIBILITY_EDITOR] = 2 _copyObj[c4d.ID_BASEOBJECT_VISIBILITY_RENDER] = 2 doc.InsertObject(_copyObj); _copyObj.InsertAfter(obj) for tag in _copyObj.GetTags(): if isinstance(tag, c4d.modules.character.CAWeightTag): tag.Remove() for child in _copyObj.GetChildren(): if child.CheckType(c4d.Oskin): child.Remove() return _copyObj def addPoseMorph(target, obj): pmTag = obj.MakeTag(1024237) priorityData = c4d.PriorityData() priorityData.SetPriorityValue(c4d.PRIORITYVALUE_MODE, c4d.CYCLE_INITIAL) pmTag[c4d.ID_CA_POSE_BASE_PRI] = priorityData pmTag[c4d.ID_CA_POSE_POINTS] = 1 baseMorph = pmTag.AddMorph() # id0 targetMorph = pmTag.AddMorph() # id1 pmTag.UpdateMorphs() targetMorph.SetName('target') pmTag.SetActiveMorphIndex(1) pmTag[c4d.ID_CA_POSE_TARGET] = target pmTag[c4d.ID_CA_POSE_MODE] = 1 return pmTag def addMorphDeformer(obj, tag): morph = c4d.BaseObject(1019768) morph.InsertUnder(obj) morph[c4d.ID_CA_MORPH_DEFORMER_OBJECT_TAG] = tag morph[c4d.ID_CA_MORPH_DEFORMER_OBJECT_APPLY_BASEPOSE] = True def create(): sel = doc.GetSelection() if not sel: return doc.StartUndo() for o in sel: doc.AddUndo(c4d.UNDOTYPE_CHANGE, o) o[c4d.ID_BASEOBJECT_VISIBILITY_EDITOR] = 1 o[c4d.ID_BASEOBJECT_VISIBILITY_RENDER] = 1 cObj = copyObj(o) pmTag = addPoseMorph(o, cObj) addMorphDeformer(cObj, pmTag) doc.EndUndo() c4d.EventAdd() if __name__ == '__main__': create()
-
How to hide object local coordinates
As shown in the picture, I have hidden the selected objects in the outliner, but when I middle-click on the Null object, I can still see the local coordinate axes in the viewport and the number of selected objects in the attribute panel. Is there any way to completely hide these objects?
import c4d doc = c4d.documents.GetActiveDocument() def hide_obj(): doc.StartUndo() sel=doc.GetSelection() for obj in sel: doc.AddUndo(c4d.UNDOTYPE_CHANGE, obj) obj.ChangeNBit(c4d.NBIT_OHIDE, c4d.NBITCONTROL_SET) doc.EndUndo() c4d.EventAdd() if __name__ == '__main__': hide_obj()
-
RE: TimeLine Window Custom open
Cool idea:), it's similar to Animbot in MAYA with custom widgets on the timeline, though I don't know how to do it, but I'm looking forward to you being able to implement it!