Acoreconsole with [LispFunction(<commandname>)]

Acoreconsole with [LispFunction(<commandname>)]

Anonymous
Not applicable
2,298 Views
12 Replies
Message 1 of 13

Acoreconsole with [LispFunction(<commandname>)]

Anonymous
Not applicable

Hello,

 

How can use [LispFunction(<commandname>)] created in .NET dll with Accorconsole.exe to run in multiple threads. What should I write in the script file to execute this custom command. Examples given at all places is of [CommandMethod("<commandname>")] 

 

I have used LispFunction because I want to send some command line parameters to the function. Please see below

 

[LispFunction("<commandname>")]
public static void batchprog(ResultBuffer Args)
{

..........

..........

}

 

How can use this in the script file for accoreconsole.exe calling. Ofcourse, parameters will be dynamic. Do I need to create .scr file on the fly(dynamic) or please suggest alternative.

 

Thanks in advance,

0 Likes
2,299 Views
12 Replies
Replies (12)
Message 2 of 13

Anonymous
Not applicable

Short answer, you can't and your wasting your time.

 

One of the HOB guys (Skylar) has just about stretched the core console to all its possible limits. We even did a test loading every dbx, crx and dll packaged with AutoCAD trying to unlock additional functionality.

 

The only good new I can give you is that "some" of the VL functions do work in core console and dbx's can be loaded to partially support 3rd party objects, but absolutely no VLA, ActiveX, Arx or .Net.

 

Note: Arx was not extensively tested, but I know the Autodesk Fabrication one definitively doesn't work.

0 Likes
Message 3 of 13

Anonymous
Not applicable

Hello,

Thanks for the reply. But [CommandMethod("<commandname>")] works perfectly with accoreconsole.exe but [LispFunction(<commandmethod>)] dont know how to do that.

 

Whether I need to create .scr file dynamically with passing arguments. Nobody there from Autodesk to answer??

 

 

0 Likes
Message 4 of 13

_gile
Consultant
Consultant

Hi,

 

If I do not misunderstand what you're trying to do, I'd say you can run a script in the accoreconsole which calls a .NET LispFunction with parameters, but these parameters have to be hard coded in the script.

 

A simple working example.

 

C# LispFunction

using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.Runtime;
using System;

namespace AcCoreConsoleLispFunction
{
    public class LispFunctions
    {
        [LispFunction("MakeCircle")]
        public object MakeCircle(ResultBuffer resbuf)
        {
            if (resbuf == null)
                return null;
            var args = resbuf.AsArray();
            if (args.Length != 2)
                return null;

            Point3d center;
            var arg = args[0];
            if (arg.TypeCode == (int)LispDataType.Point3d)
                center = (Point3d)arg.Value;
            else if (arg.TypeCode == (int)LispDataType.Point2d)
            {
                var pt = (Point2d)arg.Value;
                center = new Point3d(pt.X, pt.Y, 0.0);
            }
            else
                return null;

            double radius;
            arg = args[1];
            if (arg.TypeCode == (int)LispDataType.Double ||
                arg.TypeCode == (int)LispDataType.Int16 ||
                arg.TypeCode == (int)LispDataType.Int32)
                radius = Convert.ToDouble(arg.Value);
            else
                return null;

            var db = HostApplicationServices.WorkingDatabase;
            ObjectId id;
            using (var tr = db.TransactionManager.StartTransaction())
            {
                var ms = (BlockTableRecord)tr.GetObject(
                    SymbolUtilityServices.GetBlockModelSpaceId(db), OpenMode.ForWrite);
                var circle = new Circle(center, Vector3d.ZAxis, radius);
                id = ms.AppendEntity(circle);
                tr.AddNewlyCreatedDBObject(circle, true);
                tr.Commit();
            }
            return id;
        }
    }
}

script file:

NETLOAD "AcCoreConsoleLispFunction.dll"
(MakeCircle '(0 0) 20)
_qsave

 



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 5 of 13

Anonymous
Not applicable

Thanks Gile. You got it exactly what I am trying to mention in the post. But parameters can not be hard coded unfortunately. Basically I am running accorconsole.exe in the batch which gets/read parameters from the predefined text file. Can you please guide how to achieve it. Do I need to create .scr file dynamically through the program?

 

Thanks in advance,

0 Likes
Message 6 of 13

_gile
Consultant
Consultant

pushpakp a écrit :

Do I need to create .scr file dynamically through the program?


I think so, but if you need to create a different script per dwg you'd lose the benefit of a batch processing with the accoreconsole...



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 7 of 13

Anonymous
Not applicable

I tried below

 

string currentFile = @"C:\Temp\Drawing1.dwg";
String consoleOutput = String.Empty;
String entityBreakup = String.Empty;
using (Process coreprocess = new Process())
{
coreprocess.StartInfo.UseShellExecute = false;
coreprocess.StartInfo.CreateNoWindow = true;
coreprocess.StartInfo.RedirectStandardOutput = true;
coreprocess.StartInfo.FileName = @"C:\Program Files\Autodesk\AutoCAD 2016\accoreconsole.exe";

coreprocess.StartInfo.Arguments = string.Format("/i \"{0}\" /s \"{1}\" /l en-US", currentFile, @"C:\Temp\test.scr");

coreprocess.Start();

// Max wait for 5 seconds
coreprocess.WaitForExit(5000);

StreamReader outputStream
= coreprocess.StandardOutput;
consoleOutput = outputStream.ReadToEnd();
String cleaned =
consoleOutput.Replace("\0", string.Empty);

int first = cleaned.IndexOf("BreakupBegin") + "BreakupBegin".Length;
int last = cleaned.IndexOf("BreakupEnd");
if (first != -1 && last != -1)
entityBreakup =
cleaned.Substring(first, last - first);

outputStream.Close();

}

 

test.scr as below

NETLOAD
C:\\IFP20\\IFP20.dll
(MakeCircle '(0 0) 20)
_qsave

 

But it does not create any circle in the given dwg file.

 

Where I am making mistake. Please guide.

0 Likes
Message 8 of 13

_gile
Consultant
Consultant

In your script file, you may not use double anti-slashes and since AutoCAD 2014 the C:\IFP20 folder have to be added to trusted paths.

 

NETLOAD
C:\IFP20\IFP20.dll
(MakeCircle '(0 0) 20)
_.qsave

You should first test the script directly from an AutoCAD session using the SCRIPT command.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 9 of 13

Anonymous
Not applicable

Interesting,

 

There must be something in our DLL's preventing their use then. We tried 3 of our own DLL's that we regularly use and none of them worked. They loaded, but they didn't actually do what they were intended to do inside core console.

 

I guess we'll have to make an attempt to attach the debugger to core console and see if we can isolate what is causing that.

0 Likes
Message 10 of 13

Anonymous
Not applicable

Hello Gile, Thanks for the reply. I ran the script directly into the AutoCAD and it runs absolutely perfect. But when I run through accoreconsole process in the code below

 

string currentFile = @"C:\Temp\Drawing1.dwg";
String consoleOutput = String.Empty;
String entityBreakup = String.Empty;

using (Process coreprocess = new Process())
{
coreprocess.StartInfo.UseShellExecute = false;
coreprocess.StartInfo.CreateNoWindow = true;
coreprocess.StartInfo.RedirectStandardOutput = true;
coreprocess.StartInfo.FileName = @"C:\Program Files\Autodesk\AutoCAD 2016\accoreconsole.exe";

coreprocess.StartInfo.Arguments = string.Format("/i \"{0}\" /s \"{1}\" /l en-US", currentFile, @"C:\Temp\test.scr");

coreprocess.Start();

// Max wait for 5 seconds
//coreprocess.WaitForExit(5000); //commented this line just for information

StreamReader outputStream
= coreprocess.StandardOutput;
consoleOutput = outputStream.ReadToEnd();
String cleaned =
consoleOutput.Replace("\0", string.Empty);

int first = cleaned.IndexOf("BreakupBegin") + "BreakupBegin".Length;
int last = cleaned.IndexOf("BreakupEnd");
if (first != -1 && last != -1)
entityBreakup =
cleaned.Substring(first, last - first);

outputStream.Close();

}

 

it shows output as below

 

Redirect stdout (file: C:\Users\PP\AppData\Local\Temp\accc201362).
AutoCAD Core Engine Console - Copyright Autodesk, Inc 2009-2013.
CoreHeartBeat
Regenerating model.
CoreHeartBeat


Command:
Command:

Command:
Command: NETLOAD
Assembly file name: C:\IFP20\IFP20.dll

Command: (MakeCircle '(0 0) 20)

 

it does not create circle in the C:\Temp\Drawing1.dwg 

 

What is going wrong, please guide. I am using AutoCAD 2016 64 bit

 

test.scr is as below

NETLOAD
C:\IFP20\IFP20.dll
(MakeCircle '(0 0) 20)
_.qsave

 

Please note C:\IFP20 is in the trusted path of AutoCAD also.

 

0 Likes
Message 11 of 13

_gile
Consultant
Consultant

It looks like "Command; _.qsave" and "Command: _quit" are missing in the output.

 

This is the way I do this:

 

var args = $"/i \"{filename}\" /s \"{scriptFile}\"";
var startInfo = new ProcessStartInfo(accorePath, args);
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
var process = Process.Start(startInfo);
process.WaitForExit();


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 12 of 13

Anonymous
Not applicable

Hello Gile,

 

After executing below code it crashes and show error as 'AutoCAD component has stopped working' Do you want to debug. After pressing debug it is showing attached error image. What is wrong now? I am using .NET framework 4.0 both at exe and dll

 

string currentFile = @"C:\Temp\Drawing1.dwg";
string accorePath = @"C:\Program Files\Autodesk\AutoCAD 2016\accoreconsole.exe";
var args1 = $"/i \"{currentFile}\" /s \"{ @"C:\Temp\test.scr"}\"";
var startInfo = new ProcessStartInfo(accorePath, args1);
startInfo.WindowStyle = ProcessWindowStyle.Hidden;

var process = Process.Start(startInfo);
process.WaitForExit();

 

It is very hard for me to find out what is wrong. Please help. Thanks.

0 Likes
Message 13 of 13

_gile
Consultant
Consultant

Here's a minimalist testing console application working for me.

 

script:

NETLOAD "C:\Program Files\Autodesk\ApplicationPlugins\AcCoreConsoleLispFunction.dll"
(MakeCircle '(0 0) 20)
_.qsave

Console application

using System;
using System.Diagnostics;

namespace TestConsoleApplication
{
    class Program
    {
        static void Main()
        {
            var acCoreConsole = @"C:\Program Files\Autodesk\AutoCAD 2016\accoreconsole.exe";
            var scriptFile = @"C:\Temp\RunLisp.scr";
            var filename = @"c:\Temp\Dessin1.dwg";

            var args = $"/i \"{filename}\" /s \"{scriptFile}\"";
            var startInfo = new ProcessStartInfo(acCoreConsole, args);
            startInfo.UseShellExecute = false;
            startInfo.RedirectStandardOutput = true;
            startInfo.WindowStyle = ProcessWindowStyle.Hidden;
            var process = Process.Start(startInfo);
            var output = process.StandardOutput.ReadToEnd().Replace("\0", "");
            process.WaitForExit();

            Console.WriteLine(output);
            Console.ReadLine();
        }
    }
}

 

output:

 

accoreconsole_output.png



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes