Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware 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

    Get the preview images from c4d files

    Cinema 4D SDK
    c++ s26
    3
    5
    881
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • H
      hof
      last edited by

      I saw you can browse a folder of files and get the file informations here:
      https://developers.maxon.net/docs/cpp/2023_2/page_manual_browsefiles.html

      Is it also possible to get the preview images from those files? And how?

      1 Reply Last reply Reply Quote 0
      • FSSF
        FSS
        last edited by FSS

        https://forums.cgsociety.org/t/set-preview-in-content-browser-via-python-script/2056787

        Not certain it solves your problem but in this post somebody changed the preview picture in python.

        https://developers.maxon.net/forum/topic/7666/9673_set-document-preview/2

        1 Reply Last reply Reply Quote 0
        • H
          hof
          last edited by

          not really
          you can get the preview from a BaseDocument with GetDocPreviewBitmap();
          but this works only with loaded files, and i don't want to load all files first.

          1 Reply Last reply Reply Quote 0
          • ManuelM
            Manuel
            last edited by Manuel

            Hi,

            I guess you are talking about retrieving the preview of c4d files only. If you want to retrieve preview of any kind of files, you need to use the OS functionalities and of course they are different if you are using windows or OSX.

            But for c4d files you can proceed like so. You have to load the document to have access to the bitmap, but you can do it with the flag SCENEFILTER::NONE that way, the minimum will be loaded.

            #include "maxon/apibase.h"
            #include "maxon/errorbase.h"
            #include "maxon/errortypes.h"
            #include "maxon/url.h"
            #include "maxon/iobrowse.h"
            #include "maxon/fileformat_handler.h"
            #include "maxon/dataformat.h"
            
            #include "c4d_general.h"
            #include "c4d_commanddata.h"
            #include "c4d_baseplugin.h"
            #include "c4d_basedocument.h"
            #include "c4d_basebitmap.h"
            #include "lib_description.h"
            #include "customgui_bitmapbutton.h"
            
            static maxon::Result<void> pc14103(BaseDocument* doc)
            {
            	iferr_scope;
            	maxon::Url baseDirectory { maxon::URLSCHEME_FILESYSTEM };
            	baseDirectory.SetPath("D:/temp/c4d"_s) iferr_return;
            	
            	for (const auto& it : baseDirectory.GetBrowseIterator(maxon::GETBROWSEITERATORFLAGS::NONE))
            	{
            		const maxon::Url filePath = it.GetCurrentPath() iferr_return;
            		if (filePath.GetSuffix() == "c4d"_s)
            		{
            			Filename maxonFile = MaxonConvert(filePath);
            			BaseDocument* myDoc = LoadDocument(maxonFile, SCENEFILTER::NONE, nullptr);
            			if (myDoc == nullptr)
            				continue;
            
            			BaseBitmap* docPreview = myDoc->GetDocPreviewBitmap();
            			if (docPreview && (docPreview->GetBw() > 0) && (docPreview->GetBh() > 0))
            				ShowBitmap(docPreview);
            			KillDocument(myDoc);
            		}
            	}
            
            	return maxon::OK;
            }
            
            

            Cheers,
            Manuel

            MAXON SDK Specialist

            MAXON Registered Developer

            1 Reply Last reply Reply Quote 0
            • H
              hof
              last edited by

              thanks that works.

              1 Reply Last reply Reply Quote 0
              • First post
                Last post