Skip to content

Commit 8c19d3b

Browse files
author
Nikolay Belykh
committed
initial
1 parent 9c7047f commit 8c19d3b

9 files changed

+290
-0
lines changed

Python-logo.png

4.07 KB
Loading

runPythonScript.ico

59.1 KB
Binary file not shown.

runPythonScript.lpi

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<CONFIG>
3+
<ProjectOptions>
4+
<Version Value="12"/>
5+
<PathDelim Value="\"/>
6+
<General>
7+
<Flags>
8+
<CompatibilityMode Value="True"/>
9+
</Flags>
10+
<SessionStorage Value="InProjectDir"/>
11+
<Title Value="runPythonScriptFromVisio"/>
12+
<ResourceType Value="res"/>
13+
<UseXPManifest Value="True"/>
14+
<Icon Value="0"/>
15+
</General>
16+
<VersionInfo>
17+
<UseVersionInfo Value="True"/>
18+
<MajorVersionNr Value="1"/>
19+
<MinorVersionNr Value="1"/>
20+
<Language Value="0809"/>
21+
<StringTable CompanyName="Paul Herber" FileDescription="Run Python script from Visio" LegalCopyright="Paul Herber 2022" ProductName="Run Python From Visio" ProductVersion="1.1.0"/>
22+
</VersionInfo>
23+
<BuildModes Count="1">
24+
<Item1 Name="Default" Default="True"/>
25+
</BuildModes>
26+
<PublishOptions>
27+
<Version Value="2"/>
28+
</PublishOptions>
29+
<RunParams>
30+
<FormatVersion Value="2"/>
31+
<Modes Count="1">
32+
<Mode0 Name="default"/>
33+
</Modes>
34+
</RunParams>
35+
<RequiredPackages Count="1">
36+
<Item1>
37+
<PackageName Value="LCL"/>
38+
</Item1>
39+
</RequiredPackages>
40+
<Units Count="2">
41+
<Unit0>
42+
<Filename Value="runPythonScript.lpr"/>
43+
<IsPartOfProject Value="True"/>
44+
</Unit0>
45+
<Unit1>
46+
<Filename Value="unit1.pas"/>
47+
<IsPartOfProject Value="True"/>
48+
<ComponentName Value="Form1"/>
49+
<HasResources Value="True"/>
50+
<ResourceBaseClass Value="Form"/>
51+
<UnitName Value="Unit1"/>
52+
</Unit1>
53+
</Units>
54+
</ProjectOptions>
55+
<CompilerOptions>
56+
<Version Value="11"/>
57+
<PathDelim Value="\"/>
58+
<Target>
59+
<Filename Value="runPythonScriptFromVisio"/>
60+
</Target>
61+
<SearchPaths>
62+
<IncludeFiles Value="$(ProjOutDir)"/>
63+
<UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
64+
</SearchPaths>
65+
<Linking>
66+
<Debugging>
67+
<GenerateDebugInfo Value="False"/>
68+
</Debugging>
69+
<Options>
70+
<Win32>
71+
<GraphicApplication Value="True"/>
72+
</Win32>
73+
</Options>
74+
</Linking>
75+
</CompilerOptions>
76+
<Debugging>
77+
<Exceptions Count="3">
78+
<Item1>
79+
<Name Value="EAbort"/>
80+
</Item1>
81+
<Item2>
82+
<Name Value="ECodetoolError"/>
83+
</Item2>
84+
<Item3>
85+
<Name Value="EFOpenError"/>
86+
</Item3>
87+
</Exceptions>
88+
</Debugging>
89+
</CONFIG>

runPythonScript.lpr

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
program runPythonScript;
2+
3+
{$mode objfpc}{$H+}
4+
5+
uses
6+
{$IFDEF UNIX}{$IFDEF UseCThreads}
7+
cthreads,
8+
{$ENDIF}{$ENDIF}
9+
Interfaces, // this includes the LCL widgetset
10+
Forms, Unit1,
11+
SysUtils, ShellApi;
12+
13+
{$R *.res}
14+
15+
var
16+
theScript: string;
17+
params: string;
18+
ext: string;
19+
i: integer;
20+
status: integer;
21+
begin
22+
Application.Title:='runPythonScriptFromVisio';
23+
RequireDerivedFormResource:=True;
24+
Application.Initialize;
25+
Application.CreateForm(TForm1, Form1);
26+
27+
if ParamCount > 4 then
28+
begin
29+
// get the script name
30+
theScript := ParamStr(5);
31+
// replace any %20 in script name with space
32+
theScript := StringReplace(theScript, '%20', ' ', [rfReplaceAll]);
33+
34+
// get any parameters
35+
params := '';
36+
//Form1.Memo1.Lines.Add('Param count = ' + IntToStr(ParamCount));
37+
if ParamCount > 5 then
38+
begin
39+
for i := 6 to ParamCount do
40+
begin
41+
params := params + ParamStr(i) + ' ';
42+
end;
43+
end;
44+
// replace any %20 in param with space
45+
if params <> '' then
46+
theScript := StringReplace(params, '%20', ' ', [rfReplaceAll]);
47+
48+
// output them for debugging
49+
//Form1.Memo1.Lines.Add(theScript);
50+
//Form1.Memo1.lines.Add(params);
51+
// get the script extension
52+
ext := ExtractFileExt(theScript);
53+
// only work with python extensions
54+
if (ext = '.py') or (ext = '.py3') or (ext = '.pyc') or (ext = '.pyw') then
55+
begin
56+
//Form1.Memo1.lines.Add('Found Python file');
57+
// run the script
58+
status := ShellExecute(0,'open',PChar(theScript),PChar(params),PChar(ExtractFilePath(theScript)),0);
59+
// check for success
60+
if status > 32 then
61+
begin
62+
//success
63+
Form1.Memo1.lines.Add('Run Python Scripts in Visio V1.1');
64+
end
65+
else
66+
begin
67+
// return values 0..32 are errors
68+
Form1.Memo1.lines.Add('Error ' + IntToStr(status));
69+
end;
70+
end;
71+
end;
72+
73+
Application.Run;
74+
end.
75+

