Create Sections and Section Groups with Macros

June 27, 2017
Macros were able to create pages and page content which makes it very easy to generate lots of pages like the Diary Pages macro which creates a page for each day in a month or the Daily Manager Log macro which can create a page for each day in a whole year. However until now Macros didn't have the ability to create section group/section hierarchies, which are very important units of organization in larger notebooks.

With an update today, Onetastic Macros can now create new sections and section groups in notebooks and other section groups. This can be done with InsertObject function which is already used for creating pages and page content. The object type passed to the function can now be "Section" or "SectionGroup" and the parent object can be a notebook or a section group object.

Following is an example of creating a section group/section hierarchy in the current notebook. You can also download this sample macro here: Sample Create Section Hierarchy.

$notebook = GetCurrentNotebook() $SGDocs = InsertObject($notebook, "SectionGroup", -1) $SGDocs.name = "Macro Documentation" InsertObject($SGDocs, "Section", -1).name = "Getting Started" $SGFunctions = InsertObject($SGDocs, "SectionGroup", -1) $SGFunctions.name = "Functions" InsertObject($SGFunctions, "Section", -1).name = "Array Functions" InsertObject($SGFunctions, "Section", -1).name = "DateTime Functions" InsertObject($SGFunctions, "Section", -1).name = "Dialog Box Functions" InsertObject($SGFunctions, "Section", -1).name = "Macro Execution Functions" InsertObject($SGFunctions, "Section", -1).name = "Object Functions" InsertObject($SGFunctions, "Section", -1).name = "String Functions" $SGOperators = InsertObject($SGDocs, "SectionGroup", -1) $SGOperators.name = "Operators" InsertObject($SGOperators, "Section", -1).name = "Arithmetic Operators" InsertObject($SGOperators, "Section", -1).name = "Assignment Operators" InsertObject($SGOperators, "Section", -1).name = "Comparison Operators" InsertObject($SGOperators, "Section", -1).name = "Logical Operators" InsertObject($SGOperators, "Section", -1).name = "String Concatenation Operator" InsertObject($SGOperators, "Section", -1).name = "Ternary Operator"

Macro Updates

Following macros in Macroland are updated:

Search & Replace

Added option to search in selected pages in the current section. Useful if you want to search and replace only in certain pages in the current section.

Extract highlighted Text

Added option to extract highlighted text in Current Section, Current Section Group, Current Notebook, and All Notebooks. The results are displayed in a new page (if the scope is not current page), grouped by section > page and links are provided for each of the highlighted text.

Sort Pages

Updated to sort numerically if page names start with numbers like 1, 2 etc. This correctly puts a section named 10... after sections named 1... through 9...

Search & Replace in Hyperlinks

Added option to do case insensitive search

Weekly Planner

Added option to pick Monday vs. Sunday as the first day of the week as well as ability to pick a range of weeks or a specific week in the future

New Macros

Several new macros have been added to Macroland since the last update. Check them out:

Sample Create Section Hierarchy

Creates a sample section group/section hierarchy

Proofing Language -> Swedish

Sets the proofing language on selected text to Swedish

Select Between First two Heading 1

Selects all content between the first and the second Heading 1 styled paragraphs in the current page

Format Numbers

Applies specific formatting to all numbers in the selection or the current page

Append Date to Title (dd.mm.yy)

Modifies the page title to append the date in DD.MM.YY format

Comments

Name
Comment
Darell - 2017-08-23
cheap car insurance
auto insurance quotes
cheap insurance for cars
cheap auto insurance
Omer Atay - 2017-08-15
gamiclea: This would happen if there is already a section group with the same name. Since you can't have two section groups (or sections) with the same name in a notebook, updating the name fails and the section group gets a generated name, a unique identifier.
gamiclea - 2017-08-14
I tried running the sample create section hierarchy macro but am running into problems with the following command in the script:
$SGDocs.name = "Macro Documentation"
What I'm getting is that the name doesn't take...and it issues an "invalid name" error.  The section group ends up with a system generated title with a name like the following:
{357E9D36-9EC0-48E1-AAD0-9AC792E2B7EE}

What am I missing here?

Other Posts

Show all posts