Author Topic: Extending AutoLisp - Let's start with format  (Read 19725 times)

0 Members and 1 Guest are viewing this topic.

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: Extending AutoLisp - Let's start with format
« Reply #30 on: August 16, 2011, 03:44:07 AM »
OK, so basically you can compile ARX/DBX for Mac. Only you have to not only compile for 64bit OSX code, but it needs to be renamed to *.dylib for DBXes and *.bundle / *.framework for ARXes. Now for the "tricky" bit, what about BricsCAD for linux? It seems they have an API to compile their BRXes for linux:
Quote from: Bricsys Releases Bricscad V11 Pro for Linux
...is identical to the one for Windows. The sole difference is that it contains Linux-specific link libraries, instead of ones specific to Windows...
So I guess it compiles to *.so (shared object) files.

So that means ARX/DBX works fine on Mac (as long as you don't use any MFC stuff). BRX works fine on Linux and they have:
Quote from: Bricsys Releases Bricscad V11 Pro for Linux
...the BRX Linux SDK includes the Windows Platform Emulation Layer, which provides a large set of Windows API functions under Linux.
Which probably means that some calls to MFC would work there. Wish ADesk would do something similar to MFC->Cocoa, then you could create dialogs in your ARXes - and it might be possible to run ODCL through it.

Anyhow, the next step would be to check if a acedDefun would still be callable from Lisp on Mac/Linux:
Quote from: ObjectARX Reference Guide / Defining External Functions
... The following call to acedDefun() specifies that AutoLISP will recognize an external function called doit in AutoLISP, and that when AutoLISP invokes doit, it passes the function code zero (0) to the ObjectARX application:
acedDefun("doit", 0); 
The string that specifies the name of the new external function can be any valid AutoLISP symbol name. AutoLISP converts it to all uppercase and saves it as a symbol of the type Exsubr ...
So those thing "should" work, I guess...
Doing it from Lisp is not possible. As I've mentioned before, I was thinking to use a similar strategy as was done for the ActiveX stuff: i.e. have a few acedDefuns which would create linking functions on the fly to DotNet DLL's. This "should" be possible as you can use reflection on DotNet DLL's and then create defuns to link to each, or simply use a similar idea as per vlax-invoke, vlax-get & vlax-put. But the reason I asked about reflection on ARXes: Since DotNet's not available to Mac/Linux, the reflection on DLLs is a bit useless on those systems - even if you could make those defuns.

Though it seems reflection's only available on COM (ActiveX) and Net DLLs: http://www.codeproject.com/KB/DLL/Execute_DLL_Function.asp

Maybe this thread should be split in 2 though: One for implementing CL default library functions (which would mostly be possible direct through ALisp), the other about implementing ObjectARX calls as External Subs to be called from ALisp.

Edit: Possibly I should start a few Wiki pages somewhere to use as planning for these functions? Just so we can make sure of naming conventions & standardizing argument lists!
« Last Edit: August 16, 2011, 03:47:45 AM by irneb »
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: Extending AutoLisp - Let's start with format
« Reply #31 on: August 16, 2011, 06:40:01 AM »
OK I've started a Wiki on wikidot: http://alisp-ext.wikidot.com

If you want to contribute please apply to join there. I should receive notification through RSS feed so it might take a day or so at worst  :whistle: .
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: Extending AutoLisp - Let's start with format
« Reply #32 on: August 17, 2011, 09:37:36 AM »
I've just come across a small utility which installs with VC. It's called DumpBin ... usually found in C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin

This thing can list all the exported functions of any compiled DLL. As sample I ran it on Vanilla 2011's acad.exe file (it works the same on any ARX/DLL as well). The first lot has weird prefixes & suffixes (perhaps something to do with their return values / argument types, though I wouldn't know). At the bottom seems to be much more familiar stuff ... which are listed in the help files as well.

Then of course this put me in mind about the .h header files found in the SDK's inc folder. How hard could it be to generate something like an XML from those. One which lists which file it comes from, what the entry point to the function is, what data types are returned and used as arguments. Then have a run-time parsing of functions from this XML. Something like an arx-invoke defun, requiring an object, the method's name, and a list of arguments. If the object is a string, then search for such DLL/ARX/EXE/dylib/so/framework/bundle/etc. and create the entry object from there, or if there's more than one in that file, then have it listed in the xml? Same applies for the arx-get and arx-put. Perhaps we could even go further and do some arx-react functions which then works on the events - using acedInvoke to call the Lisp reactor call-back function when the event occurs.

