Ejemplo n.º 1
1
        public AddFeature(ISldWorks _swApp)
        {
            swApp = _swApp;
            Doc = swApp.ActiveDoc;
            BitmapHandler iBmp = new BitmapHandler();
            Assembly thisAssembly;
            thisAssembly = System.Reflection.Assembly.GetAssembly(this.GetType());
            var sbm = iBmp.CreateFileFromResourceBitmap("qwe.ToolbarSmall.bmp", thisAssembly);
            var lbm = iBmp.CreateFileFromResourceBitmap("qwe.ToolbarLarge.bmp", thisAssembly);
            Doc.InsertLibraryFeature("Dave's LibFeatPartNameIn");

            var tpv = swApp.CreateTaskpaneView2(lbm, "DoesIt");

            tpv.AddStandardButton(0, "HERE!");
            swApp.ActivateTaskPane(1);
            //tpv.AddStandardButton(1, "tooltip!");

            //var toolbar = swApp.AddToolbar4(

            //var SelMan = Doc.SelectionManager;
            //string[] Methods = new string[9];
            //int Names = 0;
            //int Types = 0;
            //int Values = 0;
            //int vEditBodies = 0;
            //long options = 0;
            //int dimTypes = 0;
            //int dimValue = 0;
            //string[] icons = new string[3];

            //var ThisFile = "C:/Analytics";
            //Methods[0] = ThisFile;
            //Methods[1] = "FeatureModule";
            //Methods[2] = "swmRebuild";
            //Methods[3] = ThisFile;
            //Methods[4] = "FeatureModule";
            //Methods[5] = "swmEditDefinition";
            //Methods[6] = "";
            //Methods[7] = "";
            //Methods[8] = "";  //A security routine is optional;
            //var pathname = ThisFile;
            //icons[0] = pathname + "/FeatureIcon.bmp";
            //icons[1] = pathname + "/FeatureIcon.bmp";
            //icons[2] = pathname + "/FeatureIcon.bmp";
            //options = (long)swMacroFeatureOptions_e.swMacroFeatureByDefault;

            //Feature selFeat = SelMan.GetSelectedObject6(1, -1);
            //IFeatureManager swFeatMgr = Doc.FeatureManager;
            //swFeatMgr.InsertMacroFeature3("EmptyFeature", "", (object)Methods, (object)Names, (object)Types, (object)Values, (object)dimTypes, (object)dimValue, (object)vEditBodies, (object)icons, (int)options);
            //var boolstatus = feat.MakeSubFeature(selFeat);
        }
        public static Feature InsertDummyBody(IModelDoc2 modelDoc)
        {
            modelDoc.Extension.SelectByID2("Front Plane", "PLANE", 0, 0, 0, true, 0, null, 0).Should().BeTrue();
            var plane1 = (RefPlane)modelDoc.FeatureManager.InsertRefPlane(8, 0.01, 0, 0, 0, 0);
            modelDoc.Extension.SelectByID2("Front Plane", "PLANE", 0, 0, 0, true, 0, null, 0).Should().BeTrue();
            var plane2 = (RefPlane)modelDoc.FeatureManager.InsertRefPlane(8, 0.02, 0, 0, 0, 0);

            modelDoc.Extension.SelectByID2("Plane2", "PLANE", 0, 0, 0, false, 0, null, 0).Should().BeTrue();
            var lines =
                modelDoc.SketchManager.CreateCornerRectangle(-0.02, 0.01, 0, 0.02, -0.01, 0)
                    .CastArray<ISketchSegment>();
            // Sketch to extrude
            modelDoc.Extension.SelectByID2("Sketch1", "SKETCH", 0, 0, 0, false, 0, null, 0).Should().BeTrue();
            // Start condition reference
            modelDoc.Extension.SelectByID2("Plane2", "PLANE", 0.00105020593408751, -0.00195369982668282,
                0.0248175428318827, true, 32, null, 0).Should().BeTrue();
            // End condition reference
            modelDoc.Extension.SelectByID2("Plane1", "PLANE", 0.0068370744701368, -0.004419862088339,
                0.018892268568016, true, 1, null, 0).Should().BeTrue();

            // Boss extrusion start condition reference is Plane2, and the extrusion end is offset 3 mm from the end condition reference, Plane1
            return modelDoc.FeatureManager.FeatureExtrusion3(true, false, true,
                (int)swEndConditions_e.swEndCondOffsetFromSurface, 0, 0.003, 0.003, false, false, false,
                false, 0.0174532925199433, 0.0174532925199433, false, false, false, false, true, true, true,
                (int)swStartConditions_e.swStartSurface, 0, false);
        }
 private static IDisposable Redraw(IModelDoc2 doc, double framerate = 30)
 {
     return Observable.Interval(TimeSpan.FromSeconds(1.0 / framerate))
         .ToObservableExceptional()
         .ObserveOnSolidworksThread()
         .Subscribe(_ => doc.GraphicsRedraw2());
 }
Ejemplo n.º 4
0
 public Vis(ISldWorks _swApp, IModelDoc2 _myModel)
 {
     myModel = _myModel;
     swApp = _swApp;
     myModel = (ModelDoc2)swApp.ActiveDoc;
     myPart = (PartDoc)myModel;
     myMatVisProps = myPart.GetMaterialVisualProperties();
 }
        public IDisposable DisplayUndoable(IModelDoc2 modelDoc, double framerate = 30, int layer = 0)
        {
            OnStart(DateTime.Now);

            var d = new CompositeDisposable();
            OpenGlRenderer.DisplayUndoable(this, modelDoc, layer).DisposeWith(d);
            Redraw(modelDoc, framerate).DisposeWith(d);
            return d;
        }
        public static Mounter Initialize(IModelDoc2 document)
        {
            if (Instance == null)
            {
                Instance = new Mounter(document);
            }

            return Instance;
        }
 public static void DrawPoint(IModelDoc2 model, double x, double y, double z)
 {
     Debug.WriteLine("draw point: [{0}, {1}, {2}]", x, y, z);
     model.Insert3DSketch2(true);
     model.SetAddToDB(true);
     model.SetDisplayWhenAdded(false);
     model.SketchManager.CreatePoint(x, y, z);
     model.SetDisplayWhenAdded(true);
     model.SetAddToDB(false);
     model.Insert3DSketch2(true);
 }
Ejemplo n.º 8
0
 public Triangle(IModelDoc2 _mod, UserControl1 _uc, int _id)
 {
     swModel = _mod;
     uc = _uc;
     id = _id;
     name = "Surface-Plane" + (id + 1).ToString();
     isShowing = true;
     //swModel.Extension.SelectByID(name, "SURFACEBODY", 0, 0, 0, false, 0, null);
     //Body2 body = swModel.SelectionManager.GetSelectedObject3(1);
     //var face = body.GetFirstFace();
     //face.Select(0);
     //var bRet = swModel.SelectedFaceProperties(0x00FF0000, 1, 1, 1, 1, 0, 1, false, "");
 }
 public static void DrawLine(IModelDoc2 model, double x1, double y1, double z1, double x2, double y2, double z2)
 {
     model.Insert3DSketch2(true);
     model.SetAddToDB(true);
     model.SetDisplayWhenAdded(false);
     ISketchPoint from = model.SketchManager.CreatePoint(x1, y1, z1);
     ISketchPoint to = model.SketchManager.CreatePoint(x2, y2, z2);
     ISketchSegment line = model.SketchManager.CreateLine(from.X, from.Y, from.Z, to.X, to.Y, to.Z);
     Debug.WriteLine("draw line(length = {6}): from [{0}, {1}, {2}] to [{3}, {4}, {5}]", x1, y1, z1, x2, y2, z2, line.GetLength());
     model.SketchManager.CreatePoint(x2, y2, z2);
     model.SetDisplayWhenAdded(true);
     model.SetAddToDB(false);
     model.Insert3DSketch2(true);
 }
        public static IDisposable DisplayUndoable(IRenderer renderer, IModelDoc2 doc, int layer = 0)
        {
            if (renderer == null)
                throw new ArgumentNullException(nameof(renderer));
            if (doc == null)
                throw new ArgumentNullException(nameof(doc));

            OpenGlRenderer openGlRenderer;
            if (Lookup.TryGetValue(doc, out openGlRenderer))
            {
                return openGlRenderer.DisplayUndoableImpl(renderer, doc, layer);
            }
            throw new Exception("Can't render OpenGL content, because the model view wasn't setup properly.");
        }
        public static void Bounding(IModelDoc2 model, double[] boxFeature)
        {
            SketchManager sketchManager = default(SketchManager);
            SketchPoint[] sketchPoint = new SketchPoint[9];
            SketchSegment[] sketchSegment = new SketchSegment[13];

            Debug.Print("  point1 = " + "(" + boxFeature[0] * 1000.0 + ", " + boxFeature[1] * 1000.0 + ", " + boxFeature[2] * 1000.0 + ") mm");
            Debug.Print("  point2 = " + "(" + boxFeature[3] * 1000.0 + ", " + boxFeature[4] * 1000.0 + ", " + boxFeature[5] * 1000.0 + ") mm");
            model.Insert3DSketch2(true);
            model.SetAddToDB(true);
            model.SetDisplayWhenAdded(false);

            sketchManager = (SketchManager)model.SketchManager;

            // draw points at each corner of bounding box
            sketchPoint[0] = (SketchPoint)sketchManager.CreatePoint(boxFeature[3], boxFeature[1], boxFeature[5]);
            sketchPoint[1] = (SketchPoint)sketchManager.CreatePoint(boxFeature[0], boxFeature[1], boxFeature[5]);
            sketchPoint[2] = (SketchPoint)sketchManager.CreatePoint(boxFeature[0], boxFeature[1], boxFeature[2]);
            sketchPoint[3] = (SketchPoint)sketchManager.CreatePoint(boxFeature[3], boxFeature[1], boxFeature[2]);
            sketchPoint[4] = (SketchPoint)sketchManager.CreatePoint(boxFeature[3], boxFeature[4], boxFeature[5]);
            sketchPoint[5] = (SketchPoint)sketchManager.CreatePoint(boxFeature[0], boxFeature[4], boxFeature[5]);
            sketchPoint[6] = (SketchPoint)sketchManager.CreatePoint(boxFeature[0], boxFeature[4], boxFeature[2]);
            sketchPoint[7] = (SketchPoint)sketchManager.CreatePoint(boxFeature[3], boxFeature[4], boxFeature[2]);

            // now draw bounding box
            sketchSegment[0] = (SketchSegment)sketchManager.CreateLine(sketchPoint[0].X, sketchPoint[0].Y, sketchPoint[0].Z, sketchPoint[1].X, sketchPoint[1].Y, sketchPoint[1].Z);
            sketchSegment[1] = (SketchSegment)sketchManager.CreateLine(sketchPoint[1].X, sketchPoint[1].Y, sketchPoint[1].Z, sketchPoint[2].X, sketchPoint[2].Y, sketchPoint[2].Z);
            sketchSegment[2] = (SketchSegment)sketchManager.CreateLine(sketchPoint[2].X, sketchPoint[2].Y, sketchPoint[2].Z, sketchPoint[3].X, sketchPoint[3].Y, sketchPoint[3].Z);
            sketchSegment[3] = (SketchSegment)sketchManager.CreateLine(sketchPoint[3].X, sketchPoint[3].Y, sketchPoint[3].Z, sketchPoint[0].X, sketchPoint[0].Y, sketchPoint[0].Z);
            sketchSegment[4] = (SketchSegment)sketchManager.CreateLine(sketchPoint[0].X, sketchPoint[0].Y, sketchPoint[0].Z, sketchPoint[4].X, sketchPoint[4].Y, sketchPoint[4].Z);
            sketchSegment[5] = (SketchSegment)sketchManager.CreateLine(sketchPoint[1].X, sketchPoint[1].Y, sketchPoint[1].Z, sketchPoint[5].X, sketchPoint[5].Y, sketchPoint[5].Z);
            sketchSegment[6] = (SketchSegment)sketchManager.CreateLine(sketchPoint[2].X, sketchPoint[2].Y, sketchPoint[2].Z, sketchPoint[6].X, sketchPoint[6].Y, sketchPoint[6].Z);
            sketchSegment[7] = (SketchSegment)sketchManager.CreateLine(sketchPoint[3].X, sketchPoint[3].Y, sketchPoint[3].Z, sketchPoint[7].X, sketchPoint[7].Y, sketchPoint[7].Z);
            sketchSegment[8] = (SketchSegment)sketchManager.CreateLine(sketchPoint[4].X, sketchPoint[4].Y, sketchPoint[4].Z, sketchPoint[5].X, sketchPoint[5].Y, sketchPoint[5].Z);
            sketchSegment[9] = (SketchSegment)sketchManager.CreateLine(sketchPoint[5].X, sketchPoint[5].Y, sketchPoint[5].Z, sketchPoint[6].X, sketchPoint[6].Y, sketchPoint[6].Z);
            sketchSegment[10] = (SketchSegment)sketchManager.CreateLine(sketchPoint[6].X, sketchPoint[6].Y, sketchPoint[6].Z, sketchPoint[7].X, sketchPoint[7].Y, sketchPoint[7].Z);
            sketchSegment[11] = (SketchSegment)sketchManager.CreateLine(sketchPoint[7].X, sketchPoint[7].Y, sketchPoint[7].Z, sketchPoint[4].X, sketchPoint[4].Y, sketchPoint[4].Z);

            model.SetDisplayWhenAdded(true);
            model.SetAddToDB(false);
            model.Insert3DSketch2(true);
        }
Ejemplo n.º 12
0
 public static bool SetGlobalRadians(this IModelDoc2 doc, string name, double radians)
 {
     return(SetGlobal(doc, new SwEq(name, radians, "rad")));
 }
Ejemplo n.º 13
0
 public static IDisposable CloseDisposable(this IModelDoc2 @this)
 {
     return(Disposable.Create(@this.Close));
 }
Ejemplo n.º 14
0
 /// <summary>
 /// Get a persist id from an entity.
 ///
 /// Because we should use the same version of `GetPersistReference` and `GetObjectFromPersistReference` resp.
 /// and the persist reference is saved with the models we should never ever use another version of the two methods.
 /// For more details see http://help.solidworks.com/2016/english/api/sldworksapi/SolidWorks.interop.sldworks~SolidWorks.interop.sldworks.IModelDocExtension~GetPersistReference3.html#remarksSection
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="modelDoc"></param>
 /// <param name="obj"></param>
 /// <returns></returns>
 public static byte[] GetPersistReference <T>(this IModelDoc2 modelDoc, T obj)
 {
     return(modelDoc.Extension.GetPersistReference3(obj).CastArray <byte>());
 }
Ejemplo n.º 15
0
 public static IEnumerable <object> GetSelectedObjectsFromModel(this IModelDoc2 doc, object model)
 {
     return(SelectionDataExtensions.GetSelectionsFromModel(model)
            .SelectMany(data => data.GetObjects(doc)));
 }
Ejemplo n.º 16
0
        public static IDisposable AddSelectionsFromModel(this IModelDoc2 doc, object model)
        {
            var selections = SelectionDataExtensions.GetSelectionsFromModel(model).ToList();

            return(doc.AddSelections(selections));
        }
        private bool Initalize()
        {
            helper      = Helper.Initialize(solidWorks.IGetMathUtility());
            corpus      = new Locator(solidWorks.IGetMathUtility());
            shaft       = new Locator(solidWorks.IGetMathUtility());
            planeLocator     = new Locator(solidWorks.IGetMathUtility());
            prismLocator1    = new Locator(solidWorks.IGetMathUtility());
            prismLocator2    = new Locator(solidWorks.IGetMathUtility());

            document = solidWorks.ActiveDoc as IModelDoc2;
            assembly = document as IAssemblyDoc;

            if (assembly == null)
            {
                ShowMessage("Please, open document with assembly");
                return false;
            }

            horizont = assembly.IFeatureByName(TOP_PLANE_NAME_EN);
            horizont = horizont == null ? assembly.IFeatureByName(TOP_PLANE_NAME_RU) : horizont;
            loader = Loader.Initialize(solidWorks, assembly);
            mounter = Mounter.Initialize(document);
            Debug.WriteLine("loading of assembly ... done!");

            object[] components = assembly.GetComponents(true);
            foreach(IComponent2 component in components)
            {
                if (component.Name2.Contains(configuration[Property.MAIN_DETAIL_NAME]))
                {
                    shaft.Component = component;
                    Debug.WriteLine("shaft search ... done!");
                    break;
                }
            }

            if (shaft.Component == null)
            {
                ShowMessage("Please, add shaft to assembly or enter other/correct name");
                return false;
            }

            return true;
        }
Ejemplo n.º 18
0
           void AddSpecification1(IModelDoc2 swModel, IList<BomData> bomDataList)
        {
            var swDrawing = ((DrawingDoc)(swModel));
            if (swDrawing == null) return;

            string[] spSheetNames = { "SP1", "SP2", "SP3", "SP4", "SP5", "SP6", "SP7", "SP8", "SP9", "SP10", "GSP1", "GSP2" };

            foreach (var t in spSheetNames.Where(swDrawing.ActivateSheet))
            {
                swModel.Extension.SelectByID2(t, "SHEET", 0, 0, 0, false, 0, null, 0);
                swModel.Extension.DeleteSelection2(1);
            }

            BomDataLists(bomDataList);

            InsertBomTable(BomDataListsDivided[0], swDrawing, spSheetNames[0], BomSettings.Sp1);//"GSP-1.slddrt"

            for (var i = 1; i < BomDataListsDivided.Count ; i++)
            {
                InsertBomTable(BomDataListsDivided[i], swDrawing, spSheetNames[1], BomSettings.Sp2);        
            }
        }
