コード例 #1
0
        public static void Save(string targetFolder, string fileName, sw_DocType docType)
        {
            SldWorks  swApp;
            ModelDoc2 swModel;
            string    doc;

            swApp = SolidWorksSingleton.GetApplication();

            swModel = (ModelDoc2)swApp.ActiveDoc;

            if (docType == sw_DocType.assembly)
            {
                doc = ".sldasm";
            }
            else if (docType == sw_DocType.part)
            {
                doc = ".sldprt";
            }
            else if (docType == sw_DocType.drawing)
            {
                doc = ".slddrw";
            }
            else
            {
                throw new Exception("Kayıt yapılamadı");
            }



            swModel.SaveAs3(targetFolder + "\\" + fileName + doc, (int)swSaveAsVersion_e.swSaveAsCurrentVersion, (int)swSaveAsOptions_e.swSaveAsOptions_CopyAndOpen);

            swApp.CloseDoc(fileName + doc);
        }
コード例 #2
0
        public override void CreatePart()
        {
            swApp = SolidWorksSingleton.GetApplication();
            DocumentManager.CreateNewPartDoc();
            swModel = (ModelDoc2)swApp.ActiveDoc;

            swFeature      = swModel.FeatureByPositionReverse(3);
            swFeature.Name = "Front";

            swModel.Extension.SelectByID2("Front", "PLANE", 0, 0, 0, false, 0, null, 0);

            swModel.InsertSketch2(true);

            swModel.CreateCircleByRadius2(0, 0, 0, InsideDiameter / 2);
            swModel.CreateCircleByRadius2(0, 0, 0, OutsideDiameter / 2);

            swModel.InsertSketch2(true);

            swFeature = swModel.FeatureManager.FeatureExtrusion3(true, false, false, 0, 0, Lenght, 0, false, false, false, false, 0, 0, false, false, false, false, false, false, false, 0, 0, false);

            BasicOpertations.ChangeEntityName("FACE", MateOutsideFace, OutsideDiameter / 2, 0, Lenght / 2);

            double dim = (OutsideDiameter - InsideDiameter) / 4;

            BasicOpertations.ChangeEntityName("FACE", MateBase, (InsideDiameter / 2) + dim, 0, 0);

            DocumentManager.Save(TargetFolder, FileName, DocumentManager.sw_DocType.part);
        }
コード例 #3
0
        public static void AddComponent(Pipe pipe, AnglePart anglePart)
        {
            SldWorks    swApp;
            ModelDoc2   swModel;
            AssemblyDoc swAssy;
            object      components;

            object compNames;
            object transformationMatrix;
            object coorSysNames;

            swApp = SolidWorksSingleton.GetApplication();

            swModel = (ModelDoc2)swApp.ActiveDoc;
            swAssy  = (AssemblyDoc)swApp.ActiveDoc;

            string[] xcompnames = new string[2];

            xcompnames[0] = pipe.TargetFolder + "\\" + pipe.FileName + ".sldprt";
            xcompnames[1] = anglePart.TargetFolder + "\\" + anglePart.FileName + ".sldprt";

            string[] xcoorsysnames = new string[2];

            xcoorsysnames[0] = "Coordinate System1";
            xcoorsysnames[1] = "Coordinate System1";

            var tMatrix = new double[]
            {
                0, 0, 1,
                0, 1, 0,
                -1, 0, 0,

                pipe.Lenght, anglePart.YLenght, 0,
                0, 0, 0, 0,

                1, 0, 0,
                0, 1, 0,
                0, 0, 1,
                0, 0, 0,
                0, 0, 0, 0,
            };



            compNames            = xcompnames;
            coorSysNames         = xcoorsysnames;
            transformationMatrix = tMatrix;

            components = swAssy.AddComponents3(compNames, transformationMatrix, coorSysNames);


            swAssy = (AssemblyDoc)swApp.ActiveDoc;
            string comp = anglePart.FileName + "-1@" + anglePart.AssemblyName;

            swModel.Extension.SelectByID2(comp, "COMPONENT", 0, 0, 0, false, 0, null, 0);
            swAssy.FixComponent();
        }
コード例 #4
0
        public static void SimpleFillet(double radius)
        {
            SldWorks  swApp;
            ModelDoc2 swModel;

            swApp   = SolidWorksSingleton.GetApplication();
            swModel = swApp.ActiveDoc;

            swModel.FeatureManager.FeatureFillet3((int)swFeatureFilletOptions_e.swFeatureFilletUniformRadius, radius, 0, 0, 0, 0, 0, null, null, null, null, null, null, null);
        }