This way there's only a few functions to be written. No need to wrap the entire ObjectARX into acedDefun calls. That's handled at runtime!

And to make it into one ARX only, that XML could always be compiled into the ARX as a resource.
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

Jeff H

  • Needs a day job
  • Posts: 6144
Re: Extending AutoLisp - Let's start with format
« Reply #33 on: August 17, 2011, 09:47:57 AM »
Search google with something like 'C++ name mangling'(decorated name) for more information
But since it was compiled with VS the decorated name would be microsoft specific,
For .NET you use dumpbin.exe for PInvoke to access a funtion in ObjectArx if it is not available in .NET API
 
64bit and 32 bit will vary
 
 
http://www.theswamp.org/index.php?topic=34278.msg395750#msg395750

Jeff H

  • Needs a day job
  • Posts: 6144
Re: Extending AutoLisp - Let's start with format
« Reply #34 on: August 17, 2011, 09:54:17 AM »
A example
Quote
        [DllImport("acad.exe", EntryPoint = "?acedGetUserFavoritesDir@@YAHPA_W@Z", CharSet = CharSet.Auto)]
        public static extern bool acedGetUserFavoritesDir([MarshalAs(UnmanagedType.LPWStr)] StringBuilder sDir);

JohnK

  • Administrator
  • Seagull
  • Posts: 10605
Re: Extending AutoLisp - Let's start with format
« Reply #35 on: August 17, 2011, 02:01:28 PM »
This post will sound goofy and over simplified but hear me out and think about the first part a bit before moving on to the second part (think about the problems, moving parts, etc).

1

I have been reimagining this process.

I imagine that the "flow" may look something like this:
Call --> ARX --> Parser --> interpreter --> ARX --> Call

The parse and interpreter steps are/can be the same I suppose but what are we planning to interpret?

