Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

implementing Apprentice ClientView in c#

10 REPLIES 10
Reply
Message 1 of 11
Anonymous
3829 Views, 10 Replies

implementing Apprentice ClientView in c#

I am trying to implement the Apprentice ClientView example in the Inventor API help file.  The code is given in Basic and I am using C# and I'm running into some problems. I think the issue is in the Form1_Load procedure in the line that sets the oClientView variable. I wasn't sure how to convert this to C#. Note that the original Basic code is in comments below the C# code.  When I run the program the oClientView.Camera object throws an exception.

 

public partial class Form1 : Form
    {
        ApprenticeServerComponent oSvr = new ApprenticeServerComponent();
        ApprenticeServerDocument oAppDoc;
        ClientView oClientView;

        public Form1()
        {
            InitializeComponent();
        }

        private void pictureBox1_Click(object sender, EventArgs e)
        {
            Camera oCamera = oClientView.Camera;
            oCamera.ViewOrientationType = ViewOrientationTypeEnum.kIsoBottomLeftViewOrientation;
            oCamera.Perspective = true;
            oCamera.Apply();
            this.Refresh();
            //Dim oCamera As Camera
            //Set oCamera = oClientView.Camera
            //oCamera.ViewOrientationType = kIsoBottomLeftViewOrientation
            //oCamera.Perspective = True
            //oCamera.Apply
            //Me.Refresh
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            string fileName = @"C:\Vault Workspace\Designs\Main\Blades\SB4000\Parts SBCT - 001-040.idw";
            ApprenticeServerComponent oSvr = new ApprenticeServerComponent();
            oAppDoc = oSvr.Open(fileName);
            oClientView = oAppDoc.ClientViews.Add(pictureBox1.Handle.ToInt32());
            //Dim filename As String
            //filename = "C:\Autodesk\Inventor 10\Tutorial Files\analyze-2.iam"
            //Set oSvr = New ApprenticeServerComponent
            //Set oAppDoc = oSvr.Open(filename)
            //Set oClientView = oAppDoc.ClientViews.Add(Picture1.hWnd)
        }

        private void Form1_Paint(object sender, PaintEventArgs e)
        {
            oClientView.Update(false);
        }

 

10 REPLIES 10
Message 2 of 11
ekinsb
in reply to: Anonymous

I think the problem is that you've declared and are creating an instance of Apprentice in two places.  You create one as a member variable of the class and also one with the form load event.  You can completely remove the declaration from the form load event since you're declaring and creating the Apprentice instance when the form is created.


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
Message 3 of 11
Anonymous
in reply to: ekinsb

Yes, I should have caught that too.  All the objects seem to initialize properly now, but nothing shows up in the picturebox.  I have attached my files if you could look at it would be appreciated.  Thanks a lot for your help!

Message 4 of 11
ekinsb
in reply to: Anonymous

Attached is a test I put together.  It uses the mouse to allow you to rotate, zoom, and pan the view.  Depending on which mouse button is down you'll get one of the behaviors.  For drawings, you'll want the perspecitve to be false and you won't want to support rotating.

 


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
Message 5 of 11
Anonymous
in reply to: Anonymous

Thanks a lot, that is very helpful.

Message 6 of 11
Anonymous
in reply to: Anonymous

I have added a bit more code now to support idws and also to browse for files to open.  However I am running into the same problem I had earlier that you submitted the change request for.  As soon as I try to open the second file, the program crashes. If I re-open the first file, everything's ok.

 

How soon can we expect to see a fix for this?  Is there any way we can work around it in the meantime?

 

Thanks again for your help.

 

Lorne

Message 7 of 11
ekinsb
in reply to: Anonymous

We're investigating a potential problem.  One question that will help is, are you using Apprentice through an Inventor View or an Inventor install?


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
Message 8 of 11
Anonymous
in reply to: ekinsb

I am using Inventor view only. The machine with this issue does not have a full Inventor install. Sent from my Blackberry
Message 9 of 11
Anonymous
in reply to: ekinsb

The project that you added is working with Windows XP (x64) withAutodesk Inventor 2010.

But unfortunetely, dialog box become closed in Windows 7 (x64) with Autodesk Inventor 2013.
As I determined, dialog box become closed when it comes to the line  

 

" oClientView = oAppDoc.ClientViews.Add(pictureBox1.Handle.ToInt32()); " .


Could you please help me about the solution of this issue.

Thank you.

Message 10 of 11
xiaodong_liang
in reply to: Anonymous

Hi,

 

the code in message 4 Brian shared works well at my side (Inventor 2013 +SP1). Inventor View did had some issues. We have a SP1.1 . I cannot confirm if the problem you saw is relevant, but could you try with SP if it helps?

 

http://usa.autodesk.com/adsk/servlet/pc/item?siteID=123112&id=20462274

Message 11 of 11
Anonymous
in reply to: xiaodong_liang

I tried with SP1.1 and problem is solved.

 

Thank you.

 

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report