-Import with block name conflicts

Is there a way to either programmatically or via RhinoApp.RunScript set this prompt to “Keep current block”?

For instance, I’m calling RhinoApp.RunScript(“!_-Import \”" + FilePath + “\” _Enter", false);
and don’t get the prompt (which is the desired result. I don’t want to show a prompt), but then I have no way of scripting this choice. It just defaults to “Keep both blocks” and then bloats the current 3dm with unnecessary duplicate blocks.

I guess what I am after is a command argument like “DefaultConflictOption=KeepCurrent” that I can always pass when calling this import script to force the option.

Thanks,
Ben.

Hi @BenHaycraft,

There isn’t a way to script this today — in a scripted/batch -Import the dialog is intentionally suppressed and Rhino falls back to its built-in default for blocks, which is “keep both” with an automatic rename.

I’ve logged a ticket so we can consider a change.

– Dale

Thanks for the reply and the info. I’ll keep an eye out for any updates regarding this.

-Ben

@BenHaycraft
not tested but a simple workaround for a script would be:

Before Import:
(1) Add some custom UserData/String to the InstanceDefinitions that are in the file to mark them as “residence” / the old ones.
If you want maximum robustness use a simple key “blockStatus” and some unique value - a new Guid for example.
(2) now do the import of all files
(3) identify the new InstanceDefinitions - the key “blockStatus” does not exist or the Guid does not match.
(4) create a mapping table / dictionary for all new InstanceDefinitions that already have the corresponding “residence” InstanceDefinition - look at all Blocks Instances and check if they use a new InstanceDefinition, that needs to be replaced.
(5) delete the new, non-unique Block Instances
(6) optional: clean up the usertext with “blockStatus”

maybe above is already enough prompt to get the script from claude or chatGpt.

if you find a solution - please post it - this issue was already discussed somewhere else:

and @dale
related youtrack ?

happy coding - kind regards - tom

Hey Tom -

I ended up writing my own method until an official version is usable. It gets called in the RhinoDoc_EndOpenDocument() event method.

Because it’s internal code, I can’t share it, but here it is in pseudocode with the main steps/logic

FUNCTION MergeDuplicateDefinitions(doc, deleteOrphaned):

VALIDATE document and definitions collection – exit if invalid or empty

SET empty list of (duplicate → original) pairs

FOR EACH definition IN document:
    IF definition looks like a duplicate (based on naming or rules):
        FIND its supposed original definition (basically the name without the extra numbers)
        IF original exists and is valid:
            ADD (duplicate, original) to the list

FOR EACH pair IN list:
    GET all objects that reference the duplicate
    FOR EACH such object:
        CHANGE its reference to point to the original instead

IF deleteOrphaned is TRUE:
    FOR EACH definition IN document:
        IF definition has no remaining references AND it still looks like a duplicate:
            DELETE it

RETURN success (True)