[IronPython] Embedding Question

Tim Riley riltim at gmail.com
Thu Aug 10 22:02:13 CEST 2006


Thanks Dino. I had figured that out.

On 8/10/06, Dino Viehland <dinov at exchange.microsoft.com> wrote:
>
>  Cool, looks like I was only close though J You may have already imported
> clr into the default module, but just for the record for those who haven't
> you'll need an import clr there.  I just realized I forgot it the 1sttime, and I had a redundant "AddReference" in the delegate call.   I'm
> assuming you just fixed all that up, but just in case anyone else needs to
> do something like this, here's the correct code:
>
>
>
> delegate void AddReference(object assembly);
>
> AddReference adr = engine.CreateMethod<AddReference>("import
> clr\nclr.AddReference(assembly)");
>
> adr(typeof(SomeAutoCadType).Assembly);
>
>
>
>
>
> *From:* users-bounces at lists.ironpython.com [mailto:
> users-bounces at lists.ironpython.com] *On Behalf Of *Tim Riley
> *Sent:* Thursday, August 10, 2006 12:10 PM
>
> *To:* Discussion of IronPython
> *Subject:* Re: [IronPython] Embedding Question
>
>
>
> That's exactly what I needed. Thank you Dino.
>
> On 8/10/06, *Dino Viehland* <dinov at exchange.microsoft.com > wrote:
>
> You can get the assembly object from an AutoCAD type:
> typeof(Foo).Assembly.  From there you just need to have one helper which
> will register this in the engine, so you could do:
>
>
>
> delegate void AddReference(object assembly);
>
> AddReference adr = engine.CreateMethod<AddReference>("clr.AddReference
> (assembly)");
>
> adr.AddReference(typeof(SomeAutoCadType).Assembly);
>
>
>
> and then from there you should be able to import any of the AutoCAD
> namespaces from any of your modules.
>
>
>
> *From:* users-bounces at lists.ironpython.com [mailto:
> users-bounces at lists.ironpython.com] *On Behalf Of *Tim Riley
> *Sent:* Thursday, August 10, 2006 11:40 AM
> *To:* Discussion of IronPython
> *Subject:* Re: [IronPython] Embedding Question
>
>
>
> What I'm trying to do is sort of weird so let me see if I can elaborate
> further. I am embedding IronPython in a .NET assembly that will later be
> loaded into AutoCAD. AutoCAD has their own two .NET assemblies that must be
> referenced, " acmgd.dll" and "acdbmgd.dll". These two assemblies are
> always loaded while AutoCAD is running so their location isn't really a
> concern when creating a C# .dll. However when I want to modify AutoCAD
> entities from within my IP scripts I must first load the assemblies from
> file and path which is a problem because the file and path are different
> with each different version of AutoCAD.
>
> For example their path in my AutoCAD Mechanical 2005 is 'C:\Program
> Files\Autodesk\Acadm 2005' but with regular AutoCAD it would be 'C:\Program
> Files\Autodesk\Acad 2005'. There are so many different variations that this
> path could be that it would be a big deal to try/except load them all from
> some sort of init script.
>
> So basically I'm looking to pass a non-GAC assembly reference from my C#
> project to my IP project.
>
>
> Note: I'm fine with the import statements.
>
> On 8/10/06, *Dino Viehland* <dinov at exchange.microsoft.com> wrote:
>
> Adding references updates the entire engine, it's not local to just the
> current module.  So once you have added a reference you just need to import
> the namespace into any given module.
>
>
>
> Were you also trying to avoid the import statements?
>
>
>
> *From:* users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com]
> *On Behalf Of *Tim Riley
> *Sent:* Thursday, August 10, 2006 11:02 AM
> *To:* Discussion of IronPython
> *Subject:* [IronPython] Embedding Question
>
>
>
> If I have an embedded project can I automatically make .NET assemblies
> referenced in the project available to my python scripts? For example I have
> two assemblies(not in the GAC) that I have referenced in my project. I would
> like them always available to all python files run from this program without
> having to do the import clr, clr.AddReferenceToFileAndPath('blah') stuff
> in the beginning of each file. Is this possible?
>
>
> Regards,
> Tim Riley
>
>
> _______________________________________________
> users mailing list
> users at lists.ironpython.com
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>
>
>
>
> _______________________________________________
> users mailing list
> users at lists.ironpython.com
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>
>
>
> _______________________________________________
> users mailing list
> users at lists.ironpython.com
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ironpython-users/attachments/20060810/a4cf62c8/attachment.html>


More information about the Ironpython-users mailing list