Ejemplo n.º 19
0
        private void bulidGearButton_Click(object sender, EventArgs e)
        {
            //int Errors=0;
            //ModelDoc2 swModel;
            // swModel = (ModelDoc2)SwAddin.iSwApp.ActivateDoc3("loaded_document", false, (int)swRebuildOnActivation_e.swUserDecision, ref Errors);

            //make sure we have a part open
            string partTemplate = SwAddin.iSwApp.GetUserPreferenceStringValue((int)swUserPreferenceStringValue_e.swDefaultTemplatePart);
            if ((partTemplate != null) && (partTemplate != ""))
            {
                modDoc = (IModelDoc2)SwAddin.iSwApp.NewDocument(partTemplate, (int)swDwgPaperSizes_e.swDwgPaperA2size, 0.0, 0.0);
            }
            else
            {
                System.Windows.Forms.MessageBox.Show("There is no part template available. Please check your options and make sure there is a part template selected, or select a new part template.");
            }
            // Part.InsertSketch2 True
            //boolstatus = Part.Extension.SelectByID2("前视基准面", "PLANE", 0, 0, 0, False, 0, Nothing, 0)
            //            Part.ClearSelection2 True
            //画齿顶圆

            modDoc.InsertSketch2(true); //建立草图
            modDoc.CreateCircleByRadius2(0, 0, 0, 0.5 * pinionTipDiameter);//  SketchRectangle(0, 0, 0, .1, .1, .1, false);
            //Extrude the sketch
            IFeatureManager featMan = modDoc.FeatureManager;
            featMan.FeatureExtrusion(true,
                false, false,
                (int)swEndConditions_e.swEndCondBlind, (int)swEndConditions_e.swEndCondBlind,
                double.Parse(text_bx.Text) / 1000, 0.0,
                false, false,
                false, false,
                0.0, 0.0,
                false, false,
                false, false,
                true,
                false, false);

            double[] x = new double[15], y = new double[15], x1 = new double[15], y1 = new double[15];

            double U = Math.Sqrt(Math.Pow(pinionTipDiameter / pinionBaseDiameter, 2) - 1);//  滚动角弧度
            // 画渐开线
            for (int i = 0; i < 15; i++)
            {
                x[i] = 0.5 * pinionBaseDiameter * (Math.Sin(U * i / 14) - (U * i / 14) * Math.Cos(U * i / 14));
                y[i] = 0.5 * pinionBaseDiameter * (Math.Cos(U * i / 14) + (U * i / 14) * Math.Sin(U * i / 14));
            }
            // S = pi * m / 2 + 2 * X1 * m * Tan(a)  's为分度圆齿厚
            //sb = m * cos(alpha * pi / 180) * (0.5 * pi + z * (tan(alpha * pi / 180) - alpha * pi / 180));
            double m = double.Parse(text_mn2.Text);
            double Sb = m * Math.Cos(pressuerAngle) * (0.5 * Math.PI + pinionZ * (Math.Tan(pressuerAngle) - pressuerAngle));
            // text_mn2.Text) * 0.5 + 2 * double.Parse(text_xnx.Text) * double.Parse(text_mn2.Text) * Math.Tan(pressuerAngle);  //s为分度圆齿厚
            // double inva = Math.Tan(pressuerAngle) - pressuerAngle;
            // double Sb = double.Parse(text_mn2.Text) * Math.Cos(pressuerAngle)*(0.5 * Math.PI + pinionZ * inva);// *Math.Cos(pressuerAngle);//    's为基圆齿厚

            double temp = -(Math.PI / pinionZ - Sb / (1000 * pinionBaseDiameter));

            // 渐开线转动一个角度,使得渐开线对称,
            for (int i = 0; i < 15; i++)
            {
                x1[i] = x[i] * Math.Cos(temp) - y[i] * Math.Sin(temp);
                y1[i] = x[i] * Math.Sin(temp) + y[i] * Math.Cos(temp);
            }

            modDoc.InsertSketch2(true); //建立草图
            //'绘渐开线
            for (int i = 0; i < 15; i++)
            {
                modDoc.SketchSpline(14 - i, -x1[i], y1[i], 0);
            }
            //'绘渐开线
            for (int i = 0; i < 15; i++)
            {
                modDoc.SketchSpline(14 - i, x1[i], y1[i], 0);
            }

            double df = double.Parse(text_dfx.Text) / 1000;
            double temp1 = Math.Sqrt(0.5 * df * 0.5 * df - x1[0] * x1[0]);
            modDoc.CreateArc2(0, 0, 0, x1[14], y1[14], 0, -x1[14], y1[14], 0, 1);
            modDoc.CreateArc2(0, 0, 0, x1[0], temp1, 0, -x1[0], temp1, 0, 1);

            modDoc.CreateLine2(x1[0], y1[0], 0, x1[0], temp1, 0);
            modDoc.CreateLine2(-x1[0], y1[0], 0, -x1[0], temp1, 0);
            //Debug.Print("Error code "+temp1.ToString());
            // modDoc.CreateLine2(-x1[0], y1[0], 0, -x1[0], temp1, 0);
            //modDoc.CreateArc2(0, 0, 0, x1[0], temp1, 0, -x1[0], temp1, 0, 1);

            ModelDoc2 swModel;
            ModelDocExtension swExt;
            SelectionMgr swSelMgr;
            ISketchManager swSktMgr;
            bool boolstatus;
            //int Errors = 0;
            swModel = SwAddin.iSwApp.ActiveDoc as ModelDoc2;
            swSktMgr = swModel.SketchManager;// SwAddin.iSwApp.ActiveDoc as ISketchManager;
            //swModel = (ModelDoc2)SwAddin.iSwApp.ActiveDoc ActivateDoc3("loaded_document", false, (int)swRebuildOnActivation_e.swUserDecision, ref Errors);
            //Debug.Print("Error code after document activation: " + Errors.ToString());) ;//. ac .ActivateDoc();// as ModelDoc2;

            swExt = swModel.Extension;

            swSelMgr = swModel.SelectionManager as SelectionMgr;

            /*boolstatus = swExt.SelectByID2("Front Plane", "PLANE", 0, 0, 0, false, 0, null, 0);
            //boolstatus = swExt.SelectByID2("", "SKETCHSEGMENT", x1[0], y1[0] - 0.001, 0, true, 0, null, 0);
            //            boolstatus = swExt.SelectByID2("", "SKETCHSEGMENT", 0, 0.5 * df, 0, true, 0, null, 0);
            /*modDoc.ClearSelection2(true);
            boolstatus = swExt.SelectByID2("", "SKETCHSEGMENT", x1[0], y1[0] - 0.001, 0, false, 0, null, 0);
            boolstatus = swExt.SelectByID2("", "SKETCHSEGMENT", 0, 0.5 * df, 0, true, 0, null, 0);
            if (boolstatus)
            {
                swSktMgr.CreateFillet(0.2 * double.Parse(text_mn2.Text) * 0.001, (int)swConstrainedCornerAction_e.swConstrainedCornerInteract);
            }
            else
            {
                MessageBox.Show("fail");
            }
               // modDoc.SketchFillet2(0.2 * double.Parse(text_mn2.Text) * 0.001, 2);
               // MessageBox.Show("fail");

            //boolstatus = swExt.SelectByID2("Front Plane", "PLANE", 0, 0, 0, false, 0, null, 0);
            //boolstatus = swExt.SelectByID2("", "SKETCHSEGMENT", -x1[0], y1[0] - 0.001, 0, true, 0, null, 0);
            //boolstatus = swExt.SelectByID2("", "SKETCHSEGMENT", 0, 0.5 * df, 0, true, 0, null, 0);
            //modDoc.ClearSelection2(true);
            boolstatus = swExt.SelectByID2("", "SKETCHSEGMENT", -x1[0], y1[0] - 0.001, 0, false , 0, null, 0);
            boolstatus = swExt.SelectByID2("", "SKETCHSEGMENT", 0, 0.5 * df, 0, true, 0, null, 0);
            if (boolstatus)
            {
                swSktMgr.CreateFillet(0.2 * double.Parse(text_mn2.Text) * 0.001, (int)swConstrainedCornerAction_e.swConstrainedCornerInteract);
            }
            else
            {
                MessageBox.Show("fail");
            }
            //modDoc.SketchFillet2(0.2 * double.Parse(text_mn2.Text) * 0.001, 2);
            modDoc.ClearSelection2(true);*/

            /* boolstatus = Part.Extension.SelectByID2("Spline1", "SKETCHSEGMENT", X(1), y(1), 0, False, 0, Nothing, 0)
            Part.SketchAddConstraints "sgFIXED"
            '    boolstatus = swModelDocExt.SelectByID2("草图2", "SKETCH", 0, 0.025, 0, False, 0, Nothing, 0)
            'Set swFeature = swFeatureManager.FeatureCut3(True, False, True, swEndCondThroughAll, swEndCondBlind, 0.01, 0.01, False, False, False, False, 0.01745329251994, 0.01745329251994, False, False, False, False, False, True, True, False, False, False, swStartSketchPlane, 0, False)

            Part.SketchManager.InsertSketch True
            Part.EditRebuild3
            swModel.ClearSelection2 True
            ' Part.SelectionManager.EnableContourSelection = True*/
            modDoc.EditRebuild3();

            boolstatus = swExt.SelectByID2("草图2", "SKETCH", 0, 0, 0, false, 4, null, 0);
            if (!boolstatus)
            {
                MessageBox.Show("fail-SKETCH");
            }
            swSelMgr.EnableContourSelection = true;
            boolstatus = swExt.SelectByID2("草图2", "SKETCHREGION", 0, 0.5 * df + 0.001, 0, false, 4, null, 0);
            boolstatus = swExt.SelectByID2("草图2", "SKETCHREGION", 0, 0.5 * df + 0.001, 0, false, 4, null, 0);
            boolstatus = swExt.SelectByID2("草图2", "SKETCHREGION", 0, 0.5 * df + 0.001, 0, false, 4, null, 0);

            FeatureManager swFeatureManager = default(FeatureManager);
            Feature swFeature = default(Feature);

            swFeatureManager = (FeatureManager)modDoc.FeatureManager;

            if (!boolstatus)
            {
                MessageBox.Show("fail-SKETCHREGION");
            }

            swFeature = featMan.FeatureCut3(true, false, true,
                (int)swEndConditions_e.swEndCondBlind, (int)swEndConditions_e.swEndCondBlind,
                0.01, 0.01, false, false, false, false,
                0.01745329251994, 0.01745329251994,
                false, false, false, false, false,
                true, true, false, false, false, (int)swStartConditions_e.swStartSketchPlane, 0, false);

            /*
            ' Part.FeatureManager.FeatureCut3 False, False, False, swEndCondThroughAll, swEndCondBlind, 0.01, 0.01, False, False, False, False, 0.01745329251994, 0.01745329251994, False, False, False, False, False, True, True, False, False, False, swStartSketchPlane, 0, False
            ' Part.FeatureManager.FeatureCut3 True, False, False, swEndCondThroughAll, swEndCondBlind, 0.01, 0.01, False, False, False, False, 0.01745329251994, 0.01745329251994, False, False, False, False, False, True, True, False, False, False, swStartSketchPlane, 0, False
            Part.FeatureManager.FeatureCut3 False, False, True, swEndCondThroughAll, swEndCondBlind, 0.01, 0.01, False, False, False, False, 0.01745329251994, 0.01745329251994, False, False, False, False, False, True, True, False, False, False, swStartSketchPlane, 0, False

            '建立轴
            boolstatus = Part.Extension.SelectByID2("Point1@原点", "EXTSKETCHPOINT", 0, 0, 0, True, 0, Nothing, 0)
            boolstatus = Part.Extension.SelectByID2("", "FACE", 0, 0, 0, True, 0, Nothing, 0)
            boolstatus = Part.InsertAxis2(True)
            '阵列

            Part.ClearSelection2 True
            Part.ActivateSelectedFeature
            boolstatus = Part.Extension.SelectByID2("", "AXIS", 0, 0, 0, False, 1, Nothing, 0)
            boolstatus = Part.Extension.SelectByID2("切除-拉伸1", "BODYFEATURE", 0, 0, 0, True, 4, Nothing, 0)
            'Part.ActivateSelectedFeature
            'Part.ClearSelection2 True
            'boolstatus = Part.Extension.SelectByID2("切除-拉伸1", "BODYFEATURE", -1.69661489928785E-03, 2.34775776629448E-02, 1.60262992130811E-03, False, 4, Nothing, 0)
            'boolstatus = Part.Extension.SelectByID2("", "AXIS", -3.75572662914793E-03, 5.28101193268626E-04, 6.18986555079533E-03, True, 1, Nothing, 0)
            Dim myFeature As Object
            ' Set myFeature = Part.FeatureManager.FeatureCircularPattern3(23, 6.2831853071796, True, "NULL", False, True)

            Set myFeature = Part.FeatureManager.FeatureCircularPattern3(z, 2 * pi, True, "NULL", False, True)*/
        }
Ejemplo n.º 20
0
        private void button7_Click(object sender, EventArgs e)
        {
            //int Errors=0;
            //ModelDoc2 swModel;
            // swModel = (ModelDoc2)SwAddin.iSwApp.ActivateDoc3("loaded_document", false, (int)swRebuildOnActivation_e.swUserDecision, ref Errors);

            //make sure we have a part open
            string partTemplate = SwAddin.iSwApp.GetUserPreferenceStringValue((int)swUserPreferenceStringValue_e.swDefaultTemplatePart);
            if ((partTemplate != null) && (partTemplate != ""))
            {
                modDoc = (IModelDoc2)SwAddin.iSwApp.OpenDoc6(@"c:\mygear.SLDPRT",
                    (int)swDocumentTypes_e.swDocPART, (int)swOpenDocOptions_e.swOpenDocOptions_Silent, "",
                    (int)swFileLoadError_e.swGenericError, (int)swFileLoadWarning_e.swFileLoadWarning_AlreadyOpen);
            }
            else
            {
                System.Windows.Forms.MessageBox.Show("There is no part template available. Please check your options and make sure there is a part template selected, or select a new part template.");
            }

            //SldWorks swApp;
            IModelDoc2 swModel = default(IModelDoc2);
            ISelectionMgr swSelMgr = default(ISelectionMgr);
            Feature swFeat = default(Feature);
            HelixFeatureData swHelix = default(HelixFeatureData);
            bool bRet;
            bool boolstatus;

            swModel = SwAddin.iSwApp.ActiveDoc as ModelDoc2;
            swSelMgr = swModel.SelectionManager as SelectionMgr;

            // swModel = (ModelDoc2)swApp.ActiveDoc;
            boolstatus = swModel.Extension.SelectByID2("螺旋线", "REFERENCECURVES", 0, 0, 0, false, 0, null, 0);
            //   swSelMgr = (ISelectionMgr)swModel.SelectionManager;
            swFeat = swSelMgr.GetSelectedObject6(1, -1);
            swHelix = (HelixFeatureData)swFeat.GetDefinition();

            swHelix.Clockwise = false;
            bRet = swFeat.ModifyDefinition(swHelix, swModel, null);
        }
Ejemplo n.º 21
0
 public static void Using(this IModelDoc2 doc, ISldWorks sldWorks, Action <IModelDoc2> run)
 {
     doc.Using(m => sldWorks.CloseDoc(doc.GetTitle()), run);
 }
 private Mounter(IModelDoc2 document)
 {
     Document = document;
     Assembly = document as IAssemblyDoc;
 }
Ejemplo n.º 23
0
        private void button2_Click_2(object sender, EventArgs e)
        {
            string partTemplate = SwAddin.iSwApp.GetUserPreferenceStringValue((int)swUserPreferenceStringValue_e.swDefaultTemplatePart);
            if ((partTemplate != null) && (partTemplate != ""))
            {
                modDoc = (IModelDoc2)SwAddin.iSwApp.OpenDoc6(@"c:\mygearsharft (2).SLDPRT",
                    (int)swDocumentTypes_e.swDocPART, (int)swOpenDocOptions_e.swOpenDocOptions_Silent, "",
                    (int)swFileLoadError_e.swGenericError, (int)swFileLoadWarning_e.swFileLoadWarning_AlreadyOpen);
            }
            else
            {
                System.Windows.Forms.MessageBox.Show("There is no part template available. Please check your options and make sure there is a part template selected, or select a new part template.");
            }

            EquationMgr MyEqu = modDoc.GetEquationMgr();

            //滚动角
            double u, d_a, d_b;
            d_a = double.Parse(txtPinionTipDiameter.Text);
            d_b = double.Parse(txtPinionBaseDiameter.Text);
            u = Math.Sqrt((d_a / d_b) * (d_a / d_b) - 1);

            // 螺距
            double luoju = Math.PI * double.Parse(text_dx.Text) / Math.Tan(double.Parse(text_lb12.Text) * Math.PI / 180);

            MyEqu.set_Equation(0, "\"" + "d_b" + "\"" + "=" + txtPinionBaseDiameter.Text);//基圆
            MyEqu.set_Equation(1, "\"" + "U" + "\"" + "=" + u);//滚动角
            MyEqu.set_Equation(2, "\"" + "d" + "\"" + "=" + text_dx.Text);//分度圆
            MyEqu.set_Equation(7, "\"" + "s" + "\"" + "=" + double.Parse(text_srnx.Text));//齿弦厚
            MyEqu.set_Equation(8, "\"" + "d_f" + "\"" + "=" + text_dfx.Text);//齿根圆
            MyEqu.set_Equation(10, "\"" + "B" + "\"" + "=" + text_bx.Text);//齿宽
            MyEqu.set_Equation(13, "\"" + "z" + "\"" + "=" + txtPinionZ.Text);//齿数
            MyEqu.set_Equation(15, "\"" + "d_a" + "\"" + "=" + txtPinionTipDiameter.Text);//齿顶圆
            MyEqu.set_Equation(18, "\"" + "luoju" + "\"" + "=" + luoju);//螺距
            MyEqu.set_Equation(21, "\"" + "C_CD" + "\"" + "=" + textCDDJ.Text);//齿顶倒角

            // 左轴段1
            MyEqu.set_Equation(36, "\"" + "zzzj1" + "\"" + "=" + textZZZJ1.Text);  //直径
            MyEqu.set_Equation(37, "\"" + "zzcd1" + "\"" + "=" + textZZCD1.Text);//长度
            MyEqu.set_Equation(38, "\"" + "zzyj1" + "\"" + "=" + textZZYJ1.Text);//圆角

            MyEqu.set_Equation(39, "\"" + "zzdj1" + "\"" + "=" + textZZDJ1.Text);//倒角

            // 左2
            MyEqu.set_Equation(40, "\"" + "zzzj2" + "\"" + "=" + textZZZJ2.Text);
            MyEqu.set_Equation(41, "\"" + "zzcd2" + "\"" + "=" + textZZCD2.Text);
            MyEqu.set_Equation(42, "\"" + "zzyj2" + "\"" + "=" + textZZYJ2.Text);
            MyEqu.set_Equation(43, "\"" + "zzdj2" + "\"" + "=" + textZZDJ2.Text);

            //左3
            MyEqu.set_Equation(44, "\"" + "zzzj3" + "\"" + "=" + textZZZJ3.Text);
            MyEqu.set_Equation(45, "\"" + "zzcd3" + "\"" + "=" + textZZCD3.Text);
            MyEqu.set_Equation(46, "\"" + "zzyj3" + "\"" + "=" + textZZYJ3.Text);
            MyEqu.set_Equation(47, "\"" + "zzdj3" + "\"" + "=" + textZZDJ3.Text);

            //左4
            MyEqu.set_Equation(48, "\"" + "zzzj4" + "\"" + "=" + textZZZJ4.Text);
            MyEqu.set_Equation(49, "\"" + "zzcd4" + "\"" + "=" + textZZCD4.Text);
            MyEqu.set_Equation(50, "\"" + "zzyj4" + "\"" + "=" + textZZYJ4.Text);
            MyEqu.set_Equation(51, "\"" + "zzdj4" + "\"" + "=" + textZZDJ4.Text);

            // 右1
            MyEqu.set_Equation(52, "\"" + "yzzj1" + "\"" + "=" + textYZZJ1.Text);
            MyEqu.set_Equation(53, "\"" + "yzcd1" + "\"" + "=" + textYZCD1.Text);
            MyEqu.set_Equation(54, "\"" + "yzyj1" + "\"" + "=" + textYZYJ1.Text);
            MyEqu.set_Equation(55, "\"" + "yzdj1" + "\"" + "=" + textYZDJ1.Text);

            //右2
            MyEqu.set_Equation(56, "\"" + "yzzj2" + "\"" + "=" + textYZZJ2.Text);
            MyEqu.set_Equation(57, "\"" + "yzcd2" + "\"" + "=" + textYZCD2.Text);
            MyEqu.set_Equation(58, "\"" + "yzyj2" + "\"" + "=" + textYZYJ2.Text);
            MyEqu.set_Equation(59, "\"" + "yzdj2" + "\"" + "=" + textYZDJ2.Text);

            //右3
            MyEqu.set_Equation(60, "\"" + "yzzj3" + "\"" + "=" + textYZZJ3.Text);

            MyEqu.set_Equation(61, "\"" + "yzcd3" + "\"" + "=" + textYZCD3.Text);
            MyEqu.set_Equation(62, "\"" + "yzyj3" + "\"" + "=" + textYZYJ3.Text);
            MyEqu.set_Equation(63, "\"" + "yzdj3" + "\"" + "=" + textYZDJ3.Text);

            //右4
            MyEqu.set_Equation(64, "\"" + "yzzj4" + "\"" + "=" + textYZZJ4.Text);
            MyEqu.set_Equation(65, "\"" + "yzcd4" + "\"" + "=" + textYZCD4.Text);
            MyEqu.set_Equation(66, "\"" + "yzyj4" + "\"" + "=" + textYZYJ4.Text);
            MyEqu.set_Equation(67, "\"" + "yzdj4" + "\"" + "=" + textYZDJ4.Text);

            MyEqu.EvaluateAll();
            modDoc.EditRebuild3();
            modDoc.ShowNamedView2("*Isometric", (int)swStandardViews_e.swTrimetricView);
        }
        public static void SetManipulatorPositionToBodyCenter(ISldWorks sldWorks, TriadManipulatorTs manipulator, IBody2 body, IModelDoc2 model)
        {
            var box = body.GetBodyBoxTs();

            manipulator.Origin = (MathPoint)((IMathUtility)sldWorks.GetMathUtility()).CreatePoint(box.Center.ToDoubles());
            manipulator.UpdatePosition();
        }
