/// <inheritdoc /> public override ReturnValue OnHotGrip(ObjectId entityId, Context contextFlags) { using (IntellectualEntity) { Point3d?newInsertionPoint = null; var linearEntity = (ILinearEntity)IntellectualEntity; if (GripIndex == 0) { IntellectualEntity.InsertionPoint = linearEntity.MiddlePoints[0]; newInsertionPoint = linearEntity.MiddlePoints[0]; linearEntity.MiddlePoints.RemoveAt(0); } else if (GripIndex == linearEntity.MiddlePoints.Count + 1) { IntellectualEntity.EndPoint = linearEntity.MiddlePoints.Last(); linearEntity.MiddlePoints.RemoveAt(linearEntity.MiddlePoints.Count - 1); } else { linearEntity.MiddlePoints.RemoveAt(GripIndex - 1); } IntellectualEntity.UpdateEntities(); IntellectualEntity.BlockRecord.UpdateAnonymousBlocks(); using (var tr = AcadUtils.Database.TransactionManager.StartOpenCloseTransaction()) { var blkRef = tr.GetObject(IntellectualEntity.BlockId, OpenMode.ForWrite, true, true); if (newInsertionPoint.HasValue) { ((BlockReference)blkRef).Position = newInsertionPoint.Value; } using (var resBuf = IntellectualEntity.GetDataForXData()) { blkRef.XData = resBuf; } tr.Commit(); } } return(ReturnValue.GetNewGripPoints); }
private void Property_PropertyChanged(object sender, PropertyChangedEventArgs e) { if (_isModifiedFromAutocad) { return; } Overrule.Overruling = false; var intellectualEntityProperty = (IntellectualEntityProperty)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; }
/// <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 (IntellectualEntity) { Point3d?newInsertionPoint = null; var linearEntity = (ILinearEntity)IntellectualEntity; if (GripLeftPoint == IntellectualEntity.InsertionPoint) { linearEntity.MiddlePoints.Insert(0, NewPoint); } else if (GripLeftPoint == null) { linearEntity.MiddlePoints.Insert(0, IntellectualEntity.InsertionPoint); IntellectualEntity.InsertionPoint = NewPoint; newInsertionPoint = NewPoint; } else if (GripRightPoint == null) { linearEntity.MiddlePoints.Add(IntellectualEntity.EndPoint); IntellectualEntity.EndPoint = NewPoint; } else { linearEntity.MiddlePoints.Insert( linearEntity.MiddlePoints.IndexOf(GripLeftPoint.Value) + 1, NewPoint); } IntellectualEntity.UpdateEntities(); IntellectualEntity.BlockRecord.UpdateAnonymousBlocks(); using (var tr = AcadUtils.Database.TransactionManager.StartOpenCloseTransaction()) { var blkRef = tr.GetObject(IntellectualEntity.BlockId, OpenMode.ForWrite, true, true); if (newInsertionPoint.HasValue) { ((BlockReference)blkRef).Position = newInsertionPoint.Value; } using (var resBuf = IntellectualEntity.GetDataForXData()) { blkRef.XData = resBuf; } tr.Commit(); } } } if (newStatus == Status.GripAbort) { AcadUtils.Editor.TurnForcedPickOff(); AcadUtils.Editor.PointMonitor -= AddNewVertex_EdOnPointMonitor; } base.OnGripStatusChanged(entityId, newStatus); }