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

0 Members and 1 Guest are viewing this topic.

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8712
  • AKA Daniel
Re: Bricscad && .NET
« Reply #105 on: September 22, 2010, 11:10:23 AM »

[off Topic]

Daniel, you win:  my curiosity required a Bing of “Brugse Zot”.

 [proceed as normal]


 :-D  I'm trying to locate a bottle or two locally

jgr

  • Guest
Re: Bricscad && .NET
« Reply #106 on: September 22, 2010, 11:30:41 AM »
maybe you need to allocate the memory? I.e

Code: [Select]
Friend Shared Function entSel(ByVal message As String) As RxNet.DatabaseServices.ObjectId
Dim name As Long() = New Long(1) {}
Dim pt As Double() = New Double(2) {}
acedEntSel(message, name, pt)
Return New RxNet.DatabaseServices.ObjectId(CInt(name(0)))
End Function

It does not work.

But i changed Long by Integer, and now it works. ??

Code: [Select]
<DllImport("Brx10.DLL", CallingConvention:=CallingConvention.Cdecl, CharSet:=CharSet.Unicode)> _
Private Shared Function acedEntSel(ByVal msg As String, _
                                   ByVal name() As Integer, _
                                   ByVal point() As Double) As Integer

Friend Shared Function entSel(ByVal message As String) As RxNet.DatabaseServices.ObjectId

    Dim name(1) As Integer
    Dim pt(2) As Double
    acedEntSel(message, name, pt)

    Return New RxNet.DatabaseServices.ObjectId(name(0))
End Function

Thank you.
« Last Edit: September 22, 2010, 11:35:13 AM by jgr »

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8712
  • AKA Daniel
Re: Bricscad && .NET
« Reply #107 on: September 22, 2010, 11:35:35 AM »
Sorry my bad, I guess long is an Int64 in VB  :-o

jgr

  • Guest
Re: Bricscad && .NET
« Reply #108 on: September 22, 2010, 04:09:18 PM »
InnoSetup script that helps the installation of applications that use Rxnet.
(Pascal Scripting)

Features

On Install:
- Check if Bricscad is installed. If Bricscad is not installed, does not allow the installation.

- Check if RxNet is installed. If RxNet is not installed, does not allow the installation.

- Add text to RxLoader.txt (auto loading assemblies)

On uninstall
- Remove the added text.

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8712
  • AKA Daniel
Re: Bricscad && .NET
« Reply #109 on: September 23, 2010, 01:27:45 AM »
I don't know Arno, I've tried doing late binding but I keep getting an exception.

the module

Code: [Select]
namespace RxNetArno
{
  [Guid("D6F88E95-8A27-4ae6-B6DE-0542A0FC7039")]
  [InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
  public interface _ComCommands
  {
    [DispId(1)]
    void test02();
  }

  [Guid("13FE32AD-4BF8-495f-AB4D-6C61BD463EA4")]
  [ClassInterface(ClassInterfaceType.None)]
  [ProgId("RxNetArno.Commands")]
  public class ComCommands : _ComCommands
  {
    public ComCommands() { }

    public void test02()
    {
      var app = Application.AcadApplication as AcadApplication;
      var doc = app.ActiveDocument;
      try
      {
        double[] pnt1 = new double[]{0,0,0};
        double[] pnt2 = new double[]{100,100,0};
        var line = doc.ModelSpace.AddLine(pnt1, pnt2);
      }
      catch (System.Exception ex)
      {
        doc.Utility.Prompt(String.Format("\n{0}", ex.Message));
      }
    }
  }
}

and controller .exe

Code: [Select]
  private void button1_Click(object sender, EventArgs e)
    {
      try
      {
        Type ComCommands = Type.GetTypeFromProgID("RxNetArno.Commands");
        object ComCommandsObject = Activator.CreateInstance(ComCommands);
        ComCommands.InvokeMember("test02", BindingFlags.Instance, null, ComCommandsObject, null);
      }
      catch (System.Exception ex)
      {
        MessageBox.Show(ex.Message +"\n" + ex.Source);
      }
    }

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8712
  • AKA Daniel
Re: Bricscad && .NET
« Reply #110 on: September 23, 2010, 01:46:04 AM »
I will try late binding with reflection

iraklis