Ejemplo n.º 25
0
        private void button8_Click_1(object sender, EventArgs e)
        {
            //利用齿轮模型文件名字,读取齿轮模型
            string partTemplate = SwAddin.iSwApp.GetUserPreferenceStringValue((int)swUserPreferenceStringValue_e.swDefaultTemplatePart);
            if ((partTemplate != null) && (partTemplate != ""))
            {
                modDoc = (IModelDoc2)SwAddin.iSwApp.OpenDoc6(@"C:\第三级齿轮.SLDDRW",
                    (int)swDocumentTypes_e.swDocDRAWING, (int)swOpenDocOptions_e.swOpenDocOptions_Silent, "",
                    (int)swFileLoadError_e.swGenericError, (int)swFileLoadWarning_e.swFileLoadWarning_AlreadyOpen);
            }
            else
            {
                System.Windows.Forms.MessageBox.Show("There is no part template available. Please check your options and make sure there is a part template selected, or select a new part template.");
            }

            IModelDocExtension swModelDocExt = default(IModelDocExtension);
            ICustomPropertyManager swCustProp = default(ICustomPropertyManager);

            int status;
            swModelDocExt = modDoc.Extension;

            // Get the custom property data
            swCustProp = swModelDocExt.get_CustomPropertyManager("");
            status = swCustProp.Set("齿形角","21");
        }
 public ManipulatorSamplePropertyManagerPage(ISldWorks swApp, IModelDoc2 modelDoc)
     : base("Manipulator Sample", Options, modelDoc)
 {
 }
Ejemplo n.º 27
0
        private void button2_Click(object sender, EventArgs e)
        {
            string partTemplate = SwAddin.iSwApp.GetUserPreferenceStringValue((int)swUserPreferenceStringValue_e.swDefaultTemplatePart);
            if ((partTemplate != null) && (partTemplate != ""))
            {
                modDoc = (IModelDoc2)SwAddin.iSwApp.OpenDoc6(@"C:\HelicalGearSharftModel_42.SLDPRT",
                    (int)swDocumentTypes_e.swDocPART, (int)swOpenDocOptions_e.swOpenDocOptions_Silent, "",
                    (int)swFileLoadError_e.swGenericError, (int)swFileLoadWarning_e.swFileLoadWarning_AlreadyOpen);
            }
            else
            {
                System.Windows.Forms.MessageBox.Show("There is no part template available. Please check your options and make sure there is a part template selected, or select a new part template.");
            }

            ModelDoc2 swModel;
            ModelDocExtension swExt;
            SelectionMgr swSelMgr;
            ISketchManager swSktMgr;
            bool boolstatus;
            //int Errors = 0;
            swModel = SwAddin.iSwApp.ActiveDoc as ModelDoc2;
            swSktMgr = swModel.SketchManager;// SwAddin.iSwApp.ActiveDoc as ISketchManager;
            //swModel = (ModelDoc2)SwAddin.iSwApp.ActiveDoc ActivateDoc3("loaded_document", false, (int)swRebuildOnActivation_e.swUserDecision, ref Errors);
            //Debug.Print("Error code after document activation: " + Errors.ToString());) ;//. ac .ActivateDoc();// as ModelDoc2;

            swExt = swModel.Extension;

            swSelMgr = swModel.SelectionManager as SelectionMgr;

            boolstatus = swExt.SelectByID2("轴段2", "BODYFEATURE", 0, 0, 0, false, 0, null, (int)swSelectOption_e.swSelectOptionDefault);
            swModel.EditSuppress2();//                .EditUnsuppress2();// Unsuppress (unfold) flat-pattern feature
        }
Ejemplo n.º 28
0
 public SolidworksDocument(IModelDoc2 doc)
 {
     _doc          = doc;
     _extension    = doc.Extension;
     _selectionMgr = doc.SelectionManager;
 }
Ejemplo n.º 29
0
        static void GabaritsForPaintingCamera(IModelDoc2 swmodel)
        {
            try
            {
                const long valueset = 1000;
                const int swDocPart = 1;
                const int swDocAssembly = 2;

                var configNames = swmodel.GetConfigurationNames();

                foreach (var configname in configNames)
                {
                    try
                    {
                        IConfiguration swConf = swmodel.GetConfigurationByName(configname);
                        if (swConf.IsDerived()) continue;
                    }
                    catch (Exception)
                    {
                       //
                    }

                    swmodel.EditRebuild3();


                    switch (swmodel.GetType())
                    {
                        case swDocPart:
                            {
                                var part = (IPartDoc)swmodel;

                                var box = part.GetPartBox(true);

                                swmodel.AddCustomInfo3(configname, "Длина", 30, "");
                                swmodel.AddCustomInfo3(configname, "Ширина", 30, "");
                                swmodel.AddCustomInfo3(configname, "Высота", 30, "");

                                swmodel.CustomInfo2[configname, "Длина"] =
                                    Convert.ToString(
                                        Math.Round(Convert.ToDecimal((long) (Math.Abs(box[0] - box[3])*valueset)), 0));
                                swmodel.CustomInfo2[configname, "Ширина"] =
                                    Convert.ToString(
                                        Math.Round(Convert.ToDecimal((long) (Math.Abs(box[1] - box[4])*valueset)), 0));
                                swmodel.CustomInfo2[configname, "Высота"] =
                                    Convert.ToString(
                                        Math.Round(Convert.ToDecimal((long) (Math.Abs(box[2] - box[5])*valueset)), 0));
                            }
                            break;

                        case swDocAssembly:
                            {
                                var swAssy = (AssemblyDoc) swmodel;
                                var boxAss = swAssy.GetBox((int) swBoundingBoxOptions_e.swBoundingBoxIncludeRefPlanes);

                                swmodel.AddCustomInfo3(configname, "Длина", 30, "");
                                swmodel.AddCustomInfo3(configname, "Ширина", 30, "");
                                swmodel.AddCustomInfo3(configname, "Высота", 30, "");

                                swmodel.CustomInfo2[configname, "Длина"] =
                                    Convert.ToString(
                                        Math.Round(Convert.ToDecimal((long) (Math.Abs(boxAss[0] - boxAss[3])*valueset)), 0));
                                swmodel.CustomInfo2[configname, "Ширина"] =
                                    Convert.ToString(
                                        Math.Round(Convert.ToDecimal((long) (Math.Abs(boxAss[1] - boxAss[4])*valueset)), 0));
                                swmodel.CustomInfo2[configname, "Высота"] =
                                    Convert.ToString(
                                        Math.Round(Convert.ToDecimal((long) (Math.Abs(boxAss[2] - boxAss[5])*valueset)), 0));
                            }
                            break;
                    }
                }
            }
            catch (Exception e)
            {
                Логгер.Ошибка("Ошибка: " + e.StackTrace, e.GetHashCode().ToString("X"), null, "GabaritsForPaintingCamera");
            }
        }
Ejemplo n.º 30
0
 private static void DelEquations(int index, IModelDoc2 swModel)
 {
     try
     {
         Логгер.Информация($"Удаление уравнения #{index} в модели {swModel.GetPathName()}", "", null, "DelEquations");
         var myEqu = swModel.GetEquationMgr();
         myEqu.Delete(index);
         swModel.EditRebuild3();
         //myEqu.Add2(index, "\"" + System.Convert.ToChar(index) + "\"=" + index, false);
     }
     catch (Exception e)
     {
         Логгер.Ошибка($"Удаление уравнения #{index} в модели {swModel.GetPathName()}. {e.Message}", e.StackTrace, null, "DelEquations");
     }
 }
Ejemplo n.º 31
0
 /// <summary>
 /// Override this function to configure the dimensions of macro feature (i.e. position, style, etc.)
 /// </summary>
 /// <param name="app">Pointer to application</param>
 /// <param name="model">Pointer to current model</param>
 /// <param name="feature">Pointer to macro feature</param>
 /// <param name="dims">Pointer to dimensions of macro feature</param>
 /// <param name="parameters">Current instance of parameters (including the values of dimensions)</param>
 /// <remarks>Use the <see cref="DimensionDataExtension.SetOrientation(DimensionData, Point, Vector)"/>
 /// helper method to set the dimension orientation and position based on its values</remarks>
 protected virtual void OnSetDimensions(ISldWorks app, IModelDoc2 model, IFeature feature,
                                        MacroFeatureRebuildResult rebuildResult, DimensionDataCollection dims, TParams parameters)
 {
     OnSetDimensions(app, model, feature, dims, parameters);
 }
