private IBody2 CreateBodyFromSketchRegion(IModeler modeler, IMathUtility mathUtils, ISketchRegion skReg, double height = 1000) { var sketch = skReg.Sketch; if (sketch.Is3D()) { throw new UserErrorException("Only 2D sketches are supported"); } var transform = sketch.ModelToSketchTransform.IInverse(); var boundary = (skReg.GetEdges() as object[]) .Cast <IEdge>() .Select(e => { var curve = e.IGetCurve().ICopy(); //must copy curve otherwise CreateTrimmedSheet4 is failing return(curve); }).ToArray(); var centerPt = mathUtils.CreatePoint(new double[] { 0, 0, 0 }) as IMathPoint; var dirVec = mathUtils.CreateVector(new double[] { 0, 0, 1 }) as IMathVector; var refVec = mathUtils.CreateVector(new double[] { 1, 0, 0 }) as IMathVector; centerPt = centerPt.IMultiplyTransform(transform); dirVec = dirVec.IMultiplyTransform(transform); refVec = refVec.IMultiplyTransform(transform); var surf = modeler.CreatePlanarSurface2(centerPt.ArrayData, dirVec.ArrayData, refVec.ArrayData) as ISurface; var sheetBody = surf.CreateTrimmedSheet4(boundary, true) as Body2; if (sheetBody == null) { throw new NullReferenceException("Failed to create trimmed sheet from surface region"); } var firstBody = modeler.CreateExtrudedBody(sheetBody, dirVec as MathVector, height * 0.9 / 2) as IBody2; var secondBody = modeler.CreateExtrudedBody(sheetBody, dirVec.IScale(-1), height * 0.9 / 2) as IBody2; int err; var res = firstBody.Operations2((int)swBodyOperationType_e.SWBODYADD, secondBody, out err) as object[]; return(res.First() as IBody2); }
internal SwSketchRegion(ISketchRegion region, ISwDocument doc, ISwApplication app) : base(region, doc, app) { Region = region; }
public ISketchRegionObject(ISketchRegion ISketchRegioninstance) { ISketchRegionInstance = ISketchRegioninstance; }
internal SwSketchRegion(ISketchRegion region, ISwDocument doc) : base(region, doc) { Region = region; }
internal SwSketchRegion(ISketchRegion region, IModelDoc2 model) : base(model, region) { Region = region; }