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
    • Register
    • Login

    MergeDocument() for importing OBJ

    PYTHON Development
    0
    3
    707
    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
      Helper
      last edited by

      On 07/05/2018 at 04:47, xxxxxxxx wrote:

      Hi there,

      I'm using c4d.documents.MergeDocument() in a script to import a bunch of OBJ files into a BaseDocument.

      Here are two questions:

      1. Materials and texture paths
      If I manually use "Merge" from Cinema's file menu, everything works fine. Materials are also imported from the .MTL files including textures (located in the same folder where the OBJ and MTL files are). If I call c4d.documents.MergeDocument() from a script, the textures are not found, as Cinema assumes that all textures would be located in a standard folder. The material editor shows the message:
      file:///Applications/MAXON/CINEMA 4D R19/tex   Cause: Errno #2: No such file or directory

      Question: How can I make Cinema load the textures from the correct folder, just as if I imported the files manually?

      2. Import settings
      I need to specify some settings for the import (most importantly the scale). I can show the import dialog with c4d.documents.MergeDocument(load flags = c4d.SCENEFILTER_DIALOGSALLOWED), but since I'm importing an arbitrary numbers of files, I don't want the dialog to show up for each of them.

      Question: How can I set the import parameters used for MergeDocument() via script?

      Thanks in advance!

      Cheers,
      Frank

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

        On 08/05/2018 at 08:21, xxxxxxxx wrote:

        Hi Frank,

        I do not get the textures loaded with both merging a scene from the menu and from a script MergeDocument().
        Whereas with Open menu and LoadFile() the textures are loaded fine (but the latest function is not convenient for most scripts and automations).

        When using MergeDocument() some manual setup has to be done on the destination document and/or merged data.
        What does matter is the destination document's path, not the imported obj file directory because Cinema does not automatically change the textures file paths (these are just read from the associated mtl file).
        So the destination document's path and/or the textures file paths have to be adapted.

        Why not just show the dialog for the first imported file? Pass SCENEFILTER_DIALOGSALLOWED only for the first call to MergeDocument() then the subsequent calls will use the latest settings.

        Alternatively loader settings can be retrieved and changed via code with MSG_RETRIEVEPRIVATEDATA. There's an example for OBJ importer on GitHub: import_OBJ.py

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

          On 22/05/2018 at 02:17, xxxxxxxx wrote:

          Hi Yannick!

          Thanks for your reply! I'm actually doing a mass import of multiple .OBJ files into a new document, so the target document does not have any path yet, at the moment of merging. I'm now simply fixing the texture paths in the bitmap shaders myself. Works.

          Good idea with the dialog, I'll try that!

          Thanks & greetings,
          Frank

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