Block decomposition using rhinoinside

I am working with some models exported from SolidWorks. As a consequence, when importing those models into the Rhino, I have a situation when every detail is placed in a separate block and if in SolidWorks there were assemblies and subassemblies – those details in Rhino will be in some nested blocks. But I need to work with separate details ( here – separate closed polysurfaces).
I have made a script for interactive Rhino like this:

import Rhino
def decompose(objs):
    surfs =list()
    for obj in objs:
        if obj.ObjectType == Rhino.DocObjects.ObjectType.InstanceReference:
            decompose(obj.GetSubObjects())
        elif obj.ObjectType == Rhino.DocObjects.ObjectType.Brep:
            surfs.append(obj.Geometry)
    if surfs:
        [Rhino.RhinoDoc.ActiveDoc.Objects.AddBrep(brep) for brep in Rhino.Geometry.Brep.JoinBreps(surfs,0.1)]


doc = Rhino.RhinoDoc.ActiveDoc
objs = doc.Objects

decompose(objs)
for obj in objs:
    if obj.ObjectType == Rhino.DocObjects.ObjectType.InstanceReference:
        Rhino.RhinoDoc.ActiveDoc.Objects.Delete(obj)
doc.Views.ActiveView.Redraw()

But this script will not work when I run it in Pycharm using rhinoinside library (the idea here is to use Rhino in a headless mode.
I would be very grateful if you could recommend me how to rewrite this code so that it will work in Pycharm. As far as I see – the main problem is that in Rhino we usually work with RhinoObjects and when working in a headless mode using rhinoinside – we get some File3dmObjects. And those two classes have different methods and attributes.

@Andrii_Levchenko1 Have you seen this post on Rhino.Inside CPython?

At the very least it looks like your code will need to start with

import rhinoinside
rhinoinside.load()
import System
import Rhino

to be able to use Rhino headless from an external CPython script.