Skip to content

Commit 63ed721

Browse files
committed
clear code, readme
1 parent 89fdae5 commit 63ed721

File tree

9 files changed

+26
-79
lines changed

9 files changed

+26
-79
lines changed

CADPythonShell/CADPythonShellApplication.cs

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
using System.IO;
2-
using System.Reflection;
3-
using System.Reflection.Emit;
42
using System.Windows.Media;
53
using System.Windows.Media.Imaging;
64
using System.Xml.Linq;
@@ -73,44 +71,6 @@ public static ImageSource GetEmbeddedPng(System.Reflection.Assembly app, string
7371
}
7472

7573

76-
/// <summary>
77-
/// Creates a dynamic assembly that contains types for starting the canned commands.
78-
/// </summary>
79-
private static void CreateCommandLoaderAssembly(XDocument repository, string dllfolder, string dllname)
80-
{
81-
var assemblyName = new AssemblyName { Name = dllname + ".dll", Version = new Version(1, 0, 0, 0) };
82-
var assemblyBuilder = AppDomain.CurrentDomain.DefineDynamicAssembly(assemblyName, AssemblyBuilderAccess.RunAndSave, dllfolder);
83-
var moduleBuilder = assemblyBuilder.DefineDynamicModule("CommandLoaderModule", dllname + ".dll");
84-
85-
foreach (var command in GetCommands(repository))
86-
{
87-
var typebuilder = moduleBuilder.DefineType("Command" + command.Index,
88-
TypeAttributes.Class | TypeAttributes.Public,
89-
typeof(CommandLoaderBase));
90-
91-
// call base constructor with script path
92-
var ci = typeof(CommandLoaderBase).GetConstructor(new[] { typeof(string) });
93-
94-
var constructorBuilder = typebuilder.DefineConstructor(MethodAttributes.Public, CallingConventions.Standard, new Type[0]);
95-
var gen = constructorBuilder.GetILGenerator();
96-
gen.Emit(OpCodes.Ldarg_0); // Load "this" onto eval stack
97-
gen.Emit(OpCodes.Ldstr, command.Source); // Load the path to the command as a string onto stack
98-
gen.Emit(OpCodes.Call, ci); // call base constructor (consumes "this" and the string)
99-
gen.Emit(OpCodes.Nop); // Fill some space - this is how it is generated for equivalent C# code
100-
gen.Emit(OpCodes.Nop);
101-
gen.Emit(OpCodes.Nop);
102-
gen.Emit(OpCodes.Ret); // return from constructor
103-
typebuilder.CreateType();
104-
}
105-
assemblyBuilder.Save(dllname + ".dll");
106-
}
107-
108-
public static void OnUnloading()
109-
{
110-
// FIXME: deallocate the python shell...
111-
return;
112-
}
113-
11474
public static IRpsConfig GetConfig()
11575
{
11676
return new NpsConfig(GetSettingsFile());

CADPythonShell/ConfigureCommand.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using System.Windows.Interop;
2-
using Autodesk.AutoCAD.Runtime;
1+
using Autodesk.AutoCAD.Runtime;
32
using Application = Autodesk.AutoCAD.ApplicationServices.Core.Application;
43

54
namespace CADPythonShell

CADPythonShell/ConfigureCommandsForm.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.IO;
4-
using System.Linq;
5-
using System.Windows.Forms;
1+
using System.IO;
62

73
namespace CADPythonShell
84
{

CADPythonShell/IronPythonConsoleApp.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ namespace CADPythonShell
66
{
77
public class IronPythonConsoleApp
88
{
9+
public const string RibbonTitle = "Python Shell";
10+
public const string RibbonId = "PythonShell";
911
[CommandMethod("InitPythonConsole")]
1012
public void Execute()
1113
{
@@ -16,32 +18,28 @@ void CreateRibbon()
1618
RibbonControl ribbon = ComponentManager.Ribbon;
1719
if (ribbon != null)
1820
{
19-
RibbonTab rtab = ribbon.FindTab("PythonShell");
21+
RibbonTab rtab = ribbon.FindTab(RibbonId);
2022
if (rtab != null)
2123
{
2224
ribbon.Tabs.Remove(rtab);
2325
}
2426
rtab = new RibbonTab();
25-
rtab.Title = "Python Shell";
26-
rtab.Id = "PythonShell";
27-
//Add the Tab
27+
rtab.Title = RibbonTitle;
28+
rtab.Id = RibbonId;
2829
ribbon.Tabs.Add(rtab);
29-
addContent(rtab);
30+
AddContentToTab(rtab);
3031
}
3132
}
32-
private void addContent(RibbonTab rtab)
33+
private void AddContentToTab(RibbonTab rtab)
3334
{
3435
rtab.Panels.Add(AddOnePanel());
3536
}
3637
static RibbonPanel AddOnePanel()
3738
{
38-
//https://forums.autodesk.com/t5/net/create-custom-ribbon-tab-and-buttons-for-autocad-mechanical-2011/td-p/2834343
3939
RibbonPanelSource rps = new RibbonPanelSource();
4040
rps.Title = "Cad Python Shell";
4141
RibbonPanel rp = new RibbonPanel();
4242
rp.Source = rps;
43-
//Create a Command Item that the Dialog Launcher can use,
44-
// for this test it is just a place holder.
4543
RibbonButton rci = new RibbonButton();
4644
rci.Name = "Python Shell Console";
4745
rps.DialogLauncher = rci;
@@ -53,6 +51,7 @@ static RibbonPanel AddOnePanel()
5351
rb.Name = "Run CPS";
5452
rb.ShowText = true;
5553
rb.Text = "Run CPS";
54+
rb.Description = "Start Write Python Console\nCommand: PythonShellConsole";
5655
var addinAssembly = typeof(IronPythonConsoleApp).Assembly;
5756
rb.Image = CADPythonShellApplication.GetEmbeddedPng(addinAssembly, "CADPythonShell.Resources.Python-16.png");
5857
rb.LargeImage = CADPythonShellApplication.GetEmbeddedPng(addinAssembly, "CADPythonShell.Resources.Python-32.png");
@@ -66,6 +65,7 @@ static RibbonPanel AddOnePanel()
6665
rb2.Name = "Configure CPS";
6766
rb2.ShowText = true;
6867
rb2.Text = "Configure CPS";
68+
rb2.Description = "Configure Cad Python Shell\nCommand: PythonShellSetting";
6969
rb2.Image = CADPythonShellApplication.GetEmbeddedPng(addinAssembly, "CADPythonShell.Resources.Settings-16.png");
7070
rb2.LargeImage = CADPythonShellApplication.GetEmbeddedPng(addinAssembly, "CADPythonShell.Resources.Settings-32.png");
7171

CADPythonShell/RelayCommand.cs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,10 @@ namespace CADPythonShell
88
/// </summary>
99
public class RelayCommand : ICommand
1010
{
11-
#region Variables
1211
private readonly Predicate<object> m_canExecute;
1312
private readonly Action<object> m_execute;
1413
private readonly Action _act;
1514

16-
#endregion
17-
18-
#region Constructor
1915
public RelayCommand(Action act)
2016
{
2117
_act = act;
@@ -31,9 +27,6 @@ public RelayCommand(Action<object> execute, Predicate<object> canExecute = null)
3127
m_canExecute = canExecute;
3228
}
3329

34-
#endregion
35-
36-
#region Implementation
3730
// Evaluate the command if it is valid to execute
3831
public bool CanExecute(object parameter = null)
3932
{
@@ -54,9 +47,7 @@ public event EventHandler CanExecuteChanged
5447
add => CommandManager.RequerySuggested += value;
5548
remove => CommandManager.RequerySuggested -= value;
5649
}
57-
#endregion
5850

59-
#region Support
6051
public class CloseCommand : ICommand
6152
{
6253
public bool CanExecute(object parameter)
@@ -76,7 +67,6 @@ public void Execute(object parameter)
7667
myWin.Close();
7768
}
7869
}
79-
#endregion
8070
}
8171
}
8272

Installer/Installer.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using System;
22
using System.Collections.Generic;
33
using System.IO;
4-
using System.Linq;
54
using System.Text;
65
using System.Text.RegularExpressions;
76
using WixSharp;
Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
<UserControl x:Class="PythonConsoleControl.IronPythonConsoleControl"
2-
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3-
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4-
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
5-
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
6-
mc:Ignorable="d"
7-
d:DesignHeight="300" d:DesignWidth="300">
8-
<!--
9-
Copyright (c) 2010 Joe Moorhouse
1+
<UserControl
2+
x:Class="PythonConsoleControl.IronPythonConsoleControl"
3+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
4+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
5+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
6+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
7+
d:DesignHeight="300"
8+
d:DesignWidth="300"
9+
mc:Ignorable="d">
10+
<!--
11+
Copyright (c) 2010 Joe Moorhouse
1012
-->
11-
<Grid Name="grid">
12-
</Grid>
13+
<Grid Name="grid" />
1314
</UserControl>

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,14 @@ The biggest limitation is that you can't deploy DLLs with custom scripts at this
3939

4040
- Download last install stable(msi) from [Release](https://github.com/chuongmep/CADPythonShell/releases/latest)
4141
- Use command `PythonConsole` to open Console or use command `PythonShellSetting` to open form setting
42+
- See guide install detail at [How-to-Install-CadPythonShell](https://github.com/chuongmep/CadPythonShell/wiki/How-to-Install-CadPythonShell)
4243

4344
Note : Support for 4 last version(2018-2022) Autocad or Civil 3D. Older versions can be used but will not guarantee the expected performance.
4445

46+
4547
## How to use
4648

47-
- Open Python Console from Command Line or button APS in Ribbon.
49+
- Open Python Console from Command Line or button CPS in Ribbon.
4850

4951
![](Images/pythoncmd.png)
5052

Setup/icon.ico

-187 KB
Binary file not shown.

0 commit comments

Comments
 (0)