GUID (Model ID) when copying models

Hello everyone,

I have a question about copying models via the API.

I have a model that is successfully created and calculated via a Python script and the API. As part of a limit study, I want to perform three more calculations with slightly adjusted parameters based on this model.

My approach was to save the original model under different model names, then open, modify, and read all models. However, I noticed that the models created this way have the same GUID (Model ID) as the original model. This makes it difficult for me to specifically switch the active model or to address the models uniquely.


Does anyone have a suggestion on how I can create the new models with their own GUID? Alternatively, I would be interested to know if there is another way to specifically switch the active model via the API.

I would be very grateful for any tip.

Best regards

Philipp

Hi Philipp,

unfortunately, the desired functionality is currently not available. However, this request (save as, save as copy via the API) has already been requested by other users and forwarded to development (RUS ID = 5511). I have added you to the list of requesters, so we can keep you updated.

The GUID is unfortunately read-only (also in the UI), so the existing value cannot be overwritten.

An admittedly poor workaround would be simply to create a new model and then transfer all information from the old to the new project via the API. However, calculation results etc. would be lost in the process.

Best regards
Robert Milrath

Hi Phillipp,

I just thought of something else—you could work with templates:

import os

import dlubal.api.rfem as rfem
import dlubal.api.common as common

with rfem.Application() as rfem_app:

    # ─── 1. Create model ───────────────────────────────────────────
    model_id_1 = rfem_app.create_model(
        name="Model_1"
    )
    rfem_app.delete_all_objects()

    rfem_app.create_object_list(
        [
        rfem.structure_core.Material(no=1, name="S235"),
        rfem.structure_core.CrossSection(no=1, name="IPE 300", material=1),
        rfem.structure_core.Node(no=1, coordinate_1=0.0, coordinate_2=0.0, coordinate_3=0.0),
        rfem.structure_core.Node(no=2, coordinate_1=5.0, coordinate_2=0.0, coordinate_3=0.0),
        rfem.structure_core.Line(no=1, definition_nodes=[1, 2]),
        rfem.structure_core.Member(no=1, line=1, cross_section_start=1),
        ], 
        model_id=model_id_1
    )

    print(f"GUID_1: {model_id_1.guid}")

    # ─── 2. Save model ───────────────────────────────────────────────────
    save_path = os.path.abspath(f'./Model_1.rf6')
    rfem_app.save_model(
        model_id=model_id_1,
        path=save_path
    )
    print(f"Saved at: {save_path}")

    # ─── 3. Create copy with new ModelID and use Model 1 as template──────────
    model_id_2 = rfem_app.create_model(
        name="Model_2",
        template_path=save_path,
    )
    print(f"GUID_2: {model_id_2.guid}")
    save_path = os.path.abspath(f'./Model_2.rf6')
    rfem_app.save_model(model_id=model_id_2, path=save_path)
    print(f"Saved at: {save_path}")

    # Compare both GUIDs
    print(f"\nGUID Model_1: {model_id_1.guid}")
    print(f"GUID Model_2:    {model_id_2.guid}")
    print(f"Different: {model_id_1.guid != model_id_2.guid}")

    print(f'Opened models:\n{rfem_app.get_model_list()}')

The only downside here is that the project used as a template is always closed.

Maybe this helps you further.

Happy coding.

Best regards
Robert Milrath

Hello Robert,

first of all, thank you very much for the quick help.

If I understand you correctly, I would have to create a separate template model for each new variant and then edit and calculate the respective template model. After that, before the evaluation, I would open the original model again and then evaluate all models.

Have I understood that correctly?

Best regards
Philipp

Hello Philipp,

this should work, feel free to keep me updated.

One small tip, if you want to post example code again, please format it accordingly:

image

This way the code can be used via copy & paste, images are rather superfluous for that.

Best regards
Robert Milrath

Hello everyone,

Since I investigated a similar topic a few months ago, I might be able to help. If the active model is saved in a different location, the model is assigned a new GUID at the new storage location, right?
A script to reproduce is attached below.

Best regards

Script:

from dlubal.api import rfem
from dlubal.api.common import ModelId

path_to_source_model: str = (
    r"C:\Users\benej\Downloads\20260610_RFEM_Modell_ID_beim_Kopieren_von_Modellen\source_model.rf6"
)
path_to_copied_model: str = (
    r"C:\Users\benej\Downloads\20260610_RFEM_Modell_ID_beim_Kopieren_von_Modellen\copied_model.rf6"
)

with rfem.Application() as rfem_app:

    rfem_app.open_model(path=path_to_source_model)
    rfem_app.save_model(path=path_to_copied_model)
    rfem_app.close_model(save_changes=True)

    for model_path in [path_to_source_model, path_to_copied_model]:
        rfem_app.open_model(path=model_path)
        model_id: ModelId = rfem_app.get_active_model()
        print(f"{model_id.guid = }")

Output:

model_id.guid = '5c5ab3aa-914e-4576-9460-718146114137'
model_id.guid = '53efb5f3-178c-42e5-9472-0361c95909e4'

Hello Benedikt,

as you described, it is of course even easier.

import os
from dlubal.api import rfem

with rfem.Application() as rfem_app:
    source_path = os.path.abspath(f'./Model_1.rf6')
    save_path = os.path.abspath(f'./Model_2.rf6')

    # Open Model 1 (must already exist in the example) and save as Model 2
    # This also automatically generates a new GUID for Model 2 and closes Model 1
    # So it behaves exactly as if I had executed Save_As in the UI
    rfem_app.open_model(path=source_path)
    rfem_app.save_model(path=save_path)

    # Now reopen the closed Model 1 (as desired)
    rfem_app.open_model(path=source_path)

    # Check the GUIDs
    print(f'Opened models:\\n{rfem_app.get_model_list()}')

I had tried the same thing, but there was a small mistake in it; this is now the corrected code.

Thanks for the support.

Best regards
Robert Milrath

Hello again everyone,

the tip was very helpful. Now everything works perfectly for me.

Many thanks again for the support!

Best regards
Philipp