Getting row elements out of a generic table javascript

MagicDraw OpenAPI, scripting related questions and discussions

Moderator: Moderators

Getting row elements out of a generic table javascript

Postby matt.a.thurman@gmail.com » Mon Apr 20, 2020 5:17 pm

Hi,

I have a generic table i'm using to show my requirement trace
RequirementTrace.PNG


On the left I have 3 requirements, they trace through some functions which are grouped into different algorithms which are then installed on an FPGA. i'm trying to create a macro which will grab each requirement out of the table, and depending on what the "owning processor" is, set a value in the "processor" column. not sure if there's an easier way than using a macro.... i feel like in the code below there should be some function like "actDiagram.getRowElements();" but i can't figure out how to make that work. there's a function "get presentationElements" which work on other diagram types, but apparently not on a table

any help would be greatly appreciated. (including the model file in the post).

thanks!


with(CollectionsAndFiles)
{
var project = Application.getInstance().getProject();
var logger = Application.getInstance().getGUILog();
var actDiagram = project.getActiveDiagram();
var rowElements = new ArrayList();

rowElements = actDiagram.getRowElements();
{
You do not have the required permissions to view the files attached to this post.
matt.a.thurman@gmail.com
Forum Newbie
Forum Newbie
 
Posts: 10
Posts Rating:0
Joined: Wed Apr 26, 2017 2:46 pm

Re: Getting row elements out of a generic table javascript

Postby sat@intsv.net » Tue Jul 28, 2020 6:56 am

This code is meant to traverse the table contents. Try it out.
Code: Select all
function generate_table() {
  // get the reference for the body
  var body = document.getElementsByTagName("body")[0];

  // creates a <table> element and a <tbody> element
  var tbl = document.createElement("table");
  var tblBody = document.createElement("tbody");

  // creating all cells
  for (var i = 0; i < 2; i++) {
    // creates a table row
    var row = document.createElement("tr");

    for (var j = 0; j < 2; j++) {
      // Create a <td> element and a text node, make the text
      // node the contents of the <td>, and put the <td> at
      // the end of the table row
      var cell = document.createElement("td");
      var cellText = document.createTextNode("cell in row "+i+", column "+j);
      cell.appendChild(cellText);
      row.appendChild(cell);
    }

    // add the row to the end of the table body
    tblBody.appendChild(row);
  }

  // put the <tbody> in the <table>
  tbl.appendChild(tblBody);
  // appends <table> into <body>
  body.appendChild(tbl);
  // sets the border attribute of tbl to 2;
  tbl.setAttribute("border", "2");
}
sat@intsv.net
Forum Newbie
Forum Newbie
 
Posts: 1
Posts Rating:0
Joined: Tue Jul 28, 2020 6:49 am


Return to Programmatic Extendibility

Who is online

Users browsing this forum: No registered users and 0 guests

cron