Symbols:
If we add the back tick (`) to AutoLisp we would need to parse it as a function with arguments and return valid AutoLisp code to be evaluated by the AutoCAD interpreter. However, I would guess this could/would/will be a problem for grey areas like variables (-i.e. variable scope).

Statements:
We could pass a statement like:
(+ 2 2)
This would just be an evaluated expression but also have to return a value.

2

All these ideas beg the question: wouldn't it be easier to create a new language to parse/interpret to std lisp code from?

-e.g.
def foo ( )
    print (+ 2 2);

generates:
(defun foo ( / )
    (princ (+ 2 2))
    )

We can have a standalone parser/interpreter which we call to generate lisp code from.


3

...Oh my head hurts! I think it's gonna explode. :)
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: Extending AutoLisp - Let's start with format
« Reply #36 on: August 18, 2011, 01:30:32 AM »
I've also had an "epiphany" this morning ... though I still need to test it. And it brings me back to that ECL thing, basically I'd incorporate the ECL interpreter into the ARX as a static library (i.e. no need to runtime linking). Then just have a command (similar to the old VBARUN, VBALoad, etc.) commands to load *.LISP / *.FASL files or input CL code direct onto the command line. Probably also create acedDefuns of each as well so they can be called directly from normal AutoLisp. Then the CL code can import the header files from the ObjectARX SDK already, which means that inside the CL code you can use the entire ObjectARX library as is (as long as you have the SDK). Perhaps if you then compile to FASL it would not need the SDK anymore, don't know if there's some other way to "incorporate" the headers without infringing on ADesk's licensing. But I can't see anything wrong with compiling it ... it's the exact same idea as compiling to ARX isn't it?

Anyhow, this would then enable us to keep the old AutoLisp/VisualLisp going as-is but have an easy link between it and the ECL interpreter/compiler. It should also then not need any RPC/other form of linking as it would be internal to the ARX and thus simply an in-process library call (no OS involvement at all). What I'd like to find out though is since CL also has the same open typed variables as AL has, would it need to convert to-and-from result buffers to communicate with AL? If not it would be worth the entire thing simply for this purpose!

I'll have to investigate though!

BTW, anyone know why VSC 2010 doesn't want to even open the 2011 ObjectARX SDK's samples? The VSC 2008 works fine though, perhaps I should just stick to that.
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: Extending AutoLisp - Let's start with format
« Reply #37 on: August 21, 2011, 02:53:22 AM »
OK, I'm having trouble with just being able to create ANYTHING as an ARX. Firstly I'm on Win7-64bit. So VC-Express 2008 is problematic in the extreme in generating a 64bit ARX. Done some research and even starting it from the WinSDK 64bit's command-line has no effect. I can't even set the environment in any of the ObjectARX SDK's samples from Win32 to x64 (even if I manually add a x64 environment in VC).

So I then installed a virtual VBox WinXP-32 and ACad2008 with VC-Exp 2005 inside that. Also installed the 32bit WinSDK, but it doesn't seem to come with the LIB files required. E.g. a build of the clones project gives an error of:
Quote
LINK : fatal error LNK1104: cannot open file 'mfc80u.lib'
Doing a file search throughout the entire C drive give's no results. So I'm guessing that it's impossible to compile ARX's with the Express VSC? Is this true? Anyone got a way of how they get at least one of the samples to compile. I've used the clones one as it's one of those shown in the autodesk wiki for compiling on Mac using XCode.

Edit: And FWIW ... why does the clone example even link to MFC? Nowhere does it use such UI elements as ribbons and such! It's just working with DWG dictionaries & command-line options isn't it?
« Last Edit: August 21, 2011, 03:28:11 AM by irneb »
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

LE3

  • Guest
Re: Extending AutoLisp - Let's start with format
« Reply #38 on: August 21, 2011, 03:34:38 PM »
^

You cannot use the Visual Studio express version to generate an ObjectARX application.

For more information about the minimum requirements for ARX go to: www.objectarx.com

HTH.-

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: Extending AutoLisp - Let's start with format
« Reply #39 on: August 21, 2011, 03:59:46 PM »
Ahh! Thanks. Good point. Silly me didn't go check all that.  :-[

Oh well, back to the drawing board I guess ... uhm, I wonder if that's prophetic  :lmao:
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

LE3

  • Guest
Re: Extending AutoLisp - Let's start with format
« Reply #40 on: August 21, 2011, 04:09:23 PM »
Ahh! Thanks. Good point. Silly me didn't go check all that.  :-[

Oh well, back to the drawing board I guess ... uhm, I wonder if that's prophetic  :lmao:

There are some options, for example if you are an student Microsoft gives the chance to download the VS pro for free (afaik) there is a site for this don't have it at this moment, or try to buy the standard version that it is cheap compared to the pro version.

HTH.-

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: Extending AutoLisp - Let's start with format
« Reply #41 on: August 21, 2011, 04:53:38 PM »
Quote
or try to buy the standard version that it is cheap compared to the pro version.

There's no more standard version for VS2010, but it seems possible to have an 'Upgrade version' from any Visual Studio product (even Express Edition or Evaluation)
Speaking English as a French Frog

LE3

  • Guest
Re: Extending AutoLisp - Let's start with format
« Reply #42 on: August 21, 2011, 05:04:12 PM »
Ahh! Thanks. Good point. Silly me didn't go check all that.  :-[

Oh well, back to the drawing board I guess ... uhm, I wonder if that's prophetic  :lmao:

Also, when you get the chance to get the VS compiler, I have posted several ARX of my own samples around here at the swamp, i.e:

http://www.theswamp.org/index.php?topic=39237.msg444541#msg444541

To mention a simple one - that can be use as a guide.

HTH.-

Jeff H

  • Needs a day job
  • Posts: 6144
Re: Extending AutoLisp - Let's start with format
« Reply #43 on: August 22, 2011, 10:17:09 AM »
Ahh! Thanks. Good point. Silly me didn't go check all that.  :-[

Oh well, back to the drawing board I guess ... uhm, I wonder if that's prophetic  :lmao:

There are some options, for example if you are an student Microsoft gives the chance to download the VS pro for free (afaik) there is a site for this don't have it at this moment, or try to buy the standard version that it is cheap compared to the pro version.

HTH.-

https://www.dreamspark.com/default.aspx

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: Extending AutoLisp - Let's start with format
« Reply #44 on: August 30, 2011, 03:10:57 PM »
Thanks, will get to those when I've got less deadlines (make those guillotines) hanging over my head.  :o   Not exactly any kind of student ... at least not in a legal sense, so will have to dock up the payment. Will have to look at what's involved in "upgrade" from express (kind of "strange" if you think about it).

Anyhow, had a "quick" look at BricsCAD on Ubuntu. Was greatly surprised that the vl functions worked perfectly. Now might that mean that ADesk's Mac version would also work with COM?
« Last Edit: August 30, 2011, 03:18:41 PM by irneb »
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.