├── .gitattributes
├── .gitignore
├── .hgignore
├── .nuget
└── packages.config
├── CADtest-CS
├── AutoNetLoad2015.scr
├── AutoNetLoadCoreConsole2015.scr
├── BaseTests.cs
├── CADtest-CS 2007-11.csproj
├── CADtest-CS 2012.csproj
├── CADtest-CS 2013-14.csproj
├── CADtest-CS 2015-16.csproj
├── CADtest-CS.csproj
├── CADtest-CS.csproj.user
├── CADtestApp.cs
├── CADtestRunner.cs
├── Drawings
│ └── DrawingTest.dwg
├── Helpers
│ ├── BlockDefinition.cs
│ ├── DbEntity.cs
│ └── WorkingDatabaseSwitcher.cs
├── Properties
│ └── AssemblyInfo.cs
├── SampleTests.cs
├── SampleTestsData.cs
├── app.config
└── packages.config
├── CADtest-VB
├── AutoNetLoad2015.scr
├── AutoNetLoadCoreConsole2015.scr
├── CADtest-VB 2007-11.vbproj
├── CADtest-VB 2012.vbproj
├── CADtest-VB 2013-14.vbproj
├── CADtest-VB 2015-16.vbproj
├── CADtest-VB.vbproj
├── CADtest-VB.vbproj.user
├── CADtestApp.vb
├── CADtestRunner.vb
├── Helpers
│ ├── BlockDefinition.vb
│ └── DbEntity.vb
├── My Project
│ ├── Application.Designer.vb
│ ├── Application.myapp
│ ├── AssemblyInfo.vb
│ ├── Resources.Designer.vb
│ ├── Resources.resx
│ ├── Settings.Designer.vb
│ └── Settings.settings
├── SampleTests.vb
├── app.config
└── packages.config
├── CADtest.sln
├── License.txt
├── ReadMe.md
└── ResharperCADtestTemplates.DotSettings
/.gitattributes:
--------------------------------------------------------------------------------
1 | *.vb linguist-language=C#
2 | # this is so Github doesn't tag this repo as VB - it is primarily C#
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Ignore file for Visual Studio with some bits added by Ewen
2 | # https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
3 | # use glob syntax <== for HG only
4 | #syntax: glob - UNCOMMENT for .hgignore
5 | # last update 12.01.2016
6 |
7 | ## Ignore Visual Studio temporary files, build results, and
8 | ## files generated by popular Visual Studio add-ons.
9 |
10 | # User-specific files
11 | *.suo
12 | *.user
13 | *.userosscache
14 | *.sln.docstates
15 | *.FileListAbsolute.txt
16 |
17 |
18 | # User-specific files (MonoDevelop/Xamarin Studio)
19 | *.userprefs
20 |
21 | # Build results
22 | [Dd]ebug/
23 | [Dd]ebugPublic/
24 | [Rr]elease/
25 | [Rr]eleases/
26 | x64/
27 | x86/
28 | build/
29 | bld/
30 | [Bb]in/
31 | [Oo]bj/
32 |
33 | # Visual Studio 2015 cache/options directory
34 | .vs/
35 | # Uncomment if you have tasks that create the project's static files in wwwroot
36 | #wwwroot/
37 |
38 | # MSTest test Results
39 | [Tt]est[Rr]esult*/
40 | [Bb]uild[Ll]og.*
41 |
42 | # NUNIT
43 | *.VisualState.xml
44 | TestResult.xml
45 |
46 | # Build Results of an ATL Project
47 | [Dd]ebugPS/
48 | [Rr]eleasePS/
49 | dlldata.c
50 |
51 | # DNX
52 | project.lock.json
53 | artifacts/
54 |
55 | *_i.c
56 | *_p.c
57 | *_i.h
58 | *.ilk
59 | *.meta
60 | *.obj
61 | *.pch
62 | *.pdb
63 | *.pgc
64 | *.pgd
65 | *.rsp
66 | *.sbr
67 | *.tlb
68 | *.tli
69 | *.tlh
70 | *.tmp
71 | *.tmp_proj
72 | *.log
73 | *.vspscc
74 | *.vssscc
75 | .builds
76 | *.pidb
77 | *.svclog
78 | *.scc
79 | *.bak
80 | *.clw
81 | # Ignore all EXE's except Nuget
82 | # \b(?
2 |
3 |
4 |
--------------------------------------------------------------------------------
/CADtest-CS/AutoNetLoad2015.scr:
--------------------------------------------------------------------------------
1 | netload "C:\Codez\CadBloke\GitHub\CADtest\CADtest-CS\bin\Debug\CADtest-CS.dll"
2 | RunCADtests
3 |
--------------------------------------------------------------------------------
/CADtest-CS/AutoNetLoadCoreConsole2015.scr:
--------------------------------------------------------------------------------
1 | netload "C:\Codez\CadBloke\GitHub\CADtest\CADtest-CS\bin\DebugCoreConsole\CADtest-CS.dll"
2 | RunCADtests
3 |
--------------------------------------------------------------------------------
/CADtest-CS/BaseTests.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 | using System.Threading.Tasks;
5 | using Autodesk.AutoCAD.ApplicationServices;
6 | using Autodesk.AutoCAD.DatabaseServices;
7 | #if (ACAD2006 || ACAD2007 || ACAD2008 || ACAD2009|| ACAD2010|| ACAD2011 || ACAD2012)
8 | using Autodesk.AutoCAD.ApplicationServices;
9 | using Application = Autodesk.AutoCAD.ApplicationServices.Application;
10 | #else
11 | using Autodesk.AutoCAD.ApplicationServices.Core;
12 | using Application = Autodesk.AutoCAD.ApplicationServices.Core.Application;
13 | #endif
14 | using CADtest.Helpers;
15 | using NUnit.Framework;
16 | using System.IO;
17 |
18 | namespace CADTestRunner
19 | {
20 | public abstract class BaseTests
21 | {
22 | protected void ExecuteActionDWG(String pDrawingPath, params Action[] pActionList)
23 | {
24 | bool buildDefaultDrawing;
25 |
26 | if (String.IsNullOrEmpty(pDrawingPath))
27 | {
28 | buildDefaultDrawing = true;
29 | }
30 | else
31 | {
32 | buildDefaultDrawing = false;
33 |
34 | if (!File.Exists(pDrawingPath))
35 | {
36 | Assert.Fail("The file '{0}' doesn't exist", pDrawingPath);
37 | return;
38 | }
39 | }
40 |
41 | Exception exceptionToThrown = null;
42 |
43 | Document doc = Application.DocumentManager.MdiActiveDocument;
44 | using (doc.LockDocument())
45 | {
46 | using (Database db = new Database(buildDefaultDrawing, false))
47 | {
48 | if (!String.IsNullOrEmpty(pDrawingPath))
49 | db.ReadDwgFile(pDrawingPath, FileOpenMode.OpenForReadAndWriteNoShare, true, null);
50 |
51 | using (new WorkingDatabaseSwitcher(db))
52 | {
53 | foreach (var item in pActionList)
54 | {
55 | using (Transaction tr = db.TransactionManager.StartTransaction())
56 | {
57 | try
58 | {
59 | item(db, tr);
60 | }
61 | catch (Exception ex)
62 | {
63 | exceptionToThrown = ex;
64 | tr.Commit();
65 |
66 | //stop execution of actions
67 | break;
68 | }
69 |
70 | tr.Commit();
71 |
72 | }//transaction
73 |
74 | }//foreach
75 |
76 | }//change WorkingDatabase
77 |
78 | }//database
79 |
80 | }//lock document
81 |
82 | //throw exception outside of transaction
83 | //Sometimes Autocad crashes when exception throws
84 | if (exceptionToThrown != null)
85 | {
86 | throw exceptionToThrown;
87 | }
88 | }
89 |
90 | }
91 | }
92 |
--------------------------------------------------------------------------------
/CADtest-CS/CADtest-CS 2007-11.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {05D392C8-2C76-4764-9ADE-1AEF6EB1943D}
8 | Library
9 | Properties
10 | CADtest
11 | CADtest-CS
12 | v3.5
13 | 512
14 |
15 |
16 | true
17 | full
18 | false
19 | bin\Debug\2007-10\
20 | $(DefineConstants);DEBUG;TRACE
21 | prompt
22 | 4
23 |
24 |
25 | pdbonly
26 | true
27 | bin\Release\2007-10\
28 | $(DefineConstants);TRACE
29 | prompt
30 | 4
31 |
32 |
33 |
34 |
35 | $(Codez)\z.Libraries\AutoCAD\2007\AcMgd.dll
36 | False
37 |
38 |
39 | $(Codez)\z.Libraries\AutoCAD\2007\AcDbMgd.dll
40 | False
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
66 |
--------------------------------------------------------------------------------
/CADtest-CS/CADtest-CS 2012.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {05D392C8-2C76-4764-9ADE-1AEF6EB1943D}
8 | Library
9 | Properties
10 | CADtest
11 | CADtest-CS
12 | v4.0
13 | 512
14 |
15 |
16 | true
17 | full
18 | false
19 | bin\Debug\2012\
20 | $(DefineConstants);DEBUG;TRACE
21 | prompt
22 | 4
23 |
24 |
25 | pdbonly
26 | true
27 | bin\Release\2012\
28 | $(DefineConstants);TRACE
29 | prompt
30 | 4
31 |
32 |
33 |
34 |
35 | $(Codez)\z.Libraries\AutoCAD\2012\AcMgd.dll
36 | False
37 |
38 |
39 | $(Codez)\z.Libraries\AutoCAD\2012\AcDbMgd.dll
40 | False
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
66 |
--------------------------------------------------------------------------------
/CADtest-CS/CADtest-CS 2013-14.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {584C5F09-136B-4356-B6E9-C99A8CB90AF3}
8 | Library
9 | Properties
10 | CADtest
11 | CADtest-CS
12 | v4.5
13 | 512
14 |
15 |
16 |
17 | true
18 | full
19 | false
20 | bin\Debug\2013-14\
21 | $(DefineConstants);DEBUG;TRACE
22 | prompt
23 | 4
24 | false
25 |
26 |
27 | pdbonly
28 | true
29 | bin\Release\2013-14\
30 | $(DefineConstants);TRACE
31 | prompt
32 | 4
33 | false
34 |
35 |
36 | true
37 | full
38 | false
39 | bin\DebugCoreConsole\2013-14\
40 | $(DefineConstants);DEBUG;TRACE;CoreConsole
41 | prompt
42 | 4
43 | false
44 |
45 |
46 | pdbonly
47 | true
48 | bin\ReleaseCoreConsole\2013-14\
49 | $(DefineConstants);TRACE;CoreConsole
50 | prompt
51 | 4
52 | false
53 |
54 |
55 |
56 | $(Codez)\z.Libraries\AutoCAD\AutoCAD\2013\AcCoreMgd.dll
57 |
58 | False
59 |
60 |
61 | $(Codez)\z.Libraries\AutoCAD\AutoCAD\2013\AcDbMgd.dll
62 |
63 | False
64 |
65 |
66 | ..\packages\NUnit.3.0.1\lib\net45\nunit.framework.dll
67 | True
68 |
69 |
70 | ..\packages\NUnitLite.3.0.1\lib\net45\nunitlite.dll
71 | True
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
97 |
--------------------------------------------------------------------------------
/CADtest-CS/CADtest-CS 2015-16.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {05D392C8-2C76-4764-9ADE-1AEF6EB1943D}
8 | Library
9 | Properties
10 | CADtest
11 | CADtest-CS
12 | v4.5
13 | 512
14 |
15 |
16 | true
17 | full
18 | false
19 | bin\Debug\2015-16\
20 | $(DefineConstants);DEBUG;TRACE
21 | prompt
22 | 4
23 |
24 |
25 | pdbonly
26 | true
27 | bin\Release\2015-16\
28 | $(DefineConstants);TRACE
29 | prompt
30 | 4
31 |
32 |
33 | true
34 | full
35 | false
36 | bin\DebugCoreConsole\2015-16\
37 | $(DefineConstants);DEBUG;TRACE;CoreConsole
38 | prompt
39 | 4
40 |
41 |
42 | pdbonly
43 | true
44 | bin\ReleaseCoreConsole\2015-16\
45 | $(DefineConstants);TRACE;CoreConsole
46 | prompt
47 | 4
48 |
49 |
50 |
51 | ..\packages\AutoCAD.NET.Core.20.0.1\lib\45\AcCoreMgd.dll
52 | False
53 |
54 |
55 | ..\packages\AutoCAD.NET.Model.20.0.1\lib\45\AcDbMgd.dll
56 | False
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
82 |
--------------------------------------------------------------------------------
/CADtest-CS/CADtest-CS.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {05D392C8-2C76-4764-9ADE-1AEF6EB1943D}
8 | Library
9 | Properties
10 | CADtest
11 | CADtest-CS
12 | v4.5
13 | 512
14 |
15 |
16 | true
17 | full
18 | false
19 | bin\Debug\
20 | $(DefineConstants);DEBUG;TRACE
21 | prompt
22 | 4
23 |
24 |
25 | pdbonly
26 | true
27 | bin\Release\
28 | $(DefineConstants);TRACE
29 | prompt
30 | 4
31 |
32 |
33 | true
34 | full
35 | false
36 | bin\DebugCoreConsole\
37 | $(DefineConstants);DEBUG;TRACE;CoreConsole
38 | prompt
39 | 4
40 |
41 |
42 | pdbonly
43 | true
44 | bin\ReleaseCoreConsole\
45 | $(DefineConstants);TRACE;CoreConsole
46 | prompt
47 | 4
48 |
49 |
50 |
51 | ..\packages\AutoCAD.NET.Core.20.1.0\lib\45\AcCoreMgd.dll
52 | False
53 |
54 |
55 | ..\packages\AutoCAD.NET.20.1.0\lib\45\AcCui.dll
56 | False
57 |
58 |
59 | ..\packages\AutoCAD.NET.Model.20.1.0\lib\45\AcDbMgd.dll
60 | False
61 |
62 |
63 | ..\packages\AutoCAD.NET.Model.20.1.0\lib\45\acdbmgdbrep.dll
64 | False
65 |
66 |
67 | ..\packages\AutoCAD.NET.20.1.0\lib\45\AcDx.dll
68 | False
69 |
70 |
71 | ..\packages\AutoCAD.NET.20.1.0\lib\45\AcMgd.dll
72 | False
73 |
74 |
75 | ..\packages\AutoCAD.NET.20.1.0\lib\45\AcMr.dll
76 | False
77 |
78 |
79 | ..\packages\AutoCAD.NET.20.1.0\lib\45\AcTcMgd.dll
80 | False
81 |
82 |
83 | ..\packages\AutoCAD.NET.20.1.0\lib\45\AcWindows.dll
84 | False
85 |
86 |
87 | ..\packages\AutoCAD.NET.20.1.0\lib\45\AdWindows.dll
88 | False
89 |
90 |
91 | ..\packages\NUnit.3.0.1\lib\net45\nunit.framework.dll
92 | True
93 |
94 |
95 | ..\packages\NUnitLite.3.0.1\lib\net45\nunitlite.dll
96 | True
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 | PreserveNewest
116 |
117 |
118 |
119 |
120 |
121 | ReportUnit\ReportUnit.exe
122 | PreserveNewest
123 |
124 |
125 |
126 |
133 |
--------------------------------------------------------------------------------
/CADtest-CS/CADtest-CS.csproj.user:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Program
5 | C:\Program Files\Autodesk\AutoCAD 2016\accoreconsole.exe
6 | /s C:\Codez\CadBloke\GitHub\CADtest\CADtest-CS\AutoNetLoadCoreConsole2015.scr /isolate
7 |
8 |
9 | Program
10 | C:\Program Files\Autodesk\AutoCAD 2015\acad.exe
11 | /b C:\Codez\CadBloke\GitHub\CADtest\CADtest-CS\AutoNetLoad2015.scr
12 |
13 |
--------------------------------------------------------------------------------
/CADtest-CS/CADtestApp.cs:
--------------------------------------------------------------------------------
1 | // CADtest.NET by CAD bloke. http://CADbloke.com - See License.txt for license details
2 |
3 | using System;
4 | using System.Runtime.InteropServices;
5 | using Autodesk.AutoCAD.ApplicationServices.Core;
6 | using Autodesk.AutoCAD.Runtime;
7 | using CADTestRunner;
8 |
9 | [assembly: ExtensionApplication(typeof (NUnitRunnerApp))]
10 |
11 | namespace CADTestRunner
12 | {
13 | /// AutoCAD extension application implementation.
14 | ///
15 | public class NUnitRunnerApp : IExtensionApplication
16 | {
17 | public void Initialize()
18 | {
19 | #if !CoreConsole
20 | if ( !AttachConsole(-1) ) // Attach to a parent process console
21 | AllocConsole(); // Alloc a new console if none available
22 |
23 | #else
24 | // http://forums.autodesk.com/t5/net/accoreconsole-exe-in-2015-doesn-t-do-system-console-writeline/m-p/5551652
25 | // This code is so you can see the test results in the console window, as per the above forum thread.
26 | if (Application.Version.Major * 10 + Application.Version.Minor > 190) // >v2013
27 | {
28 | // http://stackoverflow.com/a/15960495/492
29 | // stdout's handle seems to always be equal to 7
30 | var defaultStdout = new IntPtr(7);
31 | IntPtr currentStdout = GetStdHandle(StdOutputHandle);
32 | if (currentStdout != defaultStdout)
33 | SetStdHandle(StdOutputHandle, defaultStdout);
34 |
35 | // http://forums.autodesk.com/t5/net/accoreconsole-exe-in-2015-doesn-t-do-system-console-writeline/m-p/5551652#M43708
36 | FixStdOut();
37 | }
38 | #endif
39 | }
40 |
41 | public void Terminate()
42 | {
43 | #if !CoreConsole
44 | FreeConsole();
45 | #endif
46 | }
47 |
48 | // http://stackoverflow.com/questions/3917202/how-do-i-include-a-console-in-winforms/3917353#3917353
49 | /// Allocates a new console for current process.
50 | [DllImport("kernel32.dll")]
51 | public static extern bool AllocConsole();
52 |
53 | /// Frees the console.
54 | [DllImport("kernel32.dll")]
55 | public static extern bool FreeConsole();
56 |
57 | // http://stackoverflow.com/a/8048269/492
58 | [DllImport("kernel32.dll")]
59 | private static extern bool AttachConsole(int pid);
60 |
61 | #if CoreConsole
62 | // http://forums.autodesk.com/t5/net/accoreconsole-exe-in-2015-doesn-t-do-system-console-writeline/m-p/5551652#M43708
63 | // trying to fix the telex-like line output from Core Console in versions > 2013. This didn't work for me. :(
64 | [DllImport("msvcr110.dll")]
65 | private static extern int _setmode(int fileno, int mode);
66 |
67 | public void FixStdOut() { _setmode(3, 0x4000); }
68 |
69 | // http://stackoverflow.com/a/15960495/492
70 | private const uint StdOutputHandle = 0xFFFFFFF5;
71 |
72 | [DllImport("kernel32.dll")]
73 | private static extern IntPtr GetStdHandle(uint nStdHandle);
74 |
75 | [DllImport("kernel32.dll")]
76 | private static extern void SetStdHandle(uint nStdHandle, IntPtr handle);
77 | #endif
78 | }
79 | }
--------------------------------------------------------------------------------
/CADtest-CS/CADtestRunner.cs:
--------------------------------------------------------------------------------
1 | // CADtest.NET by CAD bloke. http://CADbloke.com - See License.txt for license details
2 |
3 | #if CoreConsole
4 | #endif
5 | using System;
6 | using System.Collections.Generic;
7 | using System.IO;
8 | using Autodesk.AutoCAD.Runtime;
9 | using CADTestRunner;
10 | using NUnitLite;
11 | using System.Text;
12 | using System.Diagnostics;
13 | using System.Reflection;
14 |
15 | [assembly: CommandClass(typeof (NUnitLiteTestRunner))]
16 |
17 | namespace CADTestRunner
18 | {
19 | public class NUnitLiteTestRunner
20 | {
21 | /// This command runs the NUnit tests in this assembly.
22 | [CommandMethod("RunCADtests", CommandFlags.Session)]
23 | public void RunCADtests()
24 | {
25 | //string directoryName = Path.GetTempPath(); //Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
26 |
27 | string directoryPlugin = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
28 | string directoryReportUnit = Path.Combine(directoryPlugin, @"ReportUnit");
29 | Directory.CreateDirectory(directoryReportUnit);
30 | string fileInputXML = Path.Combine(directoryReportUnit, @"Report-NUnit.xml");
31 | string fileOutputHTML = Path.Combine(directoryReportUnit, @"Report-NUnit.html");
32 | string generatorReportUnit = Path.Combine(directoryPlugin, @"ReportUnit", @"ReportUnit.exe");
33 |
34 | string[] nunitArgs = new List
35 | {
36 | // for details of options see https://github.com/nunit/docs/wiki/Console-Command-Line
37 | "--trace=verbose" // Tell me everything
38 | ,"--result=" + fileInputXML
39 | // , "--work=" + directoryName // save TestResults.xml to the build folder
40 | // , "--wait" // Wait for input before closing console window (PAUSE). Comment this out for batch operations.
41 | }.ToArray();
42 |
43 |
44 | new AutoRun().Execute(nunitArgs);
45 | // https://github.com/nunit/nunit/commit/6331e7e694439f8cbf000156f138a3e10370ec40
46 |
47 | CreateHTMLReport(fileInputXML, fileOutputHTML, generatorReportUnit);
48 | }
49 |
50 | private void CreateHTMLReport(string pFileInputXML, string pFileOutputHTML, string pGeneratorReportUnit)
51 | {
52 | if (!File.Exists(pFileInputXML))
53 | return;
54 |
55 | if (File.Exists(pFileOutputHTML))
56 | File.Delete(pFileOutputHTML);
57 |
58 | string output = string.Empty;
59 | try
60 | {
61 | using (Process process = new Process())
62 | {
63 | process.StartInfo.UseShellExecute = false;
64 | process.StartInfo.RedirectStandardOutput = true;
65 | process.StartInfo.CreateNoWindow = true;
66 |
67 | process.StartInfo.FileName = pGeneratorReportUnit;
68 |
69 | StringBuilder param = new StringBuilder();
70 | param.AppendFormat(" \"{0}\"", pFileInputXML);
71 | param.AppendFormat(" \"{0}\"", pFileOutputHTML);
72 | process.StartInfo.Arguments = param.ToString();
73 |
74 | process.Start();
75 |
76 | // read the output to return
77 | // this will stop this execute until AutoCAD exits
78 | StreamReader outputStream = process.StandardOutput;
79 | output = outputStream.ReadToEnd();
80 | outputStream.Close();
81 | }
82 |
83 | }
84 | catch (System.Exception ex)
85 | {
86 | output = ex.Message;
87 | }
88 |
89 | }
90 | }
91 | }
92 |
--------------------------------------------------------------------------------
/CADtest-CS/Drawings/DrawingTest.dwg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CADbloke/CADtest/869d7a2bb2053c0a8a4930e5cac0101b47b0d446/CADtest-CS/Drawings/DrawingTest.dwg
--------------------------------------------------------------------------------
/CADtest-CS/Helpers/BlockDefinition.cs:
--------------------------------------------------------------------------------
1 | // CADtest.NET by CAD bloke. http://CADbloke.com - See License.txt for license details
2 |
3 | using Autodesk.AutoCAD.DatabaseServices;
4 | using Autodesk.AutoCAD.Geometry;
5 | using Autodesk.AutoCAD.Runtime;
6 | using System;
7 | using System.Collections.Generic;
8 | using Autodesk.AutoCAD.ApplicationServices.Core;
9 |
10 |
11 | namespace CADtest.Helpers
12 | {
13 | /// Static Helper methods to work with Block Definitions aka s.
14 | public class BlockDefinition
15 | {
16 | /// The X Position of the next Entity to be Inserted.
17 | public static double Xpos = 0;
18 | /// The Y Position of the next Entity to be Inserted.
19 | public static double Ypos = 0;
20 | /// The Z Position of the next Entity to be Inserted. Zero is good for me.
21 | public static double Zpos = 0;
22 | /// How much to increment the X Position by after each insertion. Default is 0.
23 | public static double Xincrement = 0;
24 | /// How much to increment the Y Position by after each insertion. Default is Y.
25 | public static double Yincrement = 5;
26 |
27 |
28 | /// Adds Entities (text, Attribute Definitions etc)to the block definition.
29 | /// for the block definition object.
30 | /// The entities to add to the block.
31 | /// true if it succeeds, false if it fails.
32 | /// The value of 'blockDefinitionObjectId' cannot be null.
33 | public static bool AddEntitiesToBlockDefinition(ObjectId blockDefinitionObjectId, ICollection entities) where T: Entity
34 | {
35 | if (blockDefinitionObjectId == null) { throw new ArgumentNullException("blockDefinitionObjectId"); }
36 | if (!blockDefinitionObjectId.IsValid) { return false;}
37 | if (entities == null) { throw new ArgumentNullException("entities"); }
38 | if (entities.Count<1) { return false; }
39 |
40 | Xpos = 0;
41 | Ypos = 0;
42 | bool workedOk = false;
43 | Database database = blockDefinitionObjectId.Database;
44 | TransactionManager transactionManager = database.TransactionManager;
45 |
46 | using (Transaction transaction = transactionManager.StartTransaction())
47 | {
48 | if (blockDefinitionObjectId.ObjectClass == (RXObject.GetClass(typeof (BlockTableRecord))))
49 | {
50 | BlockTableRecord blockDefinition =
51 | (BlockTableRecord) transactionManager.GetObject(blockDefinitionObjectId, OpenMode.ForWrite, false);
52 | if (blockDefinition != null)
53 | {
54 | foreach (T entity in entities)
55 | {
56 | DBText text = entity as DBText;
57 | if (text != null) { text.Position = new Point3d(Xpos, Ypos, Zpos); incrementXY(); }
58 | else
59 | {
60 | MText mText = entity as MText;
61 | if (mText != null) { mText.Location = new Point3d(Xpos, Ypos, Zpos); incrementXY(); }
62 | }
63 |
64 | blockDefinition.AppendEntity(entity); // todo: vertical spacing ??
65 |
66 | transactionManager.AddNewlyCreatedDBObject(entity, true);
67 | }
68 | workedOk = true;
69 | }
70 | }
71 | transaction.Commit();
72 | }
73 | return workedOk;
74 | }
75 |
76 | /// Increment the X and Y Insertion points for the next entity.
77 | private static void incrementXY()
78 | {
79 | Xpos += Xincrement;
80 | Ypos += Yincrement;
81 | }
82 |
83 |
84 | /// Adds a single Entity (text, Attribute Definition etc)to the block definition.
85 | /// for the block definition object.
86 | /// The entity.
87 | /// true if it succeeds, false if it fails.
88 | public static bool AddEntityToBlockDefinition(ObjectId blockDefinitionObjectId, T entity) where T: Entity
89 | {
90 | return AddEntitiesToBlockDefinition(blockDefinitionObjectId, new List {entity});
91 | }
92 |
93 |
94 |
95 | /// Adds a new block defintion by name. If it already exists then it returns ObjectId.Null.
96 | /// Thrown when blockDefinitionName is null or empty.
97 | /// Name of the block definition.
98 | /// An ObjectId - new if created or existing if the block already exists.
99 | public static ObjectId AddNewBlockDefintion(string blockDefinitionName)
100 | {
101 | if (string.IsNullOrEmpty(blockDefinitionName)) { throw new ArgumentNullException("blockDefinitionName"); }
102 | Database database = Application.DocumentManager.MdiActiveDocument.Database;
103 | TransactionManager transactionManager = database.TransactionManager;
104 | ObjectId newBlockId;
105 |
106 | using (Transaction transaction = transactionManager.StartTransaction())
107 | {
108 | BlockTable blockTable = transaction.GetObject(database.BlockTableId, OpenMode.ForWrite) as BlockTable;
109 | if (blockTable != null && blockTable.Has(blockDefinitionName)) { return ObjectId.Null; }
110 |
111 | using (BlockTableRecord blockTableRecord = new BlockTableRecord())
112 | {
113 | blockTableRecord.Name = blockDefinitionName;
114 | blockTableRecord.Origin = new Point3d(0, 0, 0);
115 | using (Circle circle = new Circle())
116 | {
117 | circle.Center = new Point3d(0, 0, 0);
118 | circle.Radius = 2;
119 | blockTableRecord.AppendEntity(circle);
120 | if (blockTable != null) { blockTable.Add(blockTableRecord); }
121 | transaction.AddNewlyCreatedDBObject(blockTableRecord, true);
122 | newBlockId = blockTableRecord.Id;
123 | }
124 | }
125 | transaction.Commit();
126 | }
127 | return newBlockId;
128 | }
129 |
130 |
131 | /// Gets existing block defintion by name. If it doesn't exist then it returns ObjectId.Null
132 | /// Thrown when blockDefinitionName is null or empty.
133 | /// Name of the block definition.
134 | /// An ObjectId - if the block already exists. . If it doesn't exist then it returns ObjectId.Null.
135 | public static ObjectId GetExistingBlockDefintion(string blockDefinitionName)
136 | {
137 | if (string.IsNullOrEmpty(blockDefinitionName)) { throw new ArgumentNullException("blockDefinitionName"); }
138 | Database database = Application.DocumentManager.MdiActiveDocument.Database;
139 | TransactionManager transactionManager = database.TransactionManager;
140 |
141 | using (Transaction transaction = transactionManager.StartTransaction())
142 | {
143 | BlockTable blockTable = transaction.GetObject(database.BlockTableId, OpenMode.ForWrite) as BlockTable;
144 | if (blockTable != null && blockTable.Has(blockDefinitionName)) { return blockTable[blockDefinitionName]; }
145 | }
146 | return ObjectId.Null;
147 | }
148 |
149 |
150 | /// Adds a new or gets existing block defintion by name.
151 | /// Thrown when blockDefinitionName is null or empty.
152 | /// Name of the block definition.
153 | /// An ObjectId - new if created or existing if the block already exists.
154 | public static ObjectId AddNewOrGetExistingBlockDefintion(string blockDefinitionName)
155 | {
156 | if (string.IsNullOrEmpty(blockDefinitionName)) { throw new ArgumentNullException("blockDefinitionName"); }
157 |
158 | ObjectId newBlockId = GetExistingBlockDefintion(blockDefinitionName);
159 | if (newBlockId != ObjectId.Null) return newBlockId;
160 |
161 | return AddNewBlockDefintion(blockDefinitionName);
162 | }
163 | }
164 | }
165 |
--------------------------------------------------------------------------------
/CADtest-CS/Helpers/DbEntity.cs:
--------------------------------------------------------------------------------
1 | // CADtest.NET by CAD bloke. http://CADbloke.com - See License.txt for license details
2 |
3 | using System;
4 | using System.Collections.Generic;
5 | using Autodesk.AutoCAD.DatabaseServices;
6 | using Autodesk.AutoCAD.Geometry;
7 |
8 | //
9 |
10 | namespace CADtest.Helpers
11 | {
12 | public class DbEntity // source unknown but probably http://www.theswamp.org/index.php?action=profile;u=935
13 | {
14 | /// The X Position of the next Entity to be Inserted.
15 | public static double Xpos;
16 |
17 | /// The Y Position of the next Entity to be Inserted.
18 | public static double Ypos;
19 |
20 | /// The Z Position of the next Entity to be Inserted. Zero is good for me.
21 | public static double Zpos = 0;
22 |
23 | /// How much to increment the X Position by after each insertion. Default is 0.
24 | public static double Xincrement = 0;
25 |
26 | /// How much to increment the Y Position by after each insertion. Default is Y.
27 | public static double Yincrement = 5;
28 |
29 | /// Adds a single AutoCAD to Model space.
30 | /// Thrown when one or more required arguments are null.
31 | /// The .
32 | /// The you are adding the to.
33 | /// the ObjectId of the you just added.
34 | public static ObjectId AddToModelSpace (T entity, Database database) where T: Entity
35 | {
36 | ObjectIdCollection objectIdCollection = AddToModelSpace(new List { entity }, database);
37 | return objectIdCollection[0];
38 | }
39 |
40 | /// Adds a collection of AutoCAD s to Model space.
41 | /// Thrown when one or more required arguments are null.
42 | /// The entities.
43 | /// The you are adding the s to.
44 | /// a collection of ObjectId of the s you just added.
45 | public static ObjectIdCollection AddToModelSpace (List entities, Database database) where T: Entity
46 | {
47 | var objIdCollection = new ObjectIdCollection();
48 | if (entities == null)
49 | throw new ArgumentNullException("entities");
50 | if (database == null)
51 | throw new ArgumentNullException("database");
52 |
53 | TransactionManager transactionManager = database.TransactionManager;
54 | using (Transaction transaction = transactionManager.StartTransaction())
55 | {
56 | var blockTable = (BlockTable)transactionManager.GetObject(database.BlockTableId, OpenMode.ForRead, false);
57 | var modelSpace = (BlockTableRecord)transactionManager.GetObject(blockTable[BlockTableRecord.ModelSpace], OpenMode.ForWrite, false);
58 | foreach (T entity in entities)
59 | {
60 | objIdCollection.Add(modelSpace.AppendEntity(entity));
61 |
62 | var text = entity as DBText;
63 | if (text != null)
64 | {
65 | text.Position = new Point3d(Xpos, Ypos, Zpos);
66 | incrementXY();
67 | }
68 | else
69 | {
70 | var mText = entity as MText;
71 | if (mText != null)
72 | {
73 | mText.Location = new Point3d(Xpos, Ypos, Zpos);
74 | incrementXY();
75 | }
76 | }
77 |
78 | transactionManager.AddNewlyCreatedDBObject(entity, true);
79 | }
80 | transaction.Commit();
81 | }
82 | return objIdCollection;
83 | }
84 |
85 | /// Increment the X and Y Insertion points for the next entity.
86 | private static void incrementXY()
87 | {
88 | Xpos += Xincrement;
89 | Ypos += Yincrement;
90 | }
91 | }
92 | }
--------------------------------------------------------------------------------
/CADtest-CS/Helpers/WorkingDatabaseSwitcher.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using Autodesk.AutoCAD.ApplicationServices;
7 | using Autodesk.AutoCAD.DatabaseServices;
8 | #if (ACAD2006 || ACAD2007 || ACAD2008 || ACAD2009|| ACAD2010|| ACAD2011 || ACAD2012)
9 | using Autodesk.AutoCAD.ApplicationServices;
10 | using Application = Autodesk.AutoCAD.ApplicationServices.Application;
11 | #else
12 | using Autodesk.AutoCAD.ApplicationServices.Core;
13 | using Application = Autodesk.AutoCAD.ApplicationServices.Core.Application;
14 | #endif
15 |
16 | namespace CADtest.Helpers
17 | {
18 | internal sealed class WorkingDatabaseSwitcher : IDisposable
19 | {
20 | Database _oldDb = null;
21 |
22 | ///
23 | /// Constructor.
24 | ///
25 | /// Target database.
26 | public WorkingDatabaseSwitcher(Database db)
27 | {
28 | _oldDb = HostApplicationServices.WorkingDatabase;
29 | HostApplicationServices.WorkingDatabase = db;
30 | }
31 |
32 | public void Dispose()
33 | {
34 | HostApplicationServices.WorkingDatabase = _oldDb;
35 | }
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/CADtest-CS/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("CADtest-CS")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("CADbloke")]
12 | [assembly: AssemblyProduct("CADtest")]
13 | [assembly: AssemblyCopyright("Copyright © CADbloke 2015")]
14 |
15 |
16 | // Setting ComVisible to false makes the types in this assembly not visible
17 | // to COM components. If you need to access a type in this assembly from
18 | // COM, set the ComVisible attribute to true on that type.
19 | [assembly: ComVisible(false)]
20 |
21 | // The following GUID is for the ID of the typelib if this project is exposed to COM
22 | [assembly: Guid("30360b37-d213-4b3d-8c2f-457c404ce38d")]
23 |
24 | // Version information for an assembly consists of the following four values:
25 | //
26 | // Major Version
27 | // Minor Version
28 | // Build Number
29 | // Revision
30 | //
31 | // You can specify all the values or you can default the Build and Revision Numbers
32 | // by using the '*' as shown below:
33 | // [assembly: AssemblyVersion("1.0.*")]
34 | [assembly: AssemblyVersion("1.0.0.0")]
35 | [assembly: AssemblyFileVersion("1.0.0.0")]
36 |
--------------------------------------------------------------------------------
/CADtest-CS/SampleTests.cs:
--------------------------------------------------------------------------------
1 | // CADtest.NET by CAD bloke. http://CADbloke.com - See License.txt for license details
2 |
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Threading;
8 | using Autodesk.AutoCAD.ApplicationServices;
9 | using Autodesk.AutoCAD.DatabaseServices;
10 | #if (ACAD2006 || ACAD2007 || ACAD2008 || ACAD2009|| ACAD2010|| ACAD2011 || ACAD2012)
11 | using Autodesk.AutoCAD.ApplicationServices;
12 | using Application = Autodesk.AutoCAD.ApplicationServices.Application;
13 | #else
14 | using Autodesk.AutoCAD.ApplicationServices.Core;
15 | using Application = Autodesk.AutoCAD.ApplicationServices.Core.Application;
16 | #endif
17 | using Autodesk.AutoCAD.Geometry;
18 |
19 | using CADtest.Helpers;
20 | using NUnit.Framework;
21 | using CADTestRunner;
22 | using System.IO;
23 | using System.Reflection;
24 |
25 | namespace NUnitAutoCADTestRunner
26 | {
27 | [TestFixture, Apartment(ApartmentState.STA)]
28 | public class TestClass1 : BaseTests
29 | {
30 | [Test]
31 | public void Test_method_should_pass()
32 | {
33 | Assert.Pass("Test that should pass did not pass");
34 | }
35 |
36 |
37 | [Test]
38 | public void Test_method_should_fail()
39 | {
40 | Assert.Fail("This test was supposed to fail.");
41 | }
42 |
43 | [Test]
44 | public void Test_method_existing_drawing()
45 | {
46 | //Use existing drawing
47 |
48 | string drawingPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Drawings", "DrawingTest.dwg");
49 | long lineId = 526;
50 |
51 | Action action1 = (db, trans) =>
52 | {
53 | ObjectId objectId;
54 | if (!db.TryGetObjectId(new Handle(lineId), out objectId))
55 | {
56 | Assert.Fail("ObjectID doesn't exist");
57 | }
58 |
59 | Line line = trans.GetObject(objectId, OpenMode.ForWrite) as Line;
60 |
61 | Assert.IsNotNull(line, "Line didn't found");
62 |
63 | line.Erase();
64 | };
65 |
66 | Action action2 = (db, trans) =>
67 | {
68 | //Check in another transaction if the line was erased
69 |
70 | ObjectId objectId;
71 | if (db.TryGetObjectId(new Handle(lineId), out objectId))
72 | {
73 | Assert.IsTrue(objectId.IsErased, "Line didn't erased");
74 | }
75 | };
76 |
77 | ExecuteActionDWG(drawingPath, action1, action2);
78 |
79 | }
80 |
81 |
82 | [Test]
83 | public void Test_method_new_drawing()
84 | {
85 | //Use a new drawing
86 |
87 | long lineId = 0;
88 |
89 | Action action1 = (db, trans) =>
90 | {
91 | Line line = new Line(new Point3d(0, 0, 0), new Point3d(100, 100, 100));
92 |
93 | var blockTable = (BlockTable)trans.GetObject(db.BlockTableId, OpenMode.ForRead);
94 | var modelSpace = (BlockTableRecord)trans.GetObject(blockTable[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
95 |
96 | var objectId = modelSpace.AppendEntity(line);
97 | trans.AddNewlyCreatedDBObject(line, true);
98 |
99 | lineId = objectId.Handle.Value;
100 | };
101 |
102 | Action action2 = (db, trans) =>
103 | {
104 | //Check in another transaction if the line was created
105 |
106 | ObjectId objectId;
107 | if (!db.TryGetObjectId(new Handle(lineId), out objectId))
108 | {
109 | Assert.Fail("Line didn't created");
110 | }
111 | };
112 |
113 | ExecuteActionDWG(null, action1, action2);
114 | }
115 |
116 | [Test]
117 | public void Test_method_name()
118 | {
119 | Action action1 = (db, trans) =>
120 | {
121 | DBText dbText = new DBText { TextString = "cat" };
122 | string testMe;
123 |
124 | ObjectId dbTextObjectId = DbEntity.AddToModelSpace(dbText, db);
125 | dbText.TextString = "dog";
126 |
127 | DBText testText = trans.GetObject(dbTextObjectId, OpenMode.ForRead) as DBText;
128 | testMe = testText != null ? testText.TextString : string.Empty;
129 |
130 | // Assert
131 | StringAssert.AreEqualIgnoringCase("dog", testMe, "DBText string was not changed to \"dog\".");
132 | StringAssert.AreNotEqualIgnoringCase("cat", testMe, "DBText string was not changed.");
133 | };
134 |
135 | ExecuteActionDWG(null, action1);
136 |
137 | }
138 |
139 | [Test]
140 | public void Old_Test_That_Used_to_Crash_2016_and_not_2013_but_I_fixed_it()
141 | {
142 | // Arrange
143 | Database db = HostApplicationServices.WorkingDatabase;
144 | Document doc = Application.DocumentManager.GetDocument(db);
145 |
146 | string testMe;
147 | // Act
148 | using (doc.LockDocument())
149 | {
150 | using (var tx = db.TransactionManager.StartTransaction())
151 | {
152 | using (DBText dbText = new DBText { TextString = "cat" })
153 | {
154 | ObjectId dbTextObjectId = DbEntity.AddToModelSpace(dbText, db);
155 | dbText.TextString = "dog";
156 |
157 | var testText = dbTextObjectId.Open(OpenMode.ForRead, false) as DBText;
158 | testMe = testText != null
159 | ? testText.TextString
160 | : string.Empty;
161 | }
162 | tx.Commit();
163 | }
164 | }
165 | // Assert
166 | StringAssert.AreEqualIgnoringCase("dog", testMe, "DBText string was not changed to \"dog\".");
167 | StringAssert.AreNotEqualIgnoringCase("cat", testMe, "DBText string was not changed.");
168 | }
169 |
170 | [Test, TestCaseSource(typeof(SampleTestsData), "ParametersTest")]
171 | public void Test_method_TestCaseSource(Point3d pPoint1, Point3d pPoint2, Point3d pPointResult)
172 | {
173 | List listPoints = new List (){pPoint1, pPoint2};
174 | Point3d centerPoint = new Point3d(listPoints.Average(p => p.X), listPoints.Average(p => p.Y), listPoints.Average(p => p.Z));
175 |
176 | Assert.IsTrue(centerPoint.DistanceTo(pPointResult) < 1E-5);
177 |
178 | }
179 |
180 | }
181 |
182 | }
183 |
--------------------------------------------------------------------------------
/CADtest-CS/SampleTestsData.cs:
--------------------------------------------------------------------------------
1 | // CADtest.NET by CAD bloke. http://CADbloke.com - See License.txt for license details
2 |
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Threading;
8 | using Autodesk.AutoCAD.ApplicationServices;
9 | using Autodesk.AutoCAD.DatabaseServices;
10 | #if (ACAD2006 || ACAD2007 || ACAD2008 || ACAD2009|| ACAD2010|| ACAD2011 || ACAD2012)
11 | using Autodesk.AutoCAD.ApplicationServices;
12 | using Application = Autodesk.AutoCAD.ApplicationServices.Application;
13 | #else
14 | using Autodesk.AutoCAD.ApplicationServices.Core;
15 | using Application = Autodesk.AutoCAD.ApplicationServices.Core.Application;
16 | #endif
17 | using Autodesk.AutoCAD.Geometry;
18 |
19 | using CADtest.Helpers;
20 | using NUnit.Framework;
21 | using CADTestRunner;
22 | using System.IO;
23 | using System.Reflection;
24 | using System.Collections;
25 |
26 | namespace NUnitAutoCADTestRunner
27 | {
28 | public class SampleTestsData
29 | {
30 | public static IEnumerable ParametersTest
31 | {
32 | get
33 | {
34 | string description = "Test the function Average Point";
35 | string category = "Geometry Functions";
36 |
37 | yield return new TestCaseData(
38 | new Point3d(0, 0, 0),
39 | new Point3d(1000, 1000, 1000),
40 | new Point3d(500, 500, 500))
41 | .SetDescription(description)
42 | .SetCategory(category);
43 |
44 | yield return new TestCaseData(
45 | new Point3d(0, 0, 0),
46 | new Point3d(300, 300, 0),
47 | new Point3d(150, 150, 0))
48 | .SetDescription(description)
49 | .SetCategory(category);
50 | }
51 | }
52 |
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/CADtest-CS/app.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/CADtest-CS/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/CADtest-VB/AutoNetLoad2015.scr:
--------------------------------------------------------------------------------
1 | netload "C:\Codez\CadBloke\GitHub\CADtest\CADtest-VB\bin\Debug\CADtest-VB.dll"
2 | RunCADtests
3 |
--------------------------------------------------------------------------------
/CADtest-VB/AutoNetLoadCoreConsole2015.scr:
--------------------------------------------------------------------------------
1 | netload "C:\Codez\CadBloke\GitHub\CADtest\CADtest-VB\bin\DebugCoreConsole\CADtest-VB.dll"
2 | RunCADtests
3 |
--------------------------------------------------------------------------------
/CADtest-VB/CADtest-VB 2007-11.vbproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {E466AA6E-66E2-44D9-BD55-F523B3FC82F8}
8 | Library
9 | CADtest
10 | CADtest-VB
11 | 512
12 | Windows
13 | v3.5
14 |
15 |
16 | true
17 | full
18 | true
19 | true
20 | bin\Debug\2007-11\
21 | CADtest-VB.xml
22 | 42016,41999,42017,42018,42019,42032,42036,42020,42021,42022
23 |
24 |
25 | pdbonly
26 | false
27 | true
28 | true
29 | bin\Release\2007-11\
30 | CADtest-VB.xml
31 | 42016,41999,42017,42018,42019,42032,42036,42020,42021,42022
32 |
33 |
34 |
35 | On
36 |
37 |
38 | Binary
39 |
40 |
41 | On
42 |
43 |
44 | On
45 |
46 |
47 |
48 | $(Codez)\z.Libraries\AutoCAD\2007\AcMgd.dll
49 | False
50 |
51 |
52 | $(Codez)\z.Libraries\AutoCAD\2007\AcDbMgd.dll
53 | False
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 | True
74 | Application.myapp
75 |
76 |
77 | True
78 | True
79 | Resources.resx
80 |
81 |
82 | True
83 | Settings.settings
84 | True
85 |
86 |
87 |
88 |
89 |
90 |
91 | VbMyResourcesResXFileCodeGenerator
92 | Resources.Designer.vb
93 | My.Resources
94 | Designer
95 |
96 |
97 |
98 |
99 |
100 | MyApplicationCodeGenerator
101 | Application.Designer.vb
102 |
103 |
104 | SettingsSingleFileGenerator
105 | My
106 | Settings.Designer.vb
107 |
108 |
109 |
110 |
111 |
112 |
119 |
--------------------------------------------------------------------------------
/CADtest-VB/CADtest-VB 2012.vbproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {E466AA6E-66E2-44D9-BD55-F523B3FC82F8}
8 | Library
9 | CADtest
10 | CADtest-VB
11 | 512
12 | Windows
13 | v4.0
14 |
15 |
16 | true
17 | full
18 | true
19 | true
20 | bin\Debug\2012\
21 | CADtest-VB.xml
22 | 42016,41999,42017,42018,42019,42032,42036,42020,42021,42022
23 |
24 |
25 | pdbonly
26 | false
27 | true
28 | true
29 | bin\Release\2012\
30 | CADtest-VB.xml
31 | 42016,41999,42017,42018,42019,42032,42036,42020,42021,42022
32 |
33 |
34 |
35 | On
36 |
37 |
38 | Binary
39 |
40 |
41 | On
42 |
43 |
44 | On
45 |
46 |
47 |
48 | $(Codez)\z.Libraries\AutoCAD\2012\AcMgd.dll
49 | False
50 |
51 |
52 | $(Codez)\z.Libraries\AutoCAD\2012\AcDbMgd.dll
53 | False
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 | True
74 | Application.myapp
75 |
76 |
77 | True
78 | True
79 | Resources.resx
80 |
81 |
82 | True
83 | Settings.settings
84 | True
85 |
86 |
87 |
88 |
89 |
90 |
91 | VbMyResourcesResXFileCodeGenerator
92 | Resources.Designer.vb
93 | My.Resources
94 | Designer
95 |
96 |
97 |
98 |
99 |
100 | MyApplicationCodeGenerator
101 | Application.Designer.vb
102 |
103 |
104 | SettingsSingleFileGenerator
105 | My
106 | Settings.Designer.vb
107 |
108 |
109 |
110 |
111 |
112 |
119 |
--------------------------------------------------------------------------------
/CADtest-VB/CADtest-VB 2013-14.vbproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {E466AA6E-66E2-44D9-BD55-F523B3FC82F8}
8 | Library
9 | CADtest
10 | CADtest-VB
11 | 512
12 | Windows
13 | v4.0
14 |
15 |
16 | true
17 | full
18 | true
19 | true
20 | bin\Debug\2013-14\
21 | CADtest-VB.xml
22 | 42016,41999,42017,42018,42019,42032,42036,42020,42021,42022
23 |
24 |
25 | pdbonly
26 | false
27 | true
28 | true
29 | bin\Release\2013-14\
30 | CADtest-VB.xml
31 | 42016,41999,42017,42018,42019,42032,42036,42020,42021,42022
32 |
33 |
34 | true
35 | full
36 | true
37 | true
38 | bin\DebugCoreConsole\2013-14\
39 | $(DefineConstants),CoreConsole
40 | CADtest-VB.xml
41 | 42016,41999,42017,42018,42019,42032,42036,42020,42021,42022
42 |
43 |
44 | pdbonly
45 | false
46 | true
47 | true
48 | bin\ReleaseCoreConsole\2013-14\
49 | $(DefineConstants),CoreConsole
50 | CADtest-VB.xml
51 | 42016,41999,42017,42018,42019,42032,42036,42020,42021,42022
52 |
53 |
54 | On
55 |
56 |
57 | Binary
58 |
59 |
60 | On
61 |
62 |
63 | On
64 |
65 |
66 |
67 | $(Codez)\z.Libraries\AutoCAD\2013\AcCoreMgd.dll
68 | False
69 |
70 |
71 | $(Codez)\z.Libraries\AutoCAD\2013\AcDbMgd.dll
72 | False
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 | True
93 | Application.myapp
94 |
95 |
96 | True
97 | True
98 | Resources.resx
99 |
100 |
101 | True
102 | Settings.settings
103 | True
104 |
105 |
106 |
107 |
108 |
109 |
110 | VbMyResourcesResXFileCodeGenerator
111 | Resources.Designer.vb
112 | My.Resources
113 | Designer
114 |
115 |
116 |
117 |
118 |
119 | MyApplicationCodeGenerator
120 | Application.Designer.vb
121 |
122 |
123 | SettingsSingleFileGenerator
124 | My
125 | Settings.Designer.vb
126 |
127 |
128 |
129 |
130 |
131 |
138 |
--------------------------------------------------------------------------------
/CADtest-VB/CADtest-VB 2015-16.vbproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {E466AA6E-66E2-44D9-BD55-F523B3FC82F8}
8 | Library
9 | CADtest
10 | CADtest-VB
11 | 512
12 | Windows
13 | v4.5
14 |
15 |
16 | true
17 | full
18 | true
19 | true
20 | bin\Debug\2015-16\
21 | CADtest-VB.xml
22 | 42016,41999,42017,42018,42019,42032,42036,42020,42021,42022
23 |
24 |
25 | pdbonly
26 | false
27 | true
28 | true
29 | bin\Release\2015-16\
30 | CADtest-VB.xml
31 | 42016,41999,42017,42018,42019,42032,42036,42020,42021,42022
32 |
33 |
34 | true
35 | full
36 | true
37 | true
38 | bin\DebugCoreConsole\2015-16\
39 | $(DefineConstants),CoreConsole
40 | CADtest-VB.xml
41 | 42016,41999,42017,42018,42019,42032,42036,42020,42021,42022
42 |
43 |
44 | pdbonly
45 | false
46 | true
47 | true
48 | bin\ReleaseCoreConsole\2015-16\
49 | $(DefineConstants),CoreConsole
50 | CADtest-VB.xml
51 | 42016,41999,42017,42018,42019,42032,42036,42020,42021,42022
52 |
53 |
54 | On
55 |
56 |
57 | Binary
58 |
59 |
60 | On
61 |
62 |
63 | On
64 |
65 |
66 |
67 | False
68 | ..\packages\AutoCAD.NET.Core.20.0.1\lib\45\AcCoreMgd.dll
69 | False
70 |
71 |
72 | ..\packages\AutoCAD.NET.Model.20.0.1\lib\45\AcDbMgd.dll
73 | False
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 | True
94 | Application.myapp
95 |
96 |
97 | True
98 | True
99 | Resources.resx
100 |
101 |
102 | True
103 | Settings.settings
104 | True
105 |
106 |
107 |
108 |
109 |
110 |
111 | VbMyResourcesResXFileCodeGenerator
112 | Resources.Designer.vb
113 | My.Resources
114 | Designer
115 |
116 |
117 |
118 |
119 |
120 | MyApplicationCodeGenerator
121 | Application.Designer.vb
122 |
123 |
124 | SettingsSingleFileGenerator
125 | My
126 | Settings.Designer.vb
127 |
128 |
129 |
130 |
131 |
132 |
139 |
--------------------------------------------------------------------------------
/CADtest-VB/CADtest-VB.vbproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {E466AA6E-66E2-44D9-BD55-F523B3FC82F8}
8 | Library
9 | CADtest
10 | CADtest-VB
11 | 512
12 | Windows
13 | v4.5
14 |
15 |
16 | true
17 | full
18 | true
19 | true
20 | bin\Debug\
21 | CADtest-VB.xml
22 | 42016,41999,42017,42018,42019,42032,42036,42020,42021,42022
23 |
24 |
25 | pdbonly
26 | false
27 | true
28 | true
29 | bin\Release\
30 | CADtest-VB.xml
31 | 42016,41999,42017,42018,42019,42032,42036,42020,42021,42022
32 |
33 |
34 | true
35 | full
36 | true
37 | true
38 | bin\DebugCoreConsole\
39 | $(DefineConstants),CoreConsole
40 | CADtest-VB.xml
41 | 42016,41999,42017,42018,42019,42032,42036,42020,42021,42022
42 |
43 |
44 | pdbonly
45 | false
46 | true
47 | true
48 | bin\ReleaseCoreConsole\
49 | $(DefineConstants),CoreConsole
50 | CADtest-VB.xml
51 | 42016,41999,42017,42018,42019,42032,42036,42020,42021,42022
52 |
53 |
54 | On
55 |
56 |
57 | Binary
58 |
59 |
60 | On
61 |
62 |
63 | On
64 |
65 |
66 |
67 | ..\packages\AutoCAD.NET.Core.20.1.0\lib\45\AcCoreMgd.dll
68 | False
69 |
70 |
71 | ..\packages\AutoCAD.NET.20.1.0\lib\45\AcCui.dll
72 | False
73 |
74 |
75 | ..\packages\AutoCAD.NET.Model.20.1.0\lib\45\AcDbMgd.dll
76 | False
77 |
78 |
79 | ..\packages\AutoCAD.NET.Model.20.1.0\lib\45\acdbmgdbrep.dll
80 | False
81 |
82 |
83 | ..\packages\AutoCAD.NET.20.1.0\lib\45\AcDx.dll
84 | False
85 |
86 |
87 | ..\packages\AutoCAD.NET.20.1.0\lib\45\AcMgd.dll
88 | False
89 |
90 |
91 | ..\packages\AutoCAD.NET.20.1.0\lib\45\AcMr.dll
92 | False
93 |
94 |
95 | ..\packages\AutoCAD.NET.20.1.0\lib\45\AcTcMgd.dll
96 | False
97 |
98 |
99 | ..\packages\AutoCAD.NET.20.1.0\lib\45\AcWindows.dll
100 | False
101 |
102 |
103 | ..\packages\AutoCAD.NET.20.1.0\lib\45\AdWindows.dll
104 | False
105 |
106 |
107 | ..\packages\NUnit.3.0.1\lib\net45\nunit.framework.dll
108 | True
109 |
110 |
111 | ..\packages\NUnitLite.3.0.1\lib\net45\nunitlite.dll
112 | True
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 | True
134 | Application.myapp
135 |
136 |
137 | True
138 | True
139 | Resources.resx
140 |
141 |
142 | True
143 | Settings.settings
144 | True
145 |
146 |
147 |
148 |
149 |
150 |
151 | VbMyResourcesResXFileCodeGenerator
152 | Resources.Designer.vb
153 | My.Resources
154 | Designer
155 |
156 |
157 |
158 |
159 |
160 | MyApplicationCodeGenerator
161 | Application.Designer.vb
162 |
163 |
164 | SettingsSingleFileGenerator
165 | My
166 | Settings.Designer.vb
167 |
168 |
169 |
170 |
171 |
--------------------------------------------------------------------------------
/CADtest-VB/CADtest-VB.vbproj.user:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Program
5 | C:\Program Files\Autodesk\AutoCAD 2015\accoreconsole.exe
6 | /s C:\Codez\CadBloke\GitHub\CADtest\CADtest-VB\AutoNetLoadCoreConsole2015.scr
7 |
8 |
9 | Program
10 | C:\Program Files\Autodesk\AutoCAD 2015\acad.exe
11 | /b C:\Codez\CadBloke\GitHub\CADtest\CADtest-VB\AutoNetLoad2015.scr
12 |
13 |
--------------------------------------------------------------------------------
/CADtest-VB/CADtestApp.vb:
--------------------------------------------------------------------------------
1 | ' CADtest.NET by CAD bloke. http://CADbloke.com - See License.txt for license details
2 | Imports System.Runtime.InteropServices
3 | Imports Autodesk.AutoCAD.ApplicationServices.Core
4 | Imports Autodesk.AutoCAD.Runtime
5 | Imports CADtest.CADTestRunner
6 |
7 |
8 |
9 | Namespace CADTestRunner
10 | ''' AutoCAD extension application implementation.
11 | '''
12 | Public Class NUnitRunnerApp
13 | Implements IExtensionApplication
14 |
15 | Public Sub Initialize() Implements IExtensionApplication.Initialize
16 | #If Not CoreConsole Then
17 | If Not AttachConsole(-1) Then ' Attach to a parent process console
18 | AllocConsole() ' Alloc a new console if none available
19 | End If
20 |
21 | #Else
22 | ' http://forums.autodesk.com/t5/net/accoreconsole-exe-in-2015-doesn-t-do-system-console-writeline/m-p/5551652
23 | ' This code is so you can see the test results in the console window, as per the above forum thread.
24 | If Application.Version.Major * 10 + Application.Version.Minor > 190 Then ' >v2013
25 | ' http://stackoverflow.com/a/15960495/492
26 | Dim defaultStdout As New IntPtr(7) ' stdout's handle seems to always be equal to 7
27 | Dim currentStdout As IntPtr = GetStdHandle(StdOutputHandle)
28 | If currentStdout <> defaultStdout Then
29 | SetStdHandle(StdOutputHandle, defaultStdout)
30 | End If
31 |
32 | ' http://forums.autodesk.com/t5/net/accoreconsole-exe-in-2015-doesn-t-do-system-console-writeline/m-p/5551652#M43708
33 | FixStdOut()
34 | End If
35 | #End If
36 | End Sub
37 |
38 | Public Sub Terminate() Implements IExtensionApplication.Terminate
39 | #If Not CoreConsole Then
40 | FreeConsole()
41 | #End If
42 | End Sub
43 |
44 |
45 | ' http://stackoverflow.com/questions/3917202/how-do-i-include-a-console-in-winforms/3917353#3917353
46 | ''' Allocates a new console for current process.
47 |
48 | Public Shared Function AllocConsole() As [Boolean]
49 | End Function
50 |
51 | ''' Frees the console.
52 |
53 | Public Shared Function FreeConsole() As [Boolean]
54 | End Function
55 |
56 | ' http://stackoverflow.com/a/8048269/492
57 |
58 | Private Shared Function AttachConsole(pid As Integer) As Boolean
59 | End Function
60 |
61 |
62 | #If CoreConsole Then
63 | ' http://forums.autodesk.com/t5/net/accoreconsole-exe-in-2015-doesn-t-do-system-console-writeline/m-p/5551652#M43708
64 | ' trying to fix the telex-like line output from Core Console in versions > 2013. This didn't work for me. :(
65 |
66 | Private Shared Function _setmode(fileno As Integer, mode As Integer) As Integer
67 | End Function
68 |
69 | Public Sub FixStdOut()
70 | _setmode(3, &H4000)
71 | End Sub
72 |
73 |
74 | ' http://stackoverflow.com/a/15960495/492
75 | Private Const StdOutputHandle As UInt32 = &HFFFFFFF5UI
76 |
77 |
78 | Private Shared Function GetStdHandle(nStdHandle As UInt32) As IntPtr
79 | End Function
80 |
81 |
82 | Private Shared Sub SetStdHandle(nStdHandle As UInt32, handle As IntPtr)
83 | End Sub
84 |
85 | #End If
86 | End Class
87 | End Namespace
88 |
--------------------------------------------------------------------------------
/CADtest-VB/CADtestRunner.vb:
--------------------------------------------------------------------------------
1 | ' CADtest.NET by CAD bloke. http://CADbloke.com - See License.txt for license details
2 |
3 | Imports System.IO
4 | Imports System.Reflection
5 | Imports Autodesk.AutoCAD.Runtime
6 | Imports CADtest.CADTestRunner
7 | Imports NUnitLite
8 | #If CoreConsole Then
9 | Imports System
10 | #End If
11 |
12 |
13 |
14 |
15 | Namespace CADTestRunner
16 | Public Class NUnitLiteTestRunner
17 | ''' This command runs the NUnit tests in this assembly.
18 |
19 | Public Sub RunCADtests()
20 | Dim directoryName As String = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)
21 | ' for details of options see http://www.nunit.com/index.php?p=nunitliteOptions&r=3.0
22 | ' save TestResults.xml to the build folder
23 | Dim nunitArgs As String() = New List(Of String)() From { _
24 | "--verbose" _
25 | , Convert.ToString("--work=") & directoryName _
26 | , "--wait" _
27 | }.ToArray()
28 | ' --verbose Tell me everything
29 | ' --work= ... save TestResults.xml to the build folder
30 | ' --wait Wait for input before closing console window. (PAUSE). Comment this out for batch operations.
31 |
32 | Call New AutoRun().Execute(nunitArgs)
33 |
34 | ' NOTE: BREAKING CHANGE
35 | ' new NUnitLite.Runner.AutoRun().Execute(nunitArgs); todo: Coming soon in NUnit V3 Beta 1.
36 | ' https://github.com/nunit/nunit/commit/6331e7e694439f8cbf000156f138a3e10370ec40
37 | End Sub
38 | End Class
39 | End Namespace
40 |
--------------------------------------------------------------------------------
/CADtest-VB/Helpers/BlockDefinition.vb:
--------------------------------------------------------------------------------
1 | ' CADtest.NET by CAD bloke. http://CADbloke.com - See License.txt for license details
2 | Imports Autodesk.AutoCAD.ApplicationServices.Core
3 | Imports Autodesk.AutoCAD.DatabaseServices
4 | Imports Autodesk.AutoCAD.Geometry
5 | Imports Autodesk.AutoCAD.Runtime
6 |
7 | Namespace Helpers
8 | ''' Static Helper methods to work with Block Definitions aka
9 | ''' s.
10 | Public Class BlockDefinition
11 | ''' The X Position of the next Entity to be Inserted.
12 | Public Shared Xpos As Double = 0
13 |
14 | ''' The Y Position of the next Entity to be Inserted.
15 | Public Shared Ypos As Double = 0
16 |
17 | ''' The Z Position of the next Entity to be Inserted. Zero is good for me.
18 | Public Shared Zpos As Double = 0
19 |
20 | ''' How much to increment the X Position by after each insertion. Default is 0.
21 | Public Shared Xincrement As Double = 0
22 |
23 | ''' How much to increment the Y Position by after each insertion. Default is Y.
24 | Public Shared Yincrement As Double = 5
25 |
26 |
27 | ''' Adds Entities (text, Attribute Definitions etc)to the block definition.
28 | ''' for the block
29 | ''' definition object.
30 | ''' The entities to add to the block.
31 | ''' true if it succeeds, false if it fails.
32 | ''' The value of 'blockDefinitionObjectId' cannot be null.
33 | Public Shared Function AddEntitiesToBlockDefinition (Of T As Entity)(blockDefinitionObjectId As ObjectId,
34 | entities As ICollection(Of T)) As Boolean
35 | If blockDefinitionObjectId = ObjectId.Null Then
36 | Throw New ArgumentNullException("blockDefinitionObjectId")
37 | End If
38 | If Not blockDefinitionObjectId.IsValid Then
39 | Return False
40 | End If
41 | If entities Is Nothing Then
42 | Throw New ArgumentNullException("entities")
43 | End If
44 | If entities.Count < 1 Then
45 | Return False
46 | End If
47 |
48 | Xpos = 0
49 | Ypos = 0
50 | Dim workedOk = False
51 | Dim database As Database = blockDefinitionObjectId.Database
52 | Dim transactionManager As TransactionManager = database.TransactionManager
53 |
54 | Using transaction As Transaction = transactionManager.StartTransaction()
55 | If blockDefinitionObjectId.ObjectClass = (RXObject.GetClass(GetType(BlockTableRecord))) Then
56 | Dim blockDefinition = DirectCast(transactionManager.GetObject(blockDefinitionObjectId,
57 | OpenMode.ForWrite,
58 | False),
59 | BlockTableRecord)
60 | If blockDefinition IsNot Nothing Then
61 | For Each entity As T In entities
62 | Dim text = TryCast(entity, DBText)
63 | If text IsNot Nothing Then
64 | text.Position = New Point3d(Xpos, Ypos, Zpos)
65 | incrementXY()
66 | Else
67 | Dim mText = TryCast(entity, MText)
68 | If mText IsNot Nothing Then
69 | mText.Location = New Point3d(Xpos, Ypos, Zpos)
70 | incrementXY()
71 | End If
72 | End If
73 |
74 | blockDefinition.AppendEntity(entity)
75 | ' todo: vertical spacing ??
76 | transactionManager.AddNewlyCreatedDBObject(entity, True)
77 | Next
78 | workedOk = True
79 | End If
80 | End If
81 | transaction.Commit()
82 | End Using
83 | Return workedOk
84 | End Function
85 |
86 | ''' Increment the X and Y Insertion points for the next entity.
87 | Private Shared Sub incrementXY()
88 | Xpos += Xincrement
89 | Ypos += Yincrement
90 | End Sub
91 |
92 |
93 | ''' Adds a single Entity (text, Attribute Definition etc)to the block definition.
94 | ''' for the block definition object.
95 | ''' The entity.
96 | ''' true if it succeeds, false if it fails.
97 | Public Shared Function AddEntityToBlockDefinition (Of T As Entity)(blockDefinitionObjectId As ObjectId,
98 | entity As T) As Boolean
99 | Return AddEntitiesToBlockDefinition (Of T)(blockDefinitionObjectId,
100 | New List(Of T)() From { _
101 | entity _
102 | })
103 | End Function
104 |
105 |
106 | ''' Adds a new block defintion by name. If it already exists then it returns ObjectId.Null .
107 | ''' Thrown when blockDefinitionName is null or empty.
108 | ''' Name of the block definition.
109 | ''' An ObjectId - new if created or existing if the block already exists.
110 | Public Shared Function AddNewBlockDefintion(blockDefinitionName As String) As ObjectId
111 | If String.IsNullOrEmpty(blockDefinitionName) Then
112 | Throw New ArgumentNullException("blockDefinitionName")
113 | End If
114 | Dim database As Database = Application.DocumentManager.MdiActiveDocument.Database
115 | Dim transactionManager As TransactionManager = database.TransactionManager
116 | Dim newBlockId As ObjectId
117 |
118 | Using transaction As Transaction = transactionManager.StartTransaction()
119 | Dim blockTable = TryCast(transaction.GetObject(database.BlockTableId, OpenMode.ForWrite), BlockTable)
120 | If blockTable IsNot Nothing AndAlso blockTable.Has(blockDefinitionName) Then
121 | Return ObjectId.Null
122 | End If
123 |
124 | Using blockTableRecord As New BlockTableRecord()
125 | blockTableRecord.Name = blockDefinitionName
126 | blockTableRecord.Origin = New Point3d(0, 0, 0)
127 | Using circle As New Circle()
128 | circle.Center = New Point3d(0, 0, 0)
129 | circle.Radius = 2
130 | blockTableRecord.AppendEntity(circle)
131 | If blockTable IsNot Nothing Then
132 | blockTable.Add(blockTableRecord)
133 | End If
134 | transaction.AddNewlyCreatedDBObject(blockTableRecord, True)
135 | newBlockId = blockTableRecord.Id
136 | End Using
137 | End Using
138 | transaction.Commit()
139 | End Using
140 | Return newBlockId
141 | End Function
142 |
143 |
144 | ''' Gets existing block defintion by name. If it doesn't exist then it returns ObjectId.Null
145 | ''' Thrown when blockDefinitionName is null or empty.
146 | ''' Name of the block definition.
147 | ''' An ObjectId - if the block already exists. . If it doesn't exist then it returns ObjectId.Null .
148 | Public Shared Function GetExistingBlockDefintion(blockDefinitionName As String) As ObjectId
149 | If String.IsNullOrEmpty(blockDefinitionName) Then
150 | Throw New ArgumentNullException("blockDefinitionName")
151 | End If
152 | Dim database As Database = Application.DocumentManager.MdiActiveDocument.Database
153 | Dim transactionManager As TransactionManager = database.TransactionManager
154 |
155 | Using transaction As Transaction = transactionManager.StartTransaction()
156 | Dim blockTable = TryCast(transaction.GetObject(database.BlockTableId, OpenMode.ForWrite), BlockTable)
157 | If blockTable IsNot Nothing AndAlso blockTable.Has(blockDefinitionName) Then
158 | Return blockTable(blockDefinitionName)
159 | End If
160 | End Using
161 | Return ObjectId.Null
162 | End Function
163 |
164 |
165 | ''' Adds a new or gets existing block defintion by name.
166 | ''' Thrown when blockDefinitionName is null or empty.
167 | ''' Name of the block definition.
168 | ''' An ObjectId - new if created or existing if the block already exists.
169 | Public Shared Function AddNewOrGetExistingBlockDefintion(blockDefinitionName As String) As ObjectId
170 | If String.IsNullOrEmpty(blockDefinitionName) Then
171 | Throw New ArgumentNullException("blockDefinitionName")
172 | End If
173 |
174 | Dim newBlockId As ObjectId = GetExistingBlockDefintion(blockDefinitionName)
175 | If newBlockId <> ObjectId.Null Then
176 | Return newBlockId
177 | End If
178 |
179 | Return AddNewBlockDefintion(blockDefinitionName)
180 | End Function
181 | End Class
182 | End Namespace
183 |
--------------------------------------------------------------------------------
/CADtest-VB/Helpers/DbEntity.vb:
--------------------------------------------------------------------------------
1 | ' CADtest.NET by CAD bloke. http://CADbloke.com - See License.txt for license details
2 | Imports Autodesk.AutoCAD.DatabaseServices
3 | Imports Autodesk.AutoCAD.Geometry
4 |
5 |
6 | Namespace Helpers
7 | Public Class DbEntity
8 | ' source unknown but probably http://www.theswamp.org/index.php?action=profile;u=935
9 | ''' The X Position of the next Entity to be Inserted.
10 | Public Shared Xpos As Double = 0
11 |
12 | ''' The Y Position of the next Entity to be Inserted.
13 | Public Shared Ypos As Double = 0
14 |
15 | ''' The Z Position of the next Entity to be Inserted. Zero is good for me.
16 | Public Shared Zpos As Double = 0
17 |
18 | ''' How much to increment the X Position by after each insertion. Default is 0.
19 | Public Shared Xincrement As Double = 0
20 |
21 | ''' How much to increment the Y Position by after each insertion. Default is Y.
22 | Public Shared Yincrement As Double = 5
23 |
24 |
25 | ''' Adds a single AutoCAD to Model space.
26 | ''' Thrown when one or more required arguments are null.
27 | ''' The .
28 | ''' The you are adding the
29 | ''' to.
30 | ''' the ObjectId of the you just added.
31 | Public Shared Function AddToModelSpace (Of T As Entity)(entity As T, database As Database) As ObjectId
32 | Dim objectIdCollection As ObjectIdCollection = AddToModelSpace(New List(Of T)() From { _
33 | entity _
34 | },
35 | database)
36 | Return objectIdCollection(0)
37 | End Function
38 |
39 |
40 | ''' Adds a collection of AutoCAD s to Model space.
41 | ''' Thrown when one or more required arguments are null.
42 | ''' The entities.
43 | ''' The you are adding the s to.
44 | ''' a collection of ObjectId of the s you just added.
45 | Public Shared Function AddToModelSpace (Of T As Entity)(entities As List(Of T), database As Database) _
46 | As ObjectIdCollection
47 | Dim objIdCollection As New ObjectIdCollection()
48 | If entities Is Nothing Then
49 | Throw New ArgumentNullException("entities")
50 | End If
51 | If database Is Nothing Then
52 | Throw New ArgumentNullException("database")
53 | End If
54 |
55 | Dim transactionManager As TransactionManager = database.TransactionManager
56 | Using transaction As Transaction = transactionManager.StartTransaction()
57 | Dim blockTable = DirectCast(transactionManager.GetObject(database.BlockTableId, OpenMode.ForRead, False), BlockTable)
58 | Dim modelSpace = DirectCast(transactionManager.GetObject(blockTable(BlockTableRecord.ModelSpace),
59 | OpenMode.ForWrite,
60 | False),
61 | BlockTableRecord)
62 | For Each entity As T In entities
63 | objIdCollection.Add(modelSpace.AppendEntity(entity))
64 |
65 | Dim text = TryCast(entity, DBText)
66 | If text IsNot Nothing Then
67 | text.Position = New Point3d(Xpos, Ypos, Zpos)
68 | incrementXY()
69 | Else
70 | Dim mText = TryCast(entity, MText)
71 | If mText IsNot Nothing Then
72 | mText.Location = New Point3d(Xpos, Ypos, Zpos)
73 | incrementXY()
74 | End If
75 | End If
76 |
77 | transactionManager.AddNewlyCreatedDBObject(entity, True)
78 | Next
79 | transaction.Commit()
80 | End Using
81 | Return objIdCollection
82 | End Function
83 |
84 |
85 | ''' Increment the X and Y Insertion points for the next entity.
86 | Private Shared Sub incrementXY()
87 | Xpos += Xincrement
88 | Ypos += Yincrement
89 | End Sub
90 | End Class
91 | End Namespace
92 |
--------------------------------------------------------------------------------
/CADtest-VB/My Project/Application.Designer.vb:
--------------------------------------------------------------------------------
1 | '------------------------------------------------------------------------------
2 | '
3 | ' This code was generated by a tool.
4 | ' Runtime Version:4.0.30319.18444
5 | '
6 | ' Changes to this file may cause incorrect behavior and will be lost if
7 | ' the code is regenerated.
8 | '
9 | '------------------------------------------------------------------------------
10 |
11 | Option Strict On
12 | Option Explicit On
13 |
14 |
--------------------------------------------------------------------------------
/CADtest-VB/My Project/Application.myapp:
--------------------------------------------------------------------------------
1 |
2 |
3 | false
4 | false
5 | 0
6 | true
7 | 0
8 | 1
9 | true
10 |
11 |
--------------------------------------------------------------------------------
/CADtest-VB/My Project/AssemblyInfo.vb:
--------------------------------------------------------------------------------
1 | Imports System
2 | Imports System.Reflection
3 | Imports System.Runtime.InteropServices
4 |
5 | ' General Information about an assembly is controlled through the following
6 | ' set of attributes. Change these attribute values to modify the information
7 | ' associated with an assembly.
8 |
9 | ' Review the values of the assembly attributes
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 | 'The following GUID is for the ID of the typelib if this project is exposed to COM
20 |
21 |
22 | ' Version information for an assembly consists of the following four values:
23 | '
24 | ' Major Version
25 | ' Minor Version
26 | ' Build Number
27 | ' Revision
28 | '
29 | ' You can specify all the values or you can default the Build and Revision Numbers
30 | ' by using the '*' as shown below:
31 | '
32 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/CADtest-VB/My Project/Resources.Designer.vb:
--------------------------------------------------------------------------------
1 | '------------------------------------------------------------------------------
2 | '
3 | ' This code was generated by a tool.
4 | ' Runtime Version:4.0.30319.18444
5 | '
6 | ' Changes to this file may cause incorrect behavior and will be lost if
7 | ' the code is regenerated.
8 | '
9 | '------------------------------------------------------------------------------
10 |
11 | Option Strict On
12 | Option Explicit On
13 |
14 |
15 | Namespace My.Resources
16 |
17 | 'This class was auto-generated by the StronglyTypedResourceBuilder
18 | 'class via a tool like ResGen or Visual Studio.
19 | 'To add or remove a member, edit your .ResX file then rerun ResGen
20 | 'with the /str option, or rebuild your VS project.
21 | '''
22 | ''' A strongly-typed resource class, for looking up localized strings, etc.
23 | '''
24 | _
28 | Friend Module Resources
29 |
30 | Private resourceMan As Global.System.Resources.ResourceManager
31 |
32 | Private resourceCulture As Global.System.Globalization.CultureInfo
33 |
34 | '''
35 | ''' Returns the cached ResourceManager instance used by this class.
36 | '''
37 | _
38 | Friend ReadOnly Property ResourceManager() As Global.System.Resources.ResourceManager
39 | Get
40 | If Object.ReferenceEquals(resourceMan, Nothing) Then
41 | Dim temp As Global.System.Resources.ResourceManager = New Global.System.Resources.ResourceManager("CADtest.Resources", GetType(Resources).Assembly)
42 | resourceMan = temp
43 | End If
44 | Return resourceMan
45 | End Get
46 | End Property
47 |
48 | '''
49 | ''' Overrides the current thread's CurrentUICulture property for all
50 | ''' resource lookups using this strongly typed resource class.
51 | '''
52 | _
53 | Friend Property Culture() As Global.System.Globalization.CultureInfo
54 | Get
55 | Return resourceCulture
56 | End Get
57 | Set(ByVal value As Global.System.Globalization.CultureInfo)
58 | resourceCulture = value
59 | End Set
60 | End Property
61 | End Module
62 | End Namespace
63 |
--------------------------------------------------------------------------------
/CADtest-VB/My Project/Resources.resx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 | text/microsoft-resx
107 |
108 |
109 | 2.0
110 |
111 |
112 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
113 |
114 |
115 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
116 |
117 |
--------------------------------------------------------------------------------
/CADtest-VB/My Project/Settings.Designer.vb:
--------------------------------------------------------------------------------
1 | '------------------------------------------------------------------------------
2 | '
3 | ' This code was generated by a tool.
4 | ' Runtime Version:4.0.30319.18444
5 | '
6 | ' Changes to this file may cause incorrect behavior and will be lost if
7 | ' the code is regenerated.
8 | '
9 | '------------------------------------------------------------------------------
10 |
11 | Option Strict On
12 | Option Explicit On
13 |
14 |
15 | Namespace My
16 |
17 | _
20 | Partial Friend NotInheritable Class MySettings
21 | Inherits Global.System.Configuration.ApplicationSettingsBase
22 |
23 | Private Shared defaultInstance As MySettings = CType(Global.System.Configuration.ApplicationSettingsBase.Synchronized(New MySettings), MySettings)
24 |
25 | #Region "My.Settings Auto-Save Functionality"
26 | #If _MyType = "WindowsForms" Then
27 | Private Shared addedHandler As Boolean
28 |
29 | Private Shared addedHandlerLockObject As New Object
30 |
31 | _
32 | Private Shared Sub AutoSaveSettings(ByVal sender As Global.System.Object, ByVal e As Global.System.EventArgs)
33 | If My.Application.SaveMySettingsOnExit Then
34 | My.Settings.Save()
35 | End If
36 | End Sub
37 | #End If
38 | #End Region
39 |
40 | Public Shared ReadOnly Property [Default]() As MySettings
41 | Get
42 |
43 | #If _MyType = "WindowsForms" Then
44 | If Not addedHandler Then
45 | SyncLock addedHandlerLockObject
46 | If Not addedHandler Then
47 | AddHandler My.Application.Shutdown, AddressOf AutoSaveSettings
48 | addedHandler = True
49 | End If
50 | End SyncLock
51 | End If
52 | #End If
53 | Return defaultInstance
54 | End Get
55 | End Property
56 | End Class
57 | End Namespace
58 |
59 | Namespace My
60 |
61 | _
64 | Friend Module MySettingsProperty
65 |
66 | _
67 | Friend ReadOnly Property Settings() As Global.CADtest.My.MySettings
68 | Get
69 | Return Global.CADtest.My.MySettings.Default
70 | End Get
71 | End Property
72 | End Module
73 | End Namespace
74 |
--------------------------------------------------------------------------------
/CADtest-VB/My Project/Settings.settings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/CADtest-VB/SampleTests.vb:
--------------------------------------------------------------------------------
1 | ' CADtest.NET by CAD bloke. http://CADbloke.com - See License.txt for license details
2 |
3 | Imports System.Threading
4 | Imports Autodesk.AutoCAD.ApplicationServices
5 | Imports Autodesk.AutoCAD.DatabaseServices
6 | Imports CADtest.Helpers
7 | Imports NUnit.Framework
8 | #If (ACAD2006 OrElse ACAD2007 OrElse ACAD2008 OrElse ACAD2009 OrElse ACAD2010 OrElse ACAD2011 OrElse ACAD2012) Then
9 | Imports Autodesk.AutoCAD.ApplicationServices
10 | Imports Application = Autodesk.AutoCAD.ApplicationServices.Application
11 | #Else
12 | Imports Application = Autodesk.AutoCAD.ApplicationServices.Core.Application
13 | #End If
14 |
15 | Namespace NUnitAutoCADTestRunner
16 |
17 | Public Class TestClass1
18 |
19 | Public Sub Test_method_should_pass()
20 | Assert.Pass("Test that should pass did not pass")
21 | End Sub
22 |
23 |
24 |
25 | Public Sub Test_method_should_fail()
26 | Assert.Fail("Test was supposed to fail.")
27 | End Sub
28 |
29 |
30 | Public Sub Test_method_name()
31 | ' Arrange
32 | Dim db As Database = HostApplicationServices.WorkingDatabase
33 | Dim doc As Document = Application.DocumentManager.GetDocument(db)
34 | Dim dbText As New DBText()
35 | dbText.TextString = "cat"
36 |
37 | Dim testMe As String
38 | Dim dbTextObjectID As ObjectId
39 | ' Act
40 | Using doc.LockDocument()
41 | Using transaction As Transaction = db.TransactionManager.StartTransaction()
42 | dbTextObjectID = DbEntity.AddToModelSpace(dbText, db)
43 | dbText.TextString = "dog"
44 | transaction.Commit()
45 | End Using
46 |
47 | Dim testText = TryCast(dbTextObjectID.Open(OpenMode.ForRead, False), DBText)
48 | testMe = If(testText IsNot Nothing, testText.TextString, String.Empty)
49 | End Using
50 | ' Assert
51 | StringAssert.AreEqualIgnoringCase("dog", testMe, "DBText string was not changed to dog.")
52 | StringAssert.AreNotEqualIgnoringCase("cat", testMe, "DBText string was not changed.")
53 | End Sub
54 | End Class
55 | End Namespace
56 |
--------------------------------------------------------------------------------
/CADtest-VB/app.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/CADtest-VB/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/CADtest.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 2013
4 | VisualStudioVersion = 12.0.40629.0
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CADtest-CS", "CADtest-CS\CADtest-CS.csproj", "{05D392C8-2C76-4764-9ADE-1AEF6EB1943D}"
7 | EndProject
8 | Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "CADtest-VB", "CADtest-VB\CADtest-VB.vbproj", "{E466AA6E-66E2-44D9-BD55-F523B3FC82F8}"
9 | EndProject
10 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{3D9200B6-0DAD-4D0C-B3D2-494848BA4613}"
11 | ProjectSection(SolutionItems) = preProject
12 | .nuget\packages.config = .nuget\packages.config
13 | EndProjectSection
14 | EndProject
15 | Global
16 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
17 | Debug Core Console|Any CPU = Debug Core Console|Any CPU
18 | Debug|Any CPU = Debug|Any CPU
19 | Release Core Console|Any CPU = Release Core Console|Any CPU
20 | Release|Any CPU = Release|Any CPU
21 | EndGlobalSection
22 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
23 | {05D392C8-2C76-4764-9ADE-1AEF6EB1943D}.Debug Core Console|Any CPU.ActiveCfg = Debug Core Console|Any CPU
24 | {05D392C8-2C76-4764-9ADE-1AEF6EB1943D}.Debug Core Console|Any CPU.Build.0 = Debug Core Console|Any CPU
25 | {05D392C8-2C76-4764-9ADE-1AEF6EB1943D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
26 | {05D392C8-2C76-4764-9ADE-1AEF6EB1943D}.Debug|Any CPU.Build.0 = Debug|Any CPU
27 | {05D392C8-2C76-4764-9ADE-1AEF6EB1943D}.Release Core Console|Any CPU.ActiveCfg = Release Core Console|Any CPU
28 | {05D392C8-2C76-4764-9ADE-1AEF6EB1943D}.Release Core Console|Any CPU.Build.0 = Release Core Console|Any CPU
29 | {05D392C8-2C76-4764-9ADE-1AEF6EB1943D}.Release|Any CPU.ActiveCfg = Release|Any CPU
30 | {05D392C8-2C76-4764-9ADE-1AEF6EB1943D}.Release|Any CPU.Build.0 = Release|Any CPU
31 | {E466AA6E-66E2-44D9-BD55-F523B3FC82F8}.Debug Core Console|Any CPU.ActiveCfg = Debug Core Console|Any CPU
32 | {E466AA6E-66E2-44D9-BD55-F523B3FC82F8}.Debug Core Console|Any CPU.Build.0 = Debug Core Console|Any CPU
33 | {E466AA6E-66E2-44D9-BD55-F523B3FC82F8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
34 | {E466AA6E-66E2-44D9-BD55-F523B3FC82F8}.Debug|Any CPU.Build.0 = Debug|Any CPU
35 | {E466AA6E-66E2-44D9-BD55-F523B3FC82F8}.Release Core Console|Any CPU.ActiveCfg = Release Core Console|Any CPU
36 | {E466AA6E-66E2-44D9-BD55-F523B3FC82F8}.Release Core Console|Any CPU.Build.0 = Release Core Console|Any CPU
37 | {E466AA6E-66E2-44D9-BD55-F523B3FC82F8}.Release|Any CPU.ActiveCfg = Release|Any CPU
38 | {E466AA6E-66E2-44D9-BD55-F523B3FC82F8}.Release|Any CPU.Build.0 = Release|Any CPU
39 | EndGlobalSection
40 | GlobalSection(SolutionProperties) = preSolution
41 | HideSolutionNode = FALSE
42 | EndGlobalSection
43 | EndGlobal
44 |
--------------------------------------------------------------------------------
/License.txt:
--------------------------------------------------------------------------------
1 | CAD bloke's License terms are simple: Knock yourself out, whatever, wherever, whenever, however, whyever but if it kills anything it is entirely your fault because you touched it last and you should do backups and source control. If you claim this as your own and extort funds for it then Karma will get you while you are sleeping. If you use it in anger and it works then attribution would be rather nice, if it doesn't work then you never heard of CAD bloke.
2 |
3 |
4 | ok, you want a "real" license because beancounters ...
5 |
6 | The MIT License (MIT)
7 |
8 | Copyright (c) 2015 Ewen Wallace aka CAD bloke
9 |
10 | Permission is hereby granted, free of charge, to any person obtaining a copy
11 | of this software and associated documentation files (the "Software"), to deal
12 | in the Software without restriction, including without limitation the rights
13 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14 | copies of the Software, and to permit persons to whom the Software is
15 | furnished to do so, subject to the following conditions:
16 |
17 | The above copyright notice and this permission notice shall be included in all
18 | copies or substantial portions of the Software.
19 |
20 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26 | SOFTWARE.
--------------------------------------------------------------------------------
/ReadMe.md:
--------------------------------------------------------------------------------
1 | # CADtest for [NUnit](http://www.nunit.org/) by[@CADbloke](http://CADbloke.com)
2 | #### CADtest runs [NUnitLite](http://www.nunit.org/index.php?p=nunitlite&r=3.0) [version 3](https://www.nuget.org/packages/NUnitLite) inside [AutoCAD](http://www.autodesk.com/products/autocad/overview) and/or the [AutoCAD Core Console](http://through-the-interface.typepad.com/through_the_interface/2012/02/the-autocad-2013-core-console.html)
3 | #### This project is only possible because of all the hard work done over the years by [Charlie Poole](http://www.charliepoole.org/) and the [NUnit](http://www.nunit.org/) team, this is 99.999% [their work](https://github.com/nunit), all I did was plug it in to AutoCAD.
4 |
5 | If you're a Revit user - check out https://github.com/DynamoDS/RevitTestFramework
6 |
7 | [](https://gitter.im/CADbloke/CADtest?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
8 |
9 | My Thanks and Kudos also go the the ever-resourceful AutoCAD developer crowd at [The Swamp](http://www.theswamp.org/index.php) and the [Autodesk forums](http://forums.autodesk.com/t5/net/bd-p/152) and to [@phliberato](https://github.com/phliberato) for his contributions.
10 |
11 | #### Getting Started
12 | This is meant to be a *how-to* example rather than a full implementation that you can just drop more tests into. Take a look at the code and how it works, take what you like and ignore what you don't.
13 |
14 | You will, of course, need AutoCAD installed to use this. No, it won't work in AutoCAD LT,
15 | Yes, it should work in NanoCAD, BricsCAD etc. with the right references, I am yet to try that, if you do, please let us know how you go.
16 |
17 | **Open the Visual Studio 2013 Demo solution to see how this works**.
18 | You may want to change the AutoCAD Project references - It is currently set to build AutoCAD 2016 and .NET 4.5, getting the references from Nuget. There are projects for other versions of AutoCAD in there too, they will need some tweakage to get working.
19 |
20 | The first build should fetch the Nuget packages. If the second build fails, restart Visual Studio or close the Solution and re-open it, I don't think it loves mixed C# & VB Solutions.
21 |
22 | ##### To add the NUnitLite v3 Console runner to a Visual Studio project...
23 | - There are folders for C# and VB projects. This was originally written in C# and converted to VB at http://converter.telerik.com/ so the VB code may look a bit too much like C# for your liking, it also may occasionally be missing updates that the C# code has because getting old absent minded.
24 | - Clone this repo to your local Library folder
25 | - Add a new class library project to your Solution
26 | - In `Nuget`, add [`NUnitLite 3`](https://www.nuget.org/packages/NUnitLite) and the [`NUnit 3`Framework](https://www.nuget.org/packages/NUnit) to your new class library - congratulations, it is now a test project. If it already was an `NUnit 2.*` Test project then replace it with NUnit 3. You may have to fix a few things. Such is life in an ever-changing world.
27 | - If you want to modify any CADtest code files you should copy them into your project which you can do by "Add Existing Item" and *not* linking it. Me, I generally link to them from a local library Repo by hand-editing the `CSPROJ` file but I like breaking things. How do you tihnk I discovered this?
28 | - To link them from your local library, hand-edit your `.CSPROJ | .VBPROJ` file (see below)
29 | - link or copy `App.cs | app.vb`, it has the code to display the console
30 | - link or copy `CADtestRunner.cs | CADtestRunner.vb` and tweak it as you wish, it launches NUnitLite and runs the tests. You can set all sorts of options there.
31 | - If you edit an original file linked from your library beware that this will affect everything else that links to it.
32 | - If you don't link to an original then you may need to edit a lot of projects if this gets updated and you want to use the updates.
33 | - You can set the Debug startup to run a .SCR file to netload the DLL and run the command. the .SCR file would look a lot like...
34 | ```
35 | netload "C:\Path\To\Your\TestDLL.dll"
36 | RunCADtests
37 | ```
38 | The startup parameters in Visual Studio's Debug settings would look like for AutoCAD...
39 | ```
40 | /b C:\Path\To\Your\TestNetload.scr
41 | ```
42 | ... and for the Core Console like...
43 | ```
44 | /s C:\Path\To\Your\TestNetload.scr
45 | ```
46 | because why should they be the same that would be `/b/s`.
47 |
48 | - Ctrl-F5 runs the startup project without debugging so if you set your CADtest project as the startup that will run your tests by netloading the DLL and running the command.
49 | - This is really fast in the Core Console runner. If you are using the Core Console then [Define a Build Constant](https://www.google.com.au/search?q=C%23+Define+a+Build+Constant) "`CoreConsole`" and don't reference `AcMgd.dll`
50 | - If you have Resharper and are using C# then you can add the Resharper Templates file to one of the local solution [layers in Resharper Options](https://www.jetbrains.com/resharper/help/Sharing_Configuration_Options.html) manager. The file is `ResharperCADtestTemplates.DotSettings` - it only has C# templates in it, sorry VB'ers.
51 |
52 | #### Linking the C# code files by editing `.CSPROJ`
53 | In the `CSPROJ` file, if you want to copy and modify the Command class...
54 |
55 | ```xml
56 |
64 | ```
65 |
66 | ...and this is the rest of the copy-paste into the `CSPROJ`...
67 | ```xml
68 | CADtest\%(RecursiveDir)%(Filename)%(Extension)
69 |
70 |
71 | CADtest\%(RecursiveDir)%(Filename)%(Extension)
72 |
73 | ```
74 |
75 | #### Linking the VB code files by editing `.VBPROJ`
76 | In the `VBPROJ` file, if you want to copy and modify the Command class...
77 |
78 | ```xml
79 |
87 | ```
88 |
89 | ...and this is the rest of the copy-paste into the `VBPROJ`...
90 | ```xml
91 | CADtest\%(RecursiveDir)%(Filename)%(Extension)
92 |
93 |
94 | CADtest\%(RecursiveDir)%(Filename)%(Extension)
95 |
96 | ```
97 | #### ~~Pro~~AmTip~~s~~
98 | In the Test Classes, use the Attribute `[TestFixture, Apartment(ApartmentState.STA)]`(C#) or ``(VB) ...especially for AutoCAD 2015 because it throws exceptions otherwise.
99 |
100 | Suggestions, questions and contributions are most welcome, use the [Issues here](https://github.com/CADbloke/CADtest/issues) or feel free to submit a [pull request](https://help.github.com/articles/using-pull-requests/) or ten, it's open source so it's for all of us.
101 |
102 | Cheers
103 | Ewen
104 |
--------------------------------------------------------------------------------
/ResharperCADtestTemplates.DotSettings:
--------------------------------------------------------------------------------
1 |
2 |
3 | True
4 | True
5 | AutoCAD
6 | Test
7 | cs
8 | NewFile
9 | True
10 | CADtest class
11 | True
12 | getFileNameWithoutExtension()
13 | 2
14 | True
15 | fileheader()
16 | 0
17 | True
18 | fileDefaultNamespace()
19 | 1
20 | True
21 | InCSharpProjectFile
22 | #define AutoCAD
23 | $HEADER$
24 |
25 | using System;
26 | using System.Collections.Generic;
27 | using System.Diagnostics;
28 |
29 | #if BricsCAD
30 |
31 | using Bricscad.ApplicationServices.Application;
32 | using Bricscad.ApplicationServices;
33 | using Bricscad.EditorInput;
34 | using Bricscad.Runtime; // bug: maybe wrong ??
35 | using Bricscad.Windows;
36 | using Bricscad;
37 | using Teigha.Colors;
38 | using Teigha.DatabaseServices;
39 | using Teigha.Geometry;
40 | using Teigha.GraphicsInterface;
41 | using Teigha.Runtime;
42 | using Teigha;
43 |
44 | #elif NANOCAD
45 | using HostMgd.ApplicationServices.Application;
46 | using HostMgd.ApplicationServices;
47 | using HostMgd.EditorInput;
48 | using HostMgd.Runtime; // bug: maybe wrong ??
49 | using HostMgd.Windows;
50 | using HostMgd;
51 | using Teigha.Colors;
52 | using Teigha.DatabaseServices;
53 | using Teigha.Geometry;
54 | using Teigha.GraphicsInterface;
55 | using Teigha.Runtime;
56 | using Teigha;
57 |
58 | #elif ARES
59 | // todo:
60 |
61 | #elif ZWCAD
62 |
63 | #elif TURBOCAD // not likely at $500 for LTE Pro
64 |
65 | #elif DRAFTSIGHT
66 |
67 | #elif ACAD || AutoCAD
68 | using Autodesk.AutoCAD.ApplicationServices;
69 | using Autodesk.AutoCAD.Colors;
70 | using Autodesk.AutoCAD.DatabaseServices;
71 | using Autodesk.AutoCAD.EditorInput;
72 | using Autodesk.AutoCAD.Geometry;
73 | using Autodesk.AutoCAD.GraphicsInterface;
74 | using Autodesk.AutoCAD.Internal;
75 | using Autodesk.AutoCAD.Runtime;
76 | using Autodesk.AutoCAD.Windows;
77 | using Autodesk.AutoCAD;
78 | // aliases
79 | #if (ACAD2006 || ACAD2007 || ACAD2008 || ACAD2009|| ACAD2010|| ACAD2011 || ACAD2012)
80 | using Autodesk.AutoCAD.ApplicationServices.Application;
81 | #else
82 | using Autodesk.AutoCAD.ApplicationServices.Core;
83 | #endif
84 | #endif
85 |
86 | using NUnit.Framework;
87 |
88 |
89 | namespace $NAMESPACE$
90 | {
91 | [TestFixture, Apartment(ApartmentState.STA)]
92 | public class $CLASS$
93 | {
94 | // todo: use CADtest R# shortcut to add Test Methods
95 | $END$
96 | }
97 | }
98 | True
99 | True
100 | AutoCAD
101 | Test
102 | CADtest surround
103 | True
104 | 0
105 | True
106 | True
107 | 2.0
108 | InCSharpFile
109 | True
110 | [Test]
111 | public void $Test_method_name$()
112 | {
113 | // Arrange
114 | $END$
115 | // Act
116 | Database db = HostApplicationServices.WorkingDatabase;
117 | Document doc = Application.DocumentManager.GetDocument(db);
118 | using (doc.LockDocument())
119 | {
120 | using (db.TransactionManager.StartTransaction())
121 | {
122 | $SELECTION$
123 | //todo: create object(s)
124 | Entity entity = new Entity(); // todo: change this to the type you are using
125 | //todo: add to DataBase
126 | //todo: Test Objects in the Database
127 | ObjectId entityObjectId = CADtest.Helpers.DbEntity.AddToModelSpace(entity, db);
128 | Entity testEntity = entityObjectId.Open(OpenMode.ForRead, false) as Entity; // todo: as above
129 | // todo: get properties to test
130 | }
131 | }
132 | // Assert
133 | Assert.Fail("Write this test");
134 | }
135 |
136 | True
137 | True
138 | AutoCAD
139 | Test
140 | Class for NUnit Testing CAD stuffs
141 | True
142 | JoarOyenLiveTemplateMacros.ValidIdentifier()
143 | 1
144 | True
145 | fileDefaultNamespace()
146 | 0
147 | True
148 | True
149 | 2.0
150 | InCSharpFile
151 | CADtestClass
152 | True
153 | using NUnit.Framework;
154 |
155 |
156 | namespace $NAMESPACE$
157 | {
158 | [TestFixture, Apartment(ApartmentState.STA)]
159 | public class $CLASS$
160 | {
161 | // todo: use CADtest R# shortcut to add Test Methods
162 | $END$
163 | }
164 | }
165 |
166 | True
167 | True
168 | AutoCAD
169 | Test
170 | CADtest test method, replaces spaces with underscores
171 |
172 |
173 | True
174 | JoarOyenLiveTemplateMacros.ValidIdentifier()
175 | 0
176 | True
177 | True
178 | 2.0
179 | InCSharpFile
180 | CADtest
181 | True
182 | [Test]
183 | public void $Test_method_name$()
184 | {
185 | // Arrange
186 | $END$
187 | // Act
188 | Database db = HostApplicationServices.WorkingDatabase;
189 | Document doc = Application.DocumentManager.GetDocument(db);
190 | using (doc.LockDocument())
191 | {
192 | using (db.TransactionManager.StartTransaction())
193 | {
194 | $SELECTION$
195 | //todo: create object(s)
196 | Entity entity = new Entity(); // todo: change this to the type you are using
197 | //todo: add to DataBase
198 | //todo: Test Objects in the Database
199 | ObjectId entityObjectId = CADtest.Helpers.DbEntity.AddToModelSpace(entity, db);
200 | Entity testEntity = entityObjectId.Open(OpenMode.ForRead, false) as Entity; // todo: as above
201 | // todo: get properties to test
202 | }
203 | }
204 | // Assert
205 | Assert.Fail("Write this test");
206 | }
207 |
208 |
--------------------------------------------------------------------------------