[IronPython] Problems translating from C#

Aravin avinhan at gmail.com
Fri Mar 5 04:53:05 CET 2010


Hi Dave,

In your code you are declaring designSession as an interface of
IADDesignSession:
IADDesignSession designSession;

The line, designSession = (IADDesignSession)objSession; , is simply casting
objSession into the interface IADDesignSession so that in C# you can access
its members, given that objSession implements that interface. Since python
is a dynamic language, you dont need to cast objects to access their
members. So you can even do this, if your sure objSession indeed implements
the IADDesignSession interface.

designProps = objSession.PhysicalProperties(ADAccuracySetting.AD_HIGH);

I believe that since PhysicalProperties is a function defined in
IADDesignSession interface, you might be able to call it like this too,

from <yourlib> import IADDesignSession
designProps = IADDesignSession.PhysicalProperties(objSession,
ADAccuracySetting.AD_HIGH);

hope this helps.

Aravin

On Fri, Mar 5, 2010 at 11:17 AM, David Nichols <seawolf2913 at gmail.com>wrote:

> Hi Everyone-
> I've used Python for a while and I understand the basic concepts of OOP,
> but I'm new to .NET and C#.  I'm trying to automate a 3D CAD package called
> Alibre so I can generate 300+ assemblies and export them to an industry
> standard format. I've been looking through their C# sample code for two days
> now and I understand most of it, I can translate a good portion of it,
> (IronPython in Action arrived three days ago :), but there is on line in
> particular that I can't figure out.
>
> Here's a snippet of the C# example file.  I can post the whole thing if
> needed.  //# starts comments I've added in.
>  .....
> using AlibreX
> .....
>  private void btnBrowse_Click(object sender, EventArgs e)
>         {
>             IADSession objSession;                //Holds Alibre Session
> Object
>             IADDesignSession designSession;       //Holds Alibre Design
> Session object
>             IADPhysicalProperties designProps;    //Holds Physical
> Properties object
> .....
>             OpenFileDialog ofd = new OpenFileDialog();  //# Opens a dialog
> box so you can enter the name of an existing part file.
>             ofd.Title = "Select File";
>             ofd.Filter = "Alibre Part|*.AD_PRT";
>
>             if (ofd.ShowDialog() == DialogResult.OK)
>             {
>                 txtFilePath.Text = ofd.FileName;
>
>                 if (rootObj == null)  //# rootObj is the Root Object for
> controlling Alibre Design
>                 {
>                     OpenAlibre();  //Call to method which checks to see if
> there is running instance of Alibre Design
>                                          //# This method, defined further
> down in the file, attaches to a running instance of the program, or starts a
> new instance.
>                                         //# In  either case, rootObj is
> created and attached to it.
>                 }
>                 objSession = rootObj.OpenFile(txtFilePath.Text);  //#
> Creates an instance of IADSession from the rootObj
>
>                 if (objSession.SessionType == ADObjectSubType.AD_PART)  //#
> As long as the Session is attached to a part...
>                 {
>                     //# THIS IS THE LINE I CAN'T TRANSLATE!!!
>                     designSession =
> (IADDesignSession)objSession;               //Set Design Session Object to
> be the Session you opened
>                    //# I think it's creating an instance of
> IADDesignSession based on the objSession (see code line below) and I can't
> figure out how to do it.
>                    //# designSession = objSession obviously leaves me two
> references to the same Session Object.
>                    //# I've done dir(objSession) and I don't see a method
> to create a DesignSession instance.
>                    //# Any ideas??
>
>                     designProps =
> designSession.PhysicalProperties(ADAccuracySetting.AD_HIGH);    //Set Design
> Properties object with the Physical Properties of the Part
>
> .....
>
> Thanks in Advance
> Dave
>
>
> _______________________________________________
> 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/20100305/571caa0e/attachment.html>


More information about the Ironpython-users mailing list