/// <summary> /// Creates an Arc by allowing the user to sketch through three points /// </summary> /// <param name="interval">The time in milliseconds between each check to see if the curve has been created yet</param> /// <returns>Arc created by the operation</returns> public PSArc SketchArcThroughThreePoints(int interval = 500) { // Start the sketch _powerSHAPE.DoCommand("CREATE ARC FITTED"); // Clear the created items list _powerSHAPE.ActiveModel.ClearCreatedItems(); PSArc arc = null; PSModel model = _powerSHAPE.ActiveModel; // Keep looping and picking points while (arc == null) { // Wait for half a second to see if a arc has been created yet System.Threading.Thread.Sleep(interval); // Fire in "OK" every time because if the user has finished sketching they have to confirm the radius before the creation completes _powerSHAPE.DoCommand("OK"); // See if the user finished creating the arc yet if (model.CreatedItems.Count == 1) { arc = (PSArc)model.CreatedItems[0]; // Call select to end the arc creation _powerSHAPE.DoCommand("SELECT"); // Add the new arc to the collection model.Arcs.Add(arc); } } return(arc); }
/// <summary> /// Does not work as created.number is not updated. /// </summary> /// <param name="entityToLimit">The entity to limit.</param> /// <param name="keepOption">Keep option, by default KeepOne.</param> /// <returns>The limited entity.</returns> /// <remarks></remarks> internal static PSEntity LimitEntityUsingDynamicCutter( IPSLimitable entityToLimit, LimitingKeepOptions keepOption = LimitingKeepOptions.KeepOne) { // Get PowerSHAPE instance _powerSHAPE = ((PSEntity)entityToLimit).PowerSHAPE; // Create a list of the single entity PSEntity entity = (PSEntity)entityToLimit; _powerSHAPE.ActiveModel.ClearCreatedItems(); entity.AddToSelection(true); _powerSHAPE.DoCommand("EDIT SELECTION"); _powerSHAPE.DoCommand(keepOption.ToString()); _powerSHAPE.DoCommand("Cutter_Dynamic On"); bool limitingHappened = false; PSModel model = _powerSHAPE.ActiveModel; var interval = 1000; // Keep looping and picking points while (limitingHappened == false) { // Wait for a second to see if a limit has happened yet. The item will no longer be selected when it has System.Threading.Thread.Sleep(interval); // See if the user finished creating the curve yet int selectedCount = 1; try { selectedCount = _powerSHAPE.ReadIntValue("SELECTION.NUMBER"); } catch { selectedCount = 1; } if (selectedCount == 0) { foreach (PSEntity newEntity in _powerSHAPE.ActiveModel.CreatedItems) { newEntity.Id = _powerSHAPE.ReadIntValue(newEntity.Identifier + "['" + newEntity.Name + "'].ID"); _powerSHAPE.ActiveModel.Add(newEntity); } limitingHappened = true; } } // When the limit happens we get a new entity with a new id but it has the same name as the original // So change the id of the entity we wanted to limit so things work as normal entity.Id = _powerSHAPE.ReadIntValue(entity.Identifier + "['" + entity.Name + "'].ID"); return(entity); }
/// <summary> /// Removes the specified window. /// </summary> /// <param name="window">The window to delete.</param> /// <returns>True if it succeeds.</returns> /// <remarks></remarks> public bool Remove(PSWindow window) { if (window.Exists) { // Close window window.MakeActive(); PSModel activeModel = _powerSHAPE.ActiveModel; _powerSHAPE.DoCommand("CANCEL"); _powerSHAPE.DoCommand("FILE CLOSE SELECTED YES"); _powerSHAPE.Models.Remove(activeModel); } if (Contains(window)) { return(base.Remove(window)); } return(false); }
/// <summary> /// Allows the user to sketch a curve. /// </summary> /// <param name="closeCurve">Forces the user to create a curve that is closed</param> /// <param name="interval">The number of milliseconds to wait before each check for a new curve. Defaults to 0.5seconds</param> /// <returns>Curve created by the operation</returns> public PSCurve CreateCurveFromSketch(bool closeCurve, int interval = 500) { // Clear the created items list _powerSHAPE.ActiveModel.ClearCreatedItems(); // Start the sketch _powerSHAPE.DoCommand("CREATE CURVE THROUGH"); PSCurve curve = null; PSModel model = _powerSHAPE.ActiveModel; // Keep looping and picking points while (curve == null) { // Wait for half a second to see if a Curve has been created yet System.Threading.Thread.Sleep(interval); // See if the user finished creating the curve yet if (model.CreatedItems.Count == 1 && model.CreatedItems[0].GetType() == typeof(PSCurve)) { curve = (PSCurve)model.CreatedItems[0]; // Yes, so do we need to check that it is closed? if (closeCurve && curve.IsClosed == false) { curve.Delete(); // Cancel to exit curve creation _powerSHAPE.DoCommand("CANCEL"); throw new Exception("User created an open curve"); } // Cancel to exit curve creation _powerSHAPE.DoCommand("CANCEL"); // Add the new curve to the collection _powerSHAPE.ActiveModel.Curves.Add(curve); } } return(curve); }
static void Main(string[] args) { powerSHAPE = new PSAutomation(Autodesk.ProductInterface.InstanceReuse.CreateNewInstance); powerSHAPE.Reset(); //Creating and selecting model psModel = powerSHAPE.Models.CreateEmptyModel(); //Turning off messages powerSHAPE.FormUpdateOff(); powerSHAPE.RefreshOff(); powerSHAPE.DialogsOff(); // Building model BuildingBasis(); BuildingCylinder(); CuttingCirclesInBase(); BuildingSidebars(); // Ending execution ClosingSafely(); }