コード例 #5
0
        public static void SimpleCut()
        {
            SldWorks  swApp;
            ModelDoc2 swModel;
            Feature   swFeature;

            swApp   = SolidWorksSingleton.GetApplication();
            swModel = swApp.ActiveDoc;

            swFeature = swModel.FeatureManager.FeatureCut3(true, false, false, (int)swEndConditions_e.swEndCondThroughAll, (int)swEndConditions_e.swEndCondBlind, 0, 0, false, false, false, false, 0, 0, false, false, false, false, false, true, true, false, false, false, (int)swEndConditions_e.swEndCondMidPlane, 0, true);
        }
コード例 #6
0
        public static void CreateNewPartDoc()
        {
            SldWorks  swApp;
            ModelDoc2 swModel;

            string defaultPartTemplate;

            swApp = SolidWorksSingleton.GetApplication();

            defaultPartTemplate = swApp.GetUserPreferenceStringValue((int)swUserPreferenceStringValue_e.swDefaultTemplatePart);
            swApp.NewDocument(defaultPartTemplate, 0, 0, 0);
        }
コード例 #7
0
        public static void CreateAssemblyDoc(string filePath, string FileName)
        {
            SldWorks  swApp;
            ModelDoc2 swModel;

            string defaultAssemblyTemplate;

            swApp = SolidWorksSingleton.GetApplication();

            defaultAssemblyTemplate = swApp.GetUserPreferenceStringValue((int)swUserPreferenceStringValue_e.swDefaultTemplateAssembly);
            swApp.NewDocument(defaultAssemblyTemplate, 0, 0, 0);

            swModel = (ModelDoc2)swApp.ActiveDoc;

            swModel.SaveAs3(filePath + "\\" + FileName + ".sldasm", (int)swSaveAsVersion_e.swSaveAsCurrentVersion, (int)swSaveAsOptions_e.swSaveAsOptions_CopyAndOpen);
        }
コード例 #8
0
        public static void ChangeEntityName(string Etype, string Ename, double CoorX, double CoorY, double CoorZ)
        {
            SldWorks     swApp;
            ModelDoc2    swModel;
            SelectionMgr swSelMgr;
            Face2        swFace;
            PartDoc      swPart;

            swApp = SolidWorksSingleton.GetApplication();

            swModel = swApp.ActiveDoc;

            swModel.Extension.SelectByID2("", Etype, CoorX, CoorY, CoorZ, false, 0, null, 0);

            swSelMgr = swModel.SelectionManager;
            swFace   = swSelMgr.GetSelectedObject6(1, -1);
            swPart   = swApp.ActiveDoc;

            swPart.SetEntityName(swFace, Ename);
        }
コード例 #9
0
        public static void AddDistanceMate(string Comp1, string MateFace1, string Comp2, string MateFace2, double dimension)
        {
            SldWorks    swApp;
            ModelDoc2   swModel;
            PartDoc     swPart;
            AssemblyDoc swAssy;
            Mate2       mate;
            Component2  swComponent;
            Entity      swEntity;
            Entity      swFace1;
            Entity      swFace2;
            bool        bRet;
            int         errorCode1;


            swApp = SolidWorksSingleton.GetApplication();

            swAssy = (AssemblyDoc)swApp.ActiveDoc;

            swComponent = swAssy.GetComponentByName(Comp1 + "-1");
            swModel     = swComponent.GetModelDoc2();
            swPart      = (PartDoc)swModel;
            swEntity    = swPart.GetEntityByName(MateFace1, (int)swSelectType_e.swSelFACES);
            swFace1     = swComponent.GetCorrespondingEntity(swEntity);


            swComponent = swAssy.GetComponentByName(Comp2 + "-1");
            swModel     = swComponent.GetModelDoc2();
            swPart      = (PartDoc)swModel;
            swEntity    = swPart.GetEntityByName(MateFace2, (int)swSelectType_e.swSelFACES);
            swFace2     = swComponent.GetCorrespondingEntity(swEntity);

            bRet = swFace1.Select4(false, null);
            bRet = swFace2.Select4(true, null);

            mate = swAssy.AddMate3((int)swMateType_e.swMateDISTANCE, (int)swMateAlign_e.swMateAlignALIGNED, false, dimension, dimension, dimension, 0, 0, 0, 0, 0, false, out errorCode1);

            swModel.ForceRebuild3(false);
        }
