WiseImage Open Architecture
Lessons
“Mission Impossible”
Objectives
• Learn how to use Active Script studio
• Create a new command that scales your image– Measure the distance– Convert it to paper units– Get prompted for a desired distance– Scale the image
Preparation
• Open Active Script Studio• Observe the tools
– File operations
– Edit, Search and Undo
– Run, FormWizard and Reference
• Let’s start
Step 1:Measure Distance
Step 1: Discussion
• Root objects like Document, Command
• Interaction with user – messages, prompts, forms
• Choosers – important interactive objects
Step 1: Execution
• Save your script
• Create a toolbar for your brilliant commands
• Assign a new button to your command
• Run it!
Step 2: Paper Units
• Coordinate systems: WCS, UCS, units
• What are paper units?
• How to convert data to paper units and back to world units?
• Useful transformation object - Transformer
Step 2: Code changes
Add transformation functionfunction ToPaperUnits(val){ with (Document.CoordinateSystem.PaperUnit) { val = W2U.Direct(val); return D2S(val); }}
Command.Alert("Distance is " + org_dist);
Modify your previous code by replacing
with
Command.Alert("Distance is " + ToPaperUnits(org_dist));
Step 2: Execution
Change units to inches
Run the command again
Run your command
What is the difference?
Step 3: Be Interactive!
• Script commands can be interactive
• How to get response from user?– Alert – a simple reply yes or no– Prompt – get some literate response– Forms – the most sophisticated and flexible
way
Step 3: Code changes
Modify your previous code by replacing
var res = Command.Prompt( "You have measured the distance " + ToPaperUnits(org_dist) + "\r\nEnter the required distance", "Scale Image");try { var new_dist = ToWorldUnits(res); if (new_dist == 0.0) Command.Quit(); Command.Alert(new_dist);}catch (e) { Command.Alert(e);}// TODO: Add ToWorldUnits() code
Command.Alert("Distance is " + org_dist);
with
Step 3: Execution
Run your code
Final point
• How to process images:– Tools collection– Batch commands
Final point: Code changes
Modify your previous code by replacing
with (Tools("Resample")) { ToolParam("ResampleType") = 1; ToolParam("Scale") = 100.0 * new_dist / org_dist; ToolParam("ResampleFlag") = true; WiseRun(); Document.View.Invalidate();}
with
Command.Alert("Distance is " + org_dist);
Final point: Fulfillment
• Load the sample image
• Run your command
• Enjoy
Do you know any other way how to do the same?
Be Interactive – part 2
• HTML forms
• Form Designer is part of Active Script Studio
• Form Wizard will help you to create good looking forms.
Form creation
• Create a new form• Add your controls• Save the form
FormWizard
• Create a new simple script function Main(){}
• Save it
• Run FormWizard
• Just follow instructions
• Run your script
The magic of forms
• Open the sample script Bonus\RasterResize.js
• Run it
Gifts
• Interactive Image scaling – wrap.js
• “Back to the Future” – text_rotate.js
• GIS sample