Navigation

    • Register
    • Login
    • Search
    1. Home
    2. pim
    P

    pim

    @pim

    10
    Reputation
    251
    Posts
    355
    Profile views
    0
    Followers
    0
    Following
    Joined Last Online

    • Profile
    • More
      • Following
      • Followers
      • Topics
      • Posts
      • Best
      • Groups
    pim Follow

    Best posts made by pim

    RE: Fit image to a plane maintaining the ratio of the image?

    Together with the help from the c4dlounge.eu forum the issues is solved.
    The main issue was I did not read the manual good enough.

    "Note that Size symbolizes the axis size and not the expansion of the object itself. For planar projections, the true dimension is the two/fold of the axis length."

    posted in Cinema 4D SDK •
    RE: DrawLine2D on top of everything else

    I did some more testing and I think I got it now.
    In MouseInput() get and set your coordinates.
    Then call c4d.DrawViews(). This will call Draw(), where you can (and should) do the drawing like bd.DrawLine2D().

    class PlaceTool(c4d.plugins.ToolData):       	
    
        v1 = c4d.Vector(0,0,0)
        v2 = c4d.Vector(0,0,0)
        
        def Draw(self, doc, data, bd, bh, bt, flags):	
            bd.SetPen(c4d.Vector(256,256,256))
            bd.DrawLine2D(self.v1, self.v2)
            return True
            
        def MouseInput(self, doc, data, bd, win, msg):
            self.v1 = c4d.Vector(0,0,0)
            self.v2 = c4d.Vector(msg[c4d.BFM_INPUT_X], msg[c4d.BFM_INPUT_Y], 0)
            c4d.DrawViews(c4d.DRAWFLAGS_ONLY_ACTIVE_VIEW|c4d.DRAWFLAGS_NO_THREAD|c4d.DRAWFLAGS_NO_REDUCTION|c4d.DRAWFLAGS_STATICBREAK)  #Added 
            return True
            
            
    
    posted in Cinema 4D SDK •
    RE: Insert object in Treeview

    Thanks, great explanation!
    One small issue. Delete doesn't work because objParent' is not defined.

    Traceback (most recent call last):
    File "scriptmanager", line 251, in DeletePressed
    NameError: global name 'objParent' is not defined
    

    Here the code that, I think, solves the issue:

        def DeletePressed(self, root, userdata):
            "Called when a delete event is received."
            for tex in reversed(list(TextureObjectIterator(self.listOfTexture))):
                if tex.IsSelected:
                    objParent = tex.GetParent()               # Added
                    listToRemove = objParent.GetChildren() if objParent is not None else self.listOfTexture
                    listToRemove.remove(tex)
    
    posted in Cinema 4D SDK •
    RE: Best plugin type for background (thread) processing?

    @heilei said in Best plugin type for background (thread) processing?:

    Py-TextureBaker

    That is a very good working example.
    I rebuild my plugin using py-texturebaker and now it is working!

    After some studying, I think @PluginStudent is fully correct when referring to the global scope.

    @PluginStudent said in Best plugin type for background (thread) processing?:

    Please read my post above and the C4DThread Manual carefully.

    You can start the thread in a CommandData plugin. But this plugin must not own the thread instance. The thread instance should be stored in the global scope.

    In the MessageData plugin, you should react to a core message sent from the thread. Nothing else; no creation or waiting.

    I guess it is working because in the dialog the thread class is initiated.
    textureBakerThread = None
    and further in the code it is referenced with self.textureBakerThread.

    I was using

            thread = UserThread()
            thread.Start()
    

    Everybody thanks for all the help.

    posted in Cinema 4D SDK •
    RE: Reading script file into memory

    @PluginStudent said in Reading script file into memory:

    You have to define the APIS in the projectdefinition.txt of your plugin.

    Not in the projectdefinition.txt of the solution.

    Great, tht solved it. Thanks!

    posted in Cinema 4D SDK •
    RE: Reading script file into memory

    To summarise, there are 2 projectdefinition.txt files.

    1. on main / sdk level, Define which project (plugins, etc.)
      Example:
    Platform=Win64;OSX
    Type=Solution
     
    // defines the level of rigour of the source processor's style check
    stylecheck.level=0
    
    Solution=\
    	plugins/cinema4dsdk;\
    	plugins/maxonsdk.module;\
    	plugins/commandline;\
        plugins/CommandLineRendering
    
    1. on plugin level, // Configuration of a custom solution in the projectdefinition.txt file
      Example:
    // Supported platforms
    Platform=Win64;OSX
    
    // Type of project
    Type=DLL
    
    // this plugin depends on these frameworks:
    APIS=\
      cinema.framework; \
      misc.framework; \
      image.framework; \
      core.framework; \
      python.framework
    
    // Enable some advanced classic API support; not needed for hybrid plugins
    C4D=true
    
    // Plug-in code-style check level
    stylecheck.level=0
    
    // Custom ID
    ModuleId=net.maxonexample.commandlinerender
    
    posted in Cinema 4D SDK •
    RE: Passing a variable to the python script

    Yes, I am referring to that page.
    I saw that statement, but I assumed it was the main definition for the python plugin.

      // set __name__ = __main__
      scope.Add("__name__"_s, maxon::Data("__main__"_s)) iferr_return;
    

    If I understand you correctly, I can add different parameters with different values.
    For example:

      // set __param1__ = "c:/temp"
      scope.Add("param1"_s, maxon::Data("c:/temp"_s)) iferr_return;
      scope.Add("param2"_s, maxon::Data(220)) iferr_return;
    posted in Cinema 4D SDK •
    RE: First time compiling of plugin with R21

    Yes, I must read the manuals more throroughly (RTFMS).
    Excuses: it is so much and I just wanted to compiler R20 in R21.
    But you are correct.

    BUT, adding iferr to the code worked, AND also solved the other issue.
    Everything is working now!

    Thanks!

    posted in Cinema 4D SDK •

    Latest posts made by pim

    Place multiple objects on spline and align

    I want to place multiple objects on fixed distances and align these objectsto the spline.
    For a straight spline this is ok, but for a circle things go wrong.

    Here is the script:

    from typing import Optional
    import c4d
    import random
    from c4d.utils import SplineHelp, SplineLengthData
        
    doc: c4d.documents.BaseDocument  # The active document
    op: Optional[c4d.BaseObject]  # The active object, None if unselected
    
        
    def PlaceCube(Pspline, PsplineLength, PxPosition) -> c4d.Vector:   
        # calculate x position on spline, using given x position of the object to be placed
        
        splineOffset = PxPosition / PsplineLength   # must be between 0 and 1
        point = Pspline.GetSplinePoint(splineOffset, segment=0)
        print ("splineOffset, PxPosition, point: ", splineOffset, PxPosition, point)
        return point
    
    def main() -> None:
    
        sh = SplineHelp()                 #Add an instance of the spline helper class 
        sh.InitSpline(op)		#Dont forget to initialize it to the spline
        splineLength = sh.GetSplineLength()  
            
        rXPos = 0   
        for i in range(5):       
    
            cone1 = c4d.BaseObject(c4d.Ocone) 
            cone1[c4d.PRIM_CONE_BRAD] = 100
            
            xn = rXPos + cone1[c4d.PRIM_CONE_BRAD]/2
            point = PlaceCube(op, splineLength, xn)           
    
            # align to spline
            objmtx = cone1.GetMg()	     #Get the object's global matrix
            objmtx.off = point                     #Set the matrix positon to the point array
    
            splineOffset = xn / splineLength                     # must be between 0 and 1
            normal = sh.GetNormal(splineOffset)	      #Get the normal values where the object currently is
            tangent = sh.GetTangent(splineOffset)	    #Get the tangent values where the object is ?
         
            objmtx.v3 = normal         #Align the Z axis with the normal vector
            objmtx.v1 = tangent        #Up vector to stabilize it ?            
            cone1.SetMg(objmtx)	    #Update the object's position along the spline 
            doc.InsertObject(cone1)
    
            rXPos = rXPos + cone1[c4d.PRIM_CONE_BRAD] + 100
           
                
        c4d.EventAdd()
            
    if __name__ == '__main__':
        main()
        
    

    bed48f39-7053-4f57-aa50-602d018a8fae-image.png

    posted in Cinema 4D SDK •
    RE: Setting Material Preview for 1 material

    Thank you.

    posted in Cinema 4D SDK •
    Setting Material Preview for 1 material

    I know it is possible to set the material preview in Preferences by
    Material[c4d.PREF_MM_MATSCENE] = 2000001008 #Flat projection

    When I try to do this for a single material, it is not working.
    What am I doing wrong?

    from typing import Optional
    import c4d
    
    doc: c4d.documents.BaseDocument # The active document
    op: Optional[c4d.BaseObject] # The active object, None if unselected
    
    def main() -> None:
        mat = doc.GetActiveMaterial()
        print (mat.GetName(), mat[c4d.PREF_MM_MATSCENE])
        mat[c4d.PREF_MM_MATSCENE] = 2000001008    #Flat projection
        mat.Update(True, True)
    
    if __name__ == '__main__':
        main()
        c4d.EventAdd()
    

    PS How can I set a post to 'Solved"?

    posted in Cinema 4D SDK •
    Snap to grid while MouseDrag()

    I have a ToolData plugin where the user can draw Planes.
    I use MouseInput() to get the inital point and then MouseDragStart() and MouseDrag() to get the other point of the Plane.

    Is there a way to snap to the grid using MouseDragStart() and MouseDrag() or is that something I have to do myself?
    Something like snapPoint = grid_size * round(point / grid_size)

                mousex = msg[c4d.BFM_INPUT_X]
                mousey = msg[c4d.BFM_INPUT_Y]
                
                leftTop = c4d.Vector(mousex, mousey, 0)
                win.MouseDragStart(c4d.KEY_MLEFT, mousex, mousey, c4d.MOUSEDRAGFLAGS_DONTHIDEMOUSE|c4d.MOUSEDRAGFLAGS_NOMOVE)
    
                color = c4d.Vector(256,256,256)
                bd.SetMatrix_Screen()   #Use the screen's matrix to draw on
                    
                mx = mousex
                my = mousey
                while True:
                    result, dx, dy, channels = win.MouseDrag()
                    if result!=c4d.MOUSEDRAGRESULT_CONTINUE: break
                    mx += dx
                    my += dy
                    
                    rightBottom = c4d.Vector(mx, my,0)
                    self.v1 = leftTop
                    self.v2 = rightBottom
    
                    bd.SetDepth(True) 
                    c4d.DrawViews(c4d.DA_ONLY_ACTIVE_VIEW|c4d.DA_NO_THREAD|c4d.DA_NO_ANIMATION)
    
    posted in Cinema 4D SDK •
    RE: Plugin opens on Mac not correctly

    Alas, I was wrong!
    After trying to match GroupBegin() and GroupEnd(), it proved to be ok.
    So, back to stripping the code to see where it fails.

    Doing that I found out another (related) issue.
    After stripping to only using a Treeview, I noticed that the dialog also did open completely. So yes related to the initial issue (I think).

    336dc116-3c3b-40e8-bdf0-db11eb39d37c-image.png

    It should open like this (I resized the dialog window myself).
    6fc2ff92-a96c-4a00-8b29-296a2db14c22-image.png

    After checking the example "C4D TreeView example", I am beginning to belive the issue is not in the dialog code, but in the filling of the tree.

    If you could have a look, I will send the code and some data to sdk_support(at)maxon(dot)net.

    posted in Cinema 4D SDK •
    RE: Plugin opens on Mac not correctly

    Oops, my fault!
    After stripping a lot of the plugin, I came to the conclusion that
    GroupBegin() and GroupEnd() where not matching.

    This is apparently more importan on the Mac than on the PC!

    Thanks for the patience and the support.

    Regards,
    Pim

    posted in Cinema 4D SDK •
    RE: Plugin opens on Mac not correctly

    Yes, I am using 2 user areas.
    I will check.

    posted in Cinema 4D SDK •
    RE: Plugin opens on Mac not correctly

    Thanks.
    I am stripping the plugin more and more, to see where the error / issue occurs.

    posted in Cinema 4D SDK •
    RE: Plugin opens on Mac not correctly

    Update.
    Using "BFH_SCALEFIT|c4d.BFV_SCALEFIT for the top Group" did scale the plugin dialog, but it used the given values (600x600).
    So, still the whole dialog was not shown.

    I will keep on testing.

    Regards,
    Pim

    posted in Cinema 4D SDK •
    RE: Plugin opens on Mac not correctly

    Hi Ferdinand,

    Thanks for the quick reply.

    1. yes the dialog is DLG_TYPE_ASYNC and defaulth and defaultw have no effect.
    2. I did not put in the complete dialog, because there is a lot of code.

    After Adding a menu, here the code showing we use BFH_SCALEFIT|c4d.BFV_SCALEFIT for the top Group.

    def CreateLayout(self):
    ... add menu
    
    # 3 koloms dialog
     self.GroupBegin(ID_GRP_SUB, flags=c4d.BFH_SCALEFIT|c4d.BFV_SCALEFIT, cols=3, groupflags =c4d.BFV_GRIDGROUP_ALLOW_WEIGHTS)
     self.GroupBorderSpace(10, 0, 0, 10)  # left, top, right, bottom)       
    
    1. No, it was there already in previous versions, yet I am nor sure when it started (which version).

    And yes, I fully understand it is hard to answer such a generic question.
    I was hoping you had seen this issue before.
    I will try to delete a lot of code, to find where this issue is coming from.

    Note: after resizing the plugin dialog, the next time you open it in the same cinema 4d session, it is ok.

    Pim

    posted in Cinema 4D SDK •