Esempio n. 1
0
        private static void drawRayForCamera(MathVector cameraDirection, IMathPoint centreOfVision, ModelDoc2 swDoc, SelectionMgr swSelectionMgr)
        {
            swDoc.ClearSelection2(true);
            Camera.removeRayIfPresent(swDoc);
            double[] cameraDirData    = (double[])cameraDirection.ArrayData;
            double[] cameraOriginData = (double[])centreOfVision.ArrayData;
            swDoc.Insert3DSketch2(true);
            swDoc.SketchManager.AddToDB = true;
            swDoc.CreateLine2(cameraOriginData[0], cameraOriginData[1], cameraOriginData[2],
                              cameraOriginData[0] + cameraDirData[0], cameraOriginData[1] + cameraDirData[1], cameraOriginData[2] + cameraDirData[2]);
            swDoc.Insert3DSketch2(true);
            swDoc.SketchManager.AddToDB = false;
            Feature sketch = swSelectionMgr.GetSelectedObject6(1, 0);

            sketch.Name = CAMERA_RAY_NAME;
            swDoc.ClearSelection2(true);
        }
Esempio n. 2
0
        /// <summary>
        /// Drawing segments.
        /// </summary>
        /// <param name="swModel">Solid's model.</param>
        /// <param name="segment">Segment to draw.</param>
        private void DrawSegment(ModelDoc2 swModel, Segment segment)
        {
            swModel.SetAddToDB(true);
            swModel.SetDisplayWhenAdded(false);
            swModel.Insert3DSketch2(false);

            swModel.CreateLine2
            (
                segment.GetStart().x, segment.GetStart().y, segment.GetStart().z,
                segment.GetEnd().x, segment.GetEnd().y, segment.GetEnd().z
            );

            swModel.Insert3DSketch2(true);
            swModel.ClearSelection2(true);

            swModel.SetAddToDB(false);
            swModel.SetDisplayWhenAdded(true);
        }
Esempio n. 3
0
        /// <summary>
        /// Drawing gradient curve.
        /// </summary>
        /// <param name="swModel">Solid's model.</param>
        public void Draw(ModelDoc2 swModel)
        {
            swModel.SetAddToDB(true);
            swModel.SetDisplayWhenAdded(false);
            swModel.Insert3DSketch2(false);

            for (int i = 0; i < curveSegments.Count - 1; i++)
            {
                Point start = curveSegments[i].GetStart();
                Point end   = curveSegments[i].GetEnd();

                swModel.CreateLine2(start.x, start.y, start.z, end.x, end.y, end.z);
            }

            swModel.Insert3DSketch2(true);
            swModel.ClearSelection2(true);

            swModel.SetAddToDB(false);
            swModel.SetDisplayWhenAdded(true);
        }
Esempio n. 4
0
        /// <summary>
        /// Drawing levels.
        /// </summary>
        /// <param name="swModel">Solid's model.</param>
        /// <param name="levels">Levels to draw.</param>
        public void DrawLevels(ModelDoc2 swModel, List <Level> levels)
        {
            swModel.SetAddToDB(true);
            swModel.SetDisplayWhenAdded(false);
            swModel.Insert3DSketch2(false);

            foreach (Level level in levels)
            {
                foreach (Segment segment in level.GetSegments())
                {
                    swModel.CreateLine2
                    (
                        segment.GetStart().x, segment.GetStart().y, segment.GetStart().z,
                        segment.GetEnd().x, segment.GetEnd().y, segment.GetEnd().z
                    );
                }
            }

            swModel.Insert3DSketch2(true);
            swModel.ClearSelection2(true);
            swModel.SetAddToDB(false);
            swModel.SetDisplayWhenAdded(true);
        }
Esempio n. 5
0
 public static void startSketch()
 {
     swDoc.Insert3DSketch2(true);
     swDoc.SketchManager.AddToDB = true;
     swDoc.SetDisplayWhenAdded(false);
 }
