public static BossCommentEntity ToEntity(this BossComment item) { if (null == item) { return(null); } var entInfo = EntInfo.FindById(item.CommentEntId); var entity = new BossCommentEntity(item, entInfo); return(entity); }
/// <summary> /// TODO /// </summary> /// <param name="acEnt"></param> /// <param name="eInfo"></param> /// <param name="acCurDb"></param> /// <param name="acTrans"></param> public static void AddXData(this Entity acEnt, EntInfo eInfo, Database acCurDb, Transaction acTrans) { //If solid is not open for write, open it for write acEnt.Upgrade(); // Open the Registered Applications table for read var acRegAppTbl = acTrans.GetObject(acCurDb.RegAppTableId, OpenMode.ForRead) as RegAppTable; // Check to see if the Registered Applications table record for the custom app exists if (acRegAppTbl != null && acRegAppTbl.Has(SettingsInternal.CommandGroup) == false) { using (var acRegAppTblRec = new RegAppTableRecord()) { acRegAppTblRec.Name = SettingsInternal.CommandGroup; acRegAppTbl.UpgradeOpen(); acRegAppTbl.Add(acRegAppTblRec); acTrans.AddNewlyCreatedDBObject(acRegAppTblRec, true); } } // Define the Xdata to add to each selected object using (var rBuffer = new ResultBuffer()) { rBuffer.Add(new TypedValue((int)DxfCode.ExtendedDataRegAppName, SettingsInternal.CommandGroup)); rBuffer.Add(new TypedValue((int)DxfCode.ExtendedDataAsciiString, eInfo.RcName)); rBuffer.Add(new TypedValue((int)DxfCode.ExtendedDataAsciiString, eInfo.RcInfo)); rBuffer.Add(new TypedValue((int)DxfCode.ExtendedDataReal, eInfo.Length)); rBuffer.Add(new TypedValue((int)DxfCode.ExtendedDataReal, eInfo.Width)); rBuffer.Add(new TypedValue((int)DxfCode.ExtendedDataReal, eInfo.Thickness)); rBuffer.Add(new TypedValue((int)DxfCode.ExtendedDataReal, eInfo.Volume)); rBuffer.Add(new TypedValue((int)DxfCode.ExtendedDataReal, eInfo.MaxArea)); rBuffer.Add(new TypedValue((int)DxfCode.ExtendedDataReal, eInfo.MaxPerimeter)); rBuffer.Add(new TypedValue((int)DxfCode.ExtendedDataReal, eInfo.Asymmetry)); rBuffer.Add(new TypedValue((int)DxfCode.ExtendedDataAsciiString, eInfo.AsymString)); rBuffer.Add(new TypedValue((int)DxfCode.ExtendedDataInteger32, eInfo.RcQtyOf)); rBuffer.Add(new TypedValue((int)DxfCode.ExtendedDataInteger32, eInfo.RcQtyTotal)); rBuffer.Add(new TypedValue((int)DxfCode.ExtendedDataInteger32, eInfo.NumberOfChanges)); rBuffer.Add(new TypedValue((int)DxfCode.ExtendedDataInteger32, Convert.ToInt32(eInfo.IsSweep))); rBuffer.Add(new TypedValue((int)DxfCode.ExtendedDataInteger32, Convert.ToInt32(eInfo.IsMirror))); rBuffer.Add(new TypedValue((int)DxfCode.ExtendedDataInteger32, Convert.ToInt32(eInfo.HasHoles))); rBuffer.Add(new TypedValue((int)DxfCode.ExtendedDataInteger32, eInfo.TxDirection)); rBuffer.Add(new TypedValue((int)DxfCode.ExtendedDataInteger32, eInfo.ProdType)); rBuffer.Add(new TypedValue((int)DxfCode.ExtendedDataHandle, eInfo.ParentHandle)); rBuffer.Add(new TypedValue((int)DxfCode.ExtendedDataAsciiString, string.Join(",", eInfo.ChildHandles))); // Append the extended data to the object acEnt.XData = rBuffer; } }
public static IList <BossCommentEntity> ToEntities(this IList <BossComment> items) { if (items == null || items.Count < 1) { return(null); } var result = new List <BossCommentEntity>(); foreach (var item in items) { var entInfo = EntInfo.FindById(item.CommentEntId); result.Add(new BossCommentEntity(item, entInfo)); } return(result); }
internal BossCommentEntity(BossComment source, EntInfo entInfo) { this.SetPropertyValues(source.GetPropertyValues()); //this.EntName = entInfo.EntName; if (false == string.IsNullOrEmpty(source.Voice)) { this.Voice = ImageHelper.ToAbsoluteUri(source.Voice); } if (null != source.Images && source.Images.Length > 0) { for (var i = 0; i < source.Images.Length; i++) { this.Images[i] = ImageHelper.ToAbsoluteUri(source.Images[i]); } } }
internal static void Traverse(bool reselect = false) { var acCurDoc = Application.DocumentManager.MdiActiveDocument; var acCurDb = acCurDoc.Database; var acCurEd = acCurDoc.Editor; //Start a selection set SelectionSet acSet; //Check for pick-first selection -> if none, get selection if (!acCurEd.CheckForPickFirst(out acSet)) { acSet = SelectionSet.FromObjectIds(acCurEd.GetFilteredSelection(Enums.DxfNameEnum._3Dsolid, false)); } using (var acTrans = acCurDb.TransactionManager.StartTransaction()) { using (var pWorker = new ProgressAgent("Parsing Solids: ", acSet.Count)) { var parseCount = 1; foreach (var objId in acSet.GetObjectIds()) { //Progress progress bar or exit if ESC has been pressed if (!pWorker.Progress()) { acTrans.Abort(); return; } var acSol = acTrans.GetObject(objId, OpenMode.ForRead) as Solid3d; if (acSol == null) { continue; } var entInfo = new EntInfo(acSol, acCurDb, acTrans); acSol.AddXData(entInfo, acCurDb, acTrans); if (!reselect) { acCurEd.WriteMessage("\n" + entInfo.PrintInfo(false, parseCount)); } parseCount++; #region Debug Testing //acSol.UpdateXData("TestName", Enums.XDataCode.Name, acCurDb, acTrans); //1 //acSol.UpdateXData("TestInfo", Enums.XDataCode.Info, acCurDb, acTrans); //2 //acSol.UpdateXData(10, Enums.XDataCode.Length, acCurDb, acTrans); //3 //acSol.UpdateXData(20, Enums.XDataCode.Width, acCurDb, acTrans); //4 //acSol.UpdateXData(30, Enums.XDataCode.Thickness, acCurDb, acTrans); //5 //acSol.UpdateXData(40, Enums.XDataCode.Volume, acCurDb, acTrans); //6 //acSol.UpdateXData(50, Enums.XDataCode.MaxArea, acCurDb, acTrans); //7 //acSol.UpdateXData(60, Enums.XDataCode.MaxPerimeter, acCurDb, acTrans); //8 //acSol.UpdateXData(70, Enums.XDataCode.Asymmetry, acCurDb, acTrans); //9 //acSol.UpdateXData("AxymV", Enums.XDataCode.AsymmetryVector, acCurDb, acTrans); //10 //acSol.UpdateXData(1, Enums.XDataCode.PartOf, acCurDb, acTrans); //11 //acSol.UpdateXData(2, Enums.XDataCode.PartTotal, acCurDb, acTrans); //12 //acSol.UpdateXData(3, Enums.XDataCode.NumChanges, acCurDb, acTrans); //13 //acSol.UpdateXData(false, Enums.XDataCode.IsSweep, acCurDb, acTrans); //14 //acSol.UpdateXData(true, Enums.XDataCode.IsMirror, acCurDb, acTrans); //15 //acSol.UpdateXData(false, Enums.XDataCode.HasHoles, acCurDb, acTrans); //16 //acSol.UpdateXData(Enums.Texture.Across, Enums.XDataCode.Texture, acCurDb, acTrans); //17 //acSol.UpdateXData(Enums.Production.MillingTwoSide, Enums.XDataCode.Production, acCurDb, acTrans); //18 //acSol.UpdateXData(acSol.Handle, Enums.XDataCode.ParentObject, acCurDb, acTrans); //19 //acSol.UpdateXData(new List<Handle>() {acSol.Handle, acSol.Handle , acSol.Handle}, //Enums.XDataCode.ChildObjects, acCurDb, acTrans); //20 //acCurEd.WriteMessage("\n Testing XData Read"); //acCurEd.WriteMessage("\n" + acSol.GetAppName()); //acCurEd.WriteMessage("\n" + acSol.GetPartName()); //acCurEd.WriteMessage("\n" + acSol.GetPartInfo()); //acCurEd.WriteMessage("\n" + acSol.GetPartLength()); //acCurEd.WriteMessage("\n" + acSol.GetPartWidth()); //acCurEd.WriteMessage("\n" + acSol.GetPartThickness()); //acCurEd.WriteMessage("\n" + acSol.GetPartVolume()); //acCurEd.WriteMessage("\n" + acSol.GetPartArea()); //acCurEd.WriteMessage("\n" + acSol.GetPartPerimeter()); //acCurEd.WriteMessage("\n" + acSol.GetPartAsymmetry()); //acCurEd.WriteMessage("\n" + acSol.GetAsymVector()); //acCurEd.WriteMessage("\n" + acSol.GetQtyOf()); //acCurEd.WriteMessage("\n" + acSol.GetQtyTotal()); //acCurEd.WriteMessage("\n" + acSol.GetNumChanges()); //acCurEd.WriteMessage("\n" + acSol.GetIsSweep()); //acCurEd.WriteMessage("\n" + acSol.GetIsMirror()); //acCurEd.WriteMessage("\n" + acSol.GetHasHoles()); //acCurEd.WriteMessage("\n" + acSol.GetTextureDirection()); //acCurEd.WriteMessage("\n" + acSol.GetProductionType()); //acCurEd.WriteMessage("\n" + acSol.GetParent()); //acCurEd.WriteMessage("\n" + String.Join(",",acSol.GetChildren())); #endregion } if (reselect) { acCurEd.SetImpliedSelection(acSet.GetObjectIds()); } } acTrans.Commit(); } }
public void Cmd_EdgeBand() { if (!LicensingAgent.Check()) { return; } var acCurDoc = Application.DocumentManager.MdiActiveDocument; var acCurDb = acCurDoc.Database; var acCurEd = acCurDoc.Editor; //Call user to select a face var userSel = acCurEd.SelectSubentity(SubentityType.Face, "\nSelect a FACE to use as cutting criteria: "); if (userSel == null) { return; } if (userSel.Item1 == ObjectId.Null) { return; } if (userSel.Item2 == SubentityId.Null) { return; } var insetOpts = new PromptDistanceOptions("\nEnter edge banding thickness: ") { AllowNone = false, AllowZero = false, AllowNegative = false, DefaultValue = SettingsUser.EdgeBandThickness }; //Get the offset distance var insetRes = acCurEd.GetDistance(insetOpts); if (insetRes.Status != PromptStatus.OK) { return; } SettingsUser.EdgeBandThickness = insetRes.Value; // ReSharper disable once CompareOfFloatsByEqualityOperator if (SettingsUser.EdgeBandThickness <= 0) { return; } Entity faceEnt = null; Surface tempSurf = null; Solid3d tempSol = null; try { //Open a transaction using (var acTrans = acCurDb.TransactionManager.StartTransaction()) { var acSol = acTrans.GetObject(userSel.Item1, OpenMode.ForWrite) as Solid3d; if (acSol == null) { acTrans.Abort(); return; } var innerSol = acSol.Clone() as Solid3d; if (innerSol == null) { acTrans.Abort(); return; } acSol.Layer = acCurDb.GetCLayer(acTrans); acCurDb.AppendEntity(innerSol); faceEnt = acSol.GetSubentity(userSel.Item2); var eInfo = new EntInfo(acSol, acCurDb, acTrans); var largestM = eInfo.GetLargestMeasurement(); using (tempSurf = faceEnt.CreateSurfaceFromFace(acCurDb, acTrans, false)) { var thickness = largestM + SettingsUser.EdgeBandThickness; using (tempSol = tempSurf.Thicken(-(thickness * 2), true)) { tempSol.OffsetBody(-SettingsUser.EdgeBandThickness); var cutSol = tempSol.Slice(tempSurf, true); cutSol.Dispose(); acSol.BooleanOperation(BooleanOperationType.BoolSubtract, tempSol); } } var acBool1 = new[] { innerSol.ObjectId }; var acBool2 = new[] { acSol.ObjectId }; acBool1.SolidSubtrahend(acBool2, acCurDb, acTrans, false); acTrans.Commit(); } } catch (Exception e) { acCurEd.WriteMessage(e.Message); MailAgent.Report(e.Message); } finally { if (faceEnt != null) { faceEnt.Dispose(); } if (tempSurf != null) { tempSurf.Dispose(); } if (tempSol != null) { tempSol.Dispose(); } } }
public void Cmd_RcFlip() { if (!LicensingAgent.Check()) { return; } var acCurDoc = Application.DocumentManager.MdiActiveDocument; var acCurDb = acCurDoc.Database; var acCurEd = acCurDoc.Editor; //Prompt To Select Solids to perform Lay Command On var objIds = acCurEd.GetFilteredSelection(Enums.DxfNameEnum._3Dsolid, false, null, "\nSelect 3DSOLIDS to flip on an axis: "); // Exit if selection error if (objIds.Length <= 0) { return; } // Prompt User to Select the Axis to flip on var flipAxisOpt = new PromptKeywordOptions("\nChoose axis to rotate around: "); flipAxisOpt.Keywords.Add("X"); flipAxisOpt.Keywords.Add("Y"); flipAxisOpt.Keywords.Add("Z"); flipAxisOpt.AllowNone = false; var flipAxisRes = acCurEd.GetKeywords(flipAxisOpt); if (flipAxisRes.Status != PromptStatus.OK) { return; } // Prompt User to Select the Axis to flip on var flipDegOpt = new PromptKeywordOptions("\nChoose degree to rotate around axis: "); flipDegOpt.Keywords.Add("90"); flipDegOpt.Keywords.Add("180"); flipDegOpt.Keywords.Add("270"); flipDegOpt.AllowNone = false; var flipDegRes = acCurEd.GetKeywords(flipDegOpt); if (flipDegRes.Status != PromptStatus.OK) { return; } // Get the selected keyword as a string var flipAxisKey = flipAxisRes.StringResult; var flipDegKey = flipDegRes.StringResult; var parseCount = 1; // Set selection set to user selection var solObjIds = objIds; using (var acTrans = acCurDb.TransactionManager.StartTransaction()) { using ( var pWorker = new ProgressAgent("Flipping Solids:", solObjIds.Count())) { //Parse Data for each solid in the list foreach (var acSolId in solObjIds) { //Progress progress bar or exit if ESC has been pressed if (!pWorker.Progress()) { acTrans.Abort(); return; } if (acSolId == ObjectId.Null) { continue; } // Get the Solid Information To Create a Lay Matrix var acSol = acTrans.GetObject(acSolId, OpenMode.ForWrite) as Solid3d; //Populate the solid var eInfo = new EntInfo(acSol, acCurDb, acTrans); parseCount++; //Flip the solid switch (flipAxisKey) { case "X": switch (flipDegKey) { case "90": acSol?.TransformBy(eInfo.X90); break; case "180": acSol?.TransformBy(eInfo.X180); break; case "270": acSol?.TransformBy(eInfo.X270); break; } break; case "Y": switch (flipDegKey) { case "90": acSol?.TransformBy(eInfo.Y90); break; case "180": acSol?.TransformBy(eInfo.Y180); break; case "270": acSol?.TransformBy(eInfo.Y270); break; } break; case "Z": switch (flipDegKey) { case "90": acSol?.TransformBy(eInfo.Z90); break; case "180": acSol?.TransformBy(eInfo.Z180); break; case "270": acSol?.TransformBy(eInfo.Z270); break; } break; } } } acTrans.Commit(); } }
public void Cmd_Nest() { var acCurDoc = Application.DocumentManager.MdiActiveDocument; var acCurDb = acCurDoc.Database; var acCurEd = acCurDoc.Editor; var polyId = acCurEd.SelectClosedPolyline(); if (polyId == ObjectId.Null) { return; } var nestIds = acCurEd.GetFilteredSelection(Enums.DxfNameEnum._3Dsolid, false, null, "\nSelect 3DSolids to nest inside of polyline."); if (nestIds.Length <= 0) { return; } using (var acTrans = acCurDb.TransactionManager.StartTransaction()) { var poly = acTrans.GetObject(polyId, OpenMode.ForRead) as Polyline; if (poly != null) { var solList = new List <Solid3d>(); var tooLargeList = new List <Solid3d>(); var pArea = poly.Area; var layParts = true; //TODO PackTo //TODO OffsetFromEdge //TODO GapBetween foreach (var objId in nestIds) { var acSol = acTrans.GetObject(objId, OpenMode.ForRead) as Solid3d; if (acSol == null) { continue; } var eInfo = new EntInfo(acSol, acCurDb, acTrans); var solClone = acSol.Clone() as Solid3d; if (solClone == null) { continue; } if (layParts) { solClone.TransformBy(eInfo.LayMatrix); } acCurDb.AppendEntity(solClone); solClone.TopLeftToOrigin(); var geomExt = solClone.GeometricExtents; var geomMin = geomExt.MinPoint.Flatten(); var geomMax = geomExt.MaxPoint.Flatten(); var geomArea = (geomMax.X - geomMin.X) * (geomMax.Y - geomMin.Y); if (geomArea > pArea) { //TODO check every angle tooLargeList.Add(solClone); } else { solList.Add(solClone); } } MessageBox.Show(tooLargeList.Count + " Solids are too large!"); } acTrans.Commit(); } }
public void Cmd_RcExplode() { if (!LicensingAgent.Check()) { return; } var acCurDoc = Application.DocumentManager.MdiActiveDocument; var acCurDb = acCurDoc.Database; var acCurEd = acCurDoc.Editor; var objIds = acCurEd.GetFilteredSelection(Enums.DxfNameEnum._3Dsolid, false, null, "\nSelect solid assembly to explode: "); if (objIds.Length <= 0) { return; } var explodePoint = acCurEd.Get2DPoint("\nSelect insertion point for exploded view: "); using (var acTrans = acCurDb.TransactionManager.StartTransaction()) { var extents = acTrans.GetExtents(objIds, acCurDb); var extCen = Solid3DExtensions.GetBoxCenter(extents.MinPoint, extents.MaxPoint); var centryMove = extCen.GetVectorTo(new Point3d(explodePoint.X, explodePoint.Y, extCen.Z)); foreach (var obj in objIds) { var acSol = acTrans.GetObject(obj, OpenMode.ForWrite) as Solid3d; if (acSol == null) { continue; } var cSol = acSol.Clone() as Solid3d; if (cSol == null) { continue; } var eInfo = new EntInfo(acSol, acCurDb, acTrans); var cInfo = new EntInfo(cSol, acCurDb, acTrans); acCurDb.AppendEntity(cSol, acTrans); var pHandle = acSol.Handle; var cHandle = cSol.Handle; eInfo.ChildHandles.Add(cHandle); cInfo.ParentHandle = pHandle; cInfo.ChildHandles.Clear(); acSol.AddXData(eInfo, acCurDb, acTrans); cSol.AddXData(cInfo, acCurDb, acTrans); var cCen = cSol.MassProperties.Centroid; var cPower = extCen.GetVectorTo(cCen).MultiplyBy(SettingsUser.ExplodePower); cSol.TransformBy(Matrix3d.Displacement(cPower)); cSol.TransformBy(Matrix3d.Displacement(centryMove)); } acTrans.Commit(); } }
/// <summary> /// TODO /// </summary> /// <param name="objIds"></param> /// <param name="acCurEd"></param> /// <param name="acCurDb"></param> internal static void UpdateChildren(ObjectId[] objIds, Editor acCurEd, Database acCurDb) { using (var acTrans = acCurDb.TransactionManager.StartTransaction()) { foreach (var oId in objIds) { if (oId.IsErased) { continue; } var pSol = acTrans.GetObject(oId, OpenMode.ForRead) as Solid3d; if (pSol != null) { var eInfo = new EntInfo(pSol, acCurDb, acTrans); if (eInfo.ChildHandles.Count > 0) { foreach (var cHandle in eInfo.ChildHandles) { var objId = acCurDb.GetObjectId(false, cHandle, 0); if (objId == ObjectId.Null || objId.IsErased) { continue; } Solid3d cSol = null; try { cSol = acTrans.GetObject(objId, OpenMode.ForWrite) as Solid3d; } catch (Exception) { acCurEd.WriteMessage("\nChild was erased."); } if (cSol == null) { continue; } var cInfo = new EntInfo(cSol, acCurDb, acTrans); var pClone = pSol.Clone() as Solid3d; if (pClone == null) { continue; } pClone.TransformBy(eInfo.LayMatrix); acCurDb.AppendEntity(pClone); pClone.TopLeftTo(Point3d.Origin); pClone.TransformBy(cInfo.LayMatrix.Inverse()); pClone.TransformBy(Matrix3d.Displacement( pClone.GeometricExtents.MinPoint.GetVectorTo(cSol.GeometricExtents.MinPoint))); pClone.SwapIdWith(cSol.ObjectId, true, true); cSol.Erase(); cSol.Dispose(); } } else { acCurEd.WriteMessage("\nObject has no child objects attached."); } } } acTrans.Commit(); } }