/// <summary> /// Constructs the inventor curve and adds reference to the source sheet. /// </summary> /// <param name="curve"></param> /// <param name="sheet"></param> public InventorDrawingCurve(DrawingCurve curve, Sheet sheet) { _curve = curve; _sheet = sheet; _rangeBox = _curve.Evaluator2D.RangeBox; CurveType = (CurveTypes)_curve.CurveType; }
/// <summary> /// Returns a value that indicates whether the drawing curve represents a line. /// </summary> /// <param name="drawingCurve"> /// The <see cref="DrawingCurve"/> instance that this extension method affects.</param> /// <returns><c>true</c> if the drawing curve is a line or a line segment, <c>false</c> otherwise.</returns> /// <exception cref="ArgumentNullException"><paramref name="drawingCurve"/> is <c>null</c>.</exception> public static bool IsLine(this DrawingCurve drawingCurve) { if (drawingCurve == null) { throw new ArgumentNullException(nameof(drawingCurve)); } return(drawingCurve.CurveType == CurveTypeEnum.kLineCurve || drawingCurve.CurveType == CurveTypeEnum.kLineSegmentCurve); }
/// <summary> /// Returns a value that indicates whether the drawing curve is a bend line. /// </summary> /// <param name="drawingCurve"> /// The <see cref="DrawingCurve"/> instance that this extension method affects.</param> /// <returns><c>true</c> if the drawing curve is a bend line, <c>false</c> otherwise.</returns> /// <exception cref="ArgumentNullException"><paramref name="drawingCurve"/> is <c>null</c>.</exception> public static bool IsBendLine(this DrawingCurve drawingCurve) { if (drawingCurve == null) { throw new ArgumentNullException(nameof(drawingCurve)); } return(drawingCurve.IsLine() && ( drawingCurve.EdgeType == DrawingEdgeTypeEnum.kBendDownEdge || drawingCurve.EdgeType == DrawingEdgeTypeEnum.kBendUpEdge )); }
/// <summary> /// Returns a value that indicates wheter the drawing curve is vertical. /// </summary> /// <param name="drawingCurve"> /// The <see cref="DrawingCurve"/> instance that this extension method affects.</param> /// <returns><c>true</c> if vertical, <c>false</c> otherwise.</returns> /// <exception cref="ArgumentNullException"><paramref name="drawingCurve"/> is <c>null</c>.</exception> public static bool IsVertical(this DrawingCurve drawingCurve) { if (drawingCurve == null) { throw new ArgumentNullException(nameof(drawingCurve)); } return(drawingCurve.StartPoint == null || drawingCurve.EndPoint == null ? false : Math.Abs( drawingCurve.StartPoint.X - drawingCurve.EndPoint.X) <= Math.Abs(drawingCurve.StartPoint.X * .0001 )); }
/// <summary> /// creating leader text on a sheet. /// Before running this sample, open a drawing document and select a linear drawing edge. /// </summary> /// <remarks></remarks> public void AddLeaderNote() { // 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 drawing 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 selected 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 few leader points. oLeaderPoints.Add(oTG.CreatePoint2d(oMidPoint.X + 10, oMidPoint.Y + 10)); oLeaderPoints.Add(oTG.CreatePoint2d(oMidPoint.X + 10, oMidPoint.Y + 5)); // Create an intent and add to the leader points collection. // This is the geometry that the leader text will attach to. GeometryIntent oGeometryIntent = oActiveSheet.CreateGeometryIntent(oDrawingCurve); oLeaderPoints.Add(oGeometryIntent); // Create text with simple string as input. Since this doesn't use // any text overrides, it will default to the active text style. string sText = null; sText = "API Leader Note"; LeaderNote oLeaderNote = oActiveSheet.DrawingNotes.LeaderNotes.Add(oLeaderPoints, sText); // Insert a node. LeaderNode oFirstNode = oLeaderNote.Leader.RootNode.ChildNodes[1]; LeaderNode oSecondNode = oFirstNode.ChildNodes[1]; oFirstNode.InsertNode(oSecondNode, oTG.CreatePoint2d(oMidPoint.X + 5, oMidPoint.Y + 5)); }
protected void Page_Load(object sender, EventArgs e) { DrawingCurve MyDc = new DrawingCurve(); Bitmap img = new Bitmap(100, 100); //img = MyDc.Drawing(); DataTable a = new DataTable(); DataTable b = new DataTable(); //img = MyDc.DrawingImg10("21102", "21102综采工作面", "3", "0", "2016-01-01 00:00:00", "2017-01-01 23:59:59"); //img = MyDc.DrawingImgtest("21102", "21102综采工作面", "1", "083", "2016-06-04", "2016-06-04", a, b, 15, 10); //img = MyDc.DrawingImg21("3101测区", "3101工作面顺槽","锚索"); //img = MyDc.DrawingImg24("3101测区", "3101工作面", "800", "2016-06-04", "2017-06-04", a); //img = MyDc.DrawingImg25("3101测区", "3101工作面"); //img = MyDc.DrawingImg26("3101测区", "3101工作面","2016-09-02 00:00:00","2016-09-03 23:59:59"); //img = MyDc.DrawingImg27("3101测区", "3101工作面", "035", "2016-04-02 00:00:00", "2016-09-03 23:59:59", a); img = MyDc.DrawColumn(a); string str = Server.MapPath("./xiazai/"); img.Save(str + "ZhongCaiGongZuoZuLiShiShiZaiXianJianCe.jpg"); //img1.ImageUrl = "xiazai/ZhongCaiGongZuoZuLiShiShiZaiXianJianCe.jpg"; panel1.BackImageUrl = "xiazai/ZhongCaiGongZuoZuLiShiShiZaiXianJianCe.jpg"; //string strConn = ConfigurationManager.ConnectionStrings["webConnectionString"].ToString(); //DrawImage.DrawingCurve dc = new DrawImage.DrawingCurve(strConn); //Bitmap img = DrawImage.DrawingCurve.DrawingImg3("3101测区", "3101工作面", "1", "20", "2016-08-29 00:00:01", "2017-08-29 23:00:00"); //string str = Server.MapPath("./xiazai/"); //img.Save(str + "MeiRiGongZuoZuLiFenBuQuXian.jpg"); //img1.ImageUrl = "xiazai/MeiRiGongZuoZuLiFenBuQuXian.jpg"; StringBuilder sb = new StringBuilder(); sb.Append("["); for (int i = 0; i < a.Rows.Count; i++) { if (i == 0) { sb.Append("{"); } else { sb.Append(",{"); } sb.Append(string.Format("\"{0}\":\"{1}\"", "content", a.Rows[i]["content"].ToString())); sb.Append("}"); } sb.Append("]"); txtjson.Text = sb.ToString(); }
/// <summary> /// This sample demonstrates the creation of a baseline set dimension in a drawing. /// Create a drawing view and select multiple edges in the view before running the sample. /// </summary> /// <remarks></remarks> public void CreateBaselineDimensionSet() { // 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 = default(Sheet); oActiveSheet = oDrawDoc.ActiveSheet; ObjectCollection oIntentCollection = default(ObjectCollection); oIntentCollection = _InvApplication.TransientObjects.CreateObjectCollection(); // Get all the selected drawing curve segments. DrawingCurve oDrawingCurve = default(DrawingCurve); foreach (DrawingCurveSegment oSeg in oDrawDoc.SelectSet) { // Set a reference to the drawing curve. oDrawingCurve = oSeg.Parent; GeometryIntent oDimIntent = oActiveSheet.CreateGeometryIntent(oDrawingCurve); oIntentCollection.Add(oDimIntent); } // Set a reference to the view to which the curve belongs. DrawingView oDrawingView = oDrawingCurve.Parent; // Set a reference to the baseline dimension sets collection. BaselineDimensionSets oBaselineSets = oActiveSheet.DrawingDimensions.BaselineDimensionSets; // Determine the placement point Point2d oPlacementPoint = _InvApplication.TransientGeometry.CreatePoint2d(oDrawingView.Left - 5, oDrawingView.Center.Y); // Create a vertical baseline set dimension. BaselineDimensionSet oBaselineSet = oBaselineSets.Add(oIntentCollection, oPlacementPoint, DimensionTypeEnum.kHorizontalDimensionType); }
public void Run() { FormMain f1 = (FormMain)this.Owner; for (; ;) { DrawingCurve bmp = new DrawingCurve(); //画曲线图 //Random r = new Random(); for (int j = 0; j < 11; j++) { FormDisplay.fltCurrentValues[j] = FormDisplay.fltCurrentValues[j + 1]; } if (f1.rtbReceive.Text.Trim() != "") { FormDisplay.fltCurrentValues[11] = Convert.ToSingle(f1.rtbReceive.Text.Trim());// (float)r.Next(100); } pictureBox1.Image = bmp.DrawImage(); Thread.Sleep(trackBar1.Value); } }
public Autodesk.Revit.UI.Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { ExternalCommandData cdata = commandData; Autodesk.Revit.ApplicationServices.Application app = commandData.Application.Application; Document doc = commandData.Application.ActiveUIDocument.Document; UIDocument uiDoc = commandData.Application.ActiveUIDocument; var line = Line.CreateBound(new XYZ(0, 0, 0), new XYZ(0, 40, 0)); var arc = Arc.Create(new XYZ(0, -50, 0), new XYZ(40, -50, 0), new XYZ(50, -60, 0)); var drawingLine = new DrawingCurve(doc, line); drawingLine.Draw(); var drawingArc = new DrawingCurve(doc, arc); drawingArc.Draw(); return(Result.Succeeded); }
protected void search_Click(object sender, EventArgs e) { string time1 = datemin.Value; string time2 = datemax.Value; string cequ = ddl_cequ.SelectedValue; string roadway = ddl_roadway.SelectedValue; string maoguleixing = ddl_maoguleixing.SelectedValue; string anzhuangweizhi = ddl_anzhuangweizhi.SelectedValue; DrawingCurve MyDc = new DrawingCurve(); DataTable a = new DataTable(); DataTable b = new DataTable(); string strConn = ConfigurationManager.ConnectionStrings["webConnectionString"].ToString(); DrawImage.DrawingCurve dc = new DrawImage.DrawingCurve(strConn); Bitmap img = DrawImage.DrawingCurve.DrawingImg22(cequ, roadway, maoguleixing, anzhuangweizhi, time1, time2, a); string str = Server.MapPath("./xiazai/"); img.Save(str + "maoganmaosuoshujufenxi.jpg"); panel1.BackImageUrl = "xiazai/maoganmaosuoshujufenxi.jpg"; StringBuilder sb = new StringBuilder(); sb.Append("["); for (int i = 0; i < a.Rows.Count; i++) { if (i == 0) { sb.Append("{"); } else { sb.Append(",{"); } sb.Append(string.Format("\"{0}\":\"{1}\"", "content", a.Rows[i]["content"].ToString())); sb.Append("}"); } sb.Append("]"); txtjson.Text = sb.ToString(); }
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); }
/// <summary> /// TODO Implement /// </summary> /// <param name="curveSegment"></param> public InventorDrawingCurve(DrawingCurveSegment curveSegment) { _curve = curveSegment.Parent; FindOccurence(_curve.ModelGeometry); }
/// <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); } } }
public InventorDrawingCurve(DrawingCurve curve) { _curve = curve; FindOccurence(_curve); }
/// <summary> /// Tries to get an Inventor.Document object from a supplied object within a drawing. /// If one is found it will be returned; if not, null is returned. /// </summary> /// <param name="obj">Object</param> /// <param name="document">Inventor.DrawingDocument</param> /// <returns></returns> private static Document GetDocumentFromObjectInDrawing(dynamic obj, DrawingDocument document) { Document returnDocument = null; switch (obj.type) { //Drawing View, Section View, Detail View case 117441536: //kDrawingViewObject: case 117463296: //kSectionDrawingViewObject case 117474304: //kDetailDrawingViewObject return(obj.ReferencedFile.ReferencedDocument); case 2130706445: //kGenericObject: dynamic returnObject = null; try { //try to get single document from selected part document.ProcessViewSelection((GenericObject)obj, out _, out returnObject); } catch { break; } if (returnObject == null) { break; } switch (returnObject) { case Document doc: returnDocument = doc; break; case ComponentOccurrence componentOccurrence: //if this doesn't work, try to get the component occurrence instead, and then get the document from that returnDocument = (Document)componentOccurrence.Definition.Document; break; } break; //There was an error at 'Set oCCdef = oCompOcc.Definition.Document' case 117478144: //kDrawingCurveSegmentObject //Edge Objects and Edge Proxy Objects DrawingCurveSegment drawingCurveSegment = (DrawingCurveSegment)obj; DrawingCurve drawingCurve = drawingCurveSegment.Parent; //get the modelGeometry, if it cannot be accessed, the file is likely unreferenced... dynamic modelGeometry = null; try { modelGeometry = drawingCurve.ModelGeometry; } catch { returnDocument = null; break; } try //for a selected DrawingCurveSegment belonging to an assembly component { returnDocument = (Document)modelGeometry.ContainingOccurrence.Definition.Document; break; } catch { } try //for a selected DrawingCurveSegment belonging to a part { returnDocument = (Document)modelGeometry.Parent.ComponentDefinition.Document; break; } catch { } break; case 117444096: //kPartsListObject: returnDocument = obj.ReferencedFile.ReferencedDocument; break; case 117445120: //kPartsListRowObject: returnDocument = obj.ReferencedFiles.Item(1).ReferencedDocument; break; case 100674816: //kBOMRowObject: returnDocument = obj.ComponentDefinitions(1).Document; break; default: return(null); } return(returnDocument ?? null); }
private static void wip_kDrawingCurveSegmentObject() { Inventor.Application oApp = ApplicationShim.CurrentInstance(); SelectSet oSSet = oApp.ActiveDocument.SelectSet; if (oSSet.Count == 0) { return; } Inventor.Document returnDocument = null; dynamic obj = oSSet[2]; switch (obj.type) { case 117478144: //kDrawingCurveSegmentObject //try to set the drawing curve object to point at the containingOccurrence object. //Edge Objects and Edge Proxy Objects DrawingCurveSegment drawingCurveSegment = (DrawingCurveSegment)obj; DrawingCurve drawingCurve = drawingCurveSegment.Parent; dynamic modelGeometry; try { modelGeometry = drawingCurve.ModelGeometry; } catch { Console.WriteLine("Are you sure the object can be found? The ModelGeometry cannot be located. exiting..."); Console.ReadLine(); return; } ComponentOccurrence componentOccurrence; try //for a selected DrawingCurveSegment belonging to an assembly component { componentOccurrence = modelGeometry.ContainingOccurrence; returnDocument = (Document)componentOccurrence.Definition.Document; break; } catch { } try //for a selected DrawingCurveSegment belonging to a part { returnDocument = (Document)modelGeometry.Parent.ComponentDefinition.Document; break; } catch { } break; } if (returnDocument == null) { Console.WriteLine("The document could not be found!"); } else { Console.WriteLine("Document Type: " + returnDocument.DocumentSubType); Console.WriteLine(returnDocument.FullFileName); } Console.ReadLine(); }
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 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); } //*/ } }