private void addCheekViewBlock(bool doTrans, Matrix3d trans, double xPosView, bool isLeft) { // Добавление блока вида. // Если блока нет, то выход. if (panelBase.Service.Env.IdBtrView.IsNull) { return; } Point3d ptBlView = new Point3d(xPosView, 860, 0); if (doTrans) { ptBlView = ptBlView.TransformBy(trans); } BlockReference blRefView = CreateBlRefInBtrDim(ptBlView, panelBase.Service.Env.IdBtrView, Settings.Default.SheetScale); if (blRefView == null) { return; } // атрибут Вида if (!panelBase.Service.Env.IdAttrDefView.IsNull) { using (var attrDefView = panelBase.Service.Env.IdAttrDefView.GetObject(OpenMode.ForRead, false, true) as AttributeDefinition) { var attrRefView = new AttributeReference(); attrRefView.SetAttributeFromBlock(attrDefView, blRefView.BlockTransform); attrRefView.TextString = "А"; blRefView.AttributeCollection.AppendAttribute(attrRefView); t.AddNewlyCreatedDBObject(attrRefView, true); if ((!isLeft || doTrans) && !(!isLeft && doTrans)) { attrRefView.TransformBy(Matrix3d.Mirroring( new Line3d(attrRefView.AlignmentPoint, new Point3d(attrRefView.AlignmentPoint.X, 0, 0)))); } } } if ((!isLeft || doTrans) && !(!isLeft && doTrans)) { blRefView.TransformBy(Matrix3d.Mirroring(new Line3d(ptBlView, new Point3d(ptBlView.X, 0, 0)))); } }
private void UpdateBlock() { Autodesk.AutoCAD.ApplicationServices.Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; Autodesk.AutoCAD.DatabaseServices.Database db = doc.Database; Matrix3d ucs2wcs = AcadUtility.AcadGraphics.UcsToWcs; Point3d pBaseWorld = mpBase.TransformBy(ucs2wcs); Point3d pTextWorld = mpText.TransformBy(ucs2wcs); BlockReference bref = Entity as BlockReference; bref.TransformBy(lastTransform.Inverse()); for (int i = 0; i < bref.AttributeCollection.Count; i++) { AttributeReference attRef = bref.AttributeCollection[i].GetObject(OpenMode.ForWrite) as AttributeReference; string text = attRef.TextString; attRef.SetAttributeFromBlock(mAttDict[attRef], bref.BlockTransform); attRef.TextString = text; attRef.AdjustAlignment(db); } bref.Position = pTextWorld; double scale = Math.Abs(bref.ScaleFactors[0]); // Mirror block if text is to the left of base point if (mpText.X < mpBase.X) { using (Line3d mirrorLine = new Line3d(bref.Position, bref.Position + ucs2wcs.CoordinateSystem3d.Yaxis)) { Matrix3d mirroring = Matrix3d.Mirroring(mirrorLine); bref.TransformBy(mirroring); lastTransform = mirroring; } for (int i = 0; i < bref.AttributeCollection.Count; i++) { AttributeReference attRef = bref.AttributeCollection[i].GetObject(OpenMode.ForWrite) as AttributeReference; string text = attRef.TextString; attRef.SetAttributeFromBlock(mAttDict[attRef], bref.BlockTransform); attRef.TextString = text; Extents3d ex = attRef.GeometricExtents; Point3d midPoint = new Point3d((ex.MinPoint.X + ex.MaxPoint.X) / 2, (ex.MinPoint.Y + ex.MaxPoint.Y) / 2, (ex.MinPoint.Z + ex.MaxPoint.Z) / 2); using (Line3d mirrorLine = new Line3d(midPoint, midPoint + ucs2wcs.CoordinateSystem3d.Yaxis)) { Matrix3d mirroring = Matrix3d.Mirroring(mirrorLine); attRef.TransformBy(mirroring); } attRef.AdjustAlignment(db); } } else { lastTransform = Matrix3d.Identity; } IntegerCollection vpNumbers = AcadUtility.AcadGraphics.GetActiveViewportNumbers(); if (line == null) { line = new Line(); TransientManager.CurrentTransientManager.AddTransient(line, TransientDrawingMode.DirectShortTerm, 0, vpNumbers); } line.StartPoint = pBaseWorld; line.EndPoint = pTextWorld; TransientManager.CurrentTransientManager.UpdateTransient(line, vpNumbers); }