private static bool CreateRectangle(DataRow iRow, Sheet iSheet, DrawingSketch iSketch, TransientGeometry tg) { bool isRectangleCreated = false; try { string tempCoord = iRow.ItemArray[4].ToString(); string[] coord = tempCoord.Split(','); Double initX = Double.Parse(coord[0]); Double initY = Double.Parse(coord[1]); Double height = Double.Parse(iRow.ItemArray[1].ToString()); Double width = Double.Parse(iRow.ItemArray[2].ToString()); iSketch.Edit(); Point2d pt1 = tg.CreatePoint2d(initX, initY); Point2d pt2 = tg.CreatePoint2d(initX + width, initY); Point2d pt3 = tg.CreatePoint2d(initX + width, initY + height); Point2d pt4 = tg.CreatePoint2d(initX, initY + height); SketchLine l1 = iSketch.SketchLines.AddByTwoPoints(pt1, pt2); SketchLine l2 = iSketch.SketchLines.AddByTwoPoints(pt2, pt3); iSketch.SketchLines.AddByTwoPoints(pt3, pt4); iSketch.SketchLines.AddByTwoPoints(pt4, pt1); iSketch.ExitEdit(); GeometryIntent oGeo1 = iSheet.CreateGeometryIntent(l1, null); GeometryIntent oGeo2 = iSheet.CreateGeometryIntent(l2, null); LinearGeneralDimension iDim = iSheet.DrawingDimensions.GeneralDimensions.AddLinear(pt1, oGeo1); DimensionStyle iStyle = iDim.Style; iStyle.PartOffset = 45.0; iStyle.ShowDimensionLine = true; iSheet.DrawingDimensions.GeneralDimensions.AddLinear(pt2, oGeo2).Style = iStyle; isRectangleCreated = true; } catch (Exception e) { Console.WriteLine(e.Message); } return(isRectangleCreated); }
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); }
/// <summary> /// creation of hole tables in a drawing. /// Select a drawing view that contains holes and run the following sample /// </summary> /// <remarks></remarks> public void CreateHoleTables() { // Set a reference to the drawing document. // This assumes a drawing document is active. DrawingDocument oDrawDoc = (DrawingDocument)_InvApplication.ActiveDocument; // Set a reference to the active sheet. Sheet oActiveSheet = oDrawDoc.ActiveSheet; // Set a reference to the drawing view. // This assumes that a drawing view is selected. DrawingView oDrawingView = oDrawDoc.SelectSet[1]; // Create origin indicator if it has not been already created. if (!oDrawingView.HasOriginIndicator) { // Create point intent to anchor the origin to. GeometryIntent oDimIntent = null; Point2d oPointIntent = null; // Get the first curve on the view DrawingCurve oCurve = oDrawingView.get_DrawingCurves()[1]; // Check if it has a strt point oPointIntent = oCurve.StartPoint; if (oPointIntent == null) { // Else use the center point oPointIntent = oCurve.CenterPoint; } oDimIntent = oActiveSheet.CreateGeometryIntent(oCurve, oPointIntent); oDrawingView.CreateOriginIndicator(oDimIntent); } Point2d oPlacementPoint = null; // Set a reference to th sheet's border Inventor.Border oBorder = oActiveSheet.Border; if ((oBorder != null)) { // A border exists. The placement point // is the top-left corner of the border. oPlacementPoint = _InvApplication.TransientGeometry.CreatePoint2d(oBorder.RangeBox.MinPoint.X, oBorder.RangeBox.MaxPoint.Y); } else { // There is no border. The placement point // is the top-left corner of the sheet. oPlacementPoint = _InvApplication.TransientGeometry.CreatePoint2d(0, oActiveSheet.Height); } // Create a 'view' hole table // This hole table includes all holes as specified by the active hole table style HoleTable oViewHoleTable = default(HoleTable); oViewHoleTable = oActiveSheet.HoleTables.Add(oDrawingView, oPlacementPoint); oPlacementPoint.X = oActiveSheet.Width / 2; // Create a 'feature type' hole table // This hole table includes specified hole types only HoleTable oFeatureHoleTable = oActiveSheet.HoleTables.AddByFeatureType(oDrawingView, oPlacementPoint, true, true, true, true, false, false, false); //add a new row // get the model document Document oModelDoc = oDrawingView.ReferencedDocumentDescriptor.ReferencedDocument; HoleFeature oHoleF = null; if (oModelDoc.DocumentType == DocumentTypeEnum.kAssemblyDocumentObject) { AssemblyDocument oRefAssDoc = (AssemblyDocument)oModelDoc; AssemblyComponentDefinition oAssDef = oRefAssDoc.ComponentDefinition; if (oAssDef.Features.HoleFeatures.Count > 0) { //as a demo: get the first hole feature oHoleF = oAssDef.Features.HoleFeatures[1]; } } else if (oModelDoc.DocumentType == DocumentTypeEnum.kPartDocumentObject) { PartDocument oRefPartDoc = (PartDocument)oModelDoc; PartComponentDefinition oPartDef = oRefPartDoc.ComponentDefinition; if (oPartDef.Features.HoleFeatures.Count > 0) { //as a demo: get the first hole feature oHoleF = oPartDef.Features.HoleFeatures[1]; } } // add a new row to the hole table if ((oHoleF != null)) { DrawingCurvesEnumerator oHoleCurves = oDrawingView.get_DrawingCurves(oHoleF); if (oHoleCurves.Count > 0) { oFeatureHoleTable.HoleTableRows.Add(oHoleCurves[1]); } } }
/// <summary> /// creation of a balloon. Select a linear drawing curve and run the sample /// </summary> /// <remarks></remarks> public void CreateBalloon() { // Set a reference to the drawing document. // This assumes a drawing document is active. DrawingDocument oDrawDoc = (DrawingDocument)_InvApplication.ActiveDocument; // Set a reference to the active sheet. Sheet oActiveSheet = oDrawDoc.ActiveSheet; // Set a reference to the drawing curve segment. // This assumes that a drwaing curve is selected. DrawingCurveSegment oDrawingCurveSegment = oDrawDoc.SelectSet[1]; // Set a reference to the drawing curve. DrawingCurve oDrawingCurve = oDrawingCurveSegment.Parent; // Get the mid point of the selected curve // assuming that the selection curve is linear Point2d oMidPoint = oDrawingCurve.MidPoint; // Set a reference to the TransientGeometry object. TransientGeometry oTG = _InvApplication.TransientGeometry; ObjectCollection oLeaderPoints = _InvApplication.TransientObjects.CreateObjectCollection(); // Create a couple of leader points. oLeaderPoints.Add(oTG.CreatePoint2d(oMidPoint.X + 10, oMidPoint.Y + 10)); oLeaderPoints.Add(oTG.CreatePoint2d(oMidPoint.X + 10, oMidPoint.Y + 5)); // Add the GeometryIntent to the leader points collection. // This is the geometry that the balloon will attach to. GeometryIntent oGeometryIntent = oActiveSheet.CreateGeometryIntent(oDrawingCurve); oLeaderPoints.Add(oGeometryIntent); // Set a reference to the parent drawing view of the selected curve DrawingView oDrawingView = oDrawingCurve.Parent; // Set a reference to the referenced model document Document oModelDoc = oDrawingView.ReferencedDocumentDescriptor.ReferencedDocument; // Check if a partslist or a balloon has already been created for this model bool IsDrawingBOMDefined = false; IsDrawingBOMDefined = oDrawDoc.DrawingBOMs.IsDrawingBOMDefined(oModelDoc.FullFileName); Balloon oBalloon = null; if (IsDrawingBOMDefined) { // Just create the balloon with the leader points // All other arguments can be ignored oBalloon = oDrawDoc.ActiveSheet.Balloons.Add(oLeaderPoints); } else { // First check if the 'structured' BOM view has been enabled in the model // Set a reference to the model's BOM object AssemblyDocument oAssDoc = (AssemblyDocument)oModelDoc; AssemblyComponentDefinition oComDef = oAssDoc.ComponentDefinition; BOM oBOM = oComDef.BOM; if (oBOM.StructuredViewEnabled) { // Level needs to be specified // Numbering options have already been defined // Get the Level ('All levels' or 'First level only') // from the model BOM view - must use the same here PartsListLevelEnum Level = default(PartsListLevelEnum); if (oBOM.StructuredViewFirstLevelOnly) { Level = PartsListLevelEnum.kStructured; } else { Level = PartsListLevelEnum.kStructuredAllLevels; } // Create the balloon by specifying just the level oBalloon = oActiveSheet.Balloons.Add(oLeaderPoints, null, Level); } else { // Level and numbering options must be specified // The corresponding model BOM view will automatically be enabled NameValueMap oNumberingScheme = _InvApplication.TransientObjects.CreateNameValueMap(); // Add the option for a comma delimiter oNumberingScheme.Add("Delimiter", ","); // Create the balloon by specifying the level and numbering scheme oBalloon = oActiveSheet.Balloons.Add(oLeaderPoints, null, PartsListLevelEnum.kStructuredAllLevels, oNumberingScheme); } } }
private dynamic GetNormDirFromGeometry(GeometryIntent intent) { try { return(GetNormDir(intent.Geometry)); } catch {} try { return(GetNormDir(intent.Geometry.Geometry)); } catch {} throw new Exception(); }
public void AssemblyJoint() { #region inventor öffnen Application inventorApp = null; Document inventordoc = null; // Enable error handling. try { // Try to connect to a running instance of Inventor. inventorApp = (Application)Marshal.GetActiveObject("Inventor.Application"); } catch (Exception ex) { // Connecting to a running instance failed so try to start Inventor. try { inventorApp = (Application)Activator.CreateInstance(Type.GetTypeFromProgID("Inventor.Application"), true); inventorApp.Visible = true; } catch (Exception ex2) { // Unable to start Inventor. Console.WriteLine("Unable to connect to or start Inventor."); return; } } //System.Threading.Thread.Sleep(5000); //inventordoc = inventorApp.Documents.Add(Inventor.DocumentTypeEnum.kPartDocumentObject, "C:\\Users\\Public\\Documents\\Autodesk\\Inventor 2017\\Templates\\English\\Sheet Metal (in).ipt", true); #endregion #region Create a new assembly document. AssemblyDocument asmDoc = (AssemblyDocument)inventorApp.Documents.Add (DocumentTypeEnum.kAssemblyDocumentObject, inventorApp.FileManager.GetTemplateFile (DocumentTypeEnum.kAssemblyDocumentObject)); AssemblyComponentDefinition asmDef = asmDoc.ComponentDefinition; Matrix trans = inventorApp.TransientGeometry.CreateMatrix(); #endregion #region die Bauelemente // Place an occurrence into the assembly. ComponentOccurrence occ1 = asmDef.Occurrences.Add ("Pfad or element like c\\:...", trans); // Place a second occurrence with the matrix //adjusted so it fits correctly with the //first occurrence. trans.Cell[1, 4] = 6 * 2.54; ComponentOccurrence occ2 = asmDef.Occurrences.Add ("Pfad or element like c\\:...", trans); #endregion // Get Face 1 from occ1 and // create a FaceProxy. Face face1 = (Face)GetNamedEntity(occ1, "Face1"); // Get Face 2 from occ2 and // create a FaceProxy. Face face2 = (Face)GetNamedEntity(occ2, "Face2"); // Get Edge 1 from occ2 and // create an EdgeProxy. Edge Edge1 = (Edge)GetNamedEntity(occ2, "Edge1"); // Get Edge 3 from occ1 and // create an EdgeProxy. Edge Edge3 = (Edge)GetNamedEntity(occ1, "Edge3"); // Create an intent to the // center of Edge1. GeometryIntent edge1Intent = asmDef.CreateGeometryIntent (Edge1, PointIntentEnum.kMidPointIntent); // Create an intent to the center of Edge3. GeometryIntent edge3Intent = asmDef.CreateGeometryIntent (Edge3, PointIntentEnum.kMidPointIntent); // Create two intents to define // the geometry for the joint. GeometryIntent intentOne = asmDef.CreateGeometryIntent (face2, edge1Intent); GeometryIntent intentTwo = asmDef.CreateGeometryIntent (face1, edge3Intent); // Create a rotation joint between the two parts. AssemblyJointDefinition jointDef = asmDef.Joints.CreateAssemblyJointDefinition (AssemblyJointTypeEnum.kRotationalJointType, intentOne, intentTwo); jointDef.FlipAlignmentDirection = false; jointDef.FlipOriginDirection = true; AssemblyJoint joint = asmDef.Joints.Add(jointDef); // Make the joint visible. joint.Visible = true; // Drive the joint to animate it. joint.DriveSettings.StartValue = "0 deg"; joint.DriveSettings.EndValue = "180 deg"; joint.DriveSettings.GoToStart(); joint.DriveSettings.PlayForward(); joint.DriveSettings.PlayReverse(); }
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); }
private static void GetDrawingDimension() { try { inventorApp = (Inventor.Application)Marshal.GetActiveObject("Inventor.Application"); Console.WriteLine("查找到可用的实例"); } catch { Console.WriteLine("未打开Inventor"); return; } DrawingDocument drawingDocument = (DrawingDocument)inventorApp.ActiveDocument; //在Inventor当前正在显示的工程图不一样的时候,ActiveSheet也会发生变化 Console.WriteLine("打开的图纸:" + drawingDocument.ActiveSheet.Name + " " + drawingDocument.FullFileName); DrawingView drawingView = drawingDocument.ActiveSheet.DrawingViews[1]; //特别注明:该类及其方法仅针对模型和草图文件 GeneralDimensionsEnumerator generalDimensionsEnumerator = drawingDocument.ActiveSheet.DrawingDimensions.GeneralDimensions.Retrieve(drawingView); Console.WriteLine("generalDimensionsEnumerator.Count = " + generalDimensionsEnumerator.Count); if (generalDimensionsEnumerator.Count != 0) { for (int i = 1; i <= generalDimensionsEnumerator.Count; i++) { Console.WriteLine(generalDimensionsEnumerator[i].Text); } } //////////////////////////////////////////////////////////////////////////////////////////////////////// BaselineDimensionSets baselineDimensionSets = drawingDocument.ActiveSheet.DrawingDimensions.BaselineDimensionSets; Console.WriteLine("baselineDimensionSets.Count = " + baselineDimensionSets.Count); if (baselineDimensionSets.Count != 0) { for (int i = 1; i <= baselineDimensionSets.Count; i++) { BaselineDimensionSet baselineDimensionSet = baselineDimensionSets[i]; Console.WriteLine("baselineDimensionSet.Members = " + baselineDimensionSet.Members); Console.WriteLine("baselineDimensionSet.DimensionType" + baselineDimensionSet.DimensionType); } } //////////////////////////////////////////////////////////////////////////////////////////////////////// Balloons ballons = drawingDocument.ActiveSheet.Balloons; Console.WriteLine("ballons.Count = " + ballons.Count); Balloon balloon = null; if (ballons.Count != 0) { for (int i = 1; i <= ballons.Count; i++) { Console.WriteLine("\n------------------------ballons[" + i + "]------------------------"); balloon = ballons[i]; //Console.WriteLine("balloon.Leader.RootNode = " + balloon.Leader.RootNode); //打印出 System.__ComObject //Console.WriteLine("balloon.Position = " + balloon.Position); //打印出 System.__ComObject AttributeSets attributeSets = balloon.AttributeSets; Console.WriteLine("attributeSets.Count = " + attributeSets.Count); for (int j = 1; j <= attributeSets.Count; j++) { AttributeSet attributeSet = attributeSets[j]; Console.WriteLine("attributeSet.Name = " + attributeSet.Name); } BalloonValueSets balloonValueSets = balloon.BalloonValueSets; for (int j = 1; j <= balloonValueSets.Count; j++) { BalloonValueSet balloonValueSet = balloonValueSets[j]; Console.WriteLine("balloonValueSet.ItemNumber = " + balloonValueSet.ItemNumber); Console.WriteLine("balloonValueSet.Value = " + balloonValueSet.Value); Console.WriteLine("balloonValueSet.OverrideValue = " + balloonValueSet.OverrideValue); //Console.WriteLine("balloonValueSet.ReferencedFiles = " + balloonValueSet.ReferencedFiles); Console.WriteLine("balloonValueSet.Type = " + balloonValueSet.Type); } Leader leader = balloon.Leader; Console.WriteLine("leader.ArrowheadType = " + leader.ArrowheadType); Console.WriteLine("leader.Type = " + leader.Type); AttributeSets attributeSets_leader = leader.AttributeSets; Console.WriteLine("attributeSets_leader.Count = " + attributeSets_leader.Count); for (int j = 0; j < attributeSets_leader.Count; j++) { AttributeSet attributeSet = attributeSets[j]; Console.WriteLine("attributeSet_leader.Name = " + attributeSet.Name); } Console.WriteLine("END------------------------ballons[" + i + "]------------------------\n"); } } //////////////////////////////////////////////////////////////////////////////////////////////////////// //DrawingViews views = drawingDocument.ActiveSheet.DrawingViews; //Console.WriteLine("views.count = " + views.Count); Console.WriteLine("drawingDocument.SelectSet.Count = " + drawingDocument.SelectSet.Count); SelectSet selectSet = null; DrawingCurveSegment drawingCurveSegment = null; if (drawingDocument.SelectSet.Count == 0) { Console.WriteLine("Select a drawing view"); DrawingView view = inventorApp.CommandManager.Pick(SelectionFilterEnum.kDrawingViewFilter, "Select a drawing view"); //selectSet = inventorApp.CommandManager.Pick(SelectionFilterEnum.kDrawingSheetFilter, "Select drawing sheet!"); drawingCurveSegment = inventorApp.CommandManager.Pick(SelectionFilterEnum.kDrawingCurveSegmentFilter, "Select drawing segment filter"); } else { selectSet = drawingDocument.SelectSet; } //DrawingCurveSegment drawingCurveSegment = selectSet[1];//drawingDocument.SelectSet[1]; DrawingCurve drawingCurve = drawingCurveSegment.Parent; //Get the mid point of the selected curve assuming that the selection curve is linear Point2d MidPoint = drawingCurve.MidPoint; //Set a reference to the TransientGeometry object. TransientGeometry TG = inventorApp.TransientGeometry; Console.WriteLine("TG : " + (TG == null)); ObjectCollection LeaderPoints = inventorApp.TransientObjects.CreateObjectCollection(); Console.WriteLine("LeaderPoints : " + (LeaderPoints == null)); LeaderPoints.Add(TG.CreatePoint2d(MidPoint.X + 10, MidPoint.Y + 10)); LeaderPoints.Add(TG.CreatePoint2d(MidPoint.X + 10, MidPoint.Y + 5)); //Add the GeometryIntent to the leader points collection. //This is the geometry that the balloon will attach to. GeometryIntent geometryIntent = drawingDocument.ActiveSheet.CreateGeometryIntent(drawingCurve); LeaderPoints.Add(geometryIntent); //Set a reference to the parent drawing view of the selected curve //DrawingView drawingView = drawingCurve.Parent; //Set a reference to the referenced model document Document ModelDoc = drawingView.ReferencedDocumentDescriptor.ReferencedDocument; Console.WriteLine(ModelDoc.Type); //PartDocument ModelDoc = drawingView.ReferencedDocumentDescriptor.ReferencedDocument; //AssemblyDocument ModelDoc = drawingView.ReferencedDocumentDescriptor.ReferencedDocument; //Check if a partslist or a balloon has already been created for thie model Boolean IsDrawingBOMDefined = drawingDocument.DrawingBOMs.IsDrawingBOMDefined(ModelDoc.FullFileName); // Balloon balloon; if (IsDrawingBOMDefined) { //当DrawingBOM已经被定义了 //Just create the balloon with the leader points. All other arguments can be ignored Console.WriteLine("当DrawingBOM已经被定义了\n创建气泡标注"); balloon = drawingDocument.ActiveSheet.Balloons.Add(LeaderPoints); } else { //当DrawingBOM没有被定义 AssemblyDocument assemblyDocument = (AssemblyDocument)ModelDoc; AssemblyComponentDefinition assemblyComponentDefinition = assemblyDocument.ComponentDefinition; ///* //First check if the 'structured' BOM view has been enabled in the model //Set a reference to the model's BOM object //BOM bom = ModelDoc.ComponentDefinition.BOM; BOM bom = assemblyComponentDefinition.BOM; if (bom.StructuredViewEnabled) { //Level needs to be specifieed. Numbering options jave already been defined. //Get the Level('All levels' of 'First level only') from the model BOM view - must use the same here PartsListLevelEnum Level; if (bom.StructuredViewFirstLevelOnly) { Level = PartsListLevelEnum.kStructured; } else { Level = PartsListLevelEnum.kStructuredAllLevels; } } else { //Level and numbering options must be specifieed. //The corresponding model BOM view will automatically be enabled NameValueMap NumberingScheme = inventorApp.TransientObjects.CreateNameValueMap(); //Add the option for a comma delimiter NumberingScheme.Add("Delimeter", ","); //Create the balloon by specifying the level and numbering scheme balloon = drawingDocument.ActiveSheet.Balloons.Add(LeaderPoints, PartsListLevelEnum.kStructuredAllLevels, NumberingScheme); } //*/ } }