Click here to Skip to main content
15,893,487 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a requirement such that I have to place two base views of assemblies(.iam) on a template file(.idw). The first assembly view should be on the top half and the other should be on the lower half of the template. I am able to place views but I am not sure how to get the center point of the template(.idw). I tried following the code given in
The code I am writing is

C#
string pth = folderpath + "\\" +comboBox1.SelectedItem;  
                NameValueMap oMap = oApp.TransientObjects.CreateNameValueMap();                
                DrawingDocument oDrawDoc =(DrawingDocument)oApp.Documents.Add(DocumentTypeEnum.kDrawingDocumentObject,pth);
                oDrawDoc = (DrawingDocument)oApp.ActiveDocument;
                Sheet oSheet = (Sheet)oDrawDoc.ActiveSheet;                
                //DrawingView dv = default(DrawingView);
                //dv = (DrawingView)oSheet.DrawingViews;
                Point2d oCenter = oApp.TransientGeometry.CreatePoint2d(10.0,10.0);
                //Point2d oCenter = (Point2d)dv.Center;
                //Point2d oPlacementPoint1 = oApp.TransientGeometry.CreatePoint2d(oCenter.X - 1, oCenter.Y);
                //Point2d oPlacementPoint2 = oApp.TransientGeometry.CreatePoint2d(oCenter.X + 1, oCenter.Y);
                Point2d oPlacementPoint1 = oApp.TransientGeometry.CreatePoint2d(4.0,20.0);
                Point2d oPlacementPoint2 = oApp.TransientGeometry.CreatePoint2d(oCenter.X, oCenter.Y);
                ViewScale1 = 1.0;
                ViewScale2 = 1.0;
                ViewOrientationTypeEnum ViewOrientation1 = ViewOrientationTypeEnum.kLeftViewOrientation;
                ViewOrientationTypeEnum ViewOrientation2 = ViewOrientationTypeEnum.kRightViewOrientation;
                DrawingViewStyleEnum ViewStyle1 = DrawingViewStyleEnum.kHiddenLineDrawingViewStyle;
                DrawingViewStyleEnum ViewStyle2 = DrawingViewStyleEnum.kShadedDrawingViewStyle;
                AssemblyDocument oAssDoc =(AssemblyDocument)oApp.Documents.Open(textBox1.Text,false);
                AssemblyDocument oAssDoc2 = (AssemblyDocument)oApp.Documents.Open(textBox2.Text, false);                
                DrawingView oView=oSheet.DrawingViews.AddBaseView((_Document)oAssDoc,oPlacementPoint1,ViewScale1,ViewOrientation1,ViewStyle1);
                DrawingView oView2 = oSheet.DrawingViews.AddBaseView((_Document)oAssDoc2, oPlacementPoint2, ViewScale2, ViewOrientation2, ViewStyle2);
                oAssDoc.Close();
                oAssDoc2.Close();


The problem I am facing is on the line
C#
//DrawingView dv = default(DrawingView);
                //dv = (DrawingView)oSheet.DrawingViews;


It throws an exception cannot cast a _COM to Inventor.DrawingView. Any idea how to get the center points of the template??

Any help is appreciated. Thanks in advance
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900