SendModelingCommand, MCData result array question
-
On 29/01/2013 at 07:23, xxxxxxxx wrote:
Hi,
A recent thread made me remember that I got some months ago an interesting code snippet from the developers that was showing how to send a knife modeling command.
What's most important to understand is: MDATA_KNIFE_P1, MDATA_KNIFE_P2, MDATA_KNIFE_V1 and MDATA_KNIFE_V2 have to be given in world space.
For this purpose we can use the handy conversion methods of BaseView (parent class of BaseDraw). In the example we call BaseView.SW() to convert screen space coordinates to world space.
v1 and v2 are basically vectors showing away from the camera (and going through p1/p2). v1 % v2 build the normal of the cutting plane.The following example will show how to cut the selected spline just in the middle of the view:
import c4d from c4d import utils def SplineCutter(doc, op, bd, x1, y1, x2, y2, bSelect) : p1 = bd.SW(c4d.Vector(x1, y1, 0.0)) v1 = bd.SW(c4d.Vector(x1, y1, 100.0)) - p1 p2 = bd.SW(c4d.Vector(x2, y2, 0.0)) v2 = bd.SW(c4d.Vector(x2, y2, 100.0)) - p2 bc = c4d.BaseContainer() bc.SetVector(c4d.MDATA_KNIFE_P1, p1) bc.SetVector(c4d.MDATA_KNIFE_P2, p2) bc.SetVector(c4d.MDATA_KNIFE_V1, v1) bc.SetVector(c4d.MDATA_KNIFE_V2, v2) bc.SetBool(c4d.MDATA_KNIFE_RESTRICT, False) bc.SetBool(c4d.MDATA_KNIFE_SELECTCUTS, bSelect) if op is not None and op.CheckType(c4d.Ospline) : utils.SendModelingCommand(command = c4d.MCOMMAND_KNIFE, list = [op], bc = bc, doc = doc, flags = c4d.MODELINGCOMMANDFLAGS_CREATEUNDO) c4d.EventAdd() def main() : bd = doc.GetActiveBaseDraw() frame = bd.GetFrame() middleX = (frame['cr']-frame['cl'])/2 SplineCutter(doc, op, bd, middleX, frame['ct'], middleX, frame['cb'], True) if __name__=='__main__': main()
You can then modify the call to SplineCutter() in main() to use other coordinates from the mouse, a tool etc. You can also 'play' with others MDATA_KNIFE_ options.
EDIT: Fixed the code.
-
On 29/01/2013 at 09:17, xxxxxxxx wrote:
hey, thanks for the clarification
-
On 29/01/2013 at 11:32, xxxxxxxx wrote:
Hello Yannick
Please correct your code(if you tested it?!), if you want to post right example for help:
1. console displays: AttributeError: 'c4d.SplineObject' object has no attribute 'IsInstanceOf'
2. even seems code was wrote from scratch : bc.SetVector( c4d., v2) - > bc.SetVector(c4d.MDATA_KNIFE_V2, v2)Any way, data from bc for SendModelingCommand, should be based on bd data?... For example
c4d.ID_MODELING_POINT_ADD_TOOL at bc[c4d.MDATA_ADDPOINT_POINT] = gm.Mul(poly_center(op, i)) # vector data -
On 30/01/2013 at 00:17, xxxxxxxx wrote:
Originally posted by xxxxxxxx
Please correct your code(if you tested it?!), if you want to post right example for help:
1. console displays: AttributeError: 'c4d.SplineObject' object has no attribute 'IsInstanceOf'Yes, I tested the code (of course!) but I ported the code from C++ and used a recent version of CINEMA where C4DAtom.IsInstanceOf() is defined. With R14.034 and older releases we have to call C4DAtom.CheckType() instead.
Originally posted by xxxxxxxx
2. even seems code was wrote from scratch : bc.SetVector( c4d., v2) - bc.SetVector(c4d.MDATA_KNIFE_V2, v2)
This is an edition 'cut and copy' mistake when I wrote my post. I should have checked it and its embedded code before posting.
Originally posted by xxxxxxxx
Any way, data from bc for SendModelingCommand, should be based on bd data?... For example
c4d.ID_MODELING_POINT_ADD_TOOL at bc[c4d.MDATA_ADDPOINT_POINT] = gm.Mul(poly_center(op, i)) # vector dataThe knife example only uses the BaseDraw to convert points from screen to world coordinates. This is not needed for the setup of all modeling commands.
-
On 30/01/2013 at 10:32, xxxxxxxx wrote:
Hello.
Thank you for clarification.