コード例 #10
0
        public override void CreatePart()
        {
            swApp = SolidWorksSingleton.GetApplication();
            DocumentManager.CreateNewPartDoc();

            swModel = (ModelDoc2)swApp.ActiveDoc;

            swFeature      = swModel.FeatureByPositionReverse(3);
            swFeature.Name = "Front";

            swModel.Extension.SelectByID2("Front", "PLANE", 0, 0, 0, false, 0, null, 0);

            swModel.InsertSketch2(true);

            swModel.CreateLine2(0, 0, 0, XLenght, 0, 0);
            //swModel.AddDimension2(0,0,0);

            swModel.CreateLine2(0, 0, 0, 0, YLenght, 0);
            //swModel.AddDimension2(0, 0, 0);

            //int markHorizontal = 2;
            //int markVertical = 4;

            //swModel.Extension.SelectByID2("Point1@Origin", "EXTSKETCHSEGMENT",0,0,0,false, markHorizontal|markVertical,null,0);

            object datumDisp = "Point1@Origin";

            swModel.SketchManager.FullyDefineSketch(true, true, (int)swSketchFullyDefineRelationType_e.swSketchFullyDefineRelationType_Vertical | (int)swSketchFullyDefineRelationType_e.swSketchFullyDefineRelationType_Horizontal, true, (int)swAutodimScheme_e.swAutodimSchemeBaseline, datumDisp, (int)swAutodimScheme_e.swAutodimSchemeBaseline, datumDisp, (int)swAutodimHorizontalPlacement_e.swAutodimHorizontalPlacementBelow, (int)swAutodimVerticalPlacement_e.swAutodimVerticalPlacementLeft);

            swModel.InsertSketch2(true);

            swFeature      = swModel.FeatureByPositionReverse(0);
            swFeature.Name = "Sketch1";

            swModel.Extension.SelectByID2("Sketch1", "SKETCH", 0, 0, 0, false, 0, null, 0);

            swModel.FeatureManager.InsertSheetMetalBaseFlange2(Thickness, false, Thickness, Width, 0, true, 0, 0, 0, null, false, 0, 0, 0, 0, false, false, false, false);

            BasicOpertations.ChangeEntityName("FACE", MateRef1, Thickness, YLenght / 2, -Width / 2);

            swModel.Extension.SelectByID2("", "FACE", XLenght / 2, Thickness, -Width / 2, false, 0, null, 0);

            swModel.InsertSketch2(true);

            swModel.CreateCircleByRadius2(XLenght - X1, X2, 0, BoltHoles);
            swModel.CreateCircleByRadius2(XLenght - X1, Width - X2, 0, BoltHoles);

            swModel.InsertSketch2(true);

            swFeature      = swModel.FeatureByPositionReverse(0);
            swFeature.Name = "BoltHoles";

            swModel.Extension.SelectByID2("BoltHoles", "SKETCH", 0, 0, 0, false, 0, null, 0);

            BasicOpertations.SimpleCut();


            swPart = (PartDoc)swApp.ActiveDoc;

            swEntity = swPart.GetEntityByName(MateRef1, (int)swSelectType_e.swSelFACES);
            swEntity.Select4(false, null);

            swModel.InsertSketch2(true);

            swModel.CreateCircleByRadius2(Width / 2, YLenght - (PipeHole * 2), 0, PipeHole);
            swModel.AddDiameterDimension(0, 0, 0);

            swModel.InsertSketch2(true);

            BasicOpertations.SimpleCut();

            BasicOpertations.ChangeEntityName("FACE", MateRefHole, Thickness / 2, YLenght - PipeHole, -Width / 2);

            swModel = (ModelDoc2)swApp.ActiveDoc;

            swModel.Extension.SelectByID2("", "EDGE", XLenght, Thickness / 2, 0, false, 0, null, 0);
            swModel.Extension.SelectByID2("", "EDGE", XLenght, Thickness / 2, -Width, true, 0, null, 0);

            BasicOpertations.SimpleFillet(Rad2);

            swModel.Extension.SelectByID2("", "EDGE", Thickness / 2, YLenght, 0, false, 0, null, 0);
            swModel.Extension.SelectByID2("", "EDGE", Thickness / 2, YLenght, -Width, true, 0, null, 0);

            BasicOpertations.SimpleFillet(Rad1);

            swModel.ClearSelection2(true);
            swModel.ViewZoomtofit2();

            DocumentManager.Save(TargetFolder, FileName, DocumentManager.sw_DocType.part);
        }