  • Guest
Re: Bricscad && .NET
« Reply #111 on: September 23, 2010, 03:53:07 AM »
Hi,

I would like to run through all the custom properties in the drawing properties of a file and change their values. I do this in Acad using an enumerator:

Dim CustPops As System.Collections.IDictionaryEnumerator = SummaryInfo.CustomProperties

Do While CustPops.MoveNext = True
            info.CustomPropertyTable.Item(CustPops.Key.ToString) = ReturnFeature(CustPops.Key.ToString)
        Loop


where "ReturnFeature" is a custom function returning a value.
But I cannot find a way to have the same result with RxNet. Could yoy please give me an advice?

Thank you in advance.

Best regards,

Iraklis





It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8712
  • AKA Daniel
Re: Bricscad && .NET
« Reply #112 on: September 23, 2010, 04:17:10 AM »
Hi Daniel,

keeping the 'path' issue for what it is at this moment, I think I've run into something more complex.

What I'm trying to do is incorporating some crude number crunching to a RxNet.dll, for example exporting a lot of entity information to a file.
Let's say I gave such a command [CommandMethod("DoIt")]  :laugh: so after NetLoading the DLL I type DoIt at the command prompt and voila, magic happens.
Now I want to automate this as part of a larger process and use an ordinary COM link to the Application.ActiveDocument and call SendCommand("DoIt") to trigger the RxNet.dll.
Bad luck, bad luck, what I think is happening is this:
The COM SendCommand holds a reference (and locks?) the ActiveDocument.
When Rx tries to start the DoIt() it also tries to get a connection to the same ActiveDocument, but that fails since and external process is busy with it.  ( That's at least how it feels)
Am I correct in my observation? And if so, how do I send a command or is there an other way to start the RxNet routine?

I was reviewing the presentation of Prodok at this years conference in Brugge, also mentioning DeadLocking COM calls.
Is that a way to go?

TIA,
Arno



not having any luck.. have you tried application.RunCommand() instead of sendcommand?

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8712
  • AKA Daniel
Re: Bricscad && .NET
« Reply #113 on: September 23, 2010, 04:29:45 AM »
Hi,

I would like to run through all the custom properties in the drawing properties of a file and change their values. I do this in Acad using an enumerator:

Dim CustPops As System.Collections.IDictionaryEnumerator = SummaryInfo.CustomProperties

Do While CustPops.MoveNext = True
            info.CustomPropertyTable.Item(CustPops.Key.ToString) = ReturnFeature(CustPops.Key.ToString)
        Loop


where "ReturnFeature" is a custom function returning a value.
But I cannot find a way to have the same result with RxNet. Could yoy please give me an advice?

Thank you in advance.

Best regards,

Iraklis



if you don't mind C#

Code: [Select]
public static class ComCommands
  {
    [CommandMethod("doit")]
    static public void test02()
    {
      var app = Application.AcadApplication as AcadApplication;
      var doc = app.ActiveDocument;
      Dictionary<string, string> info = new Dictionary<string, string>();

      string key;
      string val;

      for (int idx = 0; idx < doc.SummaryInfo.NumCustomInfo(); idx++)
      {
        doc.SummaryInfo.GetCustomByIndex(idx, out key, out val);
        info.Add(key, val);
      }

      foreach (var item in info)
      {
        doc.Utility.Prompt(string.Format("\n{0}, {1}", item.Key, item.Value));
      }
    }
  }

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8712
  • AKA Daniel
Re: Bricscad && .NET
« Reply #114 on: September 23, 2010, 04:34:08 AM »
BTY, I have tool for this in here http://www.theswamp.org/index.php?topic=32990.0

Helios

  • Guest
Re: Bricscad && .NET
« Reply #115 on: September 23, 2010, 04:49:16 AM »
Daniel,

thanks for all your efford so far.
I had not tried RunCommand but it gives the same problem. See attachment.

Are we running out of options here? :|


Arno

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8712
  • AKA Daniel
Re: Bricscad && .NET
« Reply #116 on: September 23, 2010, 04:54:18 AM »
Put a try catch inside that method "Writearea"  and post the results

Code: [Select]
    [CommandMethod("WriteArea")]
    public static void WriteArea()
    {
      var app = Application.AcadApplication as AcadApplication;
      var doc = app.ActiveDocument;
      try
      {
         //your code
      }
      catch (System.Exception ex)
      {
        doc.Utility.Prompt(String.Format("\n{0}", ex.Message));
      }
    }

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8712
  • AKA Daniel
Re: Bricscad && .NET
« Reply #117 on: September 23, 2010, 05:21:10 AM »
FYI, you should always put a try catch inside command methods. If your code throws an exception, the exception unwinds the stack until a catch is found.  If the exception is caught by my InvokeCmd() method, you lose the  ability to handle /  determine the cause of the exception

iraklis

  • Guest
Re: Bricscad && .NET
« Reply #118 on: September 23, 2010, 06:02:20 AM »
Hi,

I would like to run through all the custom properties in the drawing properties of a file and change their values. I do this in Acad using an enumerator:

Dim CustPops As System.Collections.IDictionaryEnumerator = SummaryInfo.CustomProperties

Do While CustPops.MoveNext = True
            info.CustomPropertyTable.Item(CustPops.Key.ToString) = ReturnFeature(CustPops.Key.ToString)
        Loop


where "ReturnFeature" is a custom function returning a value.
But I cannot find a way to have the same result with RxNet. Could yoy please give me an advice?

Thank you in advance.

Best regards,

Iraklis



if you don't mind C#

Code: [Select]
public static class ComCommands
  {
    [CommandMethod("doit")]
    static public void test02()
    {
      var app = Application.AcadApplication as AcadApplication;
      var doc = app.ActiveDocument;
      Dictionary<string, string> info = new Dictionary<string, string>();

      string key;
      string val;

      for (int idx = 0; idx < doc.SummaryInfo.NumCustomInfo(); idx++)
      {
        doc.SummaryInfo.GetCustomByIndex(idx, out key, out val);
        info.Add(key, val);
      }

      foreach (var item in info)
      {
        doc.Utility.Prompt(string.Format("\n{0}, {1}", item.Key, item.Value));
      }
    }
  }
\

Thanks Dan

This solved my problem :-)

Helios

