<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;"># '***  Isolate V5                                            ***'
# '***  by NateLiquidGravity          12/19/2023              ***'
# '***  Isolate selected objects.                             ***'
# '**************************************************************'

# Use at your own risk. This script uses undocumented features of AlibreScript. Be extremely careful with modifications.

# V5 speeds things up. Added print of times. Only tested on Alibre Design V27 and therefore limited to Alibre Design V27.
# V4 Fix for no previous hidden.
# V3 First Public release.

from __future__ import division  # This fixes division with integers. For example the 1 / 2 = 0.5 instead of 0
import time
Win = Windows()


ScriptName = 'Isolate'
ScriptVersion = 'V5'
MinASVersion = 343543
ReqADVersion = [27030, 27038, 27039, 28098]

#########################################################################################################################
#########################################################################################################################
###  Functions
#########################################################################################################################
#########################################################################################################################

def Isolate(Occ,SelectedSet,MarkHiddenOnly = 0):
    Occs = Occ.Occurrences
    CurrentHidden = []
    CurrentSelected = []
    for r in range(0,SelectedSet.Count):
        SelectedItem = SelectedSet.Item(r)
        SelectedOcc = SelectedItem.Occurrence
        #print(SelectedOcc.Name)
        CurrentSelected.append(SelectedOcc)
    for p in range(0,Occs.Count):
        ThisOcc = Occs.Item(p)
        #print(ThisOcc.Name)
        if ThisOcc.IsHidden:
            CurrentHidden.append(str(ThisOcc.Key))
        if ThisOcc.Occurrences.Count and not ThisOcc in CurrentSelected:
            #print(ThisOcc.Occurrences.Count)
            CurrentHidden += Isolate(ThisOcc, SelectedSet, MarkHiddenOnly)
        elif ThisOcc.Occurrences.Count and ThisOcc in CurrentSelected:
            #print(ThisOcc.Occurrences.Count)
            CurrentHidden += Isolate(ThisOcc, SelectedSet, 1)
        elif ThisOcc in CurrentSelected:
            pass
            #print('found one')
        else:
            if not MarkHiddenOnly:
                ThisOcc.IsHidden = 1
    return CurrentHidden


def EndIsolate(Occ, CurrentHidden):
    Occs = Occ.Occurrences
    for p in range(0,Occs.Count):
        ThisOcc = Occs.Item(p)
        if ThisOcc.Occurrences.Count:
            EndIsolate(ThisOcc, CurrentHidden)
        elif str(ThisOcc.Key) in CurrentHidden:
            pass
            #print('found one')
        else:
            ThisOcc.IsHidden = 0
    return

def GetEnviroment():
    #Get Enviroment---------- Thanks IDSLK for idea
    try:
        Enviroment = CurrentAssembly()
        EnviromentType = 'Assembly'
    except:
        Enviroment = CurrentPart()
        EnviromentType = 'Part'
    #print(str(EnviromentType) + ': ' + str(Enviroment))
    return Enviroment, EnviromentType


def VersionCheck(MinASVersion, strictASV=0, ADVersion=None):
    # check AlibreScript has the functionality we require
    MinASVersion = float(MinASVersion)
    strictASV = float(strictASV)
    try:
        CurrentVersion = AlibreScriptVersion
    except NameError:
        CurrentVersion = 0
        print('NameError')
    langLoad_StrictAlibreScript = ' strictly requires AlibreScript version '
    langLoad_StrictUpdateAlibreScript = 'Please update AlibreScript and seek an update for this script.'
    langLoad_AlibreScriptOld = 'AlibreScript version too old'
    langLoad_StrictUpdateThisScript = 'Please seek an update for this script for AlibreScript Version '
    langLoad_AlibreScriptNew  = 'AlibreScript version too new'
    langLoad_MinAlibreScript  = ' requires AlibreScript version at least '
    langLoad_UpdateAlibreScript  = 'Please update AlibreScript.'
    langLoad_StrictAlibre  = ' strictly requires one of these Alibre Design build versions: '
    langLoad_UpdateAlibre  = 'Please seek an update for this script for Alibre Design build version '
    langLoad_WrongAlibre  = 'Wrong Alibre Design Version'
    if strictASV:
        if CurrentVersion &lt; MinASVersion:
            print(str(ScriptName) + ' ' + str(ScriptVersion) + str(langLoad_StrictAlibreScript) + str(MinASVersion) + '.\n' + str(langLoad_UpdateAlibreScript))
            Win.ErrorDialog(str(ScriptName) + ' ' + str(ScriptVersion) + str(langLoad_StrictAlibreScript) + str(MinASVersion) + '.\n' + str(langLoad_UpdateAlibreScript), str(langLoad_AlibreScriptOld))
            sys.exit()
        elif CurrentVersion &gt; MinASVersion:
            print(str(ScriptName) + ' ' + str(ScriptVersion) + str(langLoad_StrictAlibreScript) + str(MinASVersion) + '.\n' + str(langLoad_StrictUpdateThisScript) + str(CurrentVersion))
            Win.ErrorDialog(str(ScriptName) + ' ' + str(ScriptVersion) + str(langLoad_StrictAlibreScript) + str(MinASVersion) + '.\n' + str(langLoad_StrictUpdateThisScript) + str(CurrentVersion), str(langLoad_AlibreScriptNew))
            sys.exit()
    elif CurrentVersion &lt; MinASVersion:
        print(str(ScriptName) + ' ' + str(ScriptVersion) + str(langLoad_MinAlibreScript) + str(MinASVersion) + '.\n' + str(langLoad_UpdateAlibreScript))
        Win.ErrorDialog(str(ScriptName) + ' ' + str(ScriptVersion) + str(langLoad_MinAlibreScript) + str(MinASVersion) + '.\n' + str(langLoad_UpdateAlibreScript), str(langLoad_AlibreScriptOld))
        sys.exit()
    if ADVersion:
        vOK = 0
        if type(ADVersion) is list:
            for ver in ADVersion:
                if str(Global.Root.Version).split(',')[3] == str(ver):
                    vOK = 1
        else:
            if str(Global.Root.Version).split(',')[3] == str(ADVersion):
                    vOK = 1
        if not vOK:
            print(str(ScriptName) + ' ' + str(ScriptVersion) + str(langLoad_StrictAlibre) + str(ADVersion) + '.\n' + str(langLoad_UpdateAlibre) + str(Global.Root.Version).split(',')[3])
            Win.ErrorDialog(str(ScriptName) + ' ' + str(ScriptVersion) + str(langLoad_StrictAlibre) + str(ADVersion) + '.\n' + str(langLoad_UpdateAlibre) + str(Global.Root.Version).split(',')[3], str(langLoad_WrongAlibre))
            sys.exit()
    return True