Esempio n. 6
0
        /// <summary>
        /// 这里提供获取当前装配体的 bounding box
        /// </summary>
        /// <returns>返回 LxWxH</returns>
        private string GetActionAssemlbyBOX()
        {
            BoxSize newboxSize = new BoxSize();

            ModelDoc2 swModel = default(ModelDoc2);

            double L = 0;
            double W = 0;
            double H = 0;

            double[] BoxFeatureDblArray = new double[7];

            double[] BoxFaceDblArray = new double[7];

            SketchPoint[]   swSketchPt  = new SketchPoint[9];
            SketchSegment[] swSketchSeg = new SketchSegment[13];

            swModel = (ModelDoc2)iswApp.IActiveDoc2;

            AssemblyDoc assemblyDoc = (AssemblyDoc)swModel;

            BoxFeatureDblArray = (double[])assemblyDoc.GetBox((int)swBoundingBoxOptions_e.swBoundingBoxIncludeRefPlanes);

            L = (BoxFeatureDblArray[3] - BoxFeatureDblArray[0]) * 1000;
            W = (BoxFeatureDblArray[4] - BoxFeatureDblArray[1]) * 1000;
            H = (BoxFeatureDblArray[5] - BoxFeatureDblArray[2]) * 1000;

            List <double> myList = new List <double> {
                L, W, H
            };

            myList.Sort();

            newboxSize.Length = myList[2];
            newboxSize.Weigth = myList[1];
            newboxSize.Height = myList[0];

            bool b = swModel.Extension.SelectByID2("Size", "SKETCH", 0, 0, 0, false, 0, null, 0);

            if (b == false)
            {
                swModel.Insert3DSketch2(true);
                swModel.SetAddToDB(true);
                swModel.SetDisplayWhenAdded(false);

                SketchManager swSketchMgr = default(SketchManager);

                swSketchMgr = (SketchManager)swModel.SketchManager;
                // Draw points at each corner of bounding box
                swSketchPt[0] = (SketchPoint)swSketchMgr.CreatePoint(BoxFeatureDblArray[3], BoxFeatureDblArray[1], BoxFeatureDblArray[5]);
                swSketchPt[1] = (SketchPoint)swSketchMgr.CreatePoint(BoxFeatureDblArray[0], BoxFeatureDblArray[1], BoxFeatureDblArray[5]);
                swSketchPt[2] = (SketchPoint)swSketchMgr.CreatePoint(BoxFeatureDblArray[0], BoxFeatureDblArray[1], BoxFeatureDblArray[2]);
                swSketchPt[3] = (SketchPoint)swSketchMgr.CreatePoint(BoxFeatureDblArray[3], BoxFeatureDblArray[1], BoxFeatureDblArray[2]);
                swSketchPt[4] = (SketchPoint)swSketchMgr.CreatePoint(BoxFeatureDblArray[3], BoxFeatureDblArray[4], BoxFeatureDblArray[5]);
                swSketchPt[5] = (SketchPoint)swSketchMgr.CreatePoint(BoxFeatureDblArray[0], BoxFeatureDblArray[4], BoxFeatureDblArray[5]);
                swSketchPt[6] = (SketchPoint)swSketchMgr.CreatePoint(BoxFeatureDblArray[0], BoxFeatureDblArray[4], BoxFeatureDblArray[2]);
                swSketchPt[7] = (SketchPoint)swSketchMgr.CreatePoint(BoxFeatureDblArray[3], BoxFeatureDblArray[4], BoxFeatureDblArray[2]);
                // Now draw bounding box
                swSketchSeg[0]  = (SketchSegment)swSketchMgr.CreateLine(swSketchPt[0].X, swSketchPt[0].Y, swSketchPt[0].Z, swSketchPt[1].X, swSketchPt[1].Y, swSketchPt[1].Z);
                swSketchSeg[1]  = (SketchSegment)swSketchMgr.CreateLine(swSketchPt[1].X, swSketchPt[1].Y, swSketchPt[1].Z, swSketchPt[2].X, swSketchPt[2].Y, swSketchPt[2].Z);
                swSketchSeg[2]  = (SketchSegment)swSketchMgr.CreateLine(swSketchPt[2].X, swSketchPt[2].Y, swSketchPt[2].Z, swSketchPt[3].X, swSketchPt[3].Y, swSketchPt[3].Z);
                swSketchSeg[3]  = (SketchSegment)swSketchMgr.CreateLine(swSketchPt[3].X, swSketchPt[3].Y, swSketchPt[3].Z, swSketchPt[0].X, swSketchPt[0].Y, swSketchPt[0].Z);
                swSketchSeg[4]  = (SketchSegment)swSketchMgr.CreateLine(swSketchPt[0].X, swSketchPt[0].Y, swSketchPt[0].Z, swSketchPt[4].X, swSketchPt[4].Y, swSketchPt[4].Z);
                swSketchSeg[5]  = (SketchSegment)swSketchMgr.CreateLine(swSketchPt[1].X, swSketchPt[1].Y, swSketchPt[1].Z, swSketchPt[5].X, swSketchPt[5].Y, swSketchPt[5].Z);
                swSketchSeg[6]  = (SketchSegment)swSketchMgr.CreateLine(swSketchPt[2].X, swSketchPt[2].Y, swSketchPt[2].Z, swSketchPt[6].X, swSketchPt[6].Y, swSketchPt[6].Z);
                swSketchSeg[7]  = (SketchSegment)swSketchMgr.CreateLine(swSketchPt[3].X, swSketchPt[3].Y, swSketchPt[3].Z, swSketchPt[7].X, swSketchPt[7].Y, swSketchPt[7].Z);
                swSketchSeg[8]  = (SketchSegment)swSketchMgr.CreateLine(swSketchPt[4].X, swSketchPt[4].Y, swSketchPt[4].Z, swSketchPt[5].X, swSketchPt[5].Y, swSketchPt[5].Z);
                swSketchSeg[9]  = (SketchSegment)swSketchMgr.CreateLine(swSketchPt[5].X, swSketchPt[5].Y, swSketchPt[5].Z, swSketchPt[6].X, swSketchPt[6].Y, swSketchPt[6].Z);
                swSketchSeg[10] = (SketchSegment)swSketchMgr.CreateLine(swSketchPt[6].X, swSketchPt[6].Y, swSketchPt[6].Z, swSketchPt[7].X, swSketchPt[7].Y, swSketchPt[7].Z);
                swSketchSeg[11] = (SketchSegment)swSketchMgr.CreateLine(swSketchPt[7].X, swSketchPt[7].Y, swSketchPt[7].Z, swSketchPt[4].X, swSketchPt[4].Y, swSketchPt[4].Z);

                swModel.SetDisplayWhenAdded(true);
                swModel.SetAddToDB(false);

                //string actionSketchname = swModel.SketchManager.ActiveSketch.Name;

                swModel.Insert3DSketch2(true);

                swModel.SelectedFeatureProperties(0, 0, 0, 0, 0, 0, 0, true, false, "Size");
                swModel.ClearSelection2(true);

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

                swModel.BlankSketch();

                swModel.ClearSelection2(true);
            }

            BoxSize boxSize = new BoxSize();

            boxSize.Length = Math.Round(newboxSize.Length, 0);
            boxSize.Weigth = Math.Round(newboxSize.Weigth, 0);
            boxSize.Height = Math.Round(newboxSize.Height, 0);

            string proText = string.Join("x", boxSize.Length, boxSize.Weigth, boxSize.Height);

            return(proText);
        }
