Developing Plug-ins for PolyWop
Polywop is written in Visual Basic, so the explanations and
examples I use will be best understood from the Visual Basic context,
but the content can be easily converted to be used in other programming
languages.
PolyWop communicates to and from It's plugins through the VB Sendkeys routine, and the clipboard, or written Files.
PolyWop accepts an ESC macro to alert it that a plugin wishes to
communicate. This is sent to PolyWop from the plugin via the Sendkeys
command. PolyWop then waits for a following command character. If no
recognizable command key is sent, it aborts the macro.
The acceptable commands are:
O Chr(79), S Chr(83), C Chr(67), T Chr(84), X Chr(88), L Chr(76)
(the following examples require that you place a richtext
box on your form. I have used Richtextbox controls here because they
allow you to troubleshoot your output better. I works fine, but is by
far not the fastest way to write these files.)
O- Chr(79), VBKeyO
Open. Cause PolyWop to open a file to receive data.
PREP: Write data to a file in a format that PolyWop will accept. (follow the examples below)
The file path location must be sent to the clipboard.
COMMAND: Sendkeys "{ESC}o"
FOLLOW UP: none.
EXAMPLE:
Dim FN As String
(use the examples below to first fill the RichTextBox with data)
On Error GoTo FileError
FN = App.Path &
"\SKTrans.txt" ' **** this is example path & file, any will
do.
RichTextBox1.SaveFile FN, 1
Clipboard.Clear
Clipboard.SetText FN, 1
AppActivate "PolyWop", False
SendKeys "{ESC}o", True
Exit Sub
FileError:
S- Chr(83), VBKeyS
Save. Cause PolyWop to Save data to a file called pwtrans.txt stored in PolyWop's home directory.
PREP: none
COMMAND: Sendkeys "{ESC}s"
FOLLOW UP: Retrieve the file path from the clipboard,& read the file data into your plug-in.
EXAMPLE:
Dim FN As String
AppActivate "PolyWop", False
SendKeys "{ESC}s", True
On Error Resume Next
FN = Clipboard.GetText
RichTextBox1.LoadFile FN
AppActivate Me.Caption, False
Me.SetFocus
C- Chr(67), VBKeyC
Clip. Cause PolyWop to retrieve data from the system clipboard.
PREP: prepare clipboard with the data
COMMAND: Sendkeys "{ESC}c"
FOLLOW UP: switch focus to PolyWop, PolyWop will go to Paste mode.
EXAMPLE:
(use the examples below to first fill the RichTextBox with data)
Clipboard.Clear
Clipboard.SetText RichTextBox1.Text
On Error GoTo FileError
AppActivate "PolyWop"
SendKeys "{ESC}c", True
T- Chr(84), VBKeyT
Text. Cause PolyWop to retrieve data from the system clipboard.
PREP: prepare clipboard with the data
COMMAND: Sendkeys "{ESC}t"
FOLLOW UP: switch focus back to Plugin, PolyWop will go to Text mode.
EXAMPLE:
(use the examples below to first fill the RichTextBox with data)
Clipboard.Clear
Clipboard.SetText RichTextBox1.Text
On Error GoTo FileError
AppActivate "PolyWop"
SendKeys "{ESC}t", True
Me.SetFocus
X- Chr(88), VBKeyX
Capture. Cause PolyWop to send data from a capture to the system clipboard.
PREP: none.
COMMAND: Sendkeys "{ESC}x"
FOLLOW UP: Retrieve data from the system clipboard. Set focus to plugin.
EXAMPLE:
AppActivate "PolyWop", False
SendKeys "{ESC}x", True
On Error Resume Next
RichTextBox1.Text = Clipboard.GetText
AppActivate Me.Caption, False
Me.SetFocus
L- Chr(76), VBKeyL
Layer. Cause PolyWop to send data from a layer to the system clipboard.
(The layer will be the one that PolyWop is in currently).
PREP: none.
COMMAND: Sendkeys "{ESC}l"
FOLLOW UP: Retrieve data from the system clipboard.
EXAMPLE:
AppActivate "PolyWop", False
SendKeys "{ESC}l", True
On Error Resume Next
RichTextBox1.Text = Clipboard.GetText
AppActivate Me.Caption, False
Me.SetFocus
Prep Data
In various cases data must be prepared before calling the macro.
The actual poly data values are expressed in mm * 64. This was done in
PolyWop to increase the resolution of the work area and is normally
invisible to the user of PolyWop, but it must be considered when
working with the data, though in many cases it may not be critical.
So in the first example 14588.511859262 /
64 = 227.94549780096875, which is the Start X point of the
poly segment expressed in millimeters. Be advised, if your data
produces small graphics in PolyWop, it may be you have not converted
the data. Multiply * 64 and you should be ok.
The O (Open command). The header line must be included with the file.
EXAMPLE FILE:
Line# Layer SX
SY
EX
EY
Length
Angle
1 0
14588.511859262
11336.1089251633 16019.7279915353
12788.9999776521
2 0
16019.7279915353
12788.9999776521 16044.3551374249
12328.7764762373
3 0
16044.3551374249
12328.7764762373 15987.8616846126
12010.044215119
4 0
15987.8616846126
12010.044215119
15922.1493002085 11843.5750625242
5 0
15922.1493002085
11843.5750625242 14298.6654503905
10535.9779085509
6 0
14298.6654503905
10535.9779085509 13110.5971390216
9542.55641657477
7 0
13110.5971390216
9542.55641657477 12650.0235162146
9081.9025197575
8 0
12650.0235162146
9081.9025197575
12722.6900946772 8307.1498529291
9 0
12722.6900946772
8307.1498529291
12868.5661886799 7968.39571752223
10 0
12868.5661886799
7968.39571752223 13352.6580858868
7652.59134345699
11 0
13352.6580858868
7652.59134345699 13910.815399441
7216.9173561324
(Data continues)
The header line must be present.
The Data is in the format: Line#(ignored), Layer, Start X, Start Y, End
X, End Y, Length(ignored), Angle(ignored). (Each Line defines 1 poly
segment)
Each data item is separated by a Tab character Chr(9), and each data
line is ended with a Carriage Return & Line Feed Chr(13) &
Chr(10). The data that is ignored must at least have a place holder
(tab).
PROGRAMMING EXAMPLE:(This example places Header with Data from an array into a Rich Text Box in prep for an Open macro)
Dim TB as Integer, CR as Integer
Dim I as Integer, J as Integer
Dim A(5,1000) as double 'This is a Data array
TB = VBTab: CR = VBCrLf
' **** begin the Header
RichTextBox1.Text = "Line" & TB & "Layer" & TB
& "SX" & TB & "SY" & TB & "EX" & TB &
"EY" & TB & “Length” & TB &
“Angle” & CR
' **** continue with data
For I = 0 to 1000
RichTextBox1.Text = RichTextBox1.Text &
Str(A(0,I)) ' **** either empty or 0 is ok
For J = 1 to 5
RichTextBox1.Text = RichTextBox1.Text & TB & Str(A(J,I))
Next J
RichTextBox1.Text = RichTextBox1.Text & TB
& TB & CR ' **** added placeholders for length & angle
Next I
The C (Clip command). PolyWop searches for the header Line before it resolves to actually inputing data.
EXAMPLE FILE:
Line Layer SX
SY
EX EY
0
1288.375 -624.25
566.5 -624.25
0
566.5
-624.25 440
-330
0
440
-330 431.1175
-308.825
0
431.1175 -308.825
423.17 -288.75
0
423.17
-288.75 416.1575 -269.775
0
416.1575 -269.775
410.08 -251.9
0
410.08
-251.9 404.9375
-235.125
0
404.9375 -235.125
400.73 -219.45
(Data continues)
The header line must be present.
The Data is in the format: Line(ignored), Layer(ignored), Start X,
Start Y, End X, End Y. (This defines 1 poly segment).The data that is
ignored must at least have a place holder (tab).
Each data item is separated by a Tab character chr(9), and each data
line is ended with a Carriage Return & Line Feed Chr(13) &
Chr(10).
PROGRAMMING EXAMPLE:(This example places header with Data from an array into a Rich Text Box in prep for a Clip macro)
Dim TB as Integer, CR as Integer
Dim I as Integer, J as Integer
Dim A(5,1000) as double 'This is a Data array
TB = VBTab: CR = VBCrLf
' **** begin the Header
RichTextBox1.Text = "Line" & TB & "Layer" & TB
& "SX" & TB & "SY" & TB & "EX" & TB & "EY"
& CR
' **** continue with data
For I = 0 to 1000
RichTextBox1.Text = RichTextBox1.Text & Str(A(0,I)) ' **** either empty or 0 is ok
For J = 1 to 5
RichTextBox1.Text = RichTextBox1.Text & TB & Str(A(J,I))
Next J
RichTextBox1.Text = RichTextBox1.Text & CR
Next I
The T (Text command) takes
further preparation in that it also will accept a StepX and StepY
designation in the header. StepX and StepY values tell PolyWop where to
advance to the next cursor position. Minus values are also acceptable.
Further, PolyWop searches for the header Line before it resolves to actually inputing data.
EXAMPLE FILE:
StepX 3
StepY 0
Line Layer SX
SY
EX EY
0
1288.375 -624.25
566.5 -624.25
0
566.5
-624.25 440
-330
0
440
-330 431.1175
-308.825
0
431.1175 -308.825
423.17 -288.75
0
423.17
-288.75 416.1575 -269.775
0
416.1575 -269.775
410.08 -251.9
0
410.08
-251.9 404.9375
-235.125
0
404.9375 -235.125
400.73 -219.45
(Data continues)
The header line must be present.
The Data is in the format: Line(ignored), Layer(ignored), Start X,
Start Y, End X, End Y. (Each Line defines 1 poly segment).The data that
is ignored must at least have a place holder (tab).
Each data item is separated by a Tab character Chr(9), and each data
line is ended with a Carriage Return & Line Feed Chr(13) &
Chr(10).
PROGRAMMING EXAMPLE:(This example places header with Data from an array into a Rich Text Box in prep for a text macro)
Dim TB as Integer, CR as Integer
Dim I as Integer, J as Integer
Dim A(5,1000) as double 'This is a Data array
TB = VBTab: CR = VBCrLf
' **** begin the Header
RichTextBox1.Text = "StepX " & Val(Textbox1.Text) & CR ' **** Textbox1 defines a StepX value
RichTextBox1.Text = RichTextBox1.Text & "StepY " &
Val(Textbox2.Text) & CR ' **** Textbox2 defines a StepY value
RichTextBox1.Text = RichTextBox1.Text & "Line" &
TB & "Layer" & TB & "SX" & TB & "SY" & TB &
"EX" & TB & "EY" & CR
' **** continue with data
For I = 0 to 1000
RichTextBox1.Text = RichTextBox1.Text & Str(A(0,I)) ' **** either empty or 0 is ok
For J = 1 to 5
RichTextBox1.Text = RichTextBox1.Text & TB & Str(A(J,I))
Next J
RichTextBox1.Text = RichTextBox1.Text & CR
Next I