def SaveListToUserData(MyList, DataName):
    if MyList &lt;= 0 :
        print('There was nothing to save')
        DeleteUserData(DataName)
    else:
        Enviroment, EnviromentType = GetEnviroment()
        DataStringsDictionary = {}
        ID = 0
        for r in MyList:
            DataStringsDictionary[ str(ID)] = str(r)
            Enviroment.SetUserData(DataName, DataStringsDictionary)
            ID += 1

def LoadListFromUserData(DataName):
    Enviroment, EnviromentType = GetEnviroment()
    MyList = []
    DataStringsDictionary = Enviroment.GetUserData(DataName)
    if DataStringsDictionary:
        MyList = DataStringsDictionary.values()
        return MyList

def DeleteUserData(DataName, NoQuestion = 0):
    if not NoQuestion:
        QValue = Win.QuestionDialog('Are you sure you want to delete UserData stored in ' + str(DataName) + '?', 'Delete UserData?')
    else:
        QValue = 1
    if QValue:
        Enviroment, EnviromentType = GetEnviroment()
        Enviroment.SetUserData(DataName, {})


# this function checks to see if we are in an assembly or a part
# True = assembly
# False = part
def is_assembly():
    try:
        CurrentAssembly()
        return True
    except:
        return False


#########################################################################################################################
#########################################################################################################################
###  Main
#########################################################################################################################
#########################################################################################################################

print('\n')
VersionCheck(MinASVersion, ADVersion = ReqADVersion)
if is_assembly():
    Root = Global.Root
    ThisSess = Root.TopmostSession
    Occ = ThisSess.RootOccurrence
    SelectedSet = ThisSess.SelectedObjects
    ThisAssy = CurrentAssembly()

    CurrentHidden = LoadListFromUserData('liquid.project.isolate')
    if CurrentHidden:
        print('End Isolate')
        StartTime = time.time()
        ThisAssy.PauseUpdating()
        EndIsolate(Occ, CurrentHidden)
        DeleteUserData('liquid.project.isolate', 1)
        ThisAssy.ResumeUpdating()
        print('Done')
        EndTime = time.time()
        print('Time to End Isolate all of ' + str(ThisSess.PhysicalProperties(0).PartsCount) + ' parts:')
        print(str(float(EndTime) - float(StartTime)) + ' seconds.')

    else:
        if not SelectedSet.Count:
            Win.InfoDialog ("Select Items to Isolate then Close this or click OK\n\n\nNote:\nYou can select before running this script to skip this dialog box", "Start Isolation")
            SelectedSet = ThisSess.SelectedObjects
            if not SelectedSet.Count:
                print('Nothing Selected to Isolate')
                sys.exit()
        print('Isolate')
        StartTime = time.time()
        ThisAssy.PauseUpdating()
        CurrentHidden = Isolate(Occ, SelectedSet)
        ThisAssy.ResumeUpdating()
        print('Done')
        EndTime = time.time()
        print('Time to Isolate ' + str(SelectedSet.Count) + ' from ' + str(ThisSess.PhysicalProperties(0).PartsCount) +  ' parts:')
        print(str(float(EndTime) - float(StartTime)) + ' seconds.')
        if not CurrentHidden:
            CurrentHidden.append(str("None To Hide"))
        SaveListToUserData(CurrentHidden, 'liquid.project.isolate')
else:
    print('Isolate only works in an assembly.')
</pre></body></html>