static Direction GetAverageNormal(Point point, IDesignEdge designEdge) { Vector startNormal = Vector.Zero; SurfaceEvaluation surfEval = null; foreach (IDesignFace designFace in designEdge.Faces) { surfEval = designFace.Shape.Geometry.ProjectPoint(point); startNormal += surfEval.Normal.UnitVector; } return startNormal.Direction; }
protected override void OnExecute(Command command, ExecutionContext context, System.Drawing.Rectangle buttonRect) { base.OnExecute(command, context, buttonRect); Window activeWindow = Window.ActiveWindow; Part activePart = (activeWindow.Scene as Part); Layer tabLayer = NoteHelper.CreateOrGetLayer(activeWindow.ActiveContext.Context.Document, "Tabs", System.Drawing.Color.Fuchsia); IDesignEdge iDesignEdge = activeWindow.ActiveContext.SingleSelection as IDesignEdge; if (iDesignEdge == null) { return; } if (iDesignEdge.Faces.Count != 1) { return; } IDesignFace iDesignFace = null; foreach (IDesignFace testFace in iDesignEdge.Faces) { iDesignFace = testFace; } Debug.Assert(iDesignFace != null); Point startPoint = iDesignEdge.Shape.StartPoint; Point endPoint = iDesignEdge.Shape.EndPoint; if (areTabsFlipped) { Point tempPoint = startPoint; startPoint = endPoint; endPoint = tempPoint; } SurfaceEvaluation surfEval = iDesignFace.Shape.ProjectPoint(startPoint); Direction faceNormal = surfEval.Normal; Point midpoint = startPoint + (endPoint - startPoint) / 2; Double edgeLength = iDesignEdge.Shape.Length; Direction xDir = (endPoint - startPoint).Direction; List <Window> tabWindows = null; string tabFile = string.Empty; if (!isTabStartSlot) { tabFile = @"C:\Users\bcr.SPACECLAIM\Documents\Models\Dodecahedron Foldcrease\Tab-Circle-Male.scdoc"; } else { tabFile = @"C:\Users\bcr.SPACECLAIM\Documents\Models\Dodecahedron Foldcrease\Tab-Circle-Female.scdoc"; } try { tabWindows = new List <Window>(Document.Open(tabFile, ImportOptions.Create())); } catch (Exception exception) { System.Windows.Forms.MessageBox.Show(SpaceClaim.Api.V10.Application.MainWindow, exception.Message); } DesignBody tabDesignBody = null; foreach (DesignBody testBody in (tabWindows[0].Scene as Part).Bodies) { tabDesignBody = testBody; } Debug.Assert(tabDesignBody != null); tabDesignBody = DesignBody.Create(activePart, "tab", tabDesignBody.Shape.Body.Copy()); foreach (Window window in tabWindows) { window.Delete(); } Matrix scale = Matrix.CreateScale(edgeLength / 0.02, Point.Origin); Matrix trans = Matrix.CreateMapping(Frame.Create(midpoint, xDir, Direction.Cross(faceNormal, xDir))); tabDesignBody.Transform(trans * scale); tabDesignBody.Layer = tabLayer; }