Issue: Definition name changes unexpectedly when changing UpdateType

Hi there,

I have a script (python/RhinoCommon) to embed all linked blocks in my model, export a specific InstanceDefinition and restore the state to before the script.

I would expect that changing the updateType would not affect the name, however, the referenced Instancedefinitions seem to get prepended with the block name + filename they were loaded from. This effect is unexpected and makes other scripts unreliable.

Can anyone please help me with this? I’ve added my script and files below
Thanks,
Tim

before:

after:

240604_test_save_embedded.3dm (605.8 KB)

linked_blocks.zip (711.2 KB)

from time import time

import rhinoscriptsyntax as rs
import scriptcontext as sc
import Rhino
import re


def main():

    obj = rs.GetObject('select', filter=rs.filter.instance, preselect=True)
    if not obj:
        print('abort')
        return

    block_name = rs.BlockInstanceName(obj)

    # record the start time
    start = time()

    idefs = sc.doc.InstanceDefinitions.GetList(True)
    defs_to_relink = []
    for idef in idefs:

        # only change UpdateType for currently linked blocks
        if idef.UpdateType == Rhino.DocObjects.InstanceDefinitionUpdateType.Linked:

            print('embed', idef.Name, idef.IsReference)

            # skip relinking reference definitions, i.e. definitions that are linked inside another linked block 
            # if the block is a reference, it will already be relinked when it's containing definition is relinked
            if not idef.IsReference:
                defs_to_relink.append( {
                    'idef':idef,
                    'sourceArchive':idef.SourceArchive
                } )

            # set updateType back to embedded
            sc.doc.InstanceDefinitions.ModifySourceArchive(
                idefIndex = idef.Index,
                sourceArchive =  idef.SourceArchive,
                updateType= Rhino.DocObjects.InstanceDefinitionUpdateType.Static,
                quiet = False
            )
    
    # export the definition to a file 
    filename = 'D:\Temp Files/is_embedded_questionmark.3dm'
    rs.Command('-BlockManager Export "%s" "%s" _enter ' % (block_name, filename))

    print('finished', time() - start)

    # restore block UpdateType state as before running the script
    for entry in defs_to_relink:
        idef = entry['idef']
        print('relink', idef.Name)

        sourceArchive = entry['sourceArchive']

        # set updateType back to linked
        sc.doc.InstanceDefinitions.ModifySourceArchive(
            idefIndex = idef.Index,
            sourceArchive = sourceArchive,
            updateType= Rhino.DocObjects.InstanceDefinitionUpdateType.Linked,
            quiet = False
        )

    print('cleaned up', time() - start)

@lars you may want to investigate this.

@timcastelijn I was able to reproduce this. Added this to our bug tracker RH-82415.
-Lars

2 Likes