Ejemplo n.º 32
0
        private static void GabaritsForPaintingCamera(IModelDoc2 swmodel)
        {
            try
            {
                const long valueset = 1000;
                const int swDocPart = 1;
                const int swDocAssembly = 2;

                for (var i = 0; i < swmodel.GetConfigurationCount(); i++)
                {
                    i = i + 1;
                    var configname = swmodel.IGetConfigurationNames(ref i);

                    // MessageBox.Show(configname, swmodel.GetConfigurationCount().ToString());

                    Configuration swConf = swmodel.GetConfigurationByName(configname);
                    if (swConf.IsDerived()) continue;
                    //swmodel.ShowConfiguration2(configname);
                    swmodel.EditRebuild3();

                    switch (swmodel.GetType())
                    {
                        case swDocPart:
                        {
                            //    MessageBox.Show("swDocPart");
                            var part = (PartDoc) swmodel;
                            var box = part.GetPartBox(true);

                            swmodel.AddCustomInfo3(configname, "Длина", 30, "");
                            swmodel.AddCustomInfo3(configname, "Ширина", 30, "");
                            swmodel.AddCustomInfo3(configname, "Высота", 30, "");

                            // swmodel.AddCustomInfo3(configname, "Длина", , "");

                            swmodel.CustomInfo2[configname, "Длина"] =
                                Convert.ToString(
                                    Math.Round(Convert.ToDecimal((long) (Math.Abs(box[0] - box[3])*valueset)), 0));
                            swmodel.CustomInfo2[configname, "Ширина"] =
                                Convert.ToString(
                                    Math.Round(Convert.ToDecimal((long) (Math.Abs(box[1] - box[4])*valueset)), 0));
                            swmodel.CustomInfo2[configname, "Высота"] =
                                Convert.ToString(
                                    Math.Round(Convert.ToDecimal((long) (Math.Abs(box[2] - box[5])*valueset)), 0));

                        }
                            break;
                        case swDocAssembly:
                        {
                            //   MessageBox.Show("AssemblyDoc");

                            var swAssy = (AssemblyDoc) swmodel;

                            var boxAss = swAssy.GetBox((int) swBoundingBoxOptions_e.swBoundingBoxIncludeRefPlanes);

                            swmodel.AddCustomInfo3(configname, "Длина", 30, "");
                            swmodel.AddCustomInfo3(configname, "Ширина", 30, "");
                            swmodel.AddCustomInfo3(configname, "Высота", 30, "");

                            swmodel.CustomInfo2[configname, "Длина"] =
                                Convert.ToString(
                                    Math.Round(Convert.ToDecimal((long) (Math.Abs(boxAss[0] - boxAss[3])*valueset)), 0));
                            swmodel.CustomInfo2[configname, "Ширина"] =
                                Convert.ToString(
                                    Math.Round(Convert.ToDecimal((long) (Math.Abs(boxAss[1] - boxAss[4])*valueset)), 0));
                            swmodel.CustomInfo2[configname, "Высота"] =
                                Convert.ToString(
                                    Math.Round(Convert.ToDecimal((long) (Math.Abs(boxAss[2] - boxAss[5])*valueset)), 0));
                        }
                            break;
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show($"{swmodel.GetTitle()}\n{ex.Message}\n{ex.StackTrace}", "GabaritsForPaintingCamera");
            }
        }
Ejemplo n.º 33
0
 public static void ClearSelection(this IModelDoc2 doc, SelectionData selection)
 {
     doc.ClearSelections(new[] { selection });
 }
Ejemplo n.º 34
0
            public override void Build()
            {
                if (Exist)
                {
                    return;
                }

                NewComponents = null;

                MessageBox.Show(DateTime.Now.Hour.ToString());

                var modelMontageFramePath = $@"{sourceRootFolder}{TemplateFolder}\{"10-4"}.SLDASM";

                GetLastVersionAsmPdm(modelMontageFramePath, VaultName);
                GetLastVersionAsmPdm($@"{sourceRootFolder}{TemplateFolder}\10-02-01-4.SLDPRT", VaultName);

                var swDocMontageFrame = _swApp.OpenDoc6(modelMontageFramePath, (int)swDocumentTypes_e.swDocASSEMBLY,
                                                        (int)swOpenDocOptions_e.swOpenDocOptions_LoadModel, "00", 0, 0);

                _swApp.Visible = true;
                var swAsm = (AssemblyDoc)swDocMontageFrame;

                swAsm.ResolveAllLightWeightComponents(false);

                #endregion

                #region Основные размеры, величины и переменные

                // Габариты Ширина меньше ширины установки на 20мм Длина по размеру блока
                var width   = Convert.ToDouble(Width);                                                // Поперечные балки
                var lenght  = Convert.ToDouble(Lenght);                                               // Продольная балка
                var offsetI = Convert.ToDouble(Convert.ToString(Convert.ToDouble(FrameOffset) * 10)); // Смещение поперечной балки
                if (offsetI > (lenght - 125) * 10)
                {
                    offsetI = (lenght - 250) * 10;
                    MessageBox.Show("Смещение превышает допустимое значение! Программой установлено - " +
                                    (offsetI / 10));
                }

                #region  Металл и х-ки гибки

                // TODO Коэффициенты и радиусы гибов
                //var sqlBaseData = new SqlBaseData();
                //var bendParams = sqlBaseData.BendTable(Material.Thikness);
                //var bendRadius = Convert.ToDouble(bendParams[0]);
                //var kFactor = Convert.ToDouble(bendParams[1]);

                var bendRadius = Convert.ToDouble("1");
                var kFactor    = Convert.ToDouble("1");

                #endregion

                #endregion

                #region Изменение размеров элементов и компонентов сборки

                var thikness = Convert.ToDouble(Material.Thikness) / 1000;
                bendRadius = bendRadius / 1000;
                var w            = Convert.ToDouble(width) / 1000;
                var l            = Convert.ToDouble(lenght) / 1000;
                var offset       = Convert.ToDouble(offsetI) / 10000;
                var offsetMirror = Convert.ToDouble(lenght * 10 - offsetI) / 10000;

                #region 10-02-4 Зеркальная 10-01-4

                if (Type == "3")
                {
                    swDocMontageFrame.Extension.SelectByID2("10-01-01-4-1@10-4", "COMPONENT", 0, 0, 0, false, 0, null, 0);
                    swAsm = ((AssemblyDoc)(swDocMontageFrame));
                    swAsm.ReplaceComponents(sourceRootFolder + TemplateFolder + "\\10-02-01-4.SLDPRT", "", false, true);
                    swAsm.ResolveAllLightWeightComponents(false);

                    //Продольная зеркальная балка (Длина установки)
                    swDocMontageFrame.Extension.SelectByID2("D1@Эскиз1@10-02-01-4-1@10-4", "DIMENSION", 0, 0, 00, false, 0, null, 0);
                    ((Dimension)(swDocMontageFrame.Parameter("D1@Эскиз[email protected]"))).SystemValue = l;
                    //  Длина установки  0.8;

                    swDocMontageFrame.Extension.SelectByID2("D3@Эскиз25@10-02-01-4-1@10-4", "DIMENSION", 0, 0, 0, false, 0, null, 0);
                    ((Dimension)(swDocMontageFrame.Parameter("D3@Эскиз[email protected]"))).SystemValue = offsetMirror;
                    //Смещение поперечной балки от края;
                    swDocMontageFrame.EditRebuild3();
                    swDocMontageFrame.Extension.SelectByID2("Листовой металл@10-02-01-4-1@10-4", "BODYFEATURE", 0, 0, 0,
                                                            false, 0, null, 0);
                    swDocMontageFrame.ActivateSelectedFeature();
                    swDocMontageFrame.Extension.SelectByID2("D1@Листовой металл@10-02-01-4-1@10-4", "DIMENSION", 0, 0, 0,
                                                            false, 0, null, 0);
                    ((Dimension)(swDocMontageFrame.Parameter("D1@Листовой металл@10-02-01-4.Part"))).SystemValue =
                        bendRadius; // Радиус гиба  0.005;
                    swDocMontageFrame.EditRebuild3();
                    swDocMontageFrame.Extension.SelectByID2("Листовой металл@10-02-01-4-1@10-4", "BODYFEATURE", 0, 0, 0,
                                                            false, 0, null, 0);
                    swDocMontageFrame.ActivateSelectedFeature();
                    swDocMontageFrame.Extension.SelectByID2("D2@Листовой металл@10-02-01-4-1@10-4", "DIMENSION", 0, 0, 0,
                                                            false, 0, null, 0);
                    ((Dimension)(swDocMontageFrame.Parameter("D2@Листовой металл@10-01-01-4.Part"))).SystemValue = kFactor;
                    // K-Factor  0.55;
                    swDocMontageFrame.EditRebuild3();
                    swDocMontageFrame.Extension.SelectByID2("Толщина@Листовой металл@10-02-01-4-1@10-4", "DIMENSION", 0, 0,
                                                            0, false, 0, null, 0);
                    ((Dimension)(swDocMontageFrame.Parameter("Толщина@Листовой металл@10-02-01-4.Part"))).SystemValue =
                        thikness; // Толщина Листового металла 0.006;
                    swDocMontageFrame.EditRebuild3();
                    swDocMontageFrame.ClearSelection2(true);
                }


                #endregion

                //swApp.SendMsgToUser(string.Format("Thikness= {0}, BendRadius= {1}, Ширина= {2}, Длина= {3}, ", Thikness * 1000, BendRadius * 1000, Ширина * 1000, Длина * 1000));

                //Продольные балки (Длина установки)

                #region 10-01-4

                swDocMontageFrame.Extension.SelectByID2("D1@Эскиз1@10-01-01-4-2@10-4", "DIMENSION", 0, 0, 0, false, 0, null,
                                                        0);
                ((Dimension)(swDocMontageFrame.Parameter("D1@Эскиз[email protected]"))).SystemValue = l;
                //  Длина установки  0.8;
                swDocMontageFrame.Extension.SelectByID2("D3@Эскиз25@10-01-01-4-2@10-4", "DIMENSION", 0, 0, 0, false, 0, null,
                                                        0);
                ((Dimension)(swDocMontageFrame.Parameter("D3@Эскиз[email protected]"))).SystemValue = offset;
                //Смещение поперечной балки от края;
                swDocMontageFrame.EditRebuild3();
                //swApp.SendMsgToUser(Offset.ToString());
                swDocMontageFrame.Extension.SelectByID2("Листовой металл@10-01-01-4-2@10-4", "BODYFEATURE", 0, 0, 0, false,
                                                        0, null, 0);
                swDocMontageFrame.ActivateSelectedFeature();
                swDocMontageFrame.Extension.SelectByID2("D1@Листовой металл@10-01-01-4-2@10-4", "DIMENSION", 0, 0, 0, false,
                                                        0, null, 0);
                ((Dimension)(swDocMontageFrame.Parameter("D1@Листовой металл@10-01-01-4.Part"))).SystemValue = bendRadius;
                // Радиус гиба  0.005;
                swDocMontageFrame.EditRebuild3();
                swDocMontageFrame.Extension.SelectByID2("Листовой металл@10-01-01-4-2@10-4", "BODYFEATURE", 0, 0, 0, false,
                                                        0, null, 0);
                swDocMontageFrame.ActivateSelectedFeature();
                swDocMontageFrame.Extension.SelectByID2("D2@Листовой металл@10-01-01-4-2@10-4", "DIMENSION", 0, 0, 0, false,
                                                        0, null, 0);
                ((Dimension)(swDocMontageFrame.Parameter("D2@Листовой металл@10-01-01-4.Part"))).SystemValue = kFactor;
                // K-Factor  0.55;
                swDocMontageFrame.EditRebuild3();
                swDocMontageFrame.Extension.SelectByID2("Толщина@Листовой металл@10-01-01-4-2@10-4", "DIMENSION", 0, 0, 0,
                                                        false, 0, null, 0);
                ((Dimension)(swDocMontageFrame.Parameter("Толщина@Листовой металл@10-01-01-4.Part"))).SystemValue =
                    thikness; // Толщина Листового металла 0.006;
                swDocMontageFrame.EditRebuild3();
                swDocMontageFrame.ClearSelection2(true);

                #endregion

                #region 10-04-4-2

                swDocMontageFrame.Extension.SelectByID2("D1@Эскиз1@10-04-4-2@10-4", "DIMENSION", 0, 0, 0, false, 0, null, 0);
                ((Dimension)(swDocMontageFrame.Parameter("D1@Эскиз[email protected]"))).SystemValue = (l - 0.14);
                // Длина установки - 140  0.66;
                swDocMontageFrame.EditRebuild3();
                swDocMontageFrame.Extension.SelectByID2("Листовой металл@10-04-4-2@10-4", "BODYFEATURE", 0, 0, 0, false, 0,
                                                        null, 0);
                swDocMontageFrame.ActivateSelectedFeature();
                swDocMontageFrame.Extension.SelectByID2("D1@Листовой металл@10-04-4-2@10-4", "DIMENSION", 0, 0, 0, false, 0,
                                                        null, 0);
                ((Dimension)(swDocMontageFrame.Parameter("D1@Листовой металл@10-04-4.Part"))).SystemValue = bendRadius;
                // Радиус гиба  0.005;
                swDocMontageFrame.EditRebuild3();
                swDocMontageFrame.Extension.SelectByID2("Листовой металл@10-04-4-2@10-4", "BODYFEATURE", 0, 0, 0, false, 0,
                                                        null, 0);
                swDocMontageFrame.ActivateSelectedFeature();
                swDocMontageFrame.Extension.SelectByID2("D2@Листовой металл@10-04-4-2@10-4", "DIMENSION", 0, 0, 0, false, 0,
                                                        null, 0);
                ((Dimension)(swDocMontageFrame.Parameter("D2@Листовой металл@10-04-4.Part"))).SystemValue = kFactor;
                // K-Factor  0.55;
                swDocMontageFrame.EditRebuild3();
                swDocMontageFrame.Extension.SelectByID2("Толщина@Листовой металл@10-04-4-2@10-4", "DIMENSION", 0, 0, 0,
                                                        false, 0, null, 0);
                ((Dimension)(swDocMontageFrame.Parameter("Толщина@Листовой металл@10-04-4.Part"))).SystemValue = thikness;
                // Толщина Листового металла 0.006;
                swDocMontageFrame.EditRebuild3();
                swDocMontageFrame.ClearSelection2(true);

                #endregion

                //Поперечная балка (Ширина установки)

                #region 10-03-4

                swDocMontageFrame.Extension.SelectByID2("D2@Эскиз1@10-03-01-4-2@10-4", "DIMENSION", 0, 0, 0, false, 0, null, 0);
                ((Dimension)(swDocMontageFrame.Parameter("D2@Эскиз[email protected]"))).SystemValue = (w - 0.12);
                //  Ширина установки - 20 - 100  0.88;
                swDocMontageFrame.EditRebuild3();
                swDocMontageFrame.Extension.SelectByID2("Листовой металл@10-03-01-4-2@10-4", "BODYFEATURE", 0, 0, 0, false, 0, null, 0);
                swDocMontageFrame.ActivateSelectedFeature();
                swDocMontageFrame.Extension.SelectByID2("D1@Листовой металл@10-03-01-4-2@10-4", "DIMENSION", 0, 0, 0, false, 0, null, 0);
                ((Dimension)(swDocMontageFrame.Parameter("D1@Листовой металл@10-03-01-4.Part"))).SystemValue = bendRadius;
                // Радиус гиба  0.005;
                swDocMontageFrame.EditRebuild3();
                swDocMontageFrame.Extension.SelectByID2("Листовой металл@10-03-01-4-2@10-4", "BODYFEATURE", 0, 0, 0, false, 0, null, 0);
                swDocMontageFrame.ActivateSelectedFeature();
                swDocMontageFrame.Extension.SelectByID2("D2@Листовой металл@10-03-01-4-2@10-4", "DIMENSION", 0, 0, 0, false, 0, null, 0);
                ((Dimension)(swDocMontageFrame.Parameter("D2@Листовой металл@10-03-01-4.Part"))).SystemValue = kFactor;
                // K-Factor  0.55;
                swDocMontageFrame.EditRebuild3();
                swDocMontageFrame.Extension.SelectByID2("Толщина@Листовой металл@10-03-01-4-2@10-4", "DIMENSION", 0, 0, 0,
                                                        false, 0, null, 0);
                ((Dimension)(swDocMontageFrame.Parameter("Толщина@Листовой металл@10-03-01-4.Part"))).SystemValue =
                    thikness; // Толщина Листового металла 0.006;
                swDocMontageFrame.EditRebuild3();
                swDocMontageFrame.ClearSelection2(true);

                #endregion

                #endregion

                #region Удаление поперечной балки

                if (internalCrossbeam == false)
                {
                    swDocMontageFrame.Extension.SelectByID2("10-03-01-4-1@10-4", "COMPONENT", 0, 0, 0, false, 0, null, 0);
                    swDocMontageFrame.Extension.SelectByID2("Washer 11371_gost-39@10-4", "COMPONENT", 0, 0, 0, true, 0, null, 0);
                    swDocMontageFrame.Extension.SelectByID2("Washer 11371_gost-40@10-4", "COMPONENT", 0, 0, 0, true, 0, null, 0);
                    swDocMontageFrame.Extension.SelectByID2("Washer 6402_gost-23@10-4", "COMPONENT", 0, 0, 0, true, 0, null, 0);
                    swDocMontageFrame.Extension.SelectByID2("Hex Nut 5915_gost-19@10-4", "COMPONENT", 0, 0, 0, true, 0, null, 0);
                    swDocMontageFrame.Extension.SelectByID2("Hex Bolt 7805_gost-22@10-4", "COMPONENT", 0, 0, 0, true, 0, null, 0);
                    swDocMontageFrame.Extension.SelectByID2("Washer 11371_gost-41@10-4", "COMPONENT", 0, 0, 0, true, 0, null, 0);
                    swDocMontageFrame.Extension.SelectByID2("Washer 11371_gost-42@10-4", "COMPONENT", 0, 0, 0, true, 0, null, 0);
                    swDocMontageFrame.Extension.SelectByID2("Washer 6402_gost-24@10-4", "COMPONENT", 0, 0, 0, true, 0, null, 0);
                    swDocMontageFrame.Extension.SelectByID2("Hex Nut 5915_gost-20@10-4", "COMPONENT", 0, 0, 0, true, 0, null, 0);
                    swDocMontageFrame.Extension.SelectByID2("Hex Bolt 7805_gost-23@10-4", "COMPONENT", 0, 0, 0, true, 0, null, 0);
                    swDocMontageFrame.Extension.SelectByID2("Washer 11371_gost-43@10-4", "COMPONENT", 0, 0, 0, true, 0, null, 0);
                    swDocMontageFrame.Extension.SelectByID2("Washer 11371_gost-44@10-4", "COMPONENT", 0, 0, 0, true, 0, null, 0);
                    swDocMontageFrame.Extension.SelectByID2("Washer 6402_gost-25@10-4", "COMPONENT", 0, 0, 0, true, 0, null, 0);
                    swDocMontageFrame.Extension.SelectByID2("Hex Nut 5915_gost-21@10-4", "COMPONENT", 0, 0, 0, true, 0, null, 0);
                    swDocMontageFrame.Extension.SelectByID2("Hex Bolt 7805_gost-24@10-4", "COMPONENT", 0, 0, 0, true, 0, null, 0);
                    swDocMontageFrame.Extension.SelectByID2("Washer 11371_gost-45@10-4", "COMPONENT", 0, 0, 0, true, 0, null, 0);
                    swDocMontageFrame.Extension.SelectByID2("Washer 11371_gost-46@10-4", "COMPONENT", 0, 0, 0, true, 0, null, 0);
                    swDocMontageFrame.Extension.SelectByID2("Washer 6402_gost-26@10-4", "COMPONENT", 0, 0, 0, true, 0, null, 0);
                    swDocMontageFrame.Extension.SelectByID2("Hex Nut 5915_gost-22@10-4", "COMPONENT", 0, 0, 0, true, 0, null, 0);
                    swDocMontageFrame.Extension.SelectByID2("Hex Bolt 7805_gost-25@10-4", "COMPONENT", 0, 0, 0, true, 0, null, 0);
                    swDocMontageFrame.Extension.SelectByID2("Hex Bolt 7805_gost-25@10-4", "COMPONENT", 0, 0, 0, false, 0, null, 0);
                    swDocMontageFrame.EditDelete();

                    // Удаление ненужных элементов продольной балки
                    const int deleteOption =
                        (int)swDeleteSelectionOptions_e.swDelete_Absorbed +
                        (int)swDeleteSelectionOptions_e.swDelete_Children;
                    swDocMontageFrame.Extension.SelectByID2("Вырез-Вытянуть8@10-01-01-4-2@10-4", "BODYFEATURE", 0, 0, 0,
                                                            false, 0, null, 0);
                    swDocMontageFrame.Extension.DeleteSelection2(deleteOption);
                }

                #endregion

                #region Удаление продольной балки

                // Погашение внутренней продольной балки
                if (internalLongitudinalBeam == false)
                {
                    foreach (var s in new[] { "5", "6", "7", "8", "13" })
                    {
                        swDocMontageFrame.Extension.SelectByID2("Hex Bolt 7805_gost-" + s + "@10-4", "COMPONENT", 0, 0, 0, true, 0, null, 0);
                        swDocMontageFrame.EditDelete();
                    }
                    foreach (var s in new[] { "6", "7", "8", "9", "37", "38", "39", "40" })
                    {
                        swDocMontageFrame.Extension.SelectByID2("Washer 6402_gost-" + s + "@10-4", "COMPONENT", 0, 0, 0, true, 0, null, 0);
                        swDocMontageFrame.EditDelete();
                    }
                    foreach (var s in new[] { "17", "18", "19", "20", "21", "22", "23", "24", "57", "58", "59", "60" })
                    {
                        swDocMontageFrame.Extension.SelectByID2("Washer 11371_gost-" + s + "@10-4", "COMPONENT", 0, 0, 0, true, 0, null, 0);
                        swDocMontageFrame.EditDelete();
                    }

                    swDocMontageFrame.Extension.SelectByID2("10-04-4-2@10-4", "COMPONENT", 0, 0, 0, true, 0, null, 0);
                    swDocMontageFrame.EditDelete();


                    // Удаление ненужных элементов поперечной балки
                    swDocMontageFrame.Extension.SelectByID2("Регулируемая ножка-10@10-4", "COMPONENT", 0, 0, 0, false, 0, null, 0);
                    swDocMontageFrame.EditDelete();
                    swDocMontageFrame.Extension.SelectByID2("Регулируемая ножка-11@10-4", "COMPONENT", 0, 0, 0, false, 0, null, 0);
                    swDocMontageFrame.EditDelete();

                    foreach (var s in new[] { "10", "11", "40", "41", "42", "43" })
                    {
                        swDocMontageFrame.Extension.SelectByID2("Hex Nut 5915_gost-" + s + "@10-4", "COMPONENT", 0, 0, 0, true, 0, null, 0);
                        swDocMontageFrame.EditDelete();
                    }

                    const int deleteOption =
                        (int)swDeleteSelectionOptions_e.swDelete_Absorbed +
                        (int)swDeleteSelectionOptions_e.swDelete_Children;
                    swDocMontageFrame.Extension.SelectByID2("Вырез-Вытянуть5@10-03-01-4-2@10-4", "BODYFEATURE", 0, 0, 0,
                                                            false, 0, null, 0);
                    swDocMontageFrame.Extension.DeleteSelection2(deleteOption);
                    swDocMontageFrame.Extension.SelectByID2("Вырез-Вытянуть4@10-03-01-4-2@10-4", "BODYFEATURE", 0, 0, 0,
                                                            false, 0, null, 0);
                    swDocMontageFrame.Extension.DeleteSelection2(deleteOption);
                }

                #endregion

                #region Сохранение элементов и сборки, а также применение материалов

                #region Детали

                //Продольные балки (Длина установки)

                #region 10-01-01-4 - Деталь

                _swApp.IActivateDoc2("10-01-01-4", false, 0);
                IModelDoc2 swPartDoc = _swApp.IActiveDoc2;
                switch (Type)
                {
                //case "2":
                case "0":
                    typeOfMfs = "";
                    break;

                case "3":
                case "2":
                case "1":
                    typeOfMfs = "-0" + Type;
                    break;
                }


                var newPartName = string.Format("10-01-01-{0}{4}-{1}{2}{3}.SLDPRT", Material.Thikness, lenght, FrameOffset,
                                                typeOfMfs, addMatName);

                var newPartPath = $@"{destRootFolder}\{DestinationFolder}\{newPartName}";
                if (File.Exists(newPartPath))
                {
                    swDocMontageFrame = ((ModelDoc2)(_swApp.ActivateDoc2("10-4.SLDASM", true, 0)));
                    swDocMontageFrame.Extension.SelectByID2("10-01-01-4-2@10-4", "COMPONENT", 0, 0, 0, false, 0, null, 0);
                    swAsm.ReplaceComponents(newPartPath, "", true, true);
                    _swApp.CloseDoc("10-01-01-4.SLDPRT");
                }
                else
                {
                    swPartDoc.SaveAs2(newPartPath, (int)swSaveAsVersion_e.swSaveAsCurrentVersion, false, true);

                    AddMaterial(Material, newPartPath);
                    ComponentToAdd(newPartPath);

                    _swApp.CloseDoc(newPartName);
                }

                #endregion

                //

                #region 10-02-01-4 - Деталь Зеркальная 10-01-01-4

                if (Type == "3")
                {
                    _swApp.IActivateDoc2("10-02-01-4", false, 0);
                    swPartDoc = _swApp.IActiveDoc2;
                    switch (Type)
                    {
                    case "2":
                    case "0":
                        typeOfMfs = "";
                        break;

                    case "3":
                    case "1":
                        typeOfMfs = "-0" + Type;
                        break;
                    }

                    newPartName = string.Format("10-02-01-{0}{4}-{1}{2}{3}.SLDPRT", Material.Thikness, lenght, FrameOffset,
                                                typeOfMfs, addMatName);

                    newPartPath = $@"{destRootFolder}\{DestinationFolder}\{newPartName}";
                    if (File.Exists(newPartPath))
                    {
                        swDocMontageFrame = ((ModelDoc2)(_swApp.ActivateDoc2("10-4.SLDASM", true, 0)));
                        swDocMontageFrame.Extension.SelectByID2("10-02-01-4-1@10-4", "COMPONENT", 0, 0, 0, false, 0, null, 0);
                        swAsm.ReplaceComponents(newPartPath, "", false, true);
                        _swApp.CloseDoc("10-02-01-4.SLDPRT");
                    }
                    else
                    {
                        swPartDoc.SaveAs2(newPartPath, (int)swSaveAsVersion_e.swSaveAsCurrentVersion, false, true);
                        AddMaterial(Material, newPartPath);
                        _swApp.CloseDoc(newPartName);
                        ComponentToAdd(newPartName);
                    }

                    #endregion

                    #region 10-04-4 - Деталь

                    if (internalLongitudinalBeam)
                    {
                        _swApp.IActivateDoc2("10-04-4", false, 0);
                        swPartDoc = ((IModelDoc2)(_swApp.ActiveDoc));

                        newPartName = string.Format("10-04-{0}{2}-{1}.SLDPRT", Material.Thikness, (lenght - 140), addMatName);

                        newPartPath = $@"{destRootFolder}\{DestinationFolder}\{newPartName}";
                        if (File.Exists(newPartPath))
                        {
                            swDocMontageFrame = ((ModelDoc2)(_swApp.ActivateDoc2("10-4.SLDASM", true, 0)));
                            swDocMontageFrame.Extension.SelectByID2("10-04-4-2@10-4", "COMPONENT", 0, 0, 0, false, 0, null, 0);
                            swAsm.ReplaceComponents(newPartPath, "", true, true);
                            _swApp.CloseDoc("10-04-4.SLDPRT");
                        }
                        else
                        {
                            swPartDoc.SaveAs2(newPartPath, (int)swSaveAsVersion_e.swSaveAsCurrentVersion, false, true);
                            AddMaterial(Material, newPartPath);
                            _swApp.CloseDoc(newPartName);
                            ComponentToAdd(newPartPath);
                        }
                    }
                    else
                    {
                        _swApp.CloseDoc("10-04-4.SLDPRT");
                    }

                    #endregion

                    //Поперечная балка (Ширина установки)

                    #region 10-03-01-4 - Деталь

                    _swApp.IActivateDoc2("10-03-01-4", false, 0);
                    swPartDoc = ((IModelDoc2)(_swApp.ActiveDoc));

                    switch (Type)
                    {
                    case "3":
                    case "2":
                        typeOfMfs = "-0" + Type;
                        break;

                    case "1":
                    case "0":
                        typeOfMfs = "";
                        break;
                    }


                    newPartName = string.Format("10-03-01-{0}{3}-{1}{2}.SLDPRT", Material.Thikness, (width - 120), typeOfMfs, addMatName);

                    newPartPath = $@"{destRootFolder}\{DestinationFolder}\{newPartName}";
                    var newPrt0202 = string.Format("10-02-01-{0}{3}-{1}{2}.SLDPRT", Material.Thikness, (width - 120), typeOfMfs,
                                                   addMatName);
                    newPrt0202 = $@"{destRootFolder}\{DestinationFolder}\{newPrt0202}";

                    if (File.Exists(newPartPath))
                    {
                        swDocMontageFrame = ((ModelDoc2)(_swApp.ActivateDoc2("10-4.SLDASM", true, 0)));
                        swDocMontageFrame.Extension.SelectByID2("10-03-01-4-2@10-4", "COMPONENT", 0, 0, 0, false, 0, null, 0);
                        swAsm.ReplaceComponents(newPartPath, "", true, true);
                        _swApp.CloseDoc("10-03-01-4.SLDPRT");
                    }
                    else
                    {
                        swPartDoc.SaveAs2(newPartPath, (int)swSaveAsVersion_e.swSaveAsCurrentVersion, false, true);
                        AddMaterial(Material, newPartPath);
                        if (Type == "2")
                        {
                            swPartDoc.Extension.SelectByID2("D1@Эскиз28@" + Path.GetFileNameWithoutExtension(newPrt0202) + ".SLDPRT",
                                                            "DIMENSION", 0, 0, 0, false, 0, null, 0);
                            ((Dimension)(swPartDoc.Parameter("D1@Эскиз28"))).SystemValue = -0.05;

                            swPartDoc.EditRebuild3();
                            swPartDoc.SaveAs2(newPrt0202, (int)swSaveAsVersion_e.swSaveAsCurrentVersion, false, true);
                            AddMaterial(Material, newPrt0202);
                            _swApp.CloseDoc(newPrt0202);
                            ComponentToAdd(newPrt0202);
                        }
                        _swApp.CloseDoc(newPartName);
                    }

                    #endregion

                    #endregion

                    _swApp.IActivateDoc2("10-4.SLDASM", false, 0);
                    swDocMontageFrame = ((ModelDoc2)(_swApp.ActiveDoc));

                    GabaritsForPaintingCamera(swDocMontageFrame);

                    swDocMontageFrame.ForceRebuild3(true);

                    swDocMontageFrame.SaveAs2(ModelPath, (int)swSaveAsVersion_e.swSaveAsCurrentVersion, false, true);

                    ComponentToAdd(ModelPath);

                    #endregion

                    _swApp.CloseDoc(ModelPath);
                    _swApp = null;

                    List <VaultSystem.VentsCadFile> newFilesList;
                    VaultSystem.CheckInOutPdmNew(NewComponents, true, out newFilesList);

                    #region Export To XML

                    foreach (var newComponent in NewComponents)
                    {
                        //   ExportXmlSql.Export(newComponent.FullName);
                    }

                    #endregion


                    #region

                    //var drawing = "12-00";
                    //if (modelName == "12-30")
                    //{
                    //    drawing = modelName;
                    //}

                    //Dimension myDimension;
                    //var modelSpigotDrw = $@"{sourceRootFolder}{TemplateFolder}\{drawing}.SLDDRW";

                    //GetLastVersionAsmPdm(modelSpigotDrw, VaultName);

                    //if (!InitializeSw(true)) return;

                    //var swDrwSpigot = _swApp.OpenDoc6(modelSpigotDrw, (int)swDocumentTypes_e.swDocDRAWING,
                    //    (int)swOpenDocOptions_e.swOpenDocOptions_LoadModel, "", 0, 0);

                    //if (swDrwSpigot == null) return;

                    //ModelDoc2 swDoc = _swApp.ActivateDoc2("12-00", false, 0);
                    //var swAsm = (AssemblyDoc)swDoc;
                    //swAsm.ResolveAllLightWeightComponents(false);

                    //switch (modelName)
                    //{
                    //    case "12-20":
                    //        DelEquations(5, swDoc);
                    //        DelEquations(4, swDoc);
                    //        DelEquations(3, swDoc);
                    //        break;
                    //    case "12-30":
                    //        DelEquations(0, swDoc);
                    //        DelEquations(0, swDoc);
                    //        DelEquations(0, swDoc);
                    //        break;
                    //}
                    //swDoc.ForceRebuild3(true);

                    //string newPartName;
                    //string newPartPath;
                    //IModelDoc2 swPartDoc;

                    //#region Удаление ненужного

                    //string[] itemsToDelete = null;

                    //switch (Type)
                    //{
                    //    case "20":
                    //        itemsToDelete = new[] { "12-30-001-1", "12-30-001-2", "12-30-002-1", "12-30-002-2",
                    //                            "ВНС-96.61.002-1", "ВНС-96.61.002-2", "ВНС-96.61.002-3", "ВНС-96.61.002-4",
                    //                            "ВНС-96.61.002-5", "ВНС-96.61.002-6", "ВНС-96.61.002-7", "ВНС-96.61.002-8",
                    //                            "12-30-001-3", "12-30-001-4", "12-30-002-3", "12-30-002-4",
                    //                            "12-003-2", "Клей-2" };
                    //        break;
                    //    case "30":
                    //        itemsToDelete = new[] { "12-20-001-1", "12-20-001-2", "12-20-002-1", "12-20-002-2",
                    //                            "ВНС-96.61.001-1", "ВНС-96.61.001-2", "ВНС-96.61.001-3", "ВНС-96.61.001-4",
                    //                            "ВНС-96.61.001-5", "ВНС-96.61.001-6", "ВНС-96.61.001-7", "ВНС-96.61.001-8",
                    //                            "12-20-001-3", "12-20-001-4", "12-20-002-3", "12-20-002-4",
                    //                            "12-003-1", "Клей-1"};
                    //        break;
                    //}

                    //foreach (var item in itemsToDelete)
                    //{
                    //    DoWithSwDoc(_swApp, CompType.COMPONENT, item, Act.DeletWithOption);
                    //}

                    //DoWithSwDoc(_swApp, CompType.FTRFOLDER, "30", Act.Delete);
                    //DoWithSwDoc(_swApp, CompType.FTRFOLDER, "20", Act.Delete);
                    //#endregion

                    //#region Сохранение и изменение элементов

                    //string path;
                    //int fileId;
                    //int projectId;

                    //var addDimH = 1;
                    //if (modelName == "12-30")
                    //{
                    //    addDimH = 10;
                    //}

                    //var w = (Convert.ToDouble(Width) - 1) / 1000;
                    //var h = Convert.ToDouble((Convert.ToDouble(Height) + addDimH) / 1000);
                    //const double step = 50;
                    //var weldW = Convert.ToDouble((Math.Truncate(Convert.ToDouble(Width) / step) + 1));
                    //var weldH = Convert.ToDouble((Math.Truncate(Convert.ToDouble(Height) / step) + 1));

                    //if (modelName == "12-20")
                    //{
                    //    //12-20-001
                    //    _swApp.IActivateDoc2("12-20-001", false, 0);
                    //    swPartDoc = _swApp.IActiveDoc2;
                    //    newPartName = $"12-20-{Height}.SLDPRT";
                    //    newPartPath = $@"{destRootFolder}\{DestinationFolder}\{newPartName}";

                    //    if (GetExistingFile(Path.GetFileNameWithoutExtension(newPartPath), out path, out fileId, out projectId))
                    //    {
                    //        swDoc = ((ModelDoc2)(VentsCad._swApp.ActivateDoc2("12-00.SLDASM", true, 0)));
                    //        swDoc.Extension.SelectByID2("12-20-001-1@12-00", "COMPONENT", 0, 0, 0, false, 0, null, 0);
                    //        swAsm.ReplaceComponents(newPartPath, "", true, true);
                    //        _swApp.CloseDoc("12-20-001.SLDPRT");
                    //    }
                    //    else
                    //    {
                    //        swDoc.Extension.SelectByID2("D1@Вытянуть1@12-20-001-1@12-00", "DIMENSION", 0, 0, 0, false, 0, null, 0);
                    //        myDimension = ((Dimension)(swDoc.Parameter("D1@Вытянуть[email protected]")));
                    //        myDimension.SystemValue = h - 0.031;
                    //        swDoc.Extension.SelectByID2("D1@Кривая1@12-20-001-1@12-00", "DIMENSION", 0, 0, 0, false, 0, null, 0);
                    //        myDimension = ((Dimension)(swDoc.Parameter("D1@Кривая[email protected]")));
                    //        myDimension.SystemValue = weldH;
                    //        swPartDoc.SaveAs2(newPartPath, (int)swSaveAsVersion_e.swSaveAsCurrentVersion, false, true);
                    //        ComponentToAdd(newPartPath);
                    //        _swApp.CloseDoc(newPartName);
                    //    }

                    //    //12-20-002
                    //    _swApp.IActivateDoc2("12-20-002", false, 0);
                    //    swPartDoc = _swApp.IActiveDoc2;
                    //    newPartName = $"12-20-{Width}.SLDPRT";
                    //    newPartPath = $@"{destRootFolder}\{DestinationFolder}\{newPartName}";
                    //    if (GetExistingFile(Path.GetFileNameWithoutExtension(newPartPath), out path, out fileId, out projectId))
                    //    {
                    //        swDoc = ((ModelDoc2)(VentsCad._swApp.ActivateDoc2("12-00.SLDASM", true, 0)));
                    //        swDoc.Extension.SelectByID2("12-20-002-1@12-00", "COMPONENT", 0, 0, 0, false, 0, null, 0);
                    //        swAsm.ReplaceComponents(newPartPath, "", true, true);
                    //        _swApp.CloseDoc("12-20-002.SLDPRT");
                    //    }
                    //    else
                    //    {
                    //        swDoc.Extension.SelectByID2("D1@Вытянуть1@12-20-002-1@12-00", "DIMENSION", 0, 0, 0, false, 0, null, 0);
                    //        myDimension = ((Dimension)(swDoc.Parameter("D1@Вытянуть[email protected]")));
                    //        myDimension.SystemValue = w - 0.031;
                    //        swDoc.Extension.SelectByID2("D1@Кривая1@12-20-002-1@12-00", "DIMENSION", 0, 0, 0, false, 0, null, 0);
                    //        myDimension = ((Dimension)(swDoc.Parameter("D1@Кривая[email protected]")));
                    //        myDimension.SystemValue = weldW;
                    //        swPartDoc.SaveAs2(newPartPath, (int)swSaveAsVersion_e.swSaveAsCurrentVersion, false, true);
                    //        ComponentToAdd(newPartPath);
                    //        _swApp.CloseDoc(newPartName);
                    //    }

                    //    //12-003
                    //    _swApp.IActivateDoc2("12-003", false, 0);
                    //    swPartDoc = _swApp.IActiveDoc2;
                    //    newPartName = $"12-03-{Width}-{Height}.SLDPRT";
                    //    newPartPath = $@"{destRootFolder}\{DestinationFolder}\{newPartName}";
                    //    if (GetExistingFile(Path.GetFileNameWithoutExtension(newPartPath), out path, out fileId, out projectId))
                    //    {
                    //        swDoc = ((ModelDoc2)(VentsCad._swApp.ActivateDoc2("12-00.SLDASM", true, 0)));
                    //        swDoc.Extension.SelectByID2("12-003-1@12-00", "COMPONENT", 0, 0, 0, false, 0, null, 0);
                    //        swAsm.ReplaceComponents(newPartPath, "", true, true);
                    //        _swApp.CloseDoc("12-003.SLDPRT");
                    //    }
                    //    else
                    //    {
                    //        swDoc.Extension.SelectByID2("D3@Эскиз1@12-003-1@12-00", "DIMENSION", 0, 0, 0, false, 0, null, 0);
                    //        myDimension = ((Dimension)(swDoc.Parameter("D3@Эскиз[email protected]")));
                    //        myDimension.SystemValue = w;
                    //        swDoc.Extension.SelectByID2("D2@Эскиз1@12-003-1@12-00", "DIMENSION", 0, 0, 0, false, 0, null, 0);
                    //        myDimension = ((Dimension)(swDoc.Parameter("D2@Эскиз[email protected]")));
                    //        myDimension.SystemValue = h;
                    //        swDoc.EditRebuild3();
                    //        swPartDoc.SaveAs2(newPartPath, (int)swSaveAsVersion_e.swSaveAsCurrentVersion, false, true);
                    //        ComponentToAdd(newPartPath);
                    //        _swApp.CloseDoc(newPartName);
                    //    }
                    //}

                    //if (modelName == "12-30")
                    //{
                    //    //12-30-001
                    //    _swApp.IActivateDoc2("12-30-001", false, 0);
                    //    swPartDoc = _swApp.IActiveDoc2;
                    //    newPartName = $"12-30-01-{Height}.SLDPRT";
                    //    newPartPath = $@"{destRootFolder}\{DestinationFolder}\{newPartName}";
                    //    if (GetExistingFile(Path.GetFileNameWithoutExtension(newPartPath), out path, out fileId, out projectId))
                    //    {
                    //        swDoc = ((ModelDoc2)(VentsCad._swApp.ActivateDoc2("12-00.SLDASM", true, 0)));
                    //        swDoc.Extension.SelectByID2("12-30-001-1@12-00", "COMPONENT", 0, 0, 0, false, 0, null, 0);
                    //        swAsm.ReplaceComponents(newPartPath, "", true, true);
                    //        _swApp.CloseDoc("12-30-001.SLDPRT");
                    //    }
                    //    else
                    //    {
                    //        swDoc.Extension.SelectByID2("D1@Вытянуть1@12-30-001-1@12-00", "DIMENSION", 0, 0, 0, false, 0, null, 0);
                    //        myDimension = ((Dimension)(swDoc.Parameter("D1@Вытянуть[email protected]")));
                    //        myDimension.SystemValue = h - 0.031;
                    //        swDoc.Extension.SelectByID2("D1@Кривая1@12-30-001-1@12-00", "DIMENSION", 0, 0, 0, false, 0, null, 0);
                    //        myDimension = ((Dimension)(swDoc.Parameter("D1@Кривая[email protected]")));
                    //        myDimension.SystemValue = weldH;
                    //        swPartDoc.SaveAs2(newPartPath, (int)swSaveAsVersion_e.swSaveAsCurrentVersion, false, true);
                    //        ComponentToAdd(newPartPath);
                    //        _swApp.CloseDoc(newPartName);
                    //    }

                    //    //12-30-002

                    //    _swApp.IActivateDoc2("12-30-002", false, 0);
                    //    swPartDoc = _swApp.IActiveDoc2;
                    //    newPartName = $"12-30-02-{Width}.SLDPRT";
                    //    newPartPath = $@"{destRootFolder}\{DestinationFolder}\{newPartName}";
                    //    if (GetExistingFile(Path.GetFileNameWithoutExtension(newPartPath), out path, out fileId, out projectId))
                    //    {
                    //        swDoc = ((ModelDoc2)(VentsCad._swApp.ActivateDoc2("12-00.SLDASM", true, 0)));
                    //        swDoc.Extension.SelectByID2("12-30-002-1@12-00", "COMPONENT", 0, 0, 0, false, 0, null, 0);
                    //        swAsm.ReplaceComponents(newPartPath, "", true, true);
                    //        _swApp.CloseDoc("12-30-002.SLDPRT");
                    //    }
                    //    else
                    //    {
                    //        swDoc.Extension.SelectByID2("D1@Вытянуть1@12-30-002-1@12-00", "DIMENSION", 0, 0, 0, false, 0, null, 0);
                    //        myDimension = ((Dimension)(swDoc.Parameter("D1@Вытянуть[email protected]")));
                    //        myDimension.SystemValue = w - 0.031;
                    //        swDoc.Extension.SelectByID2("D1@Кривая1@12-30-002-1@12-00", "DIMENSION", 0, 0, 0, false, 0, null, 0);
                    //        myDimension = ((Dimension)(swDoc.Parameter("D1@Кривая[email protected]")));
                    //        myDimension.SystemValue = weldH;
                    //        swPartDoc.SaveAs2(newPartPath, (int)swSaveAsVersion_e.swSaveAsCurrentVersion, false, true);
                    //        ComponentToAdd(newPartPath);
                    //        _swApp.CloseDoc(newPartName);
                    //    }

                    //    //12-003

                    //    _swApp.IActivateDoc2("12-003", false, 0);
                    //    swPartDoc = _swApp.IActiveDoc2;
                    //    newPartName = $"12-03-{Width}-{Height}.SLDPRT";
                    //    newPartPath = $@"{destRootFolder}\{DestinationFolder}\{newPartName}";
                    //    if (GetExistingFile(Path.GetFileNameWithoutExtension(newPartPath), out path, out fileId, out projectId))
                    //    {
                    //        swDoc = ((ModelDoc2)(VentsCad._swApp.ActivateDoc2("12-00.SLDASM", true, 0)));
                    //        swDoc.Extension.SelectByID2("12-003-2@12-00", "COMPONENT", 0, 0, 0, false, 0, null, 0);
                    //        swAsm.ReplaceComponents(newPartPath, "", true, true);
                    //        _swApp.CloseDoc("12-003.SLDPRT");
                    //    }
                    //    else
                    //    {
                    //        swDoc.Extension.SelectByID2("D3@Эскиз1@12-003-2@12-00", "DIMENSION", 0, 0, 0, false, 0, null, 0);
                    //        myDimension = ((Dimension)(swDoc.Parameter("D3@Эскиз[email protected]")));
                    //        myDimension.SystemValue = w;
                    //        swDoc.Extension.SelectByID2("D2@Эскиз1@12-003-2@12-00", "DIMENSION", 0, 0, 0, false, 0, null, 0);
                    //        myDimension = ((Dimension)(swDoc.Parameter("D2@Эскиз[email protected]")));
                    //        myDimension.SystemValue = h;
                    //        swDoc.EditRebuild3();
                    //        swPartDoc.SaveAs2(newPartPath, (int)swSaveAsVersion_e.swSaveAsCurrentVersion, false, true);
                    //        ComponentToAdd(newPartPath);
                    //        _swApp.CloseDoc(newPartName);
                    //    }
                    //}

                    //#endregion

                    //GabaritsForPaintingCamera(swDoc);

                    //swDoc.ForceRebuild3(true);
                    //swDoc.SaveAs2(ModelPath + ".SLDASM", (int)swSaveAsVersion_e.swSaveAsCurrentVersion, false, true);
                    //_swApp.CloseDoc(ModelName + ".SLDASM");
                    //swDrwSpigot.Extension.SelectByID2("DRW1", "SHEET", 0, 0, 0, false, 0, null, 0);
                    //var drw = (DrawingDoc)(_swApp.IActivateDoc3(drawing + ".SLDDRW", true, 0));
                    //drw.ActivateSheet("DRW1");
                    //var m = 5;
                    //if (Convert.ToInt32(Width) > 500 || Convert.ToInt32(Height) > 500) { m = 10; }
                    //if (Convert.ToInt32(Width) > 850 || Convert.ToInt32(Height) > 850) { m = 15; }
                    //if (Convert.ToInt32(Width) > 1250 || Convert.ToInt32(Height) > 1250) { m = 20; }
                    //drw.SetupSheet5("DRW1", 12, 12, 1, m, true, destRootFolder + @"\Vents-PDM\\Библиотека проектирования\\Templates\\Основные надписи\\A3-A-1.slddrt", 0.42, 0.297, "По умолчанию", false);
                    //var errors = 0; var warnings = 0;

                    //swDrwSpigot.SaveAs4(ModelPath + ".SLDDRW", (int)swSaveAsVersion_e.swSaveAsCurrentVersion, (int)swSaveAsOptions_e.swSaveAsOptions_Silent, ref errors, ref warnings);
                    //ComponentToAdd(new[] { ModelPath + ".SLDDRW", ModelPath + ".SLDASM" });

                    //_swApp.CloseDoc(ModelPath);
                    //_swApp.ExitApp();
                    //_swApp = null;

                    //List<VaultSystem.VentsCadFiles> newFilesList;
                    //VaultSystem.CheckInOutPdmNew(NewComponents, true, //DestVaultName,
                    //    out newFilesList);

                    //foreach (var item in newFilesList)
                    //{
                    //    if (item.LocalPartFileInfo.ToUpper().Contains(".SLDASM"))
                    //    {
                    //        AddInSqlBaseSpigot(item.PartName.Remove(item.PartName.LastIndexOf('.')), item.PartIdPdm,
                    //       Convert.ToInt32(Type), Convert.ToInt32(Height), Convert.ToInt32(Width));
                    //    }
                    //}

                    //foreach (var newComponent in NewComponents)
                    //{
                    //    PartInfoToXml(newComponent.LocalPartFileInfo);
                    //}

                    #endregion

                    Place = GetPlace();
                }
            }
Ejemplo n.º 35
0
 public static IDisposable AddSelection(this IModelDoc2 doc, SelectionData selection)
 {
     return(doc.AddSelections(new[] { selection }));
 }
Ejemplo n.º 36
0
        public ProcessLine(IModelDoc2 pDoc, ISldWorks swApp, List <string> routingIds)
        {
            _routingIds = routingIds;

            dicSketchRefProcess = new Dictionary <string, List <CSketchFileProcess> >();

            InitializeComponent();
            this.AutoSize             = true;
            this.tvProcessLine.Height = Height;
            this.pDoc  = pDoc;
            this.swApp = swApp;

            rcontext   = new RoutingContext(DbConfig.Connection);
            rprContext = new RoutingProcessRelationContext(DbConfig.Connection);
            pfrContext = new ProcessFileRoutingContext(DbConfig.Connection);

            try
            {
                var slist = (from s in pfrContext.SketchFileProcesses
                             where _routingIds.Contains(s.RoutingId) &&
                             s.ComponentName == GlobalCache.Instance.ComponetName
                             select s).ToList <CSketchFileProcess>();

                List <CSketchFileProcess> cSketchFileProcessList = null;
                slist.ForEach((x) =>
                {
                    if (dicSketchRefProcess.ContainsKey(x.RoutingId))
                    {
                        cSketchFileProcessList = dicSketchRefProcess[x.RoutingId];
                        cSketchFileProcessList.Add(x);
                        dicSketchRefProcess[x.RoutingId] = cSketchFileProcessList;
                    }
                    else
                    {
                        dicSketchRefProcess.Add(x.RoutingId, new List <CSketchFileProcess>()
                        {
                            x
                        });
                    }
                });


                var qList = (from q in rcontext.Routings
                             where _routingIds.Contains(q.RoutingId)
                             select q).ToList <Routing>();

                foreach (var r in qList)
                {
                    TreeNode tn = new TreeNode(r.Name);
                    tn.Name     = r.Code;
                    tn.Tag      = r.RoutingId;
                    tn.ImageKey = "Routing";
                    tn.Expand();
                    AddChildTreeNode(r.RoutingId, tn);
                    tvProcessLine.Nodes.Add(tn);
                }
            }
            catch
            {
                MessageBox.Show("访问数据库失败");
            }

            ///默认第一个选中的Routing
            TreeNode[] tnodes = tvProcessLine.Nodes.Find(_routingIds.FirstOrDefault(), true);
            if (tnodes != null)
            {
                SelectedCurrentRouting(
                    tnodes.FirstOrDefault <TreeNode>(),
                    _routingIds.FirstOrDefault());

                ///初始状态没有
                GlobalCache.Instance.OperId = string.Empty;
            }

            ///初始化SketchDic
            //InitSketchDic(pDoc);

            EventHelper eh = EventHelper.GetInstance();

            eh.Testing += new TestEventHandler(SeletedProcessByComponentName);

            CurrentProcessLine = this;
        }
Ejemplo n.º 37
0
        public static Tuple <object[], int[], IView[]> GetMacroFeatureDataSelectionInfo(this IModelDoc2 doc, object model)
        {
            var view = (IView)(doc as IDrawingDoc)?.GetFirstView();

            var selections      = SelectionDataExtensions.GetSelectionsFromModel(model).ToList();
            var selectedObjects = selections.SelectMany(s => s.GetObjects(doc)).ToArray();
            var marks           = selections.SelectMany(s => Enumerable.Repeat(s.Mark, s.ObjectIds.Count)).ToArray();
            var views           = selections.SelectMany(s => Enumerable.Repeat(view, s.ObjectIds.Count)).ToArray();

            return(Tuple(selectedObjects, marks, views));
        }
Ejemplo n.º 38
0
 public static IDisposable DisplayUndoable
     (this IRenderable renderable, IModelDoc2 doc, int layer = 0)
 {
     return(OpenGlRenderer.DisplayUndoable(renderable, doc, layer));
 }
Ejemplo n.º 39
0
        /// <summary>
        /// Generates a lambda which resolves an entity from its persist reference every time you invoke it.
        /// </summary>
        /// <typeparam name="T">Entity type, e.g. IBody2</typeparam>
        /// <param name="modelDoc"></param>
        /// <param name="obj">Entity with a valid persist reference</param>
        /// <returns></returns>
        public static Func <T> GetPersistentEntityReference <T>(this IModelDoc2 modelDoc, T obj)
        {
            var persistReference = modelDoc.GetPersistReference(obj);

            return(fun(() => (T)GetObjectFromPersistReference(modelDoc, persistReference)));
        }
Ejemplo n.º 40
0
 /// <summary>
 /// Uses Display3 to render the object. This is slow for animation. Better to create a Mesh and then render it. This
 /// will use OpenGL directly.
 /// </summary>
 /// <param name="body"></param>
 /// <param name="doc"></param>
 /// <param name="c"></param>
 /// <param name="opt"></param>
 /// <returns></returns>
 public static IDisposable DisplayUndoable(this IBody2 body, IModelDoc2 doc, Color?c = null, swTempBodySelectOptions_e opt = swTempBodySelectOptions_e.swTempBodySelectOptionNone)
 {
     body.DisplayTs(doc, c, opt);
     return(Disposable.Create(() => body.Hide(doc)));
 }
Ejemplo n.º 41
0
 /// <summary>
 /// Set a global variable as you would find in the equation manager. The units
 /// of this setting will always be meters.
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="doc"></param>
 /// <param name="name"></param>
 /// <param name="meters"></param>
 /// <returns></returns>
 public static bool SetGlobalMeters(this IModelDoc2 doc, string name, double meters)
 {
     return(SetGlobal(doc, new SwEq(name, meters, "m")));
 }
Ejemplo n.º 42
0
 public static IDisposable DisplayBodiesUndoable(this IEnumerable <IBody2> bodies, IModelDoc2 doc, Color?c = null,
                                                 swTempBodySelectOptions_e opt = swTempBodySelectOptions_e.swTempBodySelectOptionNone)
 {
     return(new CompositeDisposable(bodies.Select(b => b.DisplayUndoable(doc, c, opt))));
 }
Ejemplo n.º 43
0
 public static bool SetGlobalDegrees(this IModelDoc2 doc, string name, double degrees)
 {
     return(SetGlobal(doc, new SwEq(name, degrees, "deg")));
 }
Ejemplo n.º 44
0
 /// <summary>
 /// Access the 3rd party storage store for reading or writing
 /// </summary>
 /// <param name="model">Pointer to document</param>
 /// <param name="name">Name of the stream</param>
 /// <param name="write">True to open for writing, false to open for reading</param>
 /// <returns>Pointer to the store handler</returns>
 public static IThirdPartyStoreHandler Access3rdPartyStorageStore(this IModelDoc2 model, string name, bool write)
 {
     return(new ThirdPartyStoreHandler(model, name, write));
 }
Ejemplo n.º 45
0
 /// <summary>
 /// Get all configurations
 /// </summary>
 /// <param name="modelDoc"></param>
 /// <returns></returns>
 public static IEnumerable <Configuration> GetConfigurations(this IModelDoc2 modelDoc) =>
 modelDoc
 .GetConfigurationNames()
 .CastArray <string>()
 .Select(name => (Configuration)modelDoc.GetConfigurationByName(name));
Ejemplo n.º 46
0
 public DocumentFeatureEnumerator(ISwDocument rootDoc) : base(rootDoc)
 {
     m_Model = rootDoc.Model;
     Reset();
 }
Ejemplo n.º 47
0
        private void button6_Click(object sender, EventArgs e)
        {
            //int Errors=0;
            //ModelDoc2 swModel;
            // swModel = (ModelDoc2)SwAddin.iSwApp.ActivateDoc3("loaded_document", false, (int)swRebuildOnActivation_e.swUserDecision, ref Errors);

            //make sure we have a part open
            string partTemplate = SwAddin.iSwApp.GetUserPreferenceStringValue((int)swUserPreferenceStringValue_e.swDefaultTemplatePart);
            if ((partTemplate != null) && (partTemplate != ""))
            {
                modDoc = (IModelDoc2)SwAddin.iSwApp.OpenDoc6(@"c:\mygear.SLDPRT",
                    (int)swDocumentTypes_e.swDocPART, (int)swOpenDocOptions_e.swOpenDocOptions_Silent, "",
                    (int)swFileLoadError_e.swGenericError, (int)swFileLoadWarning_e.swFileLoadWarning_AlreadyOpen);
            }
            else
            {
                System.Windows.Forms.MessageBox.Show("There is no part template available. Please check your options and make sure there is a part template selected, or select a new part template.");
            }

            EquationMgr MyEqu = modDoc.GetEquationMgr();

            //滚动角
            double u, d_a, d_b;
            d_a = double.Parse(text_dad.Text);
            d_b = double.Parse(text_dbd.Text);
            u = Math.Sqrt((d_a / d_b) * (d_a / d_b) - 1);

            // 螺距
            double luoju = Math.PI * double.Parse(text_dd.Text) / Math.Tan(double.Parse(text_lb12.Text) * Math.PI / 180);

            MyEqu.set_Equation(0, "\"" + "d_b" + "\"" + "=" + text_dbd.Text);//基圆
            MyEqu.set_Equation(1, "\"" + "U" + "\"" + "=" + u);//滚动角
            MyEqu.set_Equation(2, "\"" + "d" + "\"" + "=" + text_dd.Text);//分度圆
            MyEqu.set_Equation(7, "\"" + "s" + "\"" + "=" + double.Parse(text_srnd.Text));//齿弦厚
            MyEqu.set_Equation(8, "\"" + "d_f" + "\"" + "=" + text_dfd.Text);//齿根圆
            MyEqu.set_Equation(10, "\"" + "B" + "\"" + "=" + text_bd.Text);//齿宽
            MyEqu.set_Equation(13, "\"" + "z" + "\"" + "=" + text_zd.Text);//齿数
            MyEqu.set_Equation(15, "\"" + "d_a" + "\"" + "=" + text_dad.Text);//齿顶圆
            MyEqu.set_Equation(18, "\"" + "luoju" + "\"" + "=" + luoju);//螺距
            MyEqu.set_Equation(21, "\"" + "C_CD" + "\"" + "=" + textCDDJ.Text);//齿顶倒角
            // 腹板参数
            MyEqu.set_Equation(23, "\"" + "D_2" + "\"" + "=" + textFBWJ.Text);//腹板外径
            MyEqu.set_Equation(24, "\"" + "D_1" + "\"" + "=" + texFBNJ.Text);//腹板内径
            MyEqu.set_Equation(25, "\"" + "R_FB" + "\"" + "=" + textFBYJ.Text);//腹板外圆角
            MyEqu.set_Equation(26, "\"" + "C_FB" + "\"" + "=" + textFBDJ.Text);//腹板外倒角
            MyEqu.set_Equation(27, "\"" + "KJ_FB" + "\"" + "=" + textFBKJ.Text);//腹板孔径
            MyEqu.set_Equation(28, "\"" + "N_FB" + "\"" + "=" + textFBKS.Text);//腹板孔数

            MyEqu.set_Equation(33, "\"" + "D_FB" + "\"" + "=" + textFBH.Text);//腹板厚

            // 齿根圆角简单的计算公式:if ( "齿顶高" > = 1 , 0.38 * "m_n" , 0.46 * "m_n" )
            /*double R_CG;
            if (double.Parse(text_hax.Text) >= 1)
            {
                R_CG = 0.38 * double.Parse(text_mn2.Text);
            }
            else
            {
                R_CG = 0.46 * double.Parse(text_mn2.Text);
            }
            MyEqu.set_Equation(20, "\"" + "R_CG" + "\"" + "=" + R_CG);//齿根圆角
            MyEqu.set_Equation(21, "\"" + "C_CD" + "\"" + "=" + textCDDJ.Text);//齿顶倒角
            */

            //齿弦厚
            //double z_v,psi_v,s;
            //z_v = double.Parse (txtPinionZ.Text )/Math.Pow(Math.Cos(double.Parse(text_lb12.Text)*Math.PI /180),3);
            //psi_v = 90/z_v +(360*double.Parse (text_xnx.Text)*Math.Tan(double.Parse(text_an2.Text)))/(Math.PI *z_v);
            //s = z_v*double.Parse (text_mn2.Text)*Math.Sin(psi_v*Math.PI /180)/Math.Cos(double.Parse(text_lb12.Text)*Math.PI /180);

            // 轮毂参数
            MyEqu.set_Equation(41, "\"" + "D_LG" + "\"" + "=" + textLGZJ.Text);//轮毂直径
            MyEqu.set_Equation(42, "\"" + "J_K" + "\"" + "=" + textJK.Text);//键宽
            MyEqu.set_Equation(43, "\"" + "J_S" + "\"" + "=" + textJS.Text);//键深
            MyEqu.set_Equation(44, "\"" + "C_LG" + "\"" + "=" + textZXKDJ.Text);//轮毂倒角

            /*
            MyEqu.set_Equation(11, "\"" + "R_FBW" + "\"" + "=" + textFBWYJ.Text);//腹板外圆角
            MyEqu.set_Equation(8, "\"" + "C_CD" + "\"" + "=" + textCDDJ.Text);//齿顶倒角
            MyEqu.set_Equation(11, "\"" + "R_FBW" + "\"" + "=" + textFBWYJ.Text);//腹板外圆角
            MyEqu.set_Equation(9, "\"" + "n_FBK" + "\"" + "=" + textFBKS.Text);//腹板孔数

               // MyEqu.set_Equation(11, "\"" + "R_FBW" + "\"" + "=" + textFBWYJ.Text);//腹板外圆角
            //MyEqu.set_Equation(12, "\"" + "R_FBN" + "\"" + "=" + textFBNYJ.Text);//腹板内圆角
            MyEqu.set_Equation(13, "\"" + "C_FBW" + "\"" + "=" + textFBWDJ.Text);//腹板外倒角
            MyEqu.set_Equation(14, "\"" + "C_FBN" + "\"" + "=" + textFBNDJ.Text);//腹板内倒角
            MyEqu.set_Equation(15, "\"" + "d_Z" + "\"" + "=" + textLGZJ.Text);//轮毂直径
            MyEqu.set_Equation(16, "\"" + "j_B" + "\"" + "=" + textJK.Text);//键宽
            MyEqu.set_Equation(17, "\"" + "j_D" + "\"" + "=" + textJS.Text);//键深
            MyEqu.set_Equation(18, "\"" + "beta" + "\"" + "=" + text_lb12.Text);//螺旋角

            MyEqu.set_Equation(20, "\"" + "x_n1" + "\"" + "=" + text_xnx.Text);//本齿轮法向变位系数

            MyEqu.set_Equation(21, "\"" + "x_n2" + "\"" + "=" + text_xnd.Text);//啮合齿轮法向变位系数

            // MyEqu.set_Equation(22, "\"" + "y" + "\"" + "=" + text_xnd.Text);

            //MyEqu.set_Equation(21, "\"" + "x_n2" + "\"" + "=" + text_xnd.Text);*/

            MyEqu.EvaluateAll();
            modDoc.EditRebuild3();
            modDoc.ShowNamedView2("*Isometric", (int)swStandardViews_e.swTrimetricView);
        }
Ejemplo n.º 48
0
        static string GetFromCutlist(IModelDoc2 swModel, string property)
        {
            var propertyValue = "";

            try
            {
                Feature swFeat2 = swModel.FirstFeature();
                while (swFeat2 != null)
                {
                    if (swFeat2.GetTypeName2() == "SolidBodyFolder")
                    {
                        BodyFolder swBodyFolder = swFeat2.GetSpecificFeature2();
                        swFeat2.Select2(false, -1);
                        swBodyFolder.SetAutomaticCutList(true);
                        swBodyFolder.UpdateCutList();

                        Feature swSubFeat = swFeat2.GetFirstSubFeature();
                        while (swSubFeat != null)
                        {
                            if (swSubFeat.GetTypeName2() == "CutListFolder")
                            {
                                BodyFolder bodyFolder = swSubFeat.GetSpecificFeature2();
                                swSubFeat.Select2(false, -1);
                                bodyFolder.SetAutomaticCutList(true);
                                bodyFolder.UpdateCutList();
                                var swCustPrpMgr = swSubFeat.CustomPropertyManager;
                                string valOut;
                                swCustPrpMgr.Get4(property, true, out valOut, out propertyValue);
                            }
                            swSubFeat = swSubFeat.GetNextFeature();
                        }
                    }
                    swFeat2 = swFeat2.GetNextFeature();
                }
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.ToString());
            }

            return propertyValue;
        }
Ejemplo n.º 49
0
        private void button7_Click_1(object sender, EventArgs e)
        {
            //类变量,调研前要赋值
            xlmFileName = @"C:\齿轮轴.xml";//齿轮的XML文件名字

            XElement xe = XElement.Load(xlmFileName);

            //读取齿轮模型文件名字
            IEnumerable<XElement> elements = from 齿轮轴名称 in xe.Elements("基本信息")// where PInfo.Attribute("ID").Value == strID
                                             select 齿轮轴名称;
            //MessageBox.Show(elements.ElementAt(0).Element("齿轮名称").Value);

            //利用齿轮模型文件名字,读取齿轮模型
            string partTemplate = SwAddin.iSwApp.GetUserPreferenceStringValue((int)swUserPreferenceStringValue_e.swDefaultTemplatePart);
            if ((partTemplate != null) && (partTemplate != ""))
            {
                modDoc = (IModelDoc2)SwAddin.iSwApp.OpenDoc6(elements.ElementAt(0).Element("齿轮轴名称").Value,
                    (int)swDocumentTypes_e.swDocPART, (int)swOpenDocOptions_e.swOpenDocOptions_Silent, "",
                    (int)swFileLoadError_e.swGenericError, (int)swFileLoadWarning_e.swFileLoadWarning_AlreadyOpen);
            }
            else
            {
                System.Windows.Forms.MessageBox.Show("There is no part template available. Please check your options and make sure there is a part template selected, or select a new part template.");
            }

            elements = from 基圆直径 in xe.Elements("尺寸计算")// where PInfo.Attribute("ID").Value == strID
                       select 基圆直径;
            double d_b = double.Parse(elements.ElementAt(0).Element("基圆直径").Value) / 1000;          //基圆直径
            double d_a = double.Parse(elements.ElementAt(0).Element("齿顶圆直径").Value) / 1000;
            double u = Math.Sqrt(((d_a * 1000) / (d_b * 1000)) * ((d_a * 1000) / (d_b * 1000)) - 1);   //滚动角
            double d = double.Parse(elements.ElementAt(0).Element("分度圆直径").Value) / 1000;
            double s = double.Parse(elements.ElementAt(0).Element("齿弦厚").Value) / 1000;
            double d_f = double.Parse(elements.ElementAt(0).Element("齿根圆直径").Value) / 1000;
            double C_CD = double.Parse(elements.ElementAt(0).Element("齿顶倒角").Value) / 1000;

            elements = from 螺旋角 in xe.Elements("设计参数")// where PInfo.Attribute("ID").Value == strID
                       select 螺旋角;
            double beta = double.Parse(elements.ElementAt(0).Element("螺旋角").Value);
            double luoju = Math.PI * d / Math.Tan(beta * Math.PI / 180);
            double B = double.Parse(elements.ElementAt(0).Element("齿宽").Value) / 1000;
            double Z = double.Parse(elements.ElementAt(0).Element("齿数").Value);
            string xuanxiang = elements.ElementAt(0).Element("旋向").Value;

            double numberOfLeftShaft = double.Parse(elements.ElementAt(0).Element("左轴段数").Value);
            double numberOfRightShaft = double.Parse(elements.ElementAt(0).Element("右轴段数").Value);
            double numberOfKeySeat = double.Parse(elements.ElementAt(0).Element("键槽数").Value);

            //SldWorks swApp;
            // IModelDoc2 swModel = default(IModelDoc2);
            ISelectionMgr swSelMgr = default(ISelectionMgr);
            Feature swFeat = default(Feature);
            HelixFeatureData swHelix = default(HelixFeatureData);
            bool bRet;
            bool boolstatus;

            swSelMgr = modDoc.SelectionManager as SelectionMgr;

            // swModel = (ModelDoc2)swApp.ActiveDoc;
            boolstatus = modDoc.Extension.SelectByID2("螺旋线", "REFERENCECURVES", 0, 0, 0, false, 0, null, 0);
            swFeat = swSelMgr.GetSelectedObject6(1, -1);
            swHelix = (HelixFeatureData)swFeat.GetDefinition();
            if (xuanxiang.Equals("L"))
            {
                swHelix.Clockwise = true;
            }
            else
            {
                swHelix.Clockwise = false;
            }
            bRet = swFeat.ModifyDefinition(swHelix, modDoc, null);

            IDimension myDimension = null;

            myDimension = (IDimension)modDoc.Parameter(@"基圆@草图1");
            myDimension.SystemValue = d_b;

            myDimension = (IDimension)modDoc.Parameter(@"U@草图1");
            myDimension.SystemValue = u * Math.PI / 180;              //滚动角

            myDimension = (IDimension)modDoc.Parameter(@"分度圆@草图1");
            myDimension.SystemValue = d;

            myDimension = (IDimension)modDoc.Parameter(@"齿弦厚@草图1");
            myDimension.SystemValue = s;

            myDimension = (IDimension)modDoc.Parameter(@"齿根圆@草图5");
            myDimension.SystemValue = d_f;

            myDimension = (IDimension)modDoc.Parameter(@"D3@螺旋线");
            myDimension.SystemValue = B + 0.001;

            myDimension = (IDimension)modDoc.Parameter(@"D1@齿根圆");
            myDimension.SystemValue = B + 0.001;

            myDimension = (IDimension)modDoc.Parameter(@"B@草图6");
            myDimension.SystemValue = B;

            myDimension = (IDimension)modDoc.Parameter(@"D1@齿廓阵列");
            myDimension.SystemValue = Z;

            myDimension = (IDimension)modDoc.Parameter(@"D1@草图6");
            myDimension.SystemValue = d_a + 0.002;

            myDimension = (IDimension)modDoc.Parameter(@"D2@草图6");
            myDimension.SystemValue = B + 1;

            myDimension = (IDimension)modDoc.Parameter(@"D4@螺旋线");
            myDimension.SystemValue = luoju;

            myDimension = (IDimension)modDoc.Parameter(@"D1@齿顶倒角");
            myDimension.SystemValue = C_CD;

            myDimension = (IDimension)modDoc.Parameter(@"D1@齿顶倒角阵列");
            myDimension.SystemValue = Z;

            myDimension = (IDimension)modDoc.Parameter(@"D1@草图7");
            myDimension.SystemValue = d_a;

            myDimension = (IDimension)modDoc.Parameter(@"D1@齿顶倒角1");
            myDimension.SystemValue = C_CD;

            string zzd;
            XElement zzdEle = xe.Element("左轴段");
            for (int i = 1; i <= numberOfLeftShaft; i++)
            {
                zzd = "左轴段" + i.ToString();

                if (zzdEle != null)
                    elements = from 直径 in zzdEle.Elements(zzd)// where PInfo.Attribute("ID").Value == strID
                               select 直径;
                double D = double.Parse(elements.ElementAt(0).Element("直径").Value) / 1000;
                double L = double.Parse(elements.ElementAt(0).Element("长度").Value) / 1000;
                double C = double.Parse(elements.ElementAt(0).Element("倒角").Value) / 1000;
                double R = double.Parse(elements.ElementAt(0).Element("圆角").Value) / 1000;

                myDimension = (IDimension)modDoc.Parameter(@"D1@" + zzd + "草图");
                myDimension.SystemValue = D;
                myDimension = (IDimension)modDoc.Parameter(@"D1@" + zzd);
                myDimension.SystemValue = L;
                myDimension = (IDimension)modDoc.Parameter(@"D1@" + zzd + "倒角");
                myDimension.SystemValue = C;
                myDimension = (IDimension)modDoc.Parameter(@"D1@" + zzd + "圆角");
                myDimension.SystemValue = R;
            }
            XElement yzdEle = xe.Element("右轴段");
            string yzd;
            for (int i = 1; i <= numberOfRightShaft; i++)
            {
                yzd = "右轴段" + i.ToString();
                elements = from 直径 in yzdEle.Elements(yzd)// where PInfo.Attribute("ID").Value == strID
                           select 直径;
                double D = double.Parse(elements.ElementAt(0).Element("直径").Value) / 1000;
                double L = double.Parse(elements.ElementAt(0).Element("长度").Value) / 1000;
                double C = double.Parse(elements.ElementAt(0).Element("倒角").Value) / 1000;
                double R = double.Parse(elements.ElementAt(0).Element("圆角").Value) / 1000;

                myDimension = (IDimension)modDoc.Parameter(@"D1@" + yzd + "草图");
                myDimension.SystemValue = D;
                myDimension = (IDimension)modDoc.Parameter(@"D1@" + yzd);
                myDimension.SystemValue = L;
                myDimension = (IDimension)modDoc.Parameter(@"D1@" + yzd + "倒角");
                myDimension.SystemValue = C;
                myDimension = (IDimension)modDoc.Parameter(@"D1@" + yzd + "圆角");
                myDimension.SystemValue = R;
            }

            XElement keySeatEle = xe.Element("键槽");
            for (int i = 1; i <= numberOfKeySeat; i++)
            {
                string keySeat = "键槽" + i.ToString();
                elements = from 直径 in keySeatEle.Elements(keySeat)// where PInfo.Attribute("ID").Value == strID
                           select 直径;
                double K = double.Parse(elements.ElementAt(0).Element("宽").Value) / 1000;
                double L = double.Parse(elements.ElementAt(0).Element("长度").Value) / 1000;
                double C = double.Parse(elements.ElementAt(0).Element("定位").Value) / 1000;
                double S = double.Parse(elements.ElementAt(0).Element("深").Value) / 1000;
                string weizhi=elements.ElementAt(0).Element("位置").Value;
                if(weizhi.Substring(0,1).Equals ("左"))
                {
                   elements = from 直径 in zzdEle.Elements(weizhi)// where PInfo.Attribute("ID").Value == strID
                           select 直径;
                }
                else
                {
                    elements = from 直径 in yzdEle.Elements(weizhi)// where PInfo.Attribute("ID").Value == strID
                           select 直径;
                }
                double D = double.Parse(elements.ElementAt(0).Element("直径").Value)/ 1000 ;

                myDimension = (IDimension)modDoc.Parameter(@"D1@" + keySeat);
                myDimension.SystemValue = 0.5 * D -S;

                myDimension = (IDimension)modDoc.Parameter(@"D1@" + keySeat + "草图");
                myDimension.SystemValue = K;
                myDimension = (IDimension)modDoc.Parameter(@"D2@" + keySeat + "草图");
                myDimension.SystemValue = L;
                myDimension = (IDimension)modDoc.Parameter(@"D3@" + keySeat + "草图");
                myDimension.SystemValue = C;
            }

            modDoc.EditRebuild3();
            modDoc.ShowNamedView2("*Isometric", (int)swStandardViews_e.swTrimetricView);
            modDoc.ViewZoomtofit2 ();
        }
 public TriadManipulatorTs(IModelDoc2 doc)
 {
     _Manipulator = doc.ModelViewManager.CreateManipulator((int)swManipulatorType_e.swTriadManipulator, this);
     _Impl        = (ITriadManipulator)_Manipulator.GetSpecificManipulator();
     _Impl.Cursor = (int)swManipulatorCursor_e.swManipulatorMoveCursor;
 }
Ejemplo n.º 51
0
        private void btnGearBuild_Click(object sender, EventArgs e)
        {
            //int Errors=0;
            //ModelDoc2 swModel;
            // swModel = (ModelDoc2)SwAddin.iSwApp.ActivateDoc3("loaded_document", false, (int)swRebuildOnActivation_e.swUserDecision, ref Errors);

            //make sure we have a part open
            string partTemplate = SwAddin.iSwApp.GetUserPreferenceStringValue((int)swUserPreferenceStringValue_e.swDefaultTemplatePart);
            if ((partTemplate != null) && (partTemplate != ""))
            {
                modDoc = (IModelDoc2)SwAddin.iSwApp.OpenDoc6(@"c:\gear.SLDPRT",
                    (int)swDocumentTypes_e.swDocPART, (int)swOpenDocOptions_e.swOpenDocOptions_Silent, "",
                    (int)swFileLoadError_e.swGenericError, (int)swFileLoadWarning_e.swFileLoadWarning_AlreadyOpen);
            }
            else
            {
                System.Windows.Forms.MessageBox.Show("There is no part template available. Please check your options and make sure there is a part template selected, or select a new part template.");
            }

            EquationMgr MyEqu = modDoc.GetEquationMgr();// default(EquationMgr);
            MessageBox.Show(MyEqu.get_Equation(1));
            MyEqu.set_Equation(1, "\"" + "m" + "\"" + "=" + text_mn2.Text);//\\"\"" + System.Convert.ToChar(Index) + "\"="
            MyEqu.EvaluateAll();
            modDoc.EditRebuild3();
            modDoc.ShowNamedView2("*Isometric", (int)swStandardViews_e.swTrimetricView);
        }
 protected PropertyManagerPageBase(string name, IEnumerable <swPropertyManagerPageOptions_e> optionsE, ISldWorks swApp, IModelDoc2 modelDoc)
 {
     SwApp     = swApp;
     ModelDoc  = modelDoc;
     _Name     = name;
     _OptionsE = optionsE;
 }
Ejemplo n.º 53
0
        //public string gearFileName;
        private void button1_Click_2(object sender, EventArgs e)
        {
            //类变量,调研前要赋值
            xlmFileName = @"C:\圆柱齿轮.xml";//齿轮的XML文件名字

            XElement xe = XElement.Load(xlmFileName);

            //读取齿轮模型文件名字
            IEnumerable<XElement> elements = from 齿轮名称 in xe.Elements("基本信息")// where PInfo.Attribute("ID").Value == strID
                                             select 齿轮名称;
            //MessageBox.Show(elements.ElementAt(0).Element("齿轮名称").Value);

            //利用齿轮模型文件名字,读取齿轮模型
            string partTemplate = SwAddin.iSwApp.GetUserPreferenceStringValue((int)swUserPreferenceStringValue_e.swDefaultTemplatePart);
            if ((partTemplate != null) && (partTemplate != ""))
            {
                modDoc = (IModelDoc2)SwAddin.iSwApp.OpenDoc6(elements.ElementAt(0).Element("齿轮名称").Value,
                    (int)swDocumentTypes_e.swDocPART, (int)swOpenDocOptions_e.swOpenDocOptions_Silent, "",
                    (int)swFileLoadError_e.swGenericError, (int)swFileLoadWarning_e.swFileLoadWarning_AlreadyOpen);
            }
            else
            {
                System.Windows.Forms.MessageBox.Show("There is no part template available. Please check your options and make sure there is a part template selected, or select a new part template.");
            }

            elements = from 基圆直径 in xe.Elements("尺寸计算")// where PInfo.Attribute("ID").Value == strID
                       select 基圆直径;
            double d_b = double.Parse(elements.ElementAt(0).Element("基圆直径").Value) / 1000;          //基圆直径
            double d_a = double.Parse(elements.ElementAt(0).Element("齿顶圆直径").Value) / 1000;
            double u = Math.Sqrt(((d_a * 1000) / (d_b * 1000)) * ((d_a * 1000) / (d_b * 1000)) - 1);   //滚动角
            double d = double.Parse(elements.ElementAt(0).Element("分度圆直径").Value) / 1000;
            double s = double.Parse(elements.ElementAt(0).Element("齿弦厚").Value) / 1000;
            double d_f = double.Parse(elements.ElementAt(0).Element("齿根圆直径").Value) / 1000;
            double C_CD = double.Parse(elements.ElementAt(0).Element("齿顶倒角").Value) / 1000;

            elements = from 螺旋角 in xe.Elements("设计参数")// where PInfo.Attribute("ID").Value == strID
                       select 螺旋角;
            double beta = double.Parse(elements.ElementAt(0).Element("螺旋角").Value);
            double luoju = Math.PI * d / Math.Tan(beta * Math.PI / 180);
            double B = double.Parse(elements.ElementAt(0).Element("齿宽").Value) / 1000;
            double Z = double.Parse(elements.ElementAt(0).Element("齿数").Value);
            string xuanxiang = elements.ElementAt(0).Element("旋向").Value;

            elements = from 腹板深 in xe.Elements("腹板结构")// where PInfo.Attribute("ID").Value == strID
                       select 腹板深;
            double D_2 = double.Parse(elements.ElementAt(0).Element("腹板外径D2").Value) / 1000;
            double D_1 = double.Parse(elements.ElementAt(0).Element("腹板内径D1").Value) / 1000;
            double KJ_FB = double.Parse(elements.ElementAt(0).Element("腹板孔径dk").Value) / 1000;
            double N_FB = double.Parse(elements.ElementAt(0).Element("腹板孔数").Value);
            double D_FB = double.Parse(elements.ElementAt(0).Element("腹板深").Value) / 1000;
            double R_FB = double.Parse(elements.ElementAt(0).Element("腹板圆角").Value) / 1000;
            double C_FB = double.Parse(elements.ElementAt(0).Element("腹板倒角").Value) / 1000;

            elements = from 轮毂直径 in xe.Elements("轮毂结构")// where PInfo.Attribute("ID").Value == strID
                       select 轮毂直径;
            double D_LG = double.Parse(elements.ElementAt(0).Element("轮毂直径").Value) / 1000;
            double J_K = double.Parse(elements.ElementAt(0).Element("键宽").Value) / 1000;
            double J_S = double.Parse(elements.ElementAt(0).Element("键深").Value) / 1000;
            double C_LG = double.Parse(elements.ElementAt(0).Element("轮毂倒角").Value) / 1000;
            double R_LG = double.Parse(elements.ElementAt(0).Element("轮毂圆角").Value) / 1000;

            //SldWorks swApp;
            // IModelDoc2 swModel = default(IModelDoc2);
            ISelectionMgr swSelMgr = default(ISelectionMgr);
            Feature swFeat = default(Feature);
            HelixFeatureData swHelix = default(HelixFeatureData);
            bool bRet;
            bool boolstatus;

            swSelMgr = modDoc.SelectionManager as SelectionMgr;

            // swModel = (ModelDoc2)swApp.ActiveDoc;
            boolstatus = modDoc.Extension.SelectByID2("螺旋线", "REFERENCECURVES", 0, 0, 0, false, 0, null, 0);
            swFeat = swSelMgr.GetSelectedObject6(1, -1);
            swHelix = (HelixFeatureData)swFeat.GetDefinition();
            if (xuanxiang.Equals("L"))
            {
                swHelix.Clockwise = true;
            }
            else
            {
                swHelix.Clockwise = false;
            }
            bRet = swFeat.ModifyDefinition(swHelix, modDoc, null);

            IDimension myDimension = null;
               // int Config_count = 1;
            //string Config_names="aa";

            myDimension = (IDimension)modDoc.Parameter(@"基圆@草图1");
            myDimension.SetSystemValue3(d_b, (int)swInConfigurationOpts_e.swAllConfiguration, null);//.set.SystemValue = d_b;

            myDimension = (IDimension)modDoc.Parameter(@"U@草图1");
            myDimension.SetSystemValue3(u * Math.PI / 180, (int)swInConfigurationOpts_e.swAllConfiguration, null);
            //myDimension.SystemValue = u * Math.PI / 180;              //滚动角

            myDimension = (IDimension)modDoc.Parameter(@"分度圆@草图1");
            myDimension.SetSystemValue3(d, (int)swInConfigurationOpts_e.swAllConfiguration, null);
            myDimension.SystemValue = d;

            myDimension = (IDimension)modDoc.Parameter(@"齿弦厚@草图1");
            myDimension.SystemValue = s;

            myDimension = (IDimension)modDoc.Parameter(@"齿根圆@草图5");
            myDimension.SystemValue = d_f;

            myDimension = (IDimension)modDoc.Parameter(@"D3@螺旋线");
            myDimension.SystemValue = B + 0.001;

            myDimension = (IDimension)modDoc.Parameter(@"D1@齿根圆");
            myDimension.SystemValue = B + 0.001;

            myDimension = (IDimension)modDoc.Parameter(@"B@草图6");
            myDimension.SystemValue = B;

            myDimension = (IDimension)modDoc.Parameter(@"D1@齿廓阵列");
            myDimension.SystemValue = Z;

            myDimension = (IDimension)modDoc.Parameter(@"D1@草图6");
            myDimension.SystemValue = d_a + 0.002;

            myDimension = (IDimension)modDoc.Parameter(@"D4@螺旋线");
            myDimension.SystemValue = luoju;

            myDimension = (IDimension)modDoc.Parameter(@"D1@齿顶倒角");
            myDimension.SystemValue = C_CD;

            myDimension = (IDimension)modDoc.Parameter(@"腹板外径@草图7");
            myDimension.SystemValue = D_2;

            myDimension = (IDimension)modDoc.Parameter(@"腹板内径@草图7");
            myDimension.SystemValue = D_1;

            myDimension = (IDimension)modDoc.Parameter(@"D1@草图7");
            myDimension.SystemValue = (D_1 + D_2) / 2;

            myDimension = (IDimension)modDoc.Parameter(@"D2@草图7");
            myDimension.SystemValue = 180 / N_FB;

            myDimension = (IDimension)modDoc.Parameter(@"D1@腹板");
            myDimension.SystemValue = D_FB;

            myDimension = (IDimension)modDoc.Parameter(@"D1@腹板圆角");
            myDimension.SystemValue = R_FB;

            myDimension = (IDimension)modDoc.Parameter(@"D1@腹板倒角");
            myDimension.SystemValue = C_FB;

            myDimension = (IDimension)modDoc.Parameter(@"D1@腹板孔阵列");
            myDimension.SystemValue = N_FB;

            myDimension = (IDimension)modDoc.Parameter(@"D2@草图6");
            myDimension.SystemValue = B + 1;

            myDimension = (IDimension)modDoc.Parameter(@"D3@草图7");
            myDimension.SystemValue = KJ_FB;

            myDimension = (IDimension)modDoc.Parameter(@"D1@齿顶倒角阵列");
            myDimension.SystemValue = Z;

            myDimension = (IDimension)modDoc.Parameter(@"D1@草图8");
            myDimension.SystemValue = D_LG;

            myDimension = (IDimension)modDoc.Parameter(@"D2@草图8");
            myDimension.SystemValue = J_K;

            myDimension = (IDimension)modDoc.Parameter(@"D3@草图8");
            myDimension.SystemValue = J_S;

            myDimension = (IDimension)modDoc.Parameter(@"D1@轮毂倒角");
            myDimension.SystemValue = C_LG;

            myDimension = (IDimension)modDoc.Parameter(@"D1@轮毂圆角");
            myDimension.SystemValue = R_LG;

            myDimension = (IDimension)modDoc.Parameter(@"D1@草图9");
            myDimension.SystemValue = d_f / 2 - 0.001;

            myDimension = (IDimension)modDoc.Parameter(@"D2@草图9");
            myDimension.SystemValue = d_a / 2;

            myDimension = (IDimension)modDoc.Parameter(@"D3@草图9");
            myDimension.SystemValue = B;

            myDimension = (IDimension)modDoc.Parameter(@"D1@草图10");
            myDimension.SystemValue = d_f;

            myDimension = (IDimension)modDoc.Parameter(@"D3@阵列1");
            myDimension.SystemValue = 180 / N_FB;

            myDimension = (IDimension)modDoc.Parameter(@"D1@齿顶倒角1");
            myDimension.SystemValue = C_CD;

            modDoc.EditRebuild3();
            modDoc.ShowNamedView2("*Isometric", (int)swStandardViews_e.swTrimetricView);
        }
Ejemplo n.º 54
0
 internal SwDocument3D(IModelDoc2 model, ISldWorks app, ILogger logger) : base(model, app, logger)
 {
     m_MathUtils = app.IGetMathUtility();
 }
Ejemplo n.º 55
0
        private void button2_Click_1(object sender, EventArgs e)
        {
            string partTemplate = SwAddin.iSwApp.GetUserPreferenceStringValue((int)swUserPreferenceStringValue_e.swDefaultTemplatePart);
            if ((partTemplate != null) && (partTemplate != ""))
            {
                modDoc = (IModelDoc2)SwAddin.iSwApp.OpenDoc6(@"c:\mygearsharft.SLDPRT",
                    (int)swDocumentTypes_e.swDocPART, (int)swOpenDocOptions_e.swOpenDocOptions_Silent, "",
                    (int)swFileLoadError_e.swGenericError, (int)swFileLoadWarning_e.swFileLoadWarning_AlreadyOpen);
            }
            else
            {
                System.Windows.Forms.MessageBox.Show("There is no part template available. Please check your options and make sure there is a part template selected, or select a new part template.");
            }

            EquationMgr MyEqu = modDoc.GetEquationMgr();

            int revatal = MyEqu.GetCount();
            for (int k = 0; k < (revatal); k++)
            {
                MyEqu.ChangeSuppressionForAllConfigurations(k, false);
            }

            int revatal1 = MyEqu.GetCount();
            for (int k = 0; k < (revatal1); k++)
            {
                MyEqu.ChangeSuppressionForAllConfigurations(k, false);

            }
            MessageBox.Show("解压缩");

            //滚动角
            double u, d_a, d_b;
            d_a = double.Parse(txtPinionTipDiameter.Text);
            d_b = double.Parse(txtPinionBaseDiameter.Text);
            u = Math.Sqrt((d_a / d_b) * (d_a / d_b) - 1);

            // 螺距
            double luoju = Math.PI * double.Parse(text_dx.Text) / Math.Tan(double.Parse(text_lb12.Text) * Math.PI / 180);

            MyEqu.set_Equation(0, "\"" + "d_b" + "\"" + "=" + txtPinionBaseDiameter.Text);//基圆
            MyEqu.set_Equation(1, "\"" + "U" + "\"" + "=" + u);//滚动角
            MyEqu.set_Equation(2, "\"" + "d" + "\"" + "=" + text_dx.Text);//分度圆
            MyEqu.set_Equation(7, "\"" + "s" + "\"" + "=" + double.Parse(text_srnx.Text));//齿弦厚
            MyEqu.set_Equation(8, "\"" + "d_f" + "\"" + "=" + text_dfx.Text);//齿根圆
            MyEqu.set_Equation(10, "\"" + "B" + "\"" + "=" + text_bx.Text);//齿宽
            MyEqu.set_Equation(13, "\"" + "z" + "\"" + "=" + txtPinionZ.Text);//齿数
            MyEqu.set_Equation(15, "\"" + "d_a" + "\"" + "=" + txtPinionTipDiameter.Text);//齿顶圆
            MyEqu.set_Equation(18, "\"" + "luoju" + "\"" + "=" + luoju);//螺距
            MyEqu.set_Equation(21, "\"" + "C_CD" + "\"" + "=" + textCDDJ.Text);//齿顶倒角

            // 左轴段1
            MyEqu.set_Equation(36, "\"" + "zzzj1" + "\"" + "=" + textZZZJ1.Text);  //直径
            MyEqu.set_Equation(37, "\"" + "zzcd1" + "\"" + "=" + textZZCD1.Text);//长度
            MyEqu.set_Equation(38, "\"" + "zzyj1" + "\"" + "=" + textZZYJ1.Text);//圆角

            MyEqu.set_Equation(39, "\"" + "zzdj1" + "\"" + "=" + textZZDJ1.Text);//倒角

            // 左2
            MyEqu.set_Equation(40, "\"" + "zzzj2" + "\"" + "=" + textZZZJ2.Text);
            MyEqu.set_Equation(41, "\"" + "zzcd2" + "\"" + "=" + textZZCD2.Text);
            MyEqu.set_Equation(42, "\"" + "zzyj2" + "\"" + "=" + textZZYJ2.Text);
            MyEqu.set_Equation(43, "\"" + "zzdj2" + "\"" + "=" + textZZDJ2.Text);

            //左3
            MyEqu.set_Equation(44, "\"" + "zzzj3" + "\"" + "=" + textZZZJ3.Text);
            MyEqu.set_Equation(45, "\"" + "zzcd3" + "\"" + "=" + textZZCD3.Text);
            MyEqu.set_Equation(46, "\"" + "zzyj3" + "\"" + "=" + textZZYJ3.Text);
            MyEqu.set_Equation(47, "\"" + "zzdj3" + "\"" + "=" + textZZDJ3.Text);

            //左4
            MyEqu.set_Equation(48, "\"" + "zzzj4" + "\"" + "=" + textZZZJ4.Text);
            MyEqu.set_Equation(49, "\"" + "zzcd4" + "\"" + "=" + textZZCD4.Text);
            MyEqu.set_Equation(50, "\"" + "zzyj4" + "\"" + "=" + textZZYJ4.Text);
            MyEqu.set_Equation(51, "\"" + "zzdj4" + "\"" + "=" + textZZDJ4.Text);

            // 右1
            MyEqu.set_Equation(52, "\"" + "yzzj1" + "\"" + "=" + textYZZJ1.Text);
            MyEqu.set_Equation(53, "\"" + "yzcd1" + "\"" + "=" + textYZCD1.Text);
            MyEqu.set_Equation(54, "\"" + "yzyj1" + "\"" + "=" + textYZYJ1.Text);
            MyEqu.set_Equation(55, "\"" + "yzdj1" + "\"" + "=" + textYZDJ1.Text);

            //右2
            MyEqu.set_Equation(56, "\"" + "yzzj2" + "\"" + "=" + textYZZJ2.Text);
            MyEqu.set_Equation(57, "\"" + "yzcd2" + "\"" + "=" + textYZCD2.Text);
            MyEqu.set_Equation(58, "\"" + "yzyj2" + "\"" + "=" + textYZYJ2.Text);
            MyEqu.set_Equation(59, "\"" + "yzdj2" + "\"" + "=" + textYZDJ2.Text);

            //右3
            MyEqu.set_Equation(60, "\"" + "yzzj3" + "\"" + "=" + textYZZJ3.Text);

            MyEqu.set_Equation(61, "\"" + "yzcd3" + "\"" + "=" + textYZCD3.Text);
            MyEqu.set_Equation(62, "\"" + "yzyj3" + "\"" + "=" + textYZYJ3.Text);
            MyEqu.set_Equation(63, "\"" + "yzdj3" + "\"" + "=" + textYZDJ3.Text);

            //右4
            MyEqu.set_Equation(64, "\"" + "yzzj4" + "\"" + "=" + textYZZJ4.Text);
            MyEqu.set_Equation(65, "\"" + "yzcd4" + "\"" + "=" + textYZCD4.Text);
            MyEqu.set_Equation(66, "\"" + "yzyj4" + "\"" + "=" + textYZYJ4.Text);
            MyEqu.set_Equation(67, "\"" + "yzdj4" + "\"" + "=" + textYZDJ4.Text);

            //  左键槽
            double b = double.Parse(text_bx.Text);
            double zzj1 = double.Parse(textZZZJ1.Text);
            double zcd1 = double.Parse(textZZCD1.Text);
            double zzj2 = double.Parse(textZZZJ2.Text);
            double zcd2 = double.Parse(textZZCD2.Text);
            double zzj3 = double.Parse(textZZZJ3.Text);
            double zcd3 = double.Parse(textZZCD3.Text);
            double zzj4 = double.Parse(textZZZJ4.Text);
            double zjwz = double.Parse(textZJCWZ.Text);
            double zjs = double.Parse(textZJCS.Text);
            int i = int.Parse(textZJCZD.Text);

            switch (i)
            {
                case 1:
                    double ZJCWZ1 = b + zjwz;
                    double ZJCS1 = zzj1 / 2 - zjs;
                    MyEqu.set_Equation(100, "\"" + "zjck" + "\"" + "=" + textZJCK.Text);
                    MyEqu.set_Equation(101, "\"" + "zjcc" + "\"" + "=" + textZJCC.Text);
                    MyEqu.set_Equation(102, "\"" + "zjcs" + "\"" + "=" + ZJCS1);
                    MyEqu.set_Equation(103, "\"" + "zjcwz" + "\"" + "=" + ZJCWZ1);
                    break;

                case 2:
                    double ZJCWZ2 = b + zcd1 + zjwz;
                    double ZJCS2 = zzj2 / 2 - zjs;
                    MyEqu.set_Equation(100, "\"" + "zjck" + "\"" + "=" + textZJCK.Text);
                    MyEqu.set_Equation(101, "\"" + "zjcc" + "\"" + "=" + textZJCC.Text);
                    MyEqu.set_Equation(102, "\"" + "zjcs" + "\"" + "=" + ZJCS2);
                    MyEqu.set_Equation(103, "\"" + "zjcwz" + "\"" + "=" + ZJCWZ2);

                    break;

                case 3:
                    double ZJCWZ3 = b + zcd1 + zcd2 + zjwz;
                    double ZJCS3 = zzj3 / 2 - zjs;
                    MyEqu.set_Equation(100, "\"" + "zjck" + "\"" + "=" + textZJCK.Text);
                    MyEqu.set_Equation(101, "\"" + "zjcc" + "\"" + "=" + textZJCC.Text);
                    MyEqu.set_Equation(102, "\"" + "zjcs" + "\"" + "=" + ZJCS3);
                    MyEqu.set_Equation(103, "\"" + "zjcwz" + "\"" + "=" + ZJCWZ3);

                    break;

                case 4:
                    double ZJCWZ4 = b + zcd1 + zcd2 + zcd3 + zjwz;
                    double ZJCS4 = zzj4 / 2 - zjs;
                    MyEqu.set_Equation(100, "\"" + "zjck" + "\"" + "=" + textZJCK.Text);
                    MyEqu.set_Equation(101, "\"" + "zjcc" + "\"" + "=" + textZJCC.Text);
                    MyEqu.set_Equation(102, "\"" + "zjcs" + "\"" + "=" + ZJCS4);
                    MyEqu.set_Equation(103, "\"" + "zjcwz" + "\"" + "=" + ZJCWZ4);
                    break;

            }

            //  右键槽

            double yzj1 = double.Parse(textYZZJ1.Text);
            double ycd1 = double.Parse(textYZCD1.Text);
            double yzj2 = double.Parse(textYZZJ2.Text);
            double ycd2 = double.Parse(textYZCD2.Text);
            double yzj3 = double.Parse(textYZZJ3.Text);
            double ycd3 = double.Parse(textYZCD3.Text);
            double yzj4 = double.Parse(textYZZJ4.Text);
            double yjwz = double.Parse(textYJCWZ.Text);
            double yjs = double.Parse(textYJCS.Text);
            int j = int.Parse(textYJCZD.Text);

            switch (j)
            {
                case 1:
                    double YJCWZ1 = yjwz;
                    double YJCS1 = yzj1 / 2 - yjs;
                    MyEqu.set_Equation(104, "\"" + "yjcc" + "\"" + "=" + textYJCC.Text);
                    MyEqu.set_Equation(105, "\"" + "yjcwz" + "\"" + "=" + YJCWZ1);
                    MyEqu.set_Equation(106, "\"" + "yjck" + "\"" + "=" + textYJCK.Text);
                    MyEqu.set_Equation(107, "\"" + "yjcs" + "\"" + "=" + YJCS1);
                    break;

                case 2:
                    double YJCWZ2 = ycd1 + yjwz;
                    double YJCS2 = yzj2 / 2 - yjs;
                    MyEqu.set_Equation(104, "\"" + "yjcc" + "\"" + "=" + textYJCC.Text);
                    MyEqu.set_Equation(105, "\"" + "yjcwz" + "\"" + "=" + YJCWZ2);

                    MyEqu.set_Equation(106, "\"" + "yjck" + "\"" + "=" + textYJCK.Text);
                    MyEqu.set_Equation(107, "\"" + "yjcs" + "\"" + "=" + YJCS2);
                    break;

                case 3:
                    double YJCWZ3 = ycd1 + ycd2 + yjwz;
                    double YJCS3 = yzj3 / 2 - yjs;
                    MyEqu.set_Equation(104, "\"" + "yjcc" + "\"" + "=" + textYJCC.Text);
                    MyEqu.set_Equation(105, "\"" + "yjcwz" + "\"" + "=" + YJCWZ3);
                    MyEqu.set_Equation(106, "\"" + "yjck" + "\"" + "=" + textYJCK.Text);
                    MyEqu.set_Equation(107, "\"" + "yjcs" + "\"" + "=" + YJCS3);

                    break;

                case 4:
                    double YJCWZ4 = ycd1 + ycd2 + ycd3 + yjwz;
                    double YJCS4 = yzj4 / 2 - yjs;
                    MyEqu.set_Equation(104, "\"" + "yjcc" + "\"" + "=" + textYJCC.Text);
                    MyEqu.set_Equation(105, "\"" + "yjcwz" + "\"" + "=" + YJCWZ4);
                    MyEqu.set_Equation(106, "\"" + "yjck" + "\"" + "=" + textYJCK.Text);
                    MyEqu.set_Equation(107, "\"" + "yjcs" + "\"" + "=" + YJCS4);
                    break;

            }

            MyEqu.EvaluateAll();
            modDoc.EditRebuild3();
            modDoc.ShowNamedView2("*Isometric", (int)swStandardViews_e.swTrimetricView);

            int revatal2 = MyEqu.GetCount();
            for (int k = 0; k < (revatal2); k++)
            {
                MyEqu.ChangeSuppressionForAllConfigurations(k, true);

            }
            MessageBox.Show("压缩");
        }
Ejemplo n.º 56
0
 /// <inheritdoc cref="OnSetDimensions(ISldWorks, IModelDoc2, IFeature, MacroFeatureRebuildResult, DimensionDataCollection, TParams)"/>
 protected virtual void OnSetDimensions(ISldWorks app, IModelDoc2 model, IFeature feature,
                                        DimensionDataCollection dims, TParams parameters)
 {
 }
Ejemplo n.º 57
0
 internal static void DelEquations(int index, IModelDoc2 swModel)
 {
     try
     {
         Логгер.Информация($"Удаление уравнения #{index} в модели {swModel.GetPathName()}", null, "", "DelEquations");
         var myEqu = swModel.GetEquationMgr();
         myEqu.Delete(index);
         swModel.EditRebuild3();                
     }
     catch (Exception e)
     {
         Логгер.Ошибка($"Удаление уравнения #{index} в модели {swModel.GetPathName()}. {e.Message}", null, e.StackTrace, "DelEquations");
     }
 }
Ejemplo n.º 58
0
 /// <inheritdoc cref="SetParameters(IModelDoc2, IFeature, IMacroFeatureData, TParams)"/>
 /// <param name="state">Current state of the parameters</param>
 protected void SetParameters(IModelDoc2 model, IFeature feat, IMacroFeatureData featData, TParams parameters, out MacroFeatureOutdateState_e state)
 {
     m_ParamsParser.SetParameters(model, feat, featData, parameters, out state);
 }
Ejemplo n.º 59
0
        static string GetFromCutlist(IModelDoc2 swModel, string property)
        {
            var propertyValue = "";

            try
            {
                Feature swFeat2 = swModel.FirstFeature();
                while (swFeat2 != null)
                {
                    if (swFeat2.GetTypeName2() == "SolidBodyFolder")
                    {
                        BodyFolder swBodyFolder = swFeat2.GetSpecificFeature2();
                        swFeat2.Select2(false, -1);
                        swBodyFolder.SetAutomaticCutList(true);
                        swBodyFolder.UpdateCutList();

                        Feature swSubFeat = swFeat2.GetFirstSubFeature();
                        while (swSubFeat != null)
                        {
                            if (swSubFeat.GetTypeName2() == "CutListFolder")
                            {
                                BodyFolder bodyFolder = swSubFeat.GetSpecificFeature2();
                                swSubFeat.Select2(false, -1);
                                bodyFolder.SetAutomaticCutList(true);
                                bodyFolder.UpdateCutList();
                                var swCustPrpMgr = swSubFeat.CustomPropertyManager;
                                //swCustPrpMgr.Add("Площадь поверхности", "Текст", "\"SW-SurfaceArea@@@Элемент списка вырезов1@ВНС-901.81.002.SLDPRT\"");
                                string valOut;
                                swCustPrpMgr.Get4(property, true, out valOut, out propertyValue);
                            }
                            swSubFeat = swSubFeat.GetNextFeature();
                        }
                    }
                    swFeat2 = swFeat2.GetNextFeature();
                }
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.ToString());
            }
            return propertyValue;
        }
Ejemplo n.º 60
0
 /// <inheritdoc cref="MacroFeatureEx.OnRebuild(ISldWorks, IModelDoc2, IFeature)"/>
 /// <param name="parameters">Current instance of parameters of this macro feature</param>
 protected virtual MacroFeatureRebuildResult OnRebuild(ISldWorks app, IModelDoc2 model, IFeature feature, TParams parameters)
 {
     return(null);
 }