Author Topic: Compiling .dll's using outside applications.  (Read 2541 times)

0 Members and 1 Guest are viewing this topic.

BillZndl

  • Guest
Compiling .dll's using outside applications.
« on: September 14, 2011, 11:31:49 AM »
I need some help from someone that has more knowledge then me about using outside applications inside of .net C#.

We have a program written in VB that runs in the background of AutoCAD so when "Qsave" is used,
it saves some attribute information in an AutoCAD block and sends it to our Nesting Program that is outside AutoCAD.
The VB code works for our old R2006 and also our new 2012 Acad.
This is the core of the working code:
Code: [Select]
Dim objsn As Automation
Set objsn = New Automation
Select Case UCase$(material)
    Case "PLYWOOD"
        objsn.ExeBatchString "SET,PARTPATH,G:\SNDATA70\PARTS\WOOD\"
        objsn.ExeBatchString "SET,MACHINE,LUND"
    Case "ALUMINUM"
        objsn.ExeBatchString "SET,PARTPATH,G:\SNDATA70\PARTS\ALUMINUM\"
        objsn.ExeBatchString "SET,MACHINE,LUNDAlum"
    Case "EMBOSSED"
        objsn.ExeBatchString "SET,PARTPATH,G:\SNDATA70\PARTS\ALUMINUM\"
        objsn.ExeBatchString "SET,MACHINE,LUNDAlum"
    Case "PLUSH_CARPET"
        objsn.ExeBatchString "SET,PARTPATH,G:\SNDATA70\PARTS\CARPET\"
        objsn.ExeBatchString "SET,MACHINE,Lectra"
    Case "VINYL_CARPET"
        objsn.ExeBatchString "SET,PARTPATH,G:\SNDATA70\PARTS\CARPET\"
        objsn.ExeBatchString "SET,MACHINE,Lectra"
   
End Select
objsn.ExeBatchString "SET,DISPLAYLOGDATA,OFF"
objsn.ExeBatchString "SET,PARTREPLACE,ALL"
objsn.ExeBatchString "SET,REPLACEPATTERN,ON"
objsn.ExeBatchString "SET,MIRROR," & mirror
objsn.ExeBatchString "SET,GRAIN,OFF"
objsn.ExeBatchString "SET,ANGLE," & angle & "," & deg
objsn.ExeBatchString "SET,INTSAMEASEXT,OFF"
objsn.ExeBatchString "SET,LOOKUP,MATERIAL,OFF"
objsn.ExeBatchString "SET,LOOKUP,PROCESS,OFF"
objsn.ExeBatchString "SET,LEADIN,None"
objsn.ExeBatchString "SET,INTERNAL,LEADIN,NONE"
objsn.ExeBatchString "SAVE,PART,ON"


Now I've converted the VB code to C# and compiled it to a .dll.
It builds fine and gives no warnings and it net loads fine.
All the event handlers work when I hit qsave.
All the strings are aquired fine.
As soon as I add the SNAutomation objsn = new SNAutomation();
to the code, it's like everything falls into a black hole.
The program runs but sends nothing to the nesting program
and any writelines I add after getting the instance of the do not show up on the screen.

Just wondering if there something with .net that won't compile this outside nesting application
or if I am just missing something simple when compiling a .dll.  :blank:

I've added all the right resouces (type libraries) included with the nesting program install.
Here's the C# code:
Code: [Select]
Automation objsn = new Automation();               
           
            switch (material.ToUpper())
            {
                case "PLYWOOD":
                    objsn.ExeBatchString("SET,PARTPATH,G:\\SNDATA70\\PARTS\\WOOD\\");
                    objsn.ExeBatchString("SET,MACHINE,LUND");
                    break;

                case "ALUMINUM":
                    objsn.ExeBatchString("SET,PARTPATH,G:\\SNDATA70\\PARTS\\ALUMINUM\\");
                    objsn.ExeBatchString("SET,MACHINE,LUNDAlum");
                    break;

                case "EMBOSSED":
                    objsn.ExeBatchString("SET,PARTPATH,G:\\SNDATA70\\PARTS\\ALUMINUM\\");
                    objsn.ExeBatchString("SET,MACHINE,LUNDAlum");
                    break;

                case "PLUSH_CARPET":
                    objsn.ExeBatchString("SET,PARTPATH,G:\\SNDATA70\\PARTS\\CARPET\\");
                    objsn.ExeBatchString("SET,MACHINE,Lectra");
                    break;

                case "VINYL_CARPET":
                    objsn.ExeBatchString("SET,PARTPATH,G:\\SNDATA70\\PARTS\\CARPET\\");
                    objsn.ExeBatchString("SET,MACHINE,Lectra");
                    break;
            }

            objsn.ExeBatchString("SET,DISPLAYLOGDATA,OFF");
            objsn.ExeBatchString("SET,PARTREPLACE,ALL");
            objsn.ExeBatchString("SET,REPLACEPATTERN,ON");
            objsn.ExeBatchString("SET,MIRROR," + mirror);
            objsn.ExeBatchString("SET,GRAIN,OFF");
            objsn.ExeBatchString("SET,ANGLE," + angle + "," + deg);
            objsn.ExeBatchString("SET,INTSAMEASEXT,OFF");
            objsn.ExeBatchString("SET,LOOKUP,MATERIAL,OFF");
            objsn.ExeBatchString("SET,LOOKUP,PROCESS,OFF");
            objsn.ExeBatchString("SET,LEADIN,None");
            objsn.ExeBatchString("SET,INTERNAL,LEADIN,NONE");
            objsn.ExeBatchString("SAVE,PART,ON");
