• 0 Votes
    5 Posts
    975 Views
    i_mazlovI
    Hi @LingZA , Sorry for the delayed answer. Could you please explain the result that you're trying to achieve? It looks now that you would like to implement a modeling tool similar to Bevel, when you would like to firstly select points/edges/polys and secondly apply some changes to them. If that's the case, then you need to implement the part of your tool that selects objects. Please have a look at BaseSelect. You can also explore Flatten Polygons example. You can find a sample code snippet below that simply selects all of the edges of the polygon. You need to be in "Edges" mode for that. Additionally you can emulate the polygon highlighting yourself. Regarding the flags: PLUGINFLAG_TOOL_EDITSTATES - designates that the tool supports deformed editing PLUGINFLAG_TOOL_SWITCHACTION - allows to adjust the active tool. This works in tandem with the MSG_TOOL_SWITCHACTION message type. Namely, when the modifier (aka qualifier) key is pressed, the plugin receives this message such that it can react on this key press. PLUGINFLAG_TOOL_NO_TOPOLOGY_EDIT - flag that informs cinema that the tool doesn't perform any topology modifications (i.e. doesn't add/remove/reassign of the polygons) PLUGINFLAG_TOOL_TWEAK - if you click on the element that isn't currently selected, it will select it for you (so your tool can work with this selection), and will deselect it once your tool finishes PLUGINFLAG_TOOL_TWEAK_NO_HIGHLIGHT - same as above but without highlighting the temporarily selected element PLUGINFLAG_TOOL_DRAW_MULTIPLANE - some legacy flag that is (or at least should be) deprecated Cheers, Ilia [image: 1698935992814-cinema_4d_ezzrkgku0y.gif] import c4d PLUGIN_ID = 1234321 # Be sure to use a unique ID obtained from www.plugincafe.com class MyTool(c4d.plugins.ToolData): def __init__(self): self.selectionRadius = 10 self.highlightedPolygon: int = -1 def GetState(self, doc): if doc.GetMode() != c4d.Medges: return False return c4d.CMD_ENABLED def MouseInput(self, doc, data, bd, win, msg): # Only handle left click if msg[c4d.BFM_INPUT_CHANNEL] != c4d.BFM_INPUT_MOUSELEFT: return True # Get active object op = doc.GetActiveObject() if not op: return True if self.highlightedPolygon < 0: return True # Initialize helping Neighbor struct nbr = c4d.utils.Neighbor() nbr.Init(op) polyInfo = nbr.GetPolyInfo(self.highlightedPolygon) # get polygon information bs = c4d.BaseSelect() opPolygon: c4d.CPolygon = op.GetPolygon(self.highlightedPolygon) # Iterate over sides for side in range(4): # Skip last edge if polygon is a triangle if side == 2 and opPolygon.c == opPolygon.d: continue # Select edge edgeIdx = polyInfo['edge'][side] bs.Select(edgeIdx) # Apply selection op.SetSelectedEdges(nbr, bs, c4d.EDGESELECTIONTYPE_SELECTION) c4d.EventAdd() return True def Draw(self, doc, data, bd, bh, bt, flags): selectionColor = c4d.GetViewColor(c4d.VIEWCOLOR_SELECTION_PREVIEW) if flags & c4d.TOOLDRAWFLAGS_HIGHLIGHT: # if the DrawPass is the Highlight one if self.highlightedPolygon >= 0: # Get active object op = doc.GetActiveObject() if not op: return True bd.SetMatrix_Matrix(op, op.GetMg()) # draw in global coordinates # Get points and polygon from the object opPoints: list[c4d.Vector] = op.GetAllPoints() opPolygon: c4d.CPolygon = op.GetPolygon(self.highlightedPolygon) points = [opPoints[idx] for idx in (opPolygon.a, opPolygon.b, opPolygon.c, opPolygon.d)] colors = [selectionColor for _ in points] if len(points) == 3 or len(points) == 4: bd.DrawPolygon(points, colors) # draw the polygon highlight # Draw the outline bd.SetPen(c4d.Vector(0, 1, 0)) for point1Idx in range(-1, len(points) - 1): point1, point2 = points[point1Idx], points[point1Idx + 1] bd.DrawLine(point1, point2, c4d.NOCLIP_D) return c4d.TOOLDRAW_HIGHLIGHTS def GetCursorInfo(self, doc, data, bd, x, y, bc): self.highlightedPolygon = -1 # If the cursor has left a user area, simply return True if bc.GetId() == c4d.BFM_CURSORINFO_REMOVE or doc.GetMode() != c4d.Medges: return True # Get active object op = doc.GetActiveObject() if not op: return True # Calculates the width and height of the screen bd: c4d.BaseDraw = doc.GetActiveBaseDraw() frame = bd.GetFrame() l, r, t, b = frame["cl"], frame["cr"], frame["ct"], frame["cb"] width, height = r - l + 1, b - t + 1 # Initialize viewport select vpSelect = c4d.utils.ViewportSelect() vpSelect.Init(width, height, bd, [op], c4d.Medges, True, c4d.VIEWPORTSELECTFLAGS_IGNORE_HIDDEN_SEL) c4d.SpecialEventAdd(c4d.EVMSG_UPDATEHIGHLIGHT) # pushing highlighting event to cinema # Looking for the nearest polygon and saving it's index in self.highlightedPolygon polyInfo = vpSelect.GetNearestPolygon(op, int(x), int(y), self.selectionRadius) if not polyInfo or 'i' not in polyInfo: return True polygonIdx = polyInfo['i'] if (polygonIdx < 0 or polygonIdx >= op.GetPolygonCount()): return True self.highlightedPolygon = polygonIdx return True if __name__ == "__main__": c4d.plugins.RegisterToolPlugin(id=PLUGIN_ID, str="MyTool", info=0, icon=None, help="", dat=MyTool())
  • 0 Votes
    5 Posts
    903 Views
    G
    I want to mirror a polygon selection along specified modeling axis, but i'm kinda stuck since i can't apply the dedicated Mirror Tool, the basic Scale Tool also doesn't allow to set the tool settings...
  • How to Apply a modeling command?

    Cinema 4D SDK s26 windows python
    3
    0 Votes
    3 Posts
    544 Views
    G
    Thanks man, i'll take a look at it!
  • OBJ Import setting not changing

    Cinema 4D SDK python 2024 windows
    5
    0 Votes
    5 Posts
    926 Views
    ferdinandF
    Hey @del, Thank you for pointing out that this part of our examples, I overlooked this aspect this morning. I have fixed the issue in our local repository for import_obj_r13.py. The updated line is: objImport[c4d.OBJIMPORTOPTIONS_PHONG_ANGLE_DEFAULT] = c4d.utils.DegToRad(22.5) and it will go live with the next docs update. I cannot update the legacy version of the SDK in import_OBJ.py as I lack the permissions to write there even in our local repository. Cheers, Ferdinand
  • How to create a radial (pie) menu?

    Cinema 4D SDK windows s26 python
    6
    0 Votes
    6 Posts
    2k Views
    G
    Thanks for your detailed answers, i hoped there is a simpler way to do it)... Pie menus is a very common thing nowadays, why maxon developers haven't implemented it already? In modo for example you can create pie menus, popups...etc without any coding. Not every user is ready/have the time/etc to learn python to build a simple popup, but almost every user needs to customize their working software. I really hope you'll implement these features soon.
  • Check if a texture is missing

    Cinema 4D SDK python 2024 macos
    2
    0 Votes
    2 Posts
    624 Views
    ferdinandF
    Hello @visualride, Thank you for reaching out to us. I would recommend having a look at c4d.documents.GetAllAssetsNew . Helpful might also be the thread Get all Textures for a Material. It is one of the multiple threads where I showcased the usage of GetAllAssetsNew (search for GetAllAssetsNew and my user name to find the other threads). In this thread you can see here how to read the exists field in asset data to know if Cinema 4D can find that asset. But asset handling can get complex when node materials are involved as shown here (also a good place to better understand the data associated with MSG_GETALLASSETS). The thread shows also a simpler approach using BaseDocument.GetAllTextures. You can then just check with os.exists if the paths do exist. You might have to deal with relative paths here, depending on the document. Cheers, Ferdinand
  • Problem with MessageData plugin

    Cinema 4D SDK 2023 windows python
    5
    0 Votes
    5 Posts
    992 Views
    gheyretG
    Hi @ferdinand Thank you so much for your explain, i understand what's happen now. Cheers
  • 0 Votes
    3 Posts
    671 Views
    B
    In the past I have refrained from CallCommands and CallButtons because they used to add to the undo queue or did. But I suppose in this instance I can just do it for thise purpose.
  • Custom Build C4D.2024.py310 ?

    Cinema 4D SDK 2024 python
    7
    0 Votes
    7 Posts
    2k Views
    gheyretG
    Hi @Unit-Image-Dev Thank you for your reply. That's so cool! and i will try it.
  • 0 Votes
    6 Posts
    2k Views
    H
    Hi Ferdinand, Yeah, I'll need to do dirty checking for sure. Not because I am shipping this to any customers (unless I can find a good licensing framework ), but because the nature of my plugin is to create quite a few objects; We could easily reach 100s or even 1000s of objects, depending on the situation. So I implemented primitive dirty checking from one of the links you provided, and this helps a LOT with the performance - as you're mentioning, just ignoring the cache and recreating everything every time GetVirtualObjects is called would effectively kill Cinema 4D. Especially when fiddling with parameters, as the algorithm to layout all the objects I am creating is quite intensive. So I'm using your code from this topic https://developers.maxon.net/forum/topic/14936/difficulties-to-dedect-the-right-message-data/2 to make sure I do proper dirty checking for my own generator and all linked objects before I decide to return the cache or generate all objects again. I'm not done yet, but early tests seem pretty promosing. Now if only there was a simple way to split the large python file into multiple files, then bundle them all together for one giant python file so I wouldn't have to mess with module paths. 1000 line code files get old real fast. Thanks again!
  • 0 Votes
    4 Posts
    872 Views
    ferdinandF
    Hey @ll2pakll, yes, any kind of simulation/solver is usually quite a bit of work; and as with most things, most of it is pushing data around in a 'clever' way and not the actual algorithm. You might get away with just saturating the system (add frames or "redraws"), but be warned, you will run into more problems with this approach. To have a robust solver, you must decouple it from the FPS and scene update events; this is not just a Cinema 4D thing, but universal. Cheers, Ferdinand
  • Python tag doesn't work when rendering

    Cinema 4D SDK windows 2023 python
    6
    0 Votes
    6 Posts
    1k Views
    L
    @ferdinand Your solution of replacing the doc = c4d.documents.GetActiveDocument() line with doc: c4d.documents.BaseDocument = op.GetDocument() really worked. From my point of view, as an ordinary person, your level of understanding of the code seems to be something beyond the realm of possibility. I wish you a good day and thank you again for your help.
  • Time Shift. Python tag.

    Cinema 4D SDK windows python 2023
    3
    0 Votes
    3 Posts
    596 Views
    L
    @ferdinand Thank you very much for your reply. I only need to animate one parameter and I have already written something similar to this parameter cache myself, you saw it in a previous question and advised me to change the location of the cache for more reliability. I will take your advice in the future to avoid reinventing the wheel. Thanks again for your help.
  • 0 Votes
    2 Posts
    531 Views
    ferdinandF
    Hello Herr May, Thank you for reaching out to us. I am not quite sure why you think it should do that. The angle between two vectors u and v is defined as: theta(u, v) = arccosine(~u * ~v) I.e., the arccosine of the dot product of the two normalized vectors. This is due to the so called circle functions, specifically this identity: [image: 1697012566409-26ea0c5e-9de3-4885-bc15-34b4ee3342da-image.png] Under the hood, GetAngle does exactly what I declared above (just in a bit more efficient manner, as calculating the normalized vector is much more expensive than this little trick): [image: 1697012429446-123bbf8a-568b-49a5-9ff3-2bac41f61339-image.png] As you can see, the correct solution to the arccosine of the dot product of the null vector with itself is 0.5 π, i.e., the value you got : [image: 1697012846516-ebfd4607-e872-42ef-898c-d3a2de4d8dd8-image.png] You could now argue if that is a sensible result for a method that is called 'GetAngle' and if it should throw an error on getting an input vector or being called on a vector with the length zero. But you have also to keep in mind that the C++ backend is used by people who will know the identity pi_half = arccosine(~(0, 0, 0) * ~(0, 0, 0)) and might want to make use of it. Cheers, Ferdinand
  • Python Xpresso Node

    Cinema 4D SDK windows python 2023
    5
    0 Votes
    5 Posts
    1k Views
    M
    Hi @Brakusha, welcome in plugin cafe ! c4d.ID_OPERATOR_COFFEE is working in all versions, please open a new topic with a code that demonstrate the issue and with a short explanation about what you want to achieve. I would also highly recommend you to read our Support Guideline to know how to get the best support from us. Cheers, Maxime.
  • node size

    Cinema 4D SDK python windows 2023
    4
    0 Votes
    4 Posts
    842 Views
    L
    Thank you for the answers.
  • 0 Votes
    4 Posts
    861 Views
    ferdinandF
    Hey @jochemdk, That is the nature of threading restrictions. It is like crossing the street without looking left and right: It works fine until it doesn't Cheers, Ferdinand
  • Adding ports to nodes.

    Cinema 4D SDK 2023 python windows
    3
    0 Votes
    3 Posts
    621 Views
    L
    @ferdinand said in Adding ports to nodes.: DescID Thank you so much. I am pleasantly surprised at the level of your responsiveness. When I wrote "Global Data" I accidentally used the wrong word, I meant "Global Coordinates". I have read your links and code very carefully. Actually the concept of DescID is not so much complicated as confusing, the easiest thing would be to have something like an interactive online converter that could show the attributes of the desired objects and their corresponding id. I will try to understand the concept of DescID, deeper. And thank you again for your very detailed answer. Have a nice day.
  • Saving Documents

    Cinema 4D SDK python 2023
    3
    0 Votes
    3 Posts
    532 Views
    A
    Hi Ilia, Thanks for the reply - you're correct about what I'm trying to do! I've tried your first option and unfortunately the following dialog pops up: "Unable to write file $FILE$ (file may be write protected)" This dialog does not appear if the file is saved manually with the File -> Save Project As... Dialog The save location is a network drive. Let me know if theres a workaround? For your second option - is it possible to specify the exact filename here? EDIT: It looks like you can also specify a filename here, which has worked - thanks !
  • 0 Votes
    9 Posts
    2k Views
    S
    Hi Bjorn, I have a working version of this now which you can download from my site at https://microbion.co.uk/files/rounditr2024.zip It's PC-only at the moment and requires C4D R2024. Try this and see if it does what you need. There's some basic documentation included which I'll tidy up for the final version. There doesn't seem to be a DM facility here so we'd better take any further discussion to email. You can get hold of through the contact page on my site (link is in the PDF in the zip file). Do let me know what you think. Cheers, Steve