public void Cmd_NameParts() { if (!LicensingAgent.Check()) { return; } var acCurDoc = Application.DocumentManager.MdiActiveDocument; var acCurDb = acCurDoc.Database; var acCurEd = acCurDoc.Editor; var keyList = new List <KeywordAgent>(); var userResetPartCounter = SettingsUser.ResetPartCount; //Reset Part Number to 1 if specified in bool if (SettingsUser.ResetPartCount) { SortingAgent.CurrentPartNumber = 1; } var keyAgentName = new KeywordAgent(acCurEd, "NameFormat", "Enter naming format: ", TypeCode.String, SettingsUser.NamingConvention); var keyAgentNum = new KeywordAgent(acCurEd, "StartFrom", "Enter part number to start from: ", TypeCode.Int32, SortingAgent.CurrentPartNumber.ToString()); keyList.Add(keyAgentName); keyList.Add(keyAgentNum); //Check for pick-first selection -> if none, get selection var acSet = SelectionSet.FromObjectIds(acCurEd.GetFilteredSelection(DxfNameEnum._3Dsolid, false, keyList)); keyAgentName.Set(ref SettingsUser.NamingConvention); keyAgentNum.Set(ref SortingAgent.CurrentPartNumber); using (var acTrans = acCurDb.TransactionManager.StartTransaction()) { using (var pWorker = new ProgressAgent("Parsing Solids: ", acSet.Count)) { var eList = new List <EntInfo>(); 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; } eList.Add(new EntInfo(acSol, acCurDb, acTrans)); } //eList.SortSolids(); eList.SortAndName(pWorker, acCurDb, acCurEd, acTrans); } acTrans.Commit(); } SettingsUser.ResetPartCount = userResetPartCounter; }
public void Cmd_RcFlatten() { var acCurDoc = Application.DocumentManager.MdiActiveDocument; var acCurDb = acCurDoc.Database; var acCurEd = acCurDoc.Editor; var keys = new List <KeywordAgent>(); var keyFlatAssembly = new KeywordAgent(acCurEd, "assemBly", "Flatten Assembly? ", TypeCode.Boolean, SettingsUser.FlattenAssembly.ToSpecified()); var keyFlatAllSides = new KeywordAgent(acCurEd, "allSides", "Flatten All Sides? ", TypeCode.Boolean, SettingsUser.FlattenAllSides.ToSpecified()); var keyRetainHidden = new KeywordAgent(acCurEd, "retainHidden", "Retain Hidden Lines? ", TypeCode.Boolean, SettingsUser.RetainHiddenLines.ToSpecified()); keys.Add(keyFlatAssembly); keys.Add(keyFlatAllSides); keys.Add(keyRetainHidden); var objIds = acCurEd.GetFilteredSelection(Enums.DxfNameEnum._3Dsolid, false, keys, "\nSelect solids to flatten: "); if (objIds.Length <= 0) { return; } keyFlatAssembly.Set(ref SettingsUser.FlattenAssembly); keyFlatAllSides.Set(ref SettingsUser.FlattenAllSides); keyRetainHidden.Set(ref SettingsUser.RetainHiddenLines); using (var pWorker = new ProgressAgent("Flattening Solids: ", objIds.Length)) { using (var acTrans = acCurDb.TransactionManager.StartTransaction()) { //Set the UCS to World - save the user UCS var userCoordSystem = acCurEd.CurrentUserCoordinateSystem; acCurEd.CurrentUserCoordinateSystem = Matrix3d.Identity; if (SettingsUser.FlattenAssembly || SettingsUser.FlattenAllSides) { var objId = objIds.SolidFusion(acTrans, acCurDb, true); objIds = new[] { objId }; } foreach (var obj in objIds) { if (!pWorker.Progress()) { acTrans.Abort(); } using (var acSol = acTrans.GetObject(obj, OpenMode.ForWrite) as Solid3d) { if (acSol != null) { if (SettingsUser.FlattenAllSides) { acSol.FlattenAllSides(acCurDb, acCurEd, acTrans); } else { acSol.Flatten(acTrans, acCurDb, acCurEd, true, false, true, userCoordSystem); if (SettingsUser.RetainHiddenLines) { acSol.Flatten(acTrans, acCurDb, acCurEd, false, true, true, userCoordSystem); } acSol.Erase(); acSol.Dispose(); } } } } acCurEd.CurrentUserCoordinateSystem = userCoordSystem; acTrans.Commit(); } } }
public void Cmd_SpaceViews() { if (!LicensingAgent.Check()) { return; } var acCurDoc = Application.DocumentManager.MdiActiveDocument; var acCurDb = acCurDoc.Database; var acCurEd = acCurDoc.Editor; var keyList = new List <KeywordAgent>(); var keyAgentSpace = new KeywordAgent(acCurEd, "SpaceEqually", "Space viewports equally between two viewports? ", TypeCode.Boolean); var keyAgentDist = new KeywordAgent(acCurEd, "Distance", "Enter distance to space between viewports: ", TypeCode.Double, SettingsUser.ViewSpacing.ToString()); keyList.Add(keyAgentDist); keyList.Add(keyAgentSpace); var viewRes = acCurEd.GetFilteredSelection(Enums.DxfNameEnum.Viewport, false, keyList, "\nSelect Viewports to space or: "); if (viewRes.Length <= 0) { return; } var equalSpace = false; keyAgentSpace.Set(ref equalSpace); keyAgentDist.Set(ref SettingsUser.ViewSpacing); using (var acTrans = acCurDb.TransactionManager.StartTransaction()) { var views = viewRes.ToList(); var firstViewAr = acCurEd.GetFilteredSelection(Enums.DxfNameEnum.Viewport, true, null, "\nSelect first viewport to use as spacing criteria: "); if (firstViewAr.Length <= 0) { acTrans.Abort(); return; } var firstView = firstViewAr[0]; var fViewport = acTrans.GetObject(firstView, OpenMode.ForRead) as Viewport; if (fViewport == null) { acTrans.Abort(); return; } var fCen = fViewport.CenterPoint; if (views.Contains(firstView)) { views.Remove(firstView); } if (equalSpace) { var lastViewAr = acCurEd.GetFilteredSelection(Enums.DxfNameEnum.Viewport, true, null, "\nSelect last viewport to use as spacing criteria: "); if (lastViewAr.Length <= 0) { acTrans.Abort(); return; } var lastView = lastViewAr[0]; var lViewport = acTrans.GetObject(lastView, OpenMode.ForRead) as Viewport; if (lViewport == null) { acTrans.Abort(); return; } var lCen = lViewport.CenterPoint; if (views.Contains(lastView)) { views.Remove(lastView); } var dist = fCen.DistanceTo(lCen); var dSpace = dist / (views.Count + 1); for (var index = 0; index < views.Count; index++) { var view = views[index]; var acViewport = acTrans.GetObject(view, OpenMode.ForWrite) as Viewport; if (acViewport == null) { continue; } acViewport.CenterPoint = fCen.GetAlong(lCen, dSpace * (index + 1)); } } else { var startPoint = fCen; //prompt for end point var endPtOpts = new PromptPointOptions("\nSelect direction for spacing: ") { UseBasePoint = true, UseDashedLine = true, BasePoint = startPoint, AllowNone = false }; var endPtRes = acCurEd.GetPoint(endPtOpts); if (endPtRes.Status == PromptStatus.OK) { var endPt = endPtRes.Value; if (AcVars.OrthoMode == Enums.OrthoMode.On) { endPt = endPt.GetOrthoPoint(startPoint); } _ = fCen; var lastBounds = fViewport.Bounds; var lengthToTravel = lastBounds.GetLengthAcross(startPoint, endPt) / 2; var vPorts = new List <Viewport>(); foreach (var view in views) { var vPort = acTrans.GetObject(view, OpenMode.ForRead) as Viewport; if (vPort == null) { continue; } vPorts.Add(vPort); } var sortedVPorts = vPorts.OrderBy(e => e.CenterPoint.X).ThenBy(e => e.CenterPoint.Y); foreach (var view in sortedVPorts) { var vBounds = view.Bounds; if (vBounds == null) { continue; } var vDist = vBounds.GetLengthAcross(startPoint, endPt); lengthToTravel += vDist / 2 + SettingsUser.ViewSpacing; var newPt = startPoint.GetAlong(endPt, lengthToTravel); lengthToTravel += vDist / 2; view.UpgradeOpen(); view.CenterPoint = newPt; view.DowngradeOpen(); } } } acTrans.Commit(); } }
public void Cmd_LayParts() { if (!LicensingAgent.Check()) { return; } var acCurDoc = Application.DocumentManager.MdiActiveDocument; var acCurDb = acCurDoc.Database; var acCurEd = acCurDoc.Editor; var keys = new List <KeywordAgent>(); var keyFlatAssembly = new KeywordAgent(acCurEd, "FLatshot", "Flatten part to 2D lines? ", TypeCode.Boolean, SettingsUser.LayFlatShot.ToSpecified()); keys.Add(keyFlatAssembly); //Check for pick-first selection -> if none, get selection var acSet = SelectionSet.FromObjectIds(acCurEd.GetFilteredSelection(Enums.DxfNameEnum._3Dsolid, false, keys)); if (acSet.Count <= 0) { return; } keyFlatAssembly.Set(ref SettingsUser.LayFlatShot); if (SettingsUser.LayFlatShot) { var layFlatShot = acCurEd.GetBool("\n Create flatshot for each side?"); if (layFlatShot != null) { SettingsUser.LayAllSidesFlatShot = layFlatShot.Value; } var retainHidden = acCurEd.GetBool("\n Retain hidden lines?"); if (retainHidden != null) { SettingsUser.RetainHiddenLines = retainHidden.Value; } } else { SettingsUser.LayAllSidesFlatShot = false; } //Set the UCS to World - save the user UCS var userCoordSystem = acCurEd.CurrentUserCoordinateSystem; acCurEd.CurrentUserCoordinateSystem = Matrix3d.Identity; //Set the Grid Mode to ON if it is not ON - Get the users current grid mode var userGridMode = AcVars.GridMode; if (AcVars.GridMode != Enums.GridMode.On) { AcVars.GridMode = Enums.GridMode.On; } acCurEd.Regen(); var laypt = acCurEd.Get2DPoint("\nSelect point to lay parts at: "); // Return the Grid Mode to the Users Setting AcVars.GridMode = userGridMode; var multAmount = 1; if (SettingsUser.PromptForMultiplication) { multAmount = acCurEd.GetPositiveInteger("\nEnter number to multiply parts by: ", 1); } using (var acTrans = acCurDb.TransactionManager.StartTransaction()) { using (var pWorker = new ProgressAgent("Parsing Solids: ", acSet.Count)) { var eList = new List <EntInfo>(); 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; } eList.Add(new EntInfo(acSol, acCurDb, acTrans)); } eList.SortAndLay(laypt, pWorker, acCurDb, acCurEd, acTrans, multAmount); } acTrans.Commit(); } //Set the UCS back to the user UCS acCurEd.CurrentUserCoordinateSystem = userCoordSystem; acCurEd.Regen(); }