private void App_DocumentOpened(object sender, Autodesk.Revit.DB.Events.DocumentOpenedEventArgs e) { PipeAnnotationContext.UpdateCreater(e.Document); }
public void Execute(UpdaterData updateData) { var document = updateData.GetDocument(); var edits = updateData.GetModifiedElementIds(); var collection = PipeAnnotationContext.GetCollection(document); if (PipeAnnotationContext.IsEditing == true) { PipeAnnotationContext.IsEditing = false; return; } List <int> movedEntities = new List <int>(); foreach (var editId in edits) { var element = document.GetElement(editId); PipeAnnotationEntity entity = null; var lineMoved = collection.FirstOrDefault(c => c.LineId == editId.IntegerValue); if (lineMoved != null) { TaskDialog.Show("警告", "线移动了"); entity = lineMoved; var creater = PipeAnnotationContext.Creater; FamilyInstance line = document.GetElement(new ElementId(entity.LineId)) as FamilyInstance; XYZ skewVector = (line.Location as LocationPoint).Point - entity.StartPoint; creater.RegenerateMultipleTagSymbolByEntity(document, entity, skewVector); movedEntities.Add(entity.LineId); PipeAnnotationContext.IsEditing = true; } var pipeMoved = collection.FirstOrDefault(c => c.PipeIds.Contains(editId.IntegerValue)); if (pipeMoved != null) { TaskDialog.Show("警告", "管道移动了"); entity = pipeMoved; if (movedEntities.Contains(entity.LineId)) { continue; } var creater = PipeAnnotationContext.Creater; XYZ parallelVector = null; XYZ verticalVector = null; parallelVector = ((document.GetElement(new ElementId(entity.PipeIds.First())).Location as LocationCurve).Curve as Line).Direction; verticalVector = new XYZ(parallelVector.Y, -parallelVector.X, 0); parallelVector = VLLocationHelper.GetVectorByQuadrant(parallelVector, QuadrantType.OneAndFour, VLCoordinateType.XY); verticalVector = VLLocationHelper.GetVectorByQuadrant(verticalVector, QuadrantType.OneAndTwo, VLCoordinateType.XY); int indexOfPipe = entity.PipeIds.IndexOf(editId.IntegerValue); var startPoint = entity.StartPoint; var movedPipe = document.GetElement(new ElementId(editId.IntegerValue)) as Pipe; var pipeLine = (movedPipe.Location as LocationCurve).Curve; pipeLine.MakeUnbound(); var projectionPoint = pipeLine.Project(startPoint).XYZPoint; var line = document.GetElement(new ElementId(entity.LineId)) as FamilyInstance; double preHeight = 0; if (indexOfPipe > 0) { preHeight = line.GetParameters(string.Format("节点{0}距离", indexOfPipe + 1)).First().AsDouble(); startPoint -= preHeight * verticalVector; } creater.RegenerateMultipleTagSymbolByEntity(document, entity, startPoint - projectionPoint); movedEntities.Add(entity.LineId); PipeAnnotationContext.IsEditing = true; } var tagMoved = collection.FirstOrDefault(c => c.TagIds.Contains(editId.IntegerValue)); if (tagMoved != null) { TaskDialog.Show("警告", "标注移动了"); entity = tagMoved; if (movedEntities.Contains(entity.LineId)) { continue; } var creater = PipeAnnotationContext.Creater; var index = entity.TagIds.IndexOf(editId.IntegerValue); var subTag = document.GetElement(new ElementId(editId.IntegerValue)) as IndependentTag; var text = subTag.TagText; var textLength = System.Windows.Forms.TextRenderer.MeasureText(text, AnnotationConstaints.Font).Width; var actualLength = textLength / (creater.TextSize * creater.WidthScale); XYZ parallelVector = null; XYZ verticalVector = null; parallelVector = ((document.GetElement(new ElementId(entity.PipeIds.First())).Location as LocationCurve).Curve as Line).Direction; verticalVector = new XYZ(parallelVector.Y, -parallelVector.X, 0); parallelVector = VLLocationHelper.GetVectorByQuadrant(parallelVector, QuadrantType.OneAndFour, VLCoordinateType.XY); verticalVector = VLLocationHelper.GetVectorByQuadrant(verticalVector, QuadrantType.OneAndTwo, VLCoordinateType.XY); var height = Convert.ToDouble(document.GetElement(new ElementId(entity.LineId)).GetParameters(TagProperty.线高度1.ToString()).First().AsValueString()) + (entity.PipeIds.Count() - 1) * AnnotationConstaints.TextHeight; double skewLength = 0; XYZ startPoint = null; switch (entity.LocationType) { case MultiPipeTagLocation.OnLineEdge: skewLength = AnnotationConstaints.SkewLengthForOffLine; startPoint = subTag.TagHeadPosition - skewLength * parallelVector - actualLength / 25.4 * parallelVector - UnitHelper.ConvertToInch(height - index * AnnotationConstaints.TextHeight, AnnotationConstaints.UnitType) * verticalVector; break; case MultiPipeTagLocation.OnLine: skewLength = AnnotationConstaints.SkewLengthForOffLine; startPoint = subTag.TagHeadPosition - skewLength * parallelVector - actualLength / 25.4 * parallelVector - UnitHelper.ConvertToInch(height - index * AnnotationConstaints.TextHeight + 0.5 * AnnotationConstaints.TextHeight, AnnotationConstaints.UnitType) * verticalVector; break; } XYZ skewVector = startPoint - entity.StartPoint; creater.RegenerateMultipleTagSymbolByEntity(document, entity, skewVector); movedEntities.Add(entity.LineId); PipeAnnotationContext.IsEditing = true; } } PipeAnnotationContext.SaveCollection(document); }
public void Execute(UpdaterData updateData) { var document = updateData.GetDocument(); var changeIds = updateData.GetDeletedElementIds(); var collection = PipeAnnotationContext.GetCollection(document); if (PipeAnnotationContext.IsEditing == true) { PipeAnnotationContext.IsEditing = false; return; } foreach (var changeId in changeIds) { var element = document.GetElement(changeId); PipeAnnotationEntity entity = null; var lineMoved = collection.FirstOrDefault(c => c.LineId == changeId.IntegerValue); if (lineMoved != null) { TaskDialog.Show("警告", "线.删除了"); entity = lineMoved; foreach (var id in entity.TagIds) { document.Delete(new ElementId(id)); } collection.Remove(entity); } var pipeMoved = collection.FirstOrDefault(c => c.PipeIds.Contains(changeId.IntegerValue)); if (pipeMoved != null) { TaskDialog.Show("警告", "管道.删除了"); entity = pipeMoved; if (entity.PipeIds.Count() > 2) { var index = entity.PipeIds.IndexOf(changeId.IntegerValue); entity.PipeIds.Remove(changeId.IntegerValue); entity.TagIds.RemoveAt(index); var creater = PipeAnnotationContext.Creater; creater.RegenerateMultipleTagSymbolByEntity(document, entity, new XYZ(0, 0, 0)); PipeAnnotationContext.IsEditing = true; } else { document.Delete(new ElementId(entity.LineId)); var index = entity.PipeIds.IndexOf(changeId.IntegerValue); entity.TagIds.RemoveAt(index); document.Delete(new ElementId(entity.TagIds.First())); entity.PipeIds.Remove(changeId.IntegerValue); var pipeId = entity.PipeIds.First(); collection.Remove(entity); GenerateSingleTag(document, entity.ViewId, pipeId); } } var tagMoved = collection.FirstOrDefault(c => c.TagIds.Contains(changeId.IntegerValue)); if (tagMoved != null) { TaskDialog.Show("警告", "标注.删除了"); entity = tagMoved; if (entity.TagIds.Count() > 2) { var index = entity.TagIds.IndexOf(changeId.IntegerValue); entity.TagIds.Remove(changeId.IntegerValue); entity.PipeIds.RemoveAt(index); var creater = PipeAnnotationContext.Creater; creater.RegenerateMultipleTagSymbolByEntity(document, entity, new XYZ(0, 0, 0)); PipeAnnotationContext.IsEditing = true; } else { var index = entity.TagIds.IndexOf(changeId.IntegerValue); var pipeId = entity.PipeIds[index]; entity.TagIds.Remove(changeId.IntegerValue); document.Delete(new ElementId(entity.LineId)); foreach (var id in entity.TagIds) { document.Delete(new ElementId(id)); } collection.Remove(entity); GenerateSingleTag(document, entity.ViewId, pipeId); } } } PipeAnnotationContext.SaveCollection(document); }