Author Topic: Bricscad && .NET  (Read 62029 times)

0 Members and 1 Guest are viewing this topic.

It's Alive!

  • BricsCAD
  • Needs a day job
  • Posts: 7047
  • AKA Daniel
Re: Bricscad && .NET
« Reply #15 on: September 13, 2009, 06:47:52 PM »
Try the  RangeToString function, just see what happens

 string dbeam = RangeToString(ranga);

Jerry J

  • Newt
  • Posts: 48
Re: Bricscad && .NET
« Reply #16 on: September 13, 2009, 09:17:04 PM »
I don't have such a function (RangeToString)!  I think the interop for MicrosoftOffice 10.0 is missing this item.
I might try using SQL or like I mentioned, OpenOffice.  Discovered they have a C# library for connecting.

my using statements are:

using System;    using System.Collections.Generic;  using System.Runtime.InteropServices;  using System.Text;  using System.Collections;
using System.ComponentModel;  using Microsoft.Office.Interop.Excel;  using RxNet.ApplicationServices;  using RxNet.DatabaseServices;
using RxNet.Runtime;  using RxNet.Geometry;  using BricscadApp;  using BricscadDb;

I'll let you know how OO goes.  From what I see it passes cell contents as the type intended, rather than com object.  Might do the trick.

It's Alive!

  • BricsCAD
  • Needs a day job
  • Posts: 7047
  • AKA Daniel
Re: Bricscad && .NET
« Reply #17 on: September 13, 2009, 09:42:46 PM »
This one
string dbeam = RangeToString(ranga);

I just want to see what happens  :-)

Code: [Select]
public static string RangeToString(Range range)
  {
   object[,] values = range.get_Value
     (Excel.XlRangeValueDataType.xlRangeValueDefault) as object[,];

    StringBuilder sb = new StringBuilder();

    for (int i = 1; i <= values.GetUpperBound(0); i++)
    {
     sb.Append("\n"); // new line for each row
     for (int j = 1; j <= values.GetUpperBound(1); j++)
     {
      sb.Append(string.Format("{0} ", values[i, j]));
     }
    }
   return sb.ToString();
  }

I would recommend using SQL too, maybe SQLite http://sqlite.phxsoftware.com/

Jerry J

  • Newt
  • Posts: 48
Re: Bricscad && .NET
« Reply #18 on: September 14, 2009, 02:23:52 AM »
That one doesn't exist in any of my references. That's what I mean by needing an
upgrade of Excel.  The registered application library under com, nor the downloaded
interop for Excel 10 contains the function RangeToString.  Did a search on the objects
in the using statements..nada! 

Think I'll look into SQL, OO appears quite a undertaking for my rotten brain.  First I thought
I'd watch a few tutorials on the SQLExpress databases as it comes with C# and runs in IDE.

It's Alive!

  • BricsCAD
  • Needs a day job
  • Posts: 7047
  • AKA Daniel
Re: Bricscad && .NET
« Reply #19 on: September 14, 2009, 02:39:30 AM »
Just add the function to your class just like this..

Code: [Select]
public class findbeam
{
 public static string RangeToString(Range range)
 {
  object[,] values = range.get_Value
    (Excel.XlRangeValueDataType.xlRangeValueDefault) as object[,];

  StringBuilder sb = new StringBuilder();

  for (int i = 1; i <= values.GetUpperBound(0); i++)
  {
   sb.Append("\n"); // new line for each row
   for (int j = 1; j <= values.GetUpperBound(1); j++)
   {
    sb.Append(string.Format("{0} ", values[i, j]));
   }
  }
  return sb.ToString();
 }

 [ComVisibleAttribute(true)]
 public string FindBeam(double dist2, double w, double V, double M, double wthick)
 {
  object missing = System.Reflection.Missing.Value;
  //object newTemplate = false;
  //object docType = 0;
  //object isVisible = true;
  Excel._Application ExcelApp = new Excel.ApplicationClass();
  ExcelApp.Visible = false;
  Workbook objBook = ExcelApp.Workbooks._Open("C:\\Beam Data\\Wood.xls", Type.Missing, Type.Missing, Type.Missing,
                   Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
                   Type.Missing, Type.Missing, Type.Missing, Type.Missing);
  Worksheet objSheet = (Worksheet)objBook.Sheets["Sheet1"];
  ExcelApp.Visible = true;
  ExcelApp.WindowState = XlWindowState.xlMinimized;
  objSheet.Cells[12, 15] = w;
  Range rang;

  int off;
  if (wthick < 5.0)
  {
   rang = objSheet.get_Range("I5", "I10");
   off = 5;
  }
  else
  {
   rang = objSheet.get_Range("I11", "I15");
   off = 11;
  }
  int Vrow = (int)ExcelApp.WorksheetFunction.Match(V, rang, 1);
  Range ranga = objSheet.get_Range(objSheet.Cells[Vrow + off, 3], missing);
  return RangeToString(ranga);
 }
}

Jerry J

  • Newt
  • Posts: 48
Re: Bricscad && .NET
« Reply #20 on: September 14, 2009, 06:35:40 PM »
 :cry:  Same Exception From HRSESULT:0x800A03EC !
Since StringBuilder I assume is in the form of .append(object) and returning string, the conversion
from comobject to string is failing?  Wonder if there is some sort of Delegate that could be contrived?

BTW Saw that SQLite works in C#Express version, maybe I'll give it a try.

