Reply to topic  [ 3 posts ] 
Macro to select table and apply border. 
Author Message

Joined: 2016-04-24 00:13:31
Posts: 4
I have a Nisus document with several tables.

I wish to put the cursor in a table (something I will do manually) and then wish to run a macro to

1. to select the table
2. add a border of 1pt, including adding lines within the table (i.e. all round individual cells),with lines being solid (i.e. not dotted, dashed); and
3. increase the padding.

For 1. I can see I need to use:

Code:
Select Table


After this I am lost as how to deal with 2. and 3.

For 2. do I need to use

Code:
 LineAttributes.newWithLineType styleName
?

Even if I do it is not clear how to write the line of macro code (as the description indicates "Returns line attributes that draws using one of the given named styles:", i.e. indicates an attributable but not applies it).

Any help would be gratefully received.


2016-07-25 05:57:36
Profile
User avatar

Joined: 2007-02-07 00:58:12
Posts: 876
Location: Japan
Hello vwnisus

Since the task you are trying to achieve will require the macro language and use of the macro objects, it's usually a good idea to start with the following line:
Code:
$doc = Document.active


This gives you a "hold" on the Nisus document object, through which you access everything else. For example you will need the table that you have selected. After the above command you can get that as follows:
Code:
$sel = $doc.tableSelection
$table = $sel.table


Now what can you do with the $table? For one thing you can select it, like this:
Code:
$doc.setSelection $table


Ok, now on to your problem. You made a good start here:
vwnisus wrote:
I have a Nisus document with several tables.

For 2. do I need to use

Code:
 LineAttributes.newWithLineType styleName
?

Even if I do it is not clear how to write the line of macro code (as the description indicates "Returns line attributes that draws using one of the given named styles:", i.e. indicates an attributable but not applies it).

Well what that last bit means is that you need to assign the line attributes to something, for example a variable:
Code:
$solid = LineAttributes.newWithLineType "solid"

With that line you have solid line attributes in the variable $solid. Now you're ready to apply the line attributes to something. There are two options:
  • The cell object has a command .setLineAttributesForEdges (note the "set" and the plural here)
  • The table selection object has a command .applyLineAttributesToEdges (note the "apply" here)
If you read the fine print on these two, you'll notice that there are some differences, and you'll quickly see that the latter will be way more convenient in your case. But it requires that we have (A) a table selection, and (B) that that selection encompass the entire table.
The reason why I stress this point is that earlier I already retrieved a table selection (with the command "$sel = …"). The only problem is that that selection is whatever you may have clicked before starting the macro. So it might just be one cell of the table. But now we do have the whole table selected, so we can easily retrieve a new table selection that covers the whole table.
Code:
$sel = $doc.tableSelection    # update $sel to encompass the whole table
$sel.applyLineAttributesToEdges $solid, "Normal"

(The "Normal" means all the orthogonal edges. Look in the Macro Language Reference for other possible patterns.)

OK. So let's put it all together.
Code:
$doc = Document.active
$sel = $doc.tableSelection    # Get the selection
$table = $sel.table
$doc.setSelection $table    # Select the whole table. Could have done this with "Select Table" instead
$solid = LineAttributes.newWithLineType "solid"     # Create the line attributes
$sel = $doc.tableSelection    # Update $sel to encompass the whole table
$sel.applyLineAttributesToEdges $solid, "Normal"  # Apply the line attributes to the table


Ok. Now the only thing left is the padding. Piece of cake. And here we find … [drumroll] … :? :o There is no way to do it ! Yeah, that's right. I guess the programmer dude at Nisus was out surfing that day :P
There is no menu command to control padding, and no macro command either. So that's a bummer. Somebody once tried using AppleEvents to click in the drawer, but short of that you're just going to have to do it by hand after the macro finishes.

Anyhow hope that helps

PS: Once you get used to the macro language, you'll see that you can write the whole thing a little more compactly without all those variables, like this:
Code:
Select Table
$doc = Document.active
$doc.tableSelection.applyLineAttributesToEdges(LineAttributes.newSolid, 'Normal')

:wink:

_________________
philip


2016-07-26 00:19:51
Profile
Official Nisus Person
User avatar

Joined: 2002-07-11 17:14:10
Posts: 4251
Location: San Diego, CA
phspaelti wrote:
Now the only thing left is the padding. Piece of cake. And here we find … [drumroll] … :? :o There is no way to do it ! Yeah, that's right. I guess the programmer dude at Nisus was out surfing that day :P

There must have some bodacious waves out at Mavericks that day! ;) But seriously, I'm sorry about this restriction. Some table features are exposed only via the palettes, not via the menus and macros, and that's a shortcoming we should improve.


2016-09-21 15:51:24
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 3 posts ] 

Who is online

Users browsing this forum: Yahoo [Bot] and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group
Designed by ST Software