예제 #1
0
        protected override MacroFeatureRebuildResult OnRebuild(ISldWorks app, IModelDoc2 model,
                                                               IFeature feature)
        {
            var body = app.IGetModeler().CreateBox(new Point(0.1, 0.2, 0.3), new Vector(0, 0, 1), 0.1, 0.2, 0.3);

            return(MacroFeatureRebuildResult.FromBody(body, feature.GetDefinition() as IMacroFeatureData));
        }
 public OffsetBuilder(ISldWorks app, IModelDoc2 model)
 {
     m_App       = app;
     m_Model     = model;
     m_Modeler   = app.IGetModeler();
     m_MathUtils = m_App.IGetMathUtility();
 }
예제 #3
0
        protected override IBody2[] CreateGeometry(ISldWorks app, SplitBodyByFacesDataModel parameters)
        {
            if (parameters.Bodies != null && parameters.Bodies.Any())
            {
                var modeler = app.IGetModeler();

                var resBodies = new List <IBody2>();

                foreach (var body in parameters.Bodies)
                {
                    var faces = (body.GetFaces() as object[]).Cast <IFace2>().ToArray();

                    foreach (var face in faces)
                    {
                        var sheetBody = modeler.CreateSheetFromFaces(new IFace2[] { face });

                        resBodies.Add(sheetBody);
                    }
                }

                return(resBodies.ToArray());
            }
            else
            {
                throw new UserErrorException("No input bodies selected");
            }
        }
예제 #4
0
        protected override MacroFeatureRebuildResult OnRebuild(ISldWorks app, IModelDoc2 model, IFeature feature)
        {
            //use extension methods of IModeler to create a box body
            IBody2 tempBody = app.IGetModeler().CreateBox(new Point(0, 0, 0), new Vector(1, 0, 0), 0.1, 0.1, 0.1);

            return(MacroFeatureRebuildResult.FromBody(tempBody, feature.GetDefinition() as IMacroFeatureData, false));
        }
예제 #5
0
        internal void Load(ISldWorks app, params Type[] cmdGroupTypes)
        {
            m_Kit = new ServicesManager(this.GetType().Assembly, new IntPtr(app.IFrameObject().GetHWnd()),
                                        typeof(EulaService),
                                        typeof(UpdatesService),
                                        typeof(OpenIdConnectorService),
                                        typeof(UserSettingsService),
                                        typeof(SystemEventLogService),
                                        typeof(AboutApplicationService));

            m_Kit.HandleError += OnHandleError;
            m_Container        = new UnityContainer();

            m_Container.RegisterInstance(app);
            m_Container.RegisterInstance(app.IGetMathUtility() as IMathUtility);
            m_Container.RegisterInstance(app.IGetModeler() as IModeler);
            m_Container.RegisterInstance(m_Kit);

            m_Commands = new Dictionary <Enum, Type>();

            foreach (var cmdGrpType in cmdGroupTypes)
            {
                foreach (var cmd in Enum.GetValues(cmdGrpType).Cast <Enum>())
                {
                    Type from;
                    Type to;
                    GetCommandHandler(cmd, out from, out to);
                    m_Commands.Add(cmd, from);
                    m_Container.RegisterType(from, to,
                                             new ContainerControlledLifetimeManager());
                }
            }

            m_Kit.StartServices();
        }
        public RoundStockModel(ISldWorks app, CylindricalStockFitExtractor cylExt, ILogService log)
        {
            m_App     = app;
            m_Modeler = app.IGetModeler();
            m_CylExt  = cylExt;
            m_Log     = log;

            m_Log.LogMessage("Initialized round stock model");
        }
