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); }
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.
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!
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.
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
We're investigating a potential problem. One question that will help is, are you using Apprentice through an Inventor View or an Inventor install?
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.
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
Can't find what you're looking for? Ask the community or share your knowledge.