« Last Edit: September 15, 2011, 02:30:54 PM by BillZndl »

BillZndl

  • Guest
Re: Compiling .dll's using outside applications.
« Reply #1 on: September 14, 2011, 03:43:44 PM »
Sorry,

What I wrote was fine.

There was some things built into the .dvb that I couldn't see that was missing.
Good practice for me.  :-D

Thanks for looking.


BillZndl

  • Guest
Re: Compiling .dll's using outside applications.
« Reply #2 on: September 22, 2011, 04:14:19 PM »
Well, no joy yet.
Can't understand why creating an instance of the nesting program kills the program.
(also asked for help here: http://www.theswamp.org/index.php?topic=39476.0 )

The code looks good and the intellisense tells me I'm using the same methods as my VB program,
compiles fine but when I net load and hit "qsave" (event that triggers the program) my code does what it's supposed to
as far as reading the "TAG" block attributes and getting the information to send to the nester same as the VB program.
As soon as I create the instance of the nester to send the info to, there is an erie silence and my screen prompts quit reporting.
Even inside a try block, it doesn't report and error.

I'm running out of things to try.  :cry:

BillZndl

  • Guest
Re: Compiling .dll's using outside applications.
« Reply #3 on: September 28, 2011, 11:51:39 AM »
I may have a clue to what is going on.
I am getting 2 warnings (both the same) when I used  rebuild.

Code: [Select]
Warning 1
At least one of the arguments for 'ISNApp.ExecuteBatchListAgainstObject' cannot be marshaled by the runtime marshaler.
Such arguments will therefore be passed as a pointer and may require unsafe code to manipulate.
J:\AutoCAD2012Support\VisualStudio2010\SigmaDWG\TlbImp LundSigma

Any clue to what this means?

BillZndl

  • Guest
Re: Compiling .dll's using outside applications.
« Reply #4 on: September 28, 2011, 02:21:26 PM »
ok, got rid of the warning.
used tlbimp on the type library.
still no worky.


Jeff H

  • Needs a day job
  • Posts: 6150
Re: Compiling .dll's using outside applications.
« Reply #5 on: September 28, 2011, 04:07:27 PM »
If you open task manager and go to the 'Processes' tab and run the code do you see the nesting program exe pop up in task manager?

BillZndl

  • Guest
Re: Compiling .dll's using outside applications.
« Reply #6 on: September 28, 2011, 04:56:40 PM »
If you open task manager and go to the 'Processes' tab and run the code do you see the nesting program exe pop up in task manager?

The main nesting app is already "up" when we use the VBA code.
When the VBA code is executed, the graphics and settings just "magically appear" in the blank workspace of the nester.

(btw: I did put the call to my method in a try block and it does error out to the catch error).

I rem out every thing in the method and leave the:  SNAutomation objsn = new SNAutomation();
is all it takes and the program goes no further.

All C# code is identical to what works in VBA (except for the C# conversion).
References in the VBA show the same SN Type Library that I'm using from the install folder.
Everything compiles, no errors, no warnings.

VBA code:   Dim objsn As SNAutomation
                   SNAutomation objsn = new SNAutomation

C# code:    SNAutomation objsn = new SNAutomation();

VS Intellisense: shows same methods and properties for "objsn" as the VBA code shows.















Draftek

  • Guest
Re: Compiling .dll's using outside applications.
« Reply #7 on: September 29, 2011, 08:21:16 AM »
Assuming the 'nesting' app is unmanaged, look at using InteropServices.Marshal to get the running instance.

BillZndl

  • Guest
Re: Compiling .dll's using outside applications.
« Reply #8 on: October 12, 2011, 07:16:33 AM »
Assuming the 'nesting' app is unmanaged, look at using InteropServices.Marshal to get the running instance.

I looked into it , I guess it's a bit over my head.
What method would I use?

TIA

Draftek

  • Guest
Re: Compiling .dll's using outside applications.
« Reply #9 on: October 12, 2011, 08:25:40 AM »
The Marshal class has a static method for this purpose:

System.Runtime.InteropServices.Marshal.GetActiveObject()

BillZndl

  • Guest
Re: Compiling .dll's using outside applications.
« Reply #10 on: October 20, 2011, 03:02:15 PM »
Just a follow up:

The marshaling wasn't needed but was worth the try.

Going with a suggestion by an accomplished programmer,
I stripped everything down to creating the instance then running one line of the code that sends the part over to SN.
To my surprise, It worked!  8-)
The main problem appears to be in some of the lines that send settings to SN,
it's probably because some changes were made to the syntax of the settings.
So I'm not out of the woods yet but at least I've evercome the main roadblock I was experiencing.

Thanks for everyones help and patience.