private void Button3_Click(object sender, EventArgs e) { //Create a new drawing document. DrawingDocument oDoc = mApp.Documents.Add(DocumentTypeEnum.kDrawingDocumentObject, mApp.FileManager.GetTemplateFile(DocumentTypeEnum.kDrawingDocumentObject, SystemOfMeasureEnum.kDefaultSystemOfMeasure, DraftingStandardEnum.kDefault_DraftingStandard, null), true) as DrawingDocument; //Create a new B size sheet. Sheet oSheet = oDoc.Sheets.Add(DrawingSheetSizeEnum.kA2DrawingSheetSize, PageOrientationTypeEnum.kDefaultPageOrientation, "1", 0, 0); //Add the default border. oSheet.AddDefaultBorder(null, null, null, null, null, null, null, null, null, null, null, null, null, null); //Add ANSI A TitleBlock TitleBlock oTitleBlock = oSheet.AddTitleBlock(oDoc.TitleBlockDefinitions["ISO"], null, null); //Open the part document, invisibly. PartDocument oBlockPart = mApp.Documents.Open(@"F:\Rcadz Source Control\Inventor Api\CSharp\Drawing Document\TestPart.ipt", false) as PartDocument; TransientGeometry oTG = mApp.TransientGeometry; //Create base drawing view DrawingView oBaseView = oSheet.DrawingViews.AddBaseView(oBlockPart as _Document, oTG.CreatePoint2d(10, 10), 1, ViewOrientationTypeEnum.kFrontViewOrientation, DrawingViewStyleEnum.kHiddenLineDrawingViewStyle, "", null, null); //Create Projected views DrawingView oRightView = oSheet.DrawingViews.AddProjectedView(oBaseView, oTG.CreatePoint2d(20, 18), DrawingViewStyleEnum.kFromBaseDrawingViewStyle, null); DrawingView oIsoView = oSheet.DrawingViews.AddProjectedView(oBaseView, oTG.CreatePoint2d(10, 20), DrawingViewStyleEnum.kFromBaseDrawingViewStyle, null); //Find an edge in the part to dimension. Any method can be used, (attributes, B-Rep query, selection, etc.). This //looks through the curves in the drawing view and finds the top horizontal curve. DrawingCurve oSelectedCurve = null; foreach (DrawingCurve oCurve in oBaseView.get_DrawingCurves(null)) { //Skip Circles if (oCurve.StartPoint != null && oCurve.EndPoint != null) { if (WithinTol(oCurve.StartPoint.X, oCurve.EndPoint.X, 0.001)) { if (oSelectedCurve == null) { //This is the first horizontal curve found. oSelectedCurve = oCurve; } else { //Check to see if this curve is higher (smaller x value) than the current selected if (oCurve.MidPoint.X < oSelectedCurve.MidPoint.X) { oSelectedCurve = oCurve; } } } } } //Create geometry intents point for the curve. GeometryIntent oGeomIntent1 = oSheet.CreateGeometryIntent(oSelectedCurve, PointIntentEnum.kStartPointIntent); GeometryIntent oGeomIntent2 = oSheet.CreateGeometryIntent(oSelectedCurve, PointIntentEnum.kEndPointIntent); GeneralDimensions oGeneralDimensions = oSheet.DrawingDimensions.GeneralDimensions; Point2d oDimPos = oTG.CreatePoint2d(oSelectedCurve.MidPoint.X - 2, oSelectedCurve.MidPoint.Y); DimensionStyle dimstyle = oDoc.StylesManager.DimensionStyles["Default (ISO)"]; Layer layer = oDoc.StylesManager.Layers["Dimension (ISO)"]; //Create the dimension. LinearGeneralDimension oLinearDim; oLinearDim = oGeneralDimensions.AddLinear(oDimPos, oGeomIntent1, oGeomIntent2, DimensionTypeEnum.kAlignedDimensionType, true, dimstyle, layer); }
private void DrawPartDoc(string filename) { DrawingDocument oDoc; Sheet oSheet; ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// SetupNewDrawingDocument(out oDoc, out oSheet); ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //Open the part document, invisibly. PartDocument oBlockPart = mApp.Documents.Open(filename, false) as PartDocument; TransientGeometry oTG = mApp.TransientGeometry; //0.1 = 1:10 or 0.2 = 1:5 1:20=0.02 X-> Y ^ DrawingView oBaseView = oSheet.DrawingViews.AddBaseView(oBlockPart as _Document, oTG.CreatePoint2d(28.7, 21), 0.1, ViewOrientationTypeEnum.kFrontViewOrientation, DrawingViewStyleEnum.kHiddenLineDrawingViewStyle, "", null, null); //59.4 x 42.0 29.7 X 21.0 DrawingView oTopView = oSheet.DrawingViews.AddProjectedView(oBaseView, oTG.CreatePoint2d(28.7, 29), DrawingViewStyleEnum.kFromBaseDrawingViewStyle, null); //Projected views DrawingView oRightView = oSheet.DrawingViews.AddProjectedView(oBaseView, oTG.CreatePoint2d(45, 21), DrawingViewStyleEnum.kFromBaseDrawingViewStyle, null); //look through the curves in view finds top horiz curve. Find an edge oSheet.RevisionTables.Add(oTG.CreatePoint2d(48.4, 23.5)); //1mm div 10//1 row = 4 DrawingCurve oSelectedCurve = null; foreach (DrawingCurve oCurve in oBaseView.get_DrawingCurves(null)) { //Skip Circles if (oCurve.StartPoint != null && oCurve.EndPoint != null) { if (WithinTol(oCurve.StartPoint.Y, oCurve.EndPoint.Y, 0.001)) { if (oSelectedCurve == null) { //This is the first horizontal curve found. oSelectedCurve = oCurve; } else { //Check to see if this curve is higher (smaller x value) than the current selected if (oCurve.MidPoint.Y < oSelectedCurve.MidPoint.X) { oSelectedCurve = oCurve; } } } } } //Create geometry intents point for the curve. GeometryIntent oGeomIntent1 = oSheet.CreateGeometryIntent(oSelectedCurve, PointIntentEnum.kStartPointIntent); GeometryIntent oGeomIntent2 = oSheet.CreateGeometryIntent(oSelectedCurve, PointIntentEnum.kEndPointIntent); Point2d oDimPos = oTG.CreatePoint2d(oSelectedCurve.MidPoint.X - 2, oSelectedCurve.MidPoint.Y); //set up Dim GeneralDimensions oGeneralDimensions = oSheet.DrawingDimensions.GeneralDimensions; //Styles sty = oDoc.StylesManager.Styles ; // DimensionStyle dimstyle = oDoc.StylesManager.DimensionStyles["Drax Dim Above"]; //MessageBox.Show(cmbDimStyles.Text); DimensionStyle dimstyle = oDoc.StylesManager.DimensionStyles[cmbDimStyles.Text]; //Set Layer //Layer layer = oDoc.StylesManager.Layers["D"]; //MessageBox.Show(cmbLayers.Text); Layer layer = oDoc.StylesManager.Layers[cmbLayers.Text]; //Create the dimension. LinearGeneralDimension oLinearDim; oLinearDim = oGeneralDimensions.AddLinear(oDimPos, oGeomIntent1, oGeomIntent2, DimensionTypeEnum.kAlignedDimensionType, true, dimstyle, layer); string newfilename; string swapfilename; newfilename = ""; swapfilename = ""; //Build New Filname Inventor.PropertySet InvPropertySet = oBlockPart.PropertySets["{D5CDD505-2E9C-101B-9397-08002B2CF9AE}"]; swapfilename = oBlockPart.FullFileName.Substring(0, oBlockPart.FullFileName.LastIndexOf("\\") + 1); //MessageBox.Show(swapfilename); newfilename = swapfilename + InvPropertySet["FULLFILENAME"].Value + ".idw"; oBlockPart.Close(true); oDoc.SaveAs(newfilename, true); oDoc.Close(true); }