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

0 Members and 1 Guest are viewing this topic.

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8698
  • AKA Daniel
Re: Bricscad && .NET
« Reply #45 on: January 22, 2010, 07:39:29 AM »
netburst
Code: [Select]
using System;
using System.Collections.Generic;
using System.Threading;
using BricscadApp;
using BricscadDb;
using RxNet.Geometry;
using RxNet.ApplicationServices;
using RxNet.Runtime;

namespace RxNetTest
{
  public static class Commands
  {
    [CommandMethod("netburst")]
    public static void netburst()
    {
      AcadApplication app = Application.AcadApplication as AcadApplication;
      AcadDocument document = app.ActiveDocument;
      AcadDatabase database = document.database;
      AcadSelectionSet selection = document.SelectionSets.Add("sset");
      int[] var = new int[] { 0 ,66};
      object[] val = new object[] { "INSERT" ,1 };
      selection.SelectOnScreen(var, val);

      foreach (IAcadBlockReference blk in selection)
      {
        if (blk.HasAttributes)
        {
          IAcadBlock space = database.ObjectIdToObject(blk.OwnerID) as IAcadBlock;
          foreach (AcadEntity ent in (object[])blk.Explode())
          {
            AcadAttribute attribute = ent as AcadAttribute;
            if (attribute != null)
            {
              AcadText txt = space.AddText(attribute.TextString,
                                           attribute.InsertionPoint,
                                           attribute.Height);
              txt.Alignment = attribute.Alignment;
              txt.Backward = attribute.Backward;
              txt.color = attribute.color;
              txt.HorizontalAlignment = attribute.HorizontalAlignment;
              txt.Normal = attribute.Normal;
              txt.ObliqueAngle = attribute.ObliqueAngle;
              txt.Rotation = attribute.Rotation;
              txt.ScaleFactor = attribute.ScaleFactor;
              txt.StyleName = attribute.StyleName;
              txt.TextAlignmentPoint = attribute.TextAlignmentPoint;
              txt.VerticalAlignment = attribute.VerticalAlignment;
              txt.UpsideDown = attribute.UpsideDown;
              //add what you need
              attribute.Erase();
            }
          }
          blk.Erase();
        }
      }
      selection.Delete();
    }
  }
}
« Last Edit: January 25, 2010, 08:35:20 PM by Daniel »

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Bricscad && .NET
« Reply #46 on: January 22, 2010, 07:50:08 AM »


Looks like it's coming along for you Dan.
Pity that it needs to be COM (untill they get the BRX stuff wrapped.)
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8698
  • AKA Daniel
Re: Bricscad && .NET
« Reply #47 on: January 25, 2010, 09:39:55 PM »


Looks like it's coming along for you Dan.
Pity that it needs to be COM (untill they get the BRX stuff wrapped.)

Thanks!

COM isn't so bad when you can use C#, you don't have to deal with variants and all that carp...
I would rather write my own API then use VBA  :laugh:

FYI, I'm in the source fixing a couple of bugs I found, lf anyone needs something fixed or added, let me know

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Bricscad && .NET
« Reply #48 on: January 25, 2010, 09:48:45 PM »


Looks like it's coming along for you Dan.
Pity that it needs to be COM (untill they get the BRX stuff wrapped.)

Thanks!

COM isn't so bad when you can use C#, you don't have to deal with variants and all that carp...
I would rather write my own API then use VBA  :laugh:

FYI, I'm in the source fixing a couple of bugs I found, lf anyone needs something fixed or added, let me know



I'd rather YOU write the API  than me use VBA also.  :)
« Last Edit: January 26, 2010, 02:51:30 AM by Kerry Brown »
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8698
  • AKA Daniel
Re: Bricscad && .NET
« Reply #49 on: January 26, 2010, 01:54:23 AM »
Talking with lisp  :kewl:

Code: [Select]
(defun thisisatest (a)
 (reverse a)
)
(vl-acad-defun 'thisisatest)

Code: [Select]
[CommandMethod("doit2")]
    static public void doit2()
    {
      ResultBuffer rbOut = new ResultBuffer();
      rbOut.Add(new TypedValue((int)LispDataType.Text, "thisisatest"));

      rbOut.Add(new TypedValue((int)LispDataType.ListBegin));//list
      rbOut.Add(new TypedValue((int)LispDataType.Int32, 1));
      rbOut.Add(new TypedValue((int)LispDataType.Int32, 2));
      rbOut.Add(new TypedValue((int)LispDataType.Int32, 3));
      rbOut.Add(new TypedValue((int)LispDataType.Int32, 4));
      rbOut.Add(new TypedValue((int)LispDataType.ListEnd)); //endlist


      GlobalFunctions.Printf(string.Format("\n{0}",rbOut));
      ResultBuffer rbIn = GlobalFunctions.Invoke(rbOut); // acedinvoke
      GlobalFunctions.Printf(string.Format("\n{0}",rbIn));
    }


Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Bricscad && .NET
« Reply #50 on: January 26, 2010, 03:00:27 AM »
Dan,

so you're calling a Lisp Command from C# .... that has some potential !!

Where is the  GlobalFunctions definition ?

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

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8698
  • AKA Daniel
Re: Bricscad && .NET
« Reply #51 on: January 26, 2010, 05:26:24 AM »
I thought you might like that.  ^-^
the namespace is RxNet.RxGlobal. GlobalFunctions.Invoke
but don't try it yet because I have not uploaded the latest version yet

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8698
  • AKA Daniel
Re: Bricscad && .NET
« Reply #52 on: January 26, 2010, 05:36:15 AM »
here is how you would do it in acad

Code: [Select]
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Runtime;
using AcAp = Autodesk.AutoCAD.ApplicationServices;

[assembly: CommandClass(typeof(ExecMethod.Commands))]
namespace ExecMethod
{
 public static class Commands
 {
   [DllImport("acad.exe", CallingConvention = CallingConvention.Cdecl)]
   extern static int acedInvoke(IntPtr rbIn, out IntPtr rbOut);

   public static ResultBuffer Invoke(ResultBuffer rbIn)
   {
     IntPtr pRb = IntPtr.Zero;
     acedInvoke(rbIn.UnmanagedObject, out pRb);
     return DisposableWrapper.Create(typeof(ResultBuffer), pRb, true) as ResultBuffer;
   }

   [CommandMethod("doit")]
   public static void MyCommand()
   {
     ResultBuffer rbOut = new ResultBuffer();
     rbOut.Add(new TypedValue((int)LispDataType.Text, "thisisatest"));

     rbOut.Add(new TypedValue((int)LispDataType.ListBegin));
     rbOut.Add(new TypedValue((int)LispDataType.Int32, 1));
     rbOut.Add(new TypedValue((int)LispDataType.Int32, 2));
     rbOut.Add(new TypedValue((int)LispDataType.Int32, 3));
     rbOut.Add(new TypedValue((int)LispDataType.Int32, 4));
     rbOut.Add(new TypedValue((int)LispDataType.ListEnd));

     ResultBuffer rbIn = Invoke(rbOut);

     List<TypedValue> list = new List<TypedValue>(rbIn.AsArray());

     list.ForEach(X =>
      AcAp.Application.DocumentManager.
      MdiActiveDocument.Editor.WriteMessage(X.Value.ToString()));
   }
 }
}


It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8698
  • AKA Daniel
Re: Bricscad && .NET
« Reply #53 on: January 26, 2010, 05:42:01 AM »
A warning though, some arguments may be interpreted by lisp I.e. lisp might see a list of three doubles as a RT3DPOINT, so be careful  :police:

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8698
  • AKA Daniel
Re: Bricscad && .NET
« Reply #54 on: January 26, 2010, 05:52:52 AM »
arx version  :lol:

Code: [Select]
  static void arx_doit(void)
  {
    resbuf *pRbOut = acutBuildList(RTSTR,_T("thisisatest"),
                                   RTLB,
                                   RTSHORT, 1,
                                   RTSHORT, 2,
                                   RTSHORT, 3,
                                   RTSHORT, 4,
                                   RTLE,
                                   NULL);
    resbuf *pRbIn = NULL;
    acedInvoke(pRbOut,&pRbIn);
   
    for(resbuf*pTmp = pRbIn;pTmp!=NULL;pTmp = pTmp->rbnext)
    {
      acutPrintf(_T("%ld"),pTmp->resval.rint);
    }
    acutRelRb(pRbIn);
    acutRelRb(pRbOut);
  }

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8698
  • AKA Daniel
Re: Bricscad && .NET
« Reply #55 on: February 01, 2010, 02:07:09 AM »
Updated,

removed some of the hacks and workarounds for items that were not implemented in BRX and now are. Fixed a few bugs, wrapped a few more items.  :-)

I Also modified the installer to install for all users.

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8698
  • AKA Daniel
Re: Bricscad && .NET
« Reply #56 on: February 04, 2010, 01:33:52 AM »
A really quick sample of how to make a table and how to edit a cell  :laugh:

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Bricscad && .NET
« Reply #57 on: February 04, 2010, 01:36:41 AM »

You've been reading my mail ??


I had planned on investigating that tonight   ... you just keep on doing my homework  !!  :wink:
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

MickD

  • King Gator
  • Posts: 3636
  • (x-in)->[process]->(y-out) ... simples!
Re: Bricscad && .NET
« Reply #58 on: February 04, 2010, 01:54:15 AM »
...
I'd rather YOU write the API  than me use VBA also.  :)

Maybe you won't have to write anything - http://www.opendwg.org/the_oda_platform/dwgdirect.net

I'm not sure if you can just mix the assemblies in with Bricscad or not but if you could  that would save a fair chunk of the work :)
"Programming is really just the mundane aspect of expressing a solution to a problem."
- John Carmack

"Short cuts make long delays,' argued Pippin.”
- J.R.R. Tolkien

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8698
  • AKA Daniel
Re: Bricscad && .NET
« Reply #59 on: February 04, 2010, 02:01:02 AM »
...
I'd rather YOU write the API  than me use VBA also.  :)

Maybe you won't have to write anything - http://www.opendwg.org/the_oda_platform/dwgdirect.net

I'm not sure if you can just mix the assemblies in with Bricscad or not but if you could  that would save a fair chunk of the work :)

I've wondered what would happen if I netloaded those. I'm not an ODA member though  :|
I'm sure Bricsys will be adding em at some point though
« Last Edit: February 04, 2010, 02:09:53 AM by Daniel »