  • Guest
Re: Bricscad && .NET
« Reply #119 on: September 23, 2010, 10:34:56 AM »
 :lol:
Found the problem.

First of all : the SendCommand approach works. See snippets below.
Very basic code, does what I want.
The problem was in my Bricscad wrapper class. (Wraps AcadApplication)
It got instantiated for a COM connection at the 'outside' of Bricscad to call SendCommand, and got instantiated inside the RxNet module as well.
My class holds some static objects and the second instatiation collided with the first one.
(Enough detail?   :angel:)

Still a direct call would be nice, specially for passing parameters.
Below I use UserS1 to pass a message.

Anybody having a bright idea how to pass info?

Thanks,
Arno

From a simple form with a button:

Code: [Select]
private void button2_Click(object sender, EventArgs e)
    {
      AcadApplication app = (AcadApplication)Marshal.GetActiveObject("BricscadApp.AcadApplication.2.6");
      AcadDocument doc = app.ActiveDocument;
     
      //plug some information in the document
      doc.SetVariable("USERS1", "Someone is knocking your door!");

      doc.SendCommand("DoIt\n");

    }


Code: [Select]
using System;
using System.Collections.Generic;
using System.Text;
using RxNet.Runtime;
using BricscadApp;

namespace RxNetTest
{
  public static class Class1
  {
    [CommandMethod("DoIt")]
    public static void DoIt()
    {
      AcadApplication app = RxNet.ApplicationServices.Application.AcadApplication as AcadApplication;
      AcadDocument doc = app.ActiveDocument;
     
      try
      {
        // read the variable at RxNet end
        string message = doc.GetVariable("USERS1").ToString();

        doc.Utility.Prompt(String.Format("\n {0} : {1}", message ,DateTime.Now.ToLongTimeString()));
      }
      catch (System.Exception ex)
      {
        doc.Utility.Prompt(String.Format("\n{0}", ex.Message));
      }
    }

  }
}