Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush Python API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Unread
    • Recent
    • Tags
    • Users
    • Login
    1. Maxon Developers Forum
    2. JH23
    3. Topics
    • Profile
    • Following 7
    • Followers 0
    • Topics 13
    • Posts 48
    • Best 1
    • Controversial 0
    • Groups 0

    Topics created by JH23

    • JH23J

      Editable Object Plugin returns Null after scaling

      Cinema 4D SDK
      • python • • JH23
      4
      0
      Votes
      4
      Posts
      52
      Views

      ferdinandF

      Hey @JH23,

      there is no need to apologize for a lack of context. Now that I read your first posting again, it is actually perfectly clear what you are asking for. I just did not read it properly, my bad, sometimes this happens when I am in a hurry.

      The answer to your question is not trivial, but the TLDR is that you have only little control over it.

      There exist two commands, 'Current State to Object' (CSTO) and 'Make Editable' (ME). CSTO is basically the less aggressive version of ME, where it runs through all the elements of a cache of something and tries to collapse them gracefully (which could result in output that is still collapsible itself). ME more aggressively flattens the cache hierarchy.

      For both commands, at the very basic level, there is the distinction between generators and and non-generators. When you CSTO some generator object which just holds another generator in its cache (imagine your GetVirtualObjects or main just returning c4d.BaseObject(c4d.Ocube)), it will just return a copy of that generator (which is still a generator, i.e., something that has a cache). But when your generator returns a non-generator, i.e., a discrete PolygonObject, it will wrap the copy of this cache in a null when returning it.

      But that is not all of it. Because, there are also functions such as TransferDynamicProperties and OptimizeHierarchy which ensure that relevant scene data is kept and the output is as compact as possible. They run after ME/CSTO by further manipulating the ME/CSTO output. The original MEed/CSTOed object might have had a transform which must be copied onto the flattened output, so that it has the same transform in world space. Objects often also hold hidden data in form of tags in Cinema 4D which might have to be copied from the original object onto the flattened result. This all might lead to the functions either removing unnecessary null objects which before have been created by ME/CSTO or adding new ones.

      That your scale manipulations result in an extra null is a bit surprising, but that must have to do with the transform normalization code which runs after ME/CSTO. At first I thought, it might transfer the scale to the null object, so that it can normalize the scale of the cache. But that is not the case, it is still the cache object which has the scale 2 when you CSTO/ME your generator. I would really have to debug this in detail, to find out why exactly this happens.

      But in general, I would advise against scaling the matrix/transform of an object, and instead, apply the scale to the points of a discrete PolygonObject or the parameters of a BaseObject itself. Transforms which have axis components of non-unit length (i.e., a scale != 1.0), often lead to problems.

      The important message is that even when you find a solution which gives you the desired flat cache for this problem (by for example scaling the points), there could be countless other scenarios such as a user having a MoGraph tag on your generator or something like that, where then MEing or CSTOing would result in a null + cache output. You should not build your code on the assumption that the MEed or CSTOed output of your generator will always be flat (or the opposite), because you simply cannot guarantee that.

      Not the most satisfying answer, I know, but I hope it helps to clarify the situation.

      Cheers,
      Ferdinand

      Here is how you could post process points with a transform:

      def main(): obj: c4d.PointObject = Cube() # We could of course also just pass this #transform into your #Cube function, to do it right # there. But we are making a point of doing this as a post processing step (so that we can do # this at any point in time). We scale all points by a factor of 2 and rotate them 45° on the # Y axis in the coordinate system of the object. When we now CTSO your object, we have a flat # output. transform: c4d.Matrix = (c4d.utils.MatrixScale(c4d.Vector(2, 2, 2)) * c4d.utils.MatrixRotY(c4d.utils.DegToRad(45))) obj.SetAllPoints([n * transform for n in obj.GetAllPoints()]) obj.Message(c4d.MSG_UPDATE) return obj
    • JH23J

      lhit from BaseVolumeData

      Cinema 4D SDK
      • r21 python windows • • JH23
      3
      0
      Votes
      3
      Posts
      523
      Views

      JH23J

      Hey @m_adam,
      Thanks for the reply! What you’re saying makes a lot of sense C++ is clearly the better option for this kind of stuff, especially when you need more control and better performance. I haven’t had much chance to dive into C++ yet, but I’m well aware it’s way more powerful than Python when it comes to working with the engine.
      It’s a bit of a shame that there’s no way to directly access polygon info from Python, since that’s exactly what I needed. But still, I really appreciate you taking the time to explain it.
      Cheers,
      James H.

    • JH23J

      access the layers in the shader layer

      Cinema 4D SDK
      • python • • JH23
      10
      0
      Votes
      10
      Posts
      2.0k
      Views

      JH23J

      Hi @i_mazlov ,
      This solves my problem, for now I don't think I have another question, and I could consider my problem solved, thanks.
      cheers,
      James H.

    • JH23J

      update error?

      Cinema 4D SDK
      • r20 python • • JH23
      10
      0
      Votes
      10
      Posts
      2.3k
      Views

      JH23J

      I want to finish with this in case someone reads it. Years ago, I asked about the outdated methods when using these techniques. I tried to adjust the depth of the IK spline controls with the actual length of the spline itself. Today, I understand my mistake, as I was trying something that didn’t make logical sense. At the time, I thought it was the best option for what I was looking for.

      In short, this was never a problem, and the low response time is normal because the length depends on the depth of the controls. I thought there would be a solution, but choosing this path was not useful.

      In conclusion, what eventually satisfied my requirements was directly referencing the angles of the controls, meaning identifying how oriented each control is to another. I took this angle and used it as a factor to multiply by the depth. This model is much more logical and doesn’t have any flaws. At the time, I couldn’t think of a direct solution, but I didn’t want to leave this post like that. Thanks anyway, Ferdinand, for trying to help me.
      Cheers
      JH

    • JH23J

      Is it possible to change the mode of the Viewport without callcommands?

      Cinema 4D SDK
      • r20 python • • JH23
      6
      0
      Votes
      6
      Posts
      986
      Views

      ferdinandF

      Hello @JH23,

      without any further questions and other postings, we will consider this topic as solved and flag it as such by Friday, 17/06/2022.

      Thank you for your understanding,
      Ferdinand

    • JH23J

      import presets and be reversible

      Cinema 4D SDK
      • r20 python • • JH23
      6
      0
      Votes
      6
      Posts
      859
      Views

      ferdinandF

      Hello @JH23,

      without any further questions or postings, we will consider this thread as solved by Friday the 4th, February 2022.

      Thank you for your understanding,
      Ferdinand

    • JH23J

      preset children of objects?

      Cinema 4D SDK
      • • • JH23
      5
      0
      Votes
      5
      Posts
      674
      Views

      JH23J

      Hi
      Thank you for solving my question, and thank you very much also for the advice.

    • JH23J

      create a material with a set texture?

      General Talk
      • r20 python • • JH23
      3
      0
      Votes
      3
      Posts
      709
      Views

      JH23J

      Hi.
      Oh I understand, thanks for your answer, it has helped me a lot.

    • JH23J

      create a cube that disappears when you return?

      Cinema 4D SDK
      • • • JH23
      10
      0
      Votes
      10
      Posts
      1.4k
      Views

      ferdinandF

      Hello @JH23,

      without any further questions or postings, we will consider this topic as solved by Wednesday and flag it accordingly.

      Cheers,
      Ferdinand

    • JH23J

      How to create a material with the selected object as assigned?

      General Talk
      • r20 python • • JH23
      4
      0
      Votes
      4
      Posts
      785
      Views

      ferdinandF

      Hello @JH23,

      without further questions or postings, we will consider this topic as solved by Wednesday and flag it accordingly.

      Thank you for your understanding,
      Ferdinand

    • JH23J

      problema de regreso de código de gestor de scripts

      General Talk
      • • • JH23
      3
      0
      Votes
      3
      Posts
      668
      Views

      JH23J

      Excuse me, I thought I translated it was my mistake, and in the same way, thank you for your help.

    • JH23J

      How to create a child from the script manager?

      General Talk
      • r20 python • • JH23
      8
      0
      Votes
      8
      Posts
      1.1k
      Views

      ferdinandF

      Hello @JH23,

      first, I would like to point out that we ask the community here to post separate questions into separate postings, so that other users can find more easily answers when searching the forum. You can read more about the procedures of SDK support in our Forum Guidelines. It is okay in this case, but for future cases we have to ask you to open new topics for follow-up questions that are not directly related to the initial question of the topic (thread).

      About your question - you have two options when you want to make an object editable:

      In case you already have the object in question already inserted into the active document and are in the main thread, you can still use CallCommand. For CallCommand you have to keep in mind that it usually relies on an object selection. When running it in a script, you have then make sure that actually the objects you want to be affected are selected when you do run the CallCommand. I have provided an extension of my prior example at the end of this posting. In all other cases, i.e., when the object is either in no document or not in the active one, or you are not on the main thread, then you must use c4d.utils.SendModelingCommand Link. In this case for example for the command MCOMMAND_MAKEEDITABLE. You can find more information about that in our SDK documentation and in the code examples on GitHub.

      Cheers,
      Ferdinand

      Example code:

      import c4d def main(): # Assuming you want to use a CallCommand, you can do this. In practice # instantiating a cube object is better done in the way shown by Cairyn # in the forums. # The CallCommand for creating a cube object which will also insert and # select the cube. c4d.CallCommand(5159) # Get the currently active object; which is the new cube object due to the # prior CallCommand. The function object() created by the script log, and # used in your code, does effectively something similar. But it has the # overhead of retrieving the active object each time it is being called, # which is not necessary here. # In a script environment there are also the predefined attributes op and # doc, "variables" in non-Python terms. op is the currently active object # when the script is being run and doc the currently active document. # We cannot use op here, since the CallCommand just did change that, but # we can use doc, which we could retrieve also manually if we had to via # c4d.documents.GetActiveDocument(). cube = doc.GetActiveObject() # Set some of the parameters of that cube object. cube[c4d.ID_BASELIST_NAME] = "Cube" cube[c4d.PRIM_CUBE_LEN, c4d.VECTOR_X] = 32 cube[c4d.PRIM_CUBE_LEN, c4d.VECTOR_Y] = 32 cube[c4d.PRIM_CUBE_LEN, c4d.VECTOR_Z] = 32 cube[c4d.PRIM_CUBE_SUBX] = 11 cube[c4d.PRIM_CUBE_SUBY] = 11 cube[c4d.PRIM_CUBE_SUBZ] = 11 # Instantiate manually a cone object and insert it under that cube, i.e., # do it like Cairyn has shown it. cone = c4d.BaseObject(c4d.Ocone) # We can also set the name of a node like this, which is a bit easier to # remember than the ID. cone.SetName("Cone") # Set some parameters of the cone. You can find out parameter ids via # drag and drop and the console, read more about it here: # developers.maxon.net/docs/Cinema4DPythonSDK/html/misc/descriptions.html cone[c4d.PRIM_CONE_HEIGHT] = 32 cone[c4d.PRIM_CONE_BRAD] = 16 cone[c4d.ID_BASEOBJECT_REL_POSITION, c4d.VECTOR_Y] = 32 # Create a phong tag for the cone, so that the cone is being shaded nicely. phongTag = cone.MakeTag(c4d.Tphong) # Enable the angle limit of the phong tag. phongTag[c4d.PHONGTAG_PHONG_ANGLELIMIT] = True # Insert the cone under the cube. cone.InsertUnder(cube) # When we are doing things "manually", i.e., do not use CallCommand, we # have to push an update to Cinema 4D after we have modified the scene # graph. c4d.EventAdd() # Make the cube object the new active selection. doc.SetActiveObject(cube, c4d.SELECTION_NEW) # And run the " Make Editable" CallCommand on that c4d.CallCommand(12236) # Make Editable if __name__ == '__main__': main()
    • JH23J

      How to delete obj in the environment from a button in userdata

      Cinema 4D SDK
      • r20 python • • JH23
      4
      0
      Votes
      4
      Posts
      725
      Views

      ferdinandF

      Hello @JH23,

      without any further feedback or questions, we will consider this topic as solved by Wednesday and flag it accordingly.

      Thank you for your understanding,
      Ferdinand