Nico_be Posted November 3 Share Posted November 3 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!! Quote Link to comment
Pat Stanford Posted November 3 Share Posted November 3 There is a Vectorscript/Python procedure for returning this data. But it might require a custom node to be written. GetWSSubrowCount() It works almost exactly as you are asking except it takes a handle instead of a name for the worksheet. 1 Quote Link to comment
Nico_be Posted November 3 Author Share Posted November 3 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 Quote Link to comment
Recommended Posts
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.