/// <inheritdoc /> public override void OnGripStatusChanged(ObjectId entityId, Status newStatus) { try { // При начале перемещения запоминаем первоначальное положение ручки // Запоминаем начальные значения if (newStatus == Status.GripStart) { _gripTmp = GripPoint; } // При удачном перемещении ручки записываем новые значения в расширенные данные // По этим данным я потом получаю экземпляр класса groundLine if (newStatus == Status.GripEnd) { using (var tr = AcadUtils.Database.TransactionManager.StartOpenCloseTransaction()) { var blkRef = tr.GetObject(SmartEntity.BlockId, OpenMode.ForWrite, true, true); using (var resBuf = SmartEntity.GetDataForXData()) { blkRef.XData = resBuf; } tr.Commit(); } SmartEntity.Dispose(); } // При отмене перемещения возвращаем временные значения if (newStatus == Status.GripAbort) { if (_gripTmp != null) { if (GripIndex == 0) { SmartEntity.InsertionPoint = _gripTmp; } else if (GripIndex == ((ILinearEntity)SmartEntity).MiddlePoints.Count + 1) { SmartEntity.EndPoint = _gripTmp; } else { ((ILinearEntity)SmartEntity).MiddlePoints[GripIndex - 1] = _gripTmp; } } } base.OnGripStatusChanged(entityId, newStatus); } catch (Exception exception) { if (exception.ErrorStatus != ErrorStatus.NotAllowedForThisProxy) { ExceptionBox.Show(exception); } } }
/// <inheritdoc /> public override ReturnValue OnHotGrip(ObjectId entityId, Context contextFlags) { using (SmartEntity) { Point3d?newInsertionPoint = null; var linearEntity = (ILinearEntity)SmartEntity; if (GripIndex == 0) { SmartEntity.InsertionPoint = linearEntity.MiddlePoints[0]; newInsertionPoint = linearEntity.MiddlePoints[0]; linearEntity.MiddlePoints.RemoveAt(0); } else if (GripIndex == linearEntity.MiddlePoints.Count + 1) { SmartEntity.EndPoint = linearEntity.MiddlePoints.Last(); linearEntity.MiddlePoints.RemoveAt(linearEntity.MiddlePoints.Count - 1); } else { linearEntity.MiddlePoints.RemoveAt(GripIndex - 1); } SmartEntity.UpdateEntities(); SmartEntity.BlockRecord.UpdateAnonymousBlocks(); using (var tr = AcadUtils.Database.TransactionManager.StartOpenCloseTransaction()) { var blkRef = tr.GetObject(SmartEntity.BlockId, OpenMode.ForWrite, true, true); if (newInsertionPoint.HasValue) { ((BlockReference)blkRef).Position = newInsertionPoint.Value; } using (var resBuf = SmartEntity.GetDataForXData()) { blkRef.XData = resBuf; } tr.Commit(); } } return(ReturnValue.GetNewGripPoints); }
/// <inheritdoc /> public override void OnGripStatusChanged(ObjectId entityId, Status newStatus) { if (newStatus == Status.GripStart) { AcadUtils.Editor.TurnForcedPickOn(); AcadUtils.Editor.PointMonitor += AddNewVertex_EdOnPointMonitor; } if (newStatus == Status.GripEnd) { AcadUtils.Editor.TurnForcedPickOff(); AcadUtils.Editor.PointMonitor -= AddNewVertex_EdOnPointMonitor; using (SmartEntity) { Point3d?newInsertionPoint = null; var linearEntity = (ILinearEntity)SmartEntity; if (GripLeftPoint == SmartEntity.InsertionPoint) { linearEntity.MiddlePoints.Insert(0, NewPoint); } else if (GripLeftPoint == null) { linearEntity.MiddlePoints.Insert(0, SmartEntity.InsertionPoint); SmartEntity.InsertionPoint = NewPoint; newInsertionPoint = NewPoint; } else if (GripRightPoint == null) { linearEntity.MiddlePoints.Add(SmartEntity.EndPoint); SmartEntity.EndPoint = NewPoint; } else { linearEntity.MiddlePoints.Insert( linearEntity.MiddlePoints.IndexOf(GripLeftPoint.Value) + 1, NewPoint); } SmartEntity.UpdateEntities(); SmartEntity.BlockRecord.UpdateAnonymousBlocks(); using (var tr = AcadUtils.Database.TransactionManager.StartOpenCloseTransaction()) { var blkRef = tr.GetObject(SmartEntity.BlockId, OpenMode.ForWrite, true, true); if (newInsertionPoint.HasValue) { ((BlockReference)blkRef).Position = newInsertionPoint.Value; } using (var resBuf = SmartEntity.GetDataForXData()) { blkRef.XData = resBuf; } tr.Commit(); } } } if (newStatus == Status.GripAbort) { AcadUtils.Editor.TurnForcedPickOff(); AcadUtils.Editor.PointMonitor -= AddNewVertex_EdOnPointMonitor; } base.OnGripStatusChanged(entityId, newStatus); }
private void Property_PropertyChanged(object sender, PropertyChangedEventArgs e) { if (_isModifiedFromAutocad) { return; } Overrule.Overruling = false; var intellectualEntityProperty = (SmartEntityProperty)sender; try { using (AcadUtils.Document.LockDocument()) { using (var blockReference = _blkRefObjectId.Open(OpenMode.ForWrite, true, true) as BlockReference) { var entityType = _intellectualEntity.GetType(); var propertyInfo = entityType.GetProperty(intellectualEntityProperty.Name); if (propertyInfo != null) { if (intellectualEntityProperty.Name == "Style") { var style = StyleManager.GetStyleByName(entityType, intellectualEntityProperty.Value.ToString()); if (style != null) { _intellectualEntity.ApplyStyle(style, false); } } else if (intellectualEntityProperty.Name == "LayerName") { if (blockReference != null) { blockReference.Layer = intellectualEntityProperty.Value.ToString(); } } else if (intellectualEntityProperty.Name == "LineType") { if (blockReference != null) { blockReference.Linetype = intellectualEntityProperty.Value.ToString(); } } else { propertyInfo.SetValue(_intellectualEntity, intellectualEntityProperty.Value); } _intellectualEntity.UpdateEntities(); _intellectualEntity.GetBlockTableRecordWithoutTransaction(blockReference); using (var resBuf = _intellectualEntity.GetDataForXData()) { if (blockReference != null) { blockReference.XData = resBuf; } } if (blockReference != null) { blockReference.ResetBlock(); } } } } Autodesk.AutoCAD.Internal.Utils.FlushGraphics(); } catch (System.Exception exception) { if (exception.Message != "eOnLockedLayer") { ExceptionBox.Show(exception); } else { OnLockedLayerEventHandler?.Invoke(this, intellectualEntityProperty); } } Overrule.Overruling = true; }