Esempio n. 7
0
        public void GetBoundingBox(out BoxSize boxSize)
        {
            BoxSize newboxSize = new BoxSize();

            ModelDoc2 swModel = default(ModelDoc2);

            double L = 0;
            double W = 0;
            double H = 0;

            double[] BoxFeatureDblArray = new double[7];

            SketchManager swSketchMgr = default(SketchManager);

            SketchPoint[]   swSketchPt  = new SketchPoint[9];
            SketchSegment[] swSketchSeg = new SketchSegment[13];

            swModel = (ModelDoc2)iswApp.IActiveDoc2;

            PartDoc swPart = (PartDoc)swModel;

            double[] BoxFaceDblArray = new double[7];
            BoxFeatureDblArray = (double[])swPart.GetPartBox(true);

            Debug.Print("  Pt1 = " + "(" + BoxFeatureDblArray[0] * 1000.0 + ", " + BoxFeatureDblArray[1] * 1000.0 + ", " + BoxFeatureDblArray[2] * 1000.0 + ") mm");
            Debug.Print("  Pt2 = " + "(" + BoxFeatureDblArray[3] * 1000.0 + ", " + BoxFeatureDblArray[4] * 1000.0 + ", " + BoxFeatureDblArray[5] * 1000.0 + ") mm");
            L = (BoxFeatureDblArray[3] - BoxFeatureDblArray[0]) * 1000;
            W = (BoxFeatureDblArray[4] - BoxFeatureDblArray[1]) * 1000;
            H = (BoxFeatureDblArray[5] - BoxFeatureDblArray[2]) * 1000;

            List <double> myList = new List <double> {
                L, W, H
            };

            myList.Sort();

            newboxSize.Length = myList[2];
            newboxSize.Weigth = myList[1];
            newboxSize.Height = myList[0];

            swModel.Insert3DSketch2(true);
            swModel.SetAddToDB(true);
            swModel.SetDisplayWhenAdded(false);

            swSketchMgr = (SketchManager)swModel.SketchManager;
            // Draw points at each corner of bounding box
            swSketchPt[0] = (SketchPoint)swSketchMgr.CreatePoint(BoxFeatureDblArray[3], BoxFeatureDblArray[1], BoxFeatureDblArray[5]);
            swSketchPt[1] = (SketchPoint)swSketchMgr.CreatePoint(BoxFeatureDblArray[0], BoxFeatureDblArray[1], BoxFeatureDblArray[5]);
            swSketchPt[2] = (SketchPoint)swSketchMgr.CreatePoint(BoxFeatureDblArray[0], BoxFeatureDblArray[1], BoxFeatureDblArray[2]);
            swSketchPt[3] = (SketchPoint)swSketchMgr.CreatePoint(BoxFeatureDblArray[3], BoxFeatureDblArray[1], BoxFeatureDblArray[2]);
            swSketchPt[4] = (SketchPoint)swSketchMgr.CreatePoint(BoxFeatureDblArray[3], BoxFeatureDblArray[4], BoxFeatureDblArray[5]);
            swSketchPt[5] = (SketchPoint)swSketchMgr.CreatePoint(BoxFeatureDblArray[0], BoxFeatureDblArray[4], BoxFeatureDblArray[5]);
            swSketchPt[6] = (SketchPoint)swSketchMgr.CreatePoint(BoxFeatureDblArray[0], BoxFeatureDblArray[4], BoxFeatureDblArray[2]);
            swSketchPt[7] = (SketchPoint)swSketchMgr.CreatePoint(BoxFeatureDblArray[3], BoxFeatureDblArray[4], BoxFeatureDblArray[2]);
            // Now draw bounding box
            swSketchSeg[0]  = (SketchSegment)swSketchMgr.CreateLine(swSketchPt[0].X, swSketchPt[0].Y, swSketchPt[0].Z, swSketchPt[1].X, swSketchPt[1].Y, swSketchPt[1].Z);
            swSketchSeg[1]  = (SketchSegment)swSketchMgr.CreateLine(swSketchPt[1].X, swSketchPt[1].Y, swSketchPt[1].Z, swSketchPt[2].X, swSketchPt[2].Y, swSketchPt[2].Z);
            swSketchSeg[2]  = (SketchSegment)swSketchMgr.CreateLine(swSketchPt[2].X, swSketchPt[2].Y, swSketchPt[2].Z, swSketchPt[3].X, swSketchPt[3].Y, swSketchPt[3].Z);
            swSketchSeg[3]  = (SketchSegment)swSketchMgr.CreateLine(swSketchPt[3].X, swSketchPt[3].Y, swSketchPt[3].Z, swSketchPt[0].X, swSketchPt[0].Y, swSketchPt[0].Z);
            swSketchSeg[4]  = (SketchSegment)swSketchMgr.CreateLine(swSketchPt[0].X, swSketchPt[0].Y, swSketchPt[0].Z, swSketchPt[4].X, swSketchPt[4].Y, swSketchPt[4].Z);
            swSketchSeg[5]  = (SketchSegment)swSketchMgr.CreateLine(swSketchPt[1].X, swSketchPt[1].Y, swSketchPt[1].Z, swSketchPt[5].X, swSketchPt[5].Y, swSketchPt[5].Z);
            swSketchSeg[6]  = (SketchSegment)swSketchMgr.CreateLine(swSketchPt[2].X, swSketchPt[2].Y, swSketchPt[2].Z, swSketchPt[6].X, swSketchPt[6].Y, swSketchPt[6].Z);
            swSketchSeg[7]  = (SketchSegment)swSketchMgr.CreateLine(swSketchPt[3].X, swSketchPt[3].Y, swSketchPt[3].Z, swSketchPt[7].X, swSketchPt[7].Y, swSketchPt[7].Z);
            swSketchSeg[8]  = (SketchSegment)swSketchMgr.CreateLine(swSketchPt[4].X, swSketchPt[4].Y, swSketchPt[4].Z, swSketchPt[5].X, swSketchPt[5].Y, swSketchPt[5].Z);
            swSketchSeg[9]  = (SketchSegment)swSketchMgr.CreateLine(swSketchPt[5].X, swSketchPt[5].Y, swSketchPt[5].Z, swSketchPt[6].X, swSketchPt[6].Y, swSketchPt[6].Z);
            swSketchSeg[10] = (SketchSegment)swSketchMgr.CreateLine(swSketchPt[6].X, swSketchPt[6].Y, swSketchPt[6].Z, swSketchPt[7].X, swSketchPt[7].Y, swSketchPt[7].Z);
            swSketchSeg[11] = (SketchSegment)swSketchMgr.CreateLine(swSketchPt[7].X, swSketchPt[7].Y, swSketchPt[7].Z, swSketchPt[4].X, swSketchPt[4].Y, swSketchPt[4].Z);

            swModel.SetDisplayWhenAdded(true);
            swModel.SetAddToDB(false);

            //string actionSketchname = swModel.SketchManager.ActiveSketch.Name;

            swModel.Insert3DSketch2(true);

            swModel.SelectedFeatureProperties(0, 0, 0, 0, 0, 0, 0, true, false, "Size");

            swModel.ClearSelection2(true);

            boxSize.Length = newboxSize.Length;
            boxSize.Weigth = newboxSize.Weigth;
            boxSize.Height = newboxSize.Height;
            //  swModel.Extension.CustomPropertyManager[""].Delete("尺寸");

            swModel.Extension.CustomPropertyManager[""].Add3("尺寸", 30, "aaaa", 1);

            // swModel.AddCustomInfo("尺寸","Text", boxSize.Length.ToString());

            swModel.Save();
        }