Author Topic: Use same code for acad and bcad, references are an issue  (Read 2278 times)

0 Members and 1 Guest are viewing this topic.

jmaeding

  • Bull Frog
  • Posts: 304
  • I'm just here for the Shelties.
Use same code for acad and bcad, references are an issue
« on: August 20, 2013, 12:06:18 PM »
At the top, I have:
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.Runtime;

and so on.
I want to use Bricscad in place of the Autodesk.AutoCAD, but the only way I know is to change the text.
Not only that, but I am getting tired of maintaining several sets of code for each acad version.
I make partial classes so each has a portion that has different code for each version.

I would like to get down to one set of code that uses conditional  symbols to decide what to run.
Can conditionals be used with using statements?
James Maeding

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: Use same code for acad and bcad, references are an issue
« Reply #1 on: August 20, 2013, 12:57:38 PM »
Hi,

Maybe you ca use 'conditional compilation'.

1. Create a Visual Studio project for AutoCAD referencing AutoCAD assemblies with, at the top of each file (class):

#if ACAD
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.Runtime;
#endif
using Bricscad.DatabaseServices;
using Bricscad.EditorInput;
using Bricscad.Geometry;
using Bricscad.Runtime;

2. Add to your project properties, in the  Build tab, the Conditional compilation symbol: ACAD

3. In the same solution, create a new project referencing Bricscad assemblies.

4. Right click on the Bricscad project in the solution explorer > Add > Existing element. Select all the files (classes) from the AutoCAD project folder and change the Add button in the bottom of the dialog to Add as Link.

5. Try to compile...

This way, every changes to the AutoCAD project code will affect the Bricscad project.

PS: I'm not certain about the Visual Studio UI translation.
Speaking English as a French Frog

jmaeding

  • Bull Frog
  • Posts: 304
  • I'm just here for the Shelties.
Re: Use same code for acad and bcad, references are an issue
« Reply #2 on: August 20, 2013, 01:52:30 PM »
wow, too easy. I did that and it seemed to work.
I had thought the #if only applied at compile time, so VS would be confused during coding.
Thanks a bunch!
James Maeding

exmachina

  • Guest
Re: Use same code for acad and bcad, references are an issue
« Reply #3 on: August 20, 2013, 09:57:04 PM »
And also you can use conditional compilation in other contexts. Example:

Code - C#: [Select]
  1. #define EXTASIEXTATAMBIEN
  2.  
  3. using System;
  4.  
  5. namespace eskaralakakatua
  6. {
  7.     internal class Class1 :
  8. #if ILOVEMEZCAL
  9.     Mezcal
  10. #elif ILOVETEQUILA
  11.     Tequila
  12. #else
  13.     Vodka
  14. #endif
  15.     {
  16.  
  17. #if PRIVATE
  18.         private
  19. #else
  20.         internal
  21. #endif
  22.         void zzzz()
  23.         {
  24. #if EXTASIEXTATAMBIEN
  25.             // Rula 1
  26. #else
  27.             // Rula 2
  28. #endif
  29.         }
  30.     }
  31.  
  32.     internal class Tequila
  33.     {
  34.     }
  35.  
  36.     internal class Mezcal
  37.     {
  38.     }
  39.  
  40.     internal class Vodka
  41.     {
  42.     }
  43.  
  44. }

CADbloke

  • Bull Frog
  • Posts: 342
  • Crash Test Dummy
Re: Use same code for acad and bcad, references are an issue
« Reply #4 on: August 20, 2013, 10:22:22 PM »
I set up a project template and/or hand-edit the VS project file (it's XML). See http://www.theswamp.org/index.php?topic=41868.msg497509#msg497509 for more details, and that thread in general for other (perhaps better, less manual) ideas.