예제 #7
0
        protected override IBody2[] CreateGeometry(ISldWorks app, ExtrudeSurfaceCapDataModel parameters)
        {
            if (parameters.Profiles != null && parameters.Profiles.Any())
            {
                var bodies = new List <IBody2>();

                foreach (var profile in parameters.Profiles)
                {
                    if (profile is IFeature)
                    {
                        var sketch = (profile as IFeature).GetSpecificFeature2() as ISketch;

                        var sketchContours = sketch.GetSketchContours() as object[];

                        if (sketchContours != null)
                        {
                            foreach (ISketchContour skCont in sketchContours)
                            {
                                bodies.Add(CreateBodyFromSketchContour(app.IGetModeler(),
                                                                       app.IGetMathUtility(), skCont, parameters.Height, parameters.MidPlane));
                            }
                        }
                    }

                    if (profile is ISketchContour)
                    {
                        bodies.Add(CreateBodyFromSketchContour(app.IGetModeler(),
                                                               app.IGetMathUtility(), profile as ISketchContour,
                                                               parameters.Height, parameters.MidPlane));
                    }
                }

                return(bodies.ToArray());
            }
            else
            {
                throw new UserErrorException("Please select the profile for extrusion");
            }
        }
        protected override IBody2[] CreateGeometry(ISldWorks app, TrimSurfacesByRegionDataModel parameters)
        {
            if (parameters.TargetBodies == null || !parameters.TargetBodies.Any())
            {
                throw new UserErrorException("Select target bodies to trim");
            }

            if (parameters.TrimTools == null || !parameters.TrimTools.Any())
            {
                throw new UserErrorException("Select trim tools (sketches or sketch regions)");
            }

            var resBodies = new List <IBody2>();

            var modeler   = app.IGetModeler();
            var mathUtils = app.IGetMathUtility();

            var toolBodies = CreateToolBodies(modeler, mathUtils, parameters.TrimTools);

            if (!toolBodies.Any())
            {
                throw new UserErrorException("No closed regions found in the selected trim tools");
            }

            foreach (var surfBody in parameters.TargetBodies)
            {
                if (surfBody == null)
                {
                    continue; //TODO: investigate why first body is null
                }

                foreach (var solidBody in toolBodies)
                {
                    var targetBody = surfBody.ICopy();
                    var toolBody   = solidBody.ICopy();

                    int      err;
                    object[] res = targetBody.Operations2((int)swBodyOperationType_e.SWBODYINTERSECT, toolBody, out err) as object[];

                    if (res != null)
                    {
                        foreach (IBody2 resBody in res)
                        {
                            resBodies.Add(resBody);
                        }
                    }
                }
            }

            return(resBodies.ToArray());
        }
예제 #9
0
        protected override MacroFeatureRebuildResult OnRebuild(ISldWorks app, IModelDoc2 model,
                                                               IFeature feature, BoundingCylinderMacroFeatureParams parameters)
        {
            var modeler = app.IGetModeler();

            Point  center;
            Vector axis;
            double radius;
            double height;
            double extraHeight;

            GetCylinderParameters(parameters, out center, out axis, out radius, out height, out extraHeight);

            var cyl = modeler.CreateCylinder(center, axis, radius, height + extraHeight);

            return(MacroFeatureRebuildResult.FromBody(cyl, feature.GetDefinition() as IMacroFeatureData));
        }
예제 #10
0
        /// <summary>
        /// 从文件加载实体
        /// </summary>
        /// <param name="app"></param>
        /// <param name="filePath"></param>
        /// <returns></returns>
        public static IBody2 LoadBodyFromFile(ISldWorks app, string filePath)
        {
            IStream stream = null;

            CreateStreamOnHGlobal(IntPtr.Zero, true, ref stream);

            var comStream = new ComStreamBody(ref stream, true, true);

            using (var fileStream = File.OpenRead(filePath))
            {
                fileStream.CopyTo(comStream);
                comStream.Seek(0, SeekOrigin.Begin);
            }

            IModeler modeler = app.IGetModeler();

            return((IBody2)modeler.Restore(stream));
        }
예제 #11
0
        public double Build(double width, double height, double length, out int totalModelsBuilt)
        {
            m_TotalModelsBuilt++;

            var templatePath = m_App.GetUserPreferenceStringValue((int)swUserPreferenceStringValue_e.swDefaultTemplatePart);

            var part = m_App.NewDocument(templatePath, (int)swDwgPaperSizes_e.swDwgPapersUserDefined, 0, 0) as IPartDoc;

            var box = m_App.IGetModeler().CreateBodyFromBox(
                new double[]
            {
                0, 0, 0,
                1, 0, 0,
                width, length, height
            });

            var feat = part.CreateFeatureFromBody3(box, false, (int)swCreateFeatureBodyOpts_e.swCreateFeatureBodySimplify);

            int errs  = -1;
            int warns = -1;

            var outPath = Path.Combine(m_BuildDir, $"{DateTime.Now.ToString("yyyy-MM-dd-hh-mm-ss")}.sldprt");

            var dir = Path.GetDirectoryName(outPath);

            if (!Directory.Exists(dir))
            {
                Directory.CreateDirectory(dir);
            }

            (part as IModelDoc2).Extension.SaveAs(outPath, (int)swSaveAsVersion_e.swSaveAsCurrentVersion,
                                                  (int)swSaveAsOptions_e.swSaveAsOptions_Silent, null, ref errs, ref warns);

            totalModelsBuilt = m_TotalModelsBuilt;

            var mass = (part as IModelDoc2).Extension.CreateMassProperty().Mass;

            m_App.CloseDoc((part as IModelDoc2).GetTitle());

            return(mass);
        }
예제 #12
0
 internal SwApplication(ISldWorks app, ILogger logger)
 {
     Application     = app;
     SwDocuments     = new SwDocumentCollection(app, logger);
     GeometryBuilder = new SwGeometryBuilder(app.IGetMathUtility(), app.IGetModeler());
 }
 protected override IBody2[] CreateGeometry(ISldWorks app, CropBodiesDataModel parameters)
 {
     return(CropGeometry(app.IGetModeler(), app.IGetMathUtility(),
                         parameters.TargetBodies, parameters.TrimTools));
 }