protected override bool DoRun() { var fmt = Format(SourceFilePathResolvedValue); var extn = Extension(fmt); var fileName = Path.ChangeExtension(SourceFilePathResolvedValue, extn); var opts = ImportOptions.Create(); opts.Acis.CreateAssembly = true; opts.ImportCurves = true; opts.ImportNames = true; opts.ImportPoints = true; var windows = Document.Open(fileName, opts); Window.ActiveWindow = windows.First(); return(true); }
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; }