Jump to content
Sign in to follow this  
MaxWhite

Get visible objects from viewport in commandline

Recommended Posts

I think problem is C4d is not initialized BaseDraw from Commandline because BaseDraw, PickObject, GetFrame didn't in Gui console. I tried to take BaseDraw.GetSafeFrame () and got 0,0,0,0. Also tried to run the script from Gui, I was able to get GetFrame () when I did BaseDraw.InitializeView (self, doc, cam, editorsv) (but still not the same as the console in Gui). In fact PickObject, GetFrame work well in Gui console.

Share this post


Link to post
>>> bd = doc.GetActiveBaseDraw()
>>> print bd
<c4d.BaseDraw object called 'Perspective' with ID 110305 at 0x0000025EA376C6B0>
>>> print bd.GetSafeFrame()
{'cr': 1566, 'ct': 0, 'cb': 845, 'cl': 61}
>>> print bd.GetFrame()
{'cr': 1626, 'ct': 0, 'cb': 845, 'cl': 0}
>>> 

seems to work for me, but this is R21.

I don't actually get your issue, what are you trying to do and why do you need a BaseDraw in the command line...? What script did you run? didn't what in Gui console? Your text seems incomplete...

Share this post


Link to post
  • Topic Author
  • Author of the topic Posted
    20 minutes ago, Cairyn said:
    
    >>> bd = doc.GetActiveBaseDraw()
    >>> print bd
    <c4d.BaseDraw object called 'Perspective' with ID 110305 at 0x0000025EA376C6B0>
    >>> print bd.GetSafeFrame()
    {'cr': 1566, 'ct': 0, 'cb': 845, 'cl': 61}
    >>> print bd.GetFrame()
    {'cr': 1626, 'ct': 0, 'cb': 845, 'cl': 0}
    >>> 

    seems to work for me, but this is R21.

    I don't actually get your issue, what are you trying to do and why do you need a BaseDraw in the command line...? What script did you run? didn't what in Gui console? Your text seems incomplete...

    I am writing a script that runs the C4d command line ("Commandline.exe" - nogui, etc.) and works in it.The Gui console is the console that is called with shift+F10 in c4d.

    Share this post


    Link to post
    5 hours ago, MaxWhite said:

    I am writing a script that runs the C4d command line ("Commandline.exe" - nogui, etc.) and works in it.The Gui console is the console that is called with shift+F10 in c4d.

    Oh, that commandline. But since it does not have a GUI, I wouldn't expect anything to work that depends on GUI features. If there is no view window, there is no drawing area. I'm actually surprised that GetActiveBaseDraw wouldn't plainly return None under these circumstances, but maybe the object is needed for something internally.

    I'd suspect the whole OpenGL environment is not initialized as it normally is with a GUI, and that none of the "interactive" methods will work. But that's something you'd need to ask the developers directly on PluginCafé.

    Share this post


    Link to post
  • Topic Author
  • Author of the topic Posted
    12 hours ago, Cairyn said:

    Oh, that commandline. But since it does not have a GUI, I wouldn't expect anything to work that depends on GUI features. If there is no view window, there is no drawing area. I'm actually surprised that GetActiveBaseDraw wouldn't plainly return None under these circumstances, but maybe the object is needed for something internally.

    I'd suspect the whole OpenGL environment is not initialized as it normally is with a GUI, and that none of the "interactive" methods will work. But that's something you'd need to ask the developers directly on PluginCafé.

     

     Code example: 

    import os
    import sys
    
    import c4d
    
    def PluginMessage(_id, data):
        if _id == c4d.C4DPL_COMMANDLINEARGS:
        	print sys.argv
            walker()
            return True
        return False
    
    def walker(step_x=5,step_y=5):
            doc = c4d.documents.GetActiveDocument()
            print "Document: {}".format(doc)
            bd = doc.GetRenderBaseDraw()
            print "BaseDraw: {}".format(bd)
            safeframe = bd.GetSafeFrame()
            print "SafeFrame: {}".format(safeframe)
    
            arr_o = []
            for y in range(safeframe['cl'],safeframe['cr'],step_y):
                for x in range(safeframe['ct'],safeframe['cb'],step_x):
                    o = c4d.utils.ViewportSelect.PickObject(bd, doc, x, y, rad=1, flags=c4d.VIEWPORT_PICK_FLAGS_OGL_ONLY_TOPMOST_WITH_OBJ | c4d.VIEWPORT_PICK_FLAGS_OGL_ONLY_VISIBLE)
                    if o:
                        try:
                            arr_o.append(o[0])
                        except IndexError as e:
                            print(e)
            print "Array of objects: {}".format(arr_o)
            return arr_o

    Output:

    ['C:\\Users\\Administrator\\Documents\\1.c4d', '-nogui']
    Document: <c4d.documents.BaseDocument object called '' with ID 110059 at 0x00000
    08ABA5CC3B0>
    BaseDraw: <c4d.BaseDraw object called 'Perspective' with ID 110305 at 0x0000008A
    BA5CC3F0>
    SafeFrame: {'cr': 0, 'ct': 0, 'cb': 0, 'cl': 0}
    Array of objects: []

    Cmd command:

    C:\Program Files\MAXON\Cinema 4D R20>Commandline.exe "C:\Users\Administrator\Documents\1.c4d" -nogui

    Share this post


    Link to post

    Join the conversation

    You can post now and register later. If you have an account, sign in now to post with your account.

    Guest
    Reply to this topic...

    ×   Pasted as rich text.   Paste as plain text instead

      Only 75 emoji are allowed.

    ×   Your link has been automatically embedded.   Display as a link instead

    ×   Your previous content has been restored.   Clear editor

    ×   You cannot paste images directly. Upload or insert images from URL.

    Sign in to follow this  

    • Recently Browsing   0 members

      No registered users viewing this page.

    ×
    ×
    • Create New...

    FORUMS INFO:

    Dear members, we are aware of few more bugs that are still present withing the theme.We just wanted to let you know that we are working to fix them as soon as possible.
     

    NEW MEMBERS:

    Please be aware that we are manually approving all new registrations, due to spam prevention. Please be patient in case you cannot login right away, we will approve you within 12h or less if we decide you are not potential spammer. 

     

    Thanks for understanding! :cowboypistol: