Skip to content

Instantly share code, notes, and snippets.

Infoworks ICM - Illusive Macros in SQL

In InfoWorks ICM intermediate users may use SQL queries to automate their workflows. One part of the SQL system in InfoWorks which is fairly misunderstood is the macro system.

To be fair, macros aren't really explained very well in the help file either... The explanation given is as follows:

Macros are variables for representing values within a query. The Macro dialog is displayed when you click on either the button or the button on the User Macros tab on the SQL dialog. Enter a title and value for the macro, then click on OK.

Though this is correct, it is also a bit misleading. In this article I want to go into a little more detail as to what the Macro system actually does, and bounce around some ideas as to how it can be used.

Infoworks ICM - AFX and MFC

Ever since I started working with ICM, I have been tasked with automating aspects of it. I started my journey with knowing nothing about ICM, Ruby scripting, or even SQLs for that matter. Initially I automated ICM like I automate most applications, using low-level Windows APIs.

https://www.youtube.com/watch?v=zHVeZP6DQ2Q

I still remember having a conversation with an Innovyze support employee, while I was reporting a 'bug' where a dialog button wasn't being 'clicked' when I used PostMessage, but was only if I used SendMessage... In the end though, it wasn't really a bug, but myself misunderstanding which windows messages are used for which purposes.

Gradually over the years I have built up my knowledge of how ICM works and how to automate each aspect of it. Whether that be autonymously creating, setting up and running sims, finding and performing actions on database model objects, exporting a number of model networks, or using Ruby scripting to perform detailed analysis o

Infoworks ICM - Ruby Script Injection

Ever since I found the ruby scripting language been using it to extend existing functionality in ICM. However one thing which has struck me time and time again is the, almost, half-baked method of executing ruby scripts.

There are 4 options to execute a ruby scripts:

  1. Execute them from a ruby addon.
  2. Execute them from the user custom action menu.
  3. Execute them from the shared custom action menu.
  4. Execute them through the "run ruby script" menu item.
Time taken: 23.347s (response = 535 model objects, ran immediately after opening Database)
t1 = Time.now
$dbListPaths=""
def walk(moc)
moc.each do |mo|
$dbListPaths += mo.path + "\n"
walk(mo.children)
end
end
@sancarn
sancarn / ActivityWatcher.AHK
Last active April 2, 2018 18:38
Activity Watcher - This application monitors the windows you visit on your computer, and how long you visit them for. It was built due to my frustration with inability to remember what to put on my timesheets.
SetTimer, ActivityWatcher, 150
return
ActivityWatcher:
if !CurrentTitle
{
WinGetTitle, CurrentTitle, A
QPC(1)
}
@sancarn
sancarn / ReturnedErrors.txt
Last active May 5, 2018 19:02
Runs in ISE, Doesn't run in powershell
At C:\Users\sancarn\AppData\Local\Temp\script.ps1:20 char:20
+ $parent = [System.Windows.Forms.TreeNode]$global:database.Ite ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Unable to find type [System.Windows.Forms.TreeNode].
At C:\Users\sancarn\AppData\Local\Temp\script.ps1:27 char:36
+ ... [void]$node.nodes.add([System.Windows.Forms.TreeNode]::new(" ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Unable to find type [System.Windows.Forms.TreeNode].
At C:\Users\sancarn\AppData\Local\Temp\script.ps1:33 char:45
+ ... PSCustomObject]IWDBGetChildren([System.Windows.Forms.TreeNode]$node) ...
@sancarn
sancarn / .Infoworks-ICM-BetterTreeview.md
Last active May 8, 2018 08:45
A better Powershell treeview for ICM

Test

def proxy__enwrap(obj)
isClass = obj.is_a?(Class)
oldClass = isClass ? obj : obj.class
sNewClass = "Proxy#{oldClass.to_s}"
code = <<-EOF
class #{sNewClass}
include InstanceProxy
def self.__cinit__(obj)
@@__cobj__ = obj
end
Alter Table S104 (Add CAB Logical, KST Logical, PLT Logical)
select * from S104 where Adoption_Date <> "" into qNoBlank
select * from qNoBlank where Adoption_Date < CurDate() into qCAB
select * from qNoBlank where Adoption_Date >= CurDate() into qKST1
select * from S104 where Adoption_Date = "" into qBlank
select * from qBlank where Date_Confirmation < CurDate() or dwellings(DWF_Total_m3_per_sec) < 50 into qKST2
select * from qBlank where Date_Confirmation > CurDate() and dwellings(DWF_Total_m3_per_sec) >= 50 into qPLT
@sancarn
sancarn / .ClassAndMethodsReport.md
Last active July 2, 2018 13:54
Retrieve all Classes and Methods in Ruby.

Ruby - Class and Methods Report

Attempts to produce a list of all available classes and methods available in the current Ruby instance.

Issues

Currently does not retrieve methods of Object class and it's ancestors (e.g. BasicObject) - Perhaps this should be added