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

    xRef file path is broken if created via python

    Cinema 4D SDK
    python 2023
    2
    3
    610
    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.
    • B
      BackendKG
      last edited by

      Hello,

      I made a simple python plugin for automated project generation in C4D 2023.1.3.
      It basically loads a 3D model, creates a xRef that points to a master project file which includes all materials and then saves the document. The idea is, to have one file where I can edit materials, which automatically transfer to all my generated projects.

      Everything works fine, except the xRef connection.
      When I open my generated project, all xRef settings are greyed out and seem to have a broken file path (even though I inserted an absolute path, it displays just the filename). The weird thing is, that all the xRef materials and objects are imported successfully, but the connection to the file is lost and won't update. When I do it manually everything works as expected.

      This post helped me a lot to set it up: https://developers.maxon.net/forum/topic/14319/does-xref-or-xref-simple-are-now-accessible-with-python

      So my code looks like this (only the important parts):

      # loading the master project
      doc = c4d.documents.LoadDocument("C:/path/to/master/project.c4d", c4d.SCENEFILTER_NONE)
      
      # creating the xref for the materials
      xref_materials = c4d.BaseObject(c4d.Oxref)
      doc.InsertObject(xref_materials)
      materialFileId = c4d.DescID(c4d.DescLevel(c4d.ID_CA_XREF_FILE, c4d.DTYPE_FILENAME, 0))
      xref_materials.SetParameter(materialFileId, "C:/path/to/material/project.c4d", c4d.DESCFLAGS_SET_USERINTERACTION)
      c4d.EventAdd()
      
      # loading the 3d model
      c4d.documents.MergeDocument(doc, "C:/path/to/model.obj", c4d.SCENEFILTER_OBJECTS)
      
      # saving the project to another location
      c4d.documents.SaveDocument(doc, "C:/path/to/target/file.c4d", c4d.SAVEDOCUMENTFLAGS_NONE, c4d.FORMAT_C4DEXPORT)
      

      I also tested different path formats like "file:///" and relative paths, but the problem persists.
      Pre configuring the xRef in a seperate C4D project file and merging that into the current project, instead of creating the xRef directly, didn't work either.
      Am I missing something?

      Thank you very much for your help,
      David

      ferdinandF 1 Reply Last reply Reply Quote 0
      • ferdinandF
        ferdinand @BackendKG
        last edited by ferdinand

        @BackendKG Hello @user,

        Welcome to the Plugin Café forum and the Cinema 4D development community, it is great to have you with us!

        Getting Started

        Before creating your next postings, we would recommend making yourself accustomed with our Forum and Support Guidelines, as they line out details about the Maxon SDK Group support procedures. Of special importance are:

        • Support Procedures: Scope of Support: Lines out the things we will do and what we will not do.
        • Support Procedures: Confidential Data: Most questions should be accompanied by code but code cannot always be shared publicly. This section explains how to share code confidentially with Maxon.
        • Forum Structure and Features: Lines out how the forum works.
        • Structure of a Question: Lines out how to ask a good technical question. It is not mandatory to follow this exactly, but you should follow the idea of keeping things short and mentioning your primary question in a clear manner.

        About your First Question

        You said that you

        [...] made a simple python plugin for automated project generation in C4D 2023.1.3.

        What do you mean by that? Are you using c4dpy or are you using Cinema 4D? When I run my code from the old thread, I do not have any problems crating such Xref, saving it as a file, and loading that file back.

        760107d1-96e8-4f6e-85d3-d6482a976fb0-image.png

        1. Please share which application you are using.
        2. Please share executable code, in your snippet at least the import statements are missing.
        3. Check if your file paths are correct. You use there forward slashes for a Windows path which should work, but it is better to escape paths when you write them manually. E.g., r"e:/test.c4d" or "e://test.c4d". Finally, you could also make sure that your Urls are being interpreted as being in the file scheme with r"file:///e:/test.c4d".

        When you use c4dpy, you probably have to execute the passes on that document before saving it, or do some message magic, given how custom Xrefs are with being bound to the GUI in form of DESCFLAGS_SET_USERINTERACTION. Or in the worst case, it might be impossible to create Xref instances in a headless Cinema 4D instance, i.e., c4dpy.

        Cheers,
        Ferdinand

        MAXON SDK Specialist
        developers.maxon.net

        B 1 Reply Last reply Reply Quote 0
        • B
          BackendKG @ferdinand
          last edited by

          Sorry for not making my post as clear as it should have been, next time I will do better 🙂

          The good thing is, I fixed it! The problem was how I loaded my initial master project.

          # instead of using
          c4d.documents.LoadDocument()
          
          # i replaced it with
          c4d.documents.LoadFile()
          

          ... and now my xRef works just fine!

          Thank you again!

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