runPythonScript.lps

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<CONFIG>
3+
<ProjectSession>
4+
<PathDelim Value="\"/>
5+
<Version Value="12"/>
6+
<BuildModes Active="Default"/>
7+
<Units Count="2">
8+
<Unit0>
9+
<Filename Value="runPythonScript.lpr"/>
10+
<IsPartOfProject Value="True"/>
11+
<IsVisibleTab Value="True"/>
12+
<TopLine Value="38"/>
13+
<CursorPos X="65" Y="63"/>
14+
<UsageCount Value="21"/>
15+
<Loaded Value="True"/>
16+
</Unit0>
17+
<Unit1>
18+
<Filename Value="unit1.pas"/>
19+
<IsPartOfProject Value="True"/>
20+
<ComponentName Value="Form1"/>
21+
<HasResources Value="True"/>
22+
<ResourceBaseClass Value="Form"/>
23+
<UnitName Value="Unit1"/>
24+
<EditorIndex Value="1"/>
25+
<CursorPos Y="30"/>
26+
<UsageCount Value="21"/>
27+
<Loaded Value="True"/>
28+
</Unit1>
29+
</Units>
30+
<JumpHistory Count="4" HistoryIndex="3">
31+
<Position1>
32+
<Filename Value="runPythonScript.lpr"/>
33+
<Caret Line="65" TopLine="14"/>
34+
</Position1>
35+
<Position2>
36+
<Filename Value="runPythonScript.lpr"/>
37+
<Caret Line="21" TopLine="7"/>
38+
</Position2>
39+
<Position3>
40+
<Filename Value="runPythonScript.lpr"/>
41+
<Caret Line="11" Column="3" TopLine="5"/>
42+
</Position3>
43+
<Position4>
44+
<Filename Value="runPythonScript.lpr"/>
45+
<Caret Line="10" Column="18" TopLine="40"/>
46+
</Position4>
47+
</JumpHistory>
48+
<RunParams>
49+
<FormatVersion Value="2"/>
50+
<Modes ActiveMode="default"/>
51+
</RunParams>
52+
</ProjectSession>
53+
</CONFIG>

runPythonScript.res

61.8 KB
Binary file not shown.

unit1.lfm

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
object Form1: TForm1
2+
Left = 514
3+
Height = 233
4+
Top = 186
5+
Width = 386
6+
Caption = 'Run Python from Visio'
7+
ClientHeight = 233
8+
ClientWidth = 386
9+
OnCreate = FormCreate
10+
LCLVersion = '1.8.4.0'
11+
object Memo1: TMemo
12+
Left = 32
13+
Height = 139
14+
Top = 24
15+
Width = 304
16+
TabOrder = 0
17+
end
18+
object Button1: TButton
19+
Left = 152
20+
Height = 25
21+
Top = 184
22+
Width = 75
23+
Caption = 'OK'
24+
OnClick = Button1Click
25+
TabOrder = 1
26+
end
27+
end

unit1.pas

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
unit Unit1;
2+
3+
{$mode objfpc}{$H+}
4+
5+
interface
6+
7+
uses
8+
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls;
9+
10+
type
11+
12+
{ TForm1 }
13+
14+
TForm1 = class(TForm)
15+
Button1: TButton;
16+
Memo1: TMemo;
17+
procedure Button1Click(Sender: TObject);
18+
procedure FormCreate(Sender: TObject);
19+
private
20+
21+
public
22+
23+
end;
24+
25+
var
26+
Form1: TForm1;
27+
28+
implementation
29+
30+
{$R *.lfm}
31+
32+
{ TForm1 }
33+
34+
procedure TForm1.FormCreate(Sender: TObject);
35+
begin
36+
//
37+
end;
38+
39+
procedure TForm1.Button1Click(Sender: TObject);
40+
begin
41+
Close;
42+
end;
43+
44+
end.
45+

version.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1.1

0 commit comments

Comments
 (0)