Jump to content
Developer Wiki and Function Reference Links ×

Number of subrows in a given row in a table


Recommended Posts

Hello,

I've looked everywhere but can't find it.

Does anyone have a node that can return the number of subrows in a given row in a table?

 

Input: Table name is OK (get worksheet)

Input: Row number (Int)

Output: Number of subrows (Int)

 

Thanks!!

 

 

Link to comment

thanks @Pat Stanford

 

Thanks to Grok, I have a node that does this and also recalculates the table beforehand so that the number of subrows is correct.

 

The input requires the name of the worksheet in ‘string’ format.


 

#Marionette Node Script

@Marionette.NodeDefinition
class Params(metaclass=Marionette.OrderedClass):
    this = Marionette.Node( "Get Worksheet Subrow Count" )
    this.SetDescription( "Returns the number of displayed subrows for a specified database row in a worksheet." )
    
    # INPUTS
    worksheet_name = Marionette.PortIn( '', 'sWorksheetName' )
    worksheet_name.SetDescription( "The name of the worksheet." )
    database_row = Marionette.PortIn( 0, 'nDatabaseRow' )
    database_row.SetDescription( "The database row to query (integer)." )
    
    # OUTPUTS
    num_subrows = Marionette.PortOut( 'nNumSubrows' )
    num_subrows.SetDescription( "The number of displayed subrows." )

def RunNode(self):
    # --- Récupération des entrées ---
    ws_name = self.Params.worksheet_name.value
    if isinstance(ws_name, list) and len(ws_name) > 0:
        ws_name = ws_name[0]
    
    db_row = self.Params.database_row.value
    if isinstance(db_row, list) and len(db_row) > 0:
        db_row = db_row[0]
    
    # --- Initialisation ---
    handle = vs.GetObject(ws_name)
    subrows_count = 0
    
    if handle == vs.Handle(0):
        self.Params.num_subrows.value = 0
        return
    
    # --- FORCER L'OUVERTURE DU WORKSHEET ---
    was_visible = vs.IsWSVisible(handle)
    vs.ShowWS(handle, True)  # Ouvre le worksheet (obligatoire pour générer les subrows)
    
    # --- FORCER LE RECALCUL ---
    vs.RecalculateWS(handle)
    vs.ResetObject(handle)
    
    # --- BOUCLE D'ATTENTE : on attend que les subrows soient générés ---
    import time
    max_attempts = 50
    attempt = 0
    
    while attempt < max_attempts:
        vs.DoMenuTextByName('Redraw', 0)  # Forcer rafraîchissement
        count = vs.GetWSSubrowCount(handle, db_row)
        
        if count > 0:
            subrows_count = count
            break
        
        attempt += 1
        time.sleep(0.05)  # 50ms entre chaque tentative
    
    # --- Si toujours 0 après 2.5s, on force un dernier recalcul ---
    if subrows_count == 0:
        vs.RecalculateWS(handle)
        vs.ResetObject(handle)
        vs.DoMenuTextByName('Redraw', 0)
        time.sleep(0.1)
        subrows_count = vs.GetWSSubrowCount(handle, db_row)
    
    # --- Restaurer visibilité ---
    vs.ShowWS(handle, was_visible)
    
    # --- Sortie ---
    self.Params.num_subrows.value = subrows_count

 

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...