Jerry J

  • Newt
  • Posts: 48
Re: Bricscad && .NET
« Reply #21 on: September 14, 2009, 07:17:45 PM »

It's Alive!

  • BricsCAD
  • Needs a day job
  • Posts: 7047
  • AKA Daniel
Re: Bricscad && .NET
« Reply #22 on: September 14, 2009, 07:33:04 PM »
PM me your whole project and your excel doc, and I will test it  :-)

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Bricscad && .NET
« Reply #23 on: September 14, 2009, 07:48:28 PM »

BTW Saw that SQLite works in C#Express version, maybe I'll give it a try.

Jerry, do you have a link to the .NET library ?
or the article,
or where you saw that  ?? :)

Regards
Kerry
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

--> Donate to theSwamp<--

It's Alive!

  • BricsCAD
  • Needs a day job
  • Posts: 7047
  • AKA Daniel
Re: Bricscad && .NET
« Reply #24 on: September 14, 2009, 07:49:39 PM »

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Bricscad && .NET
« Reply #25 on: September 14, 2009, 08:02:55 PM »
this?  http://sqlite.phxsoftware.com/

Thanks Dan,
That looks interesting.

I'll have a good look on the weekend :)

ps:
I'd like to use your lispyLibrary, but need something (more)transparent and transportable ...
[ the old ARX life expectancy thingie has come into the equation] :)

Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

--> Donate to theSwamp<--

It's Alive!

  • BricsCAD
  • Needs a day job
  • Posts: 7047
  • AKA Daniel
Re: Bricscad && .NET
« Reply #26 on: September 14, 2009, 08:49:03 PM »
Thanks Dan,
That looks interesting.

I'll have a good look on the weekend :)

I haven't used it myself but it looks cool.

ps:
I'd like to use your lispyLibrary, but need something (more)transparent and transportable ...
[ the old ARX life expectancy thingie has come into the equation] :)

No worries, I have made the tool as transparent as possible by posting the source.  :wink:

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Bricscad && .NET
« Reply #27 on: September 14, 2009, 09:46:20 PM »
...........  I have made the tool as transparent as possible by posting the source.  :wink:

Yes, I know, and I appeciate it :)
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

--> Donate to theSwamp<--

It's Alive!

  • BricsCAD
  • Needs a day job
  • Posts: 7047
  • AKA Daniel
Re: Bricscad && .NET
« Reply #28 on: September 18, 2009, 02:25:14 AM »
I have updated the installers and the sample in the first post in this thread, added a method to hide dialogs
during a getXXX function call, example.

Code: [Select]
private void button_Click(object sender, EventArgs e)
  {
   //use this to hide your form and give control to Bricscad
   this.Hide();
   RxNet.ApplicationServices.Application.MainWindowIsFocused = true;
 
  your GetXXX function 

   //restore the form
   RxNet.ApplicationServices.Application.MainWindowIsFocused = false;
   this.Show();
  }
See the included sample. I will be wrapping more in the Point, Vector, and Marix classes in the coming days as these are pretty handy to have
« Last Edit: September 21, 2009, 01:19:27 AM by Daniel »

It's Alive!

  • BricsCAD
  • Needs a day job
  • Posts: 7047
  • AKA Daniel
Re: Bricscad && .NET
« Reply #29 on: September 21, 2009, 01:22:13 AM »
I made a couple of changes

if you put a file called RxLoader.txt in the same folder as RxNet.DLL, RxNet will try to run though and load the assemblies listed in the file.

here is the format
Quote
; comment
; put the full path of the dll you want to load with RxNet
C:\Dev\Projects\BrxNet\RxNetSample\RxNetSample\bin\Release\RxNetSample.dll

I hacked out wrappers for Vector2d, Point2d, Matrix2d , Vector3d, Point3d, Matrix3d.
I'm still working on testing each function, I sure could use a little help....  :evil:

Since ActiveX entities take a double[4][4] array as the parameter for transformby
I add a member functions To4x4Array() and static Matrix3d.From4x4Array to help with the conversions.

I.e

Code: [Select]
using System;
using BricscadApp;
using BricscadDb;
using RxNet.ApplicationServices;
using RxNet.Geometry;
using RxNet.Runtime;
 
namespace RxNetSample
{
 public static class DBGCommands
 {
  [CommandMethod("tran")]
  public static void DBGtran()
  {
   AcadApplication application = Application.AcadApplication as AcadApplication;
   if (application == null)
    throw new System.Exception("Could Not Get Application");

   AcadDocument Doc = application.ActiveDocument;
   AcadSelectionSet selection = Doc.SelectionSets.Add("MySel");

   try
   {
    Vector3d vec = new Point3d(100, 100, 0).GetAsVector();
    Matrix3d mat = Matrix3d.Displacement(vec);

    int[] var = new int[] { 0 };
    object[] val = new object[] { "POINT,LINE,CIRCLE" };
    selection.SelectOnScreen(var, val);

    foreach (AcadEntity e in selection)
     e.TransformBy(mat.To4x4Array()); //<--------
   }
   catch (System.Exception ex)
   {
    PInvokeMethods.sds_printf(
     String.Format("\n{0}:\n{1}",ex.Message, ex.StackTrace));
   }
   finally
   {
    selection.Delete();
   }
  }
 }
}





« Last Edit: September 21, 2009, 01:54:19 AM by Daniel »