示例#1
0
        //子线程中
        private void Creat3dBall_Click(object sender, EventArgs e)//Creat3dPoint_Click
        {
            progressBar.Value           = 0;
            DataGrid.AllowUserToAddRows = false;
            if (PartID == null)
            {
                MessageBox.Show("仿真环境未初始化!请先用工具栏初始化命令初始化运行环境!");
                return;
            }
            Creat3dBall.BackColor = SystemColors.ActiveCaption;
            ReadType = 2;
            int ERR = 0;

            if (DataGrid.RowCount < 1)
            {
                MessageBox.Show("数据为空,无法建立3D模型!");
                return;
            }
            HybridBodies Hybs = PartID.HybridBodies;
            HybridBody   Hyb  = null;

            //try
            //{
            //    Hyb = Hybs.Item("几何图形集.1");
            //}
            //catch (Exception)
            //{
            //    Hyb = Hybs.Item("Geometrical Set.1");
            //}
            progressBar.Maximum = DataGrid.RowCount;
            progressBar.Step    = 1;
            Hyb = Hybs.Add();
            for (int i = 0; i < DataGrid.RowCount; i++)
            {
                progressBar.PerformStep();
                HybridShapeFactory PartHyb = (HybridShapeFactory)PartID.HybridShapeFactory;
                //SPAWorkbench TheSPAWorkbench = (SPAWorkbench)CatDocument.GetWorkbench("SPAWorkbench");
                //Reference referenceObject = SelectArc.Item(i).Reference;
                //Measurable TheMeasurable = TheSPAWorkbench.GetMeasurable(referenceObject);
                //TheMeasurable.GetPoint(PointCoord); //读取选择的曲面坐标
                string TName;
                try
                {
                    TName = DataGrid.Rows[i].Cells[1].Value.ToString(); //读取选择的曲面名称
                }
                catch (Exception)
                {
                    continue;
                }
                HybridShapePointCoord NewPoint = PartHyb.AddNewPointCoord(Convert.ToDouble(DataGrid.Rows[i].Cells[2].Value.ToString()), Convert.ToDouble(DataGrid.Rows[i].Cells[3].Value.ToString()), Convert.ToDouble(DataGrid.Rows[i].Cells[4].Value.ToString()));
                Reference             ShapeRef = PartID.CreateReferenceFromObject(NewPoint);
                HybridShapeSphere     NewShape = PartHyb.AddNewSphere(ShapeRef, null, Convert.ToDouble(BallRadio.Text), -45.000000, 45.000000, 0.000000, 180.000000);
                NewShape.Limitation = 1;
                if (KeepName.Checked)
                {
                    NewPoint.set_Name(TName);
                    NewShape.set_Name(TName);
                }
                else
                {
                    NewPoint.set_Name("Rx_" + (i + 1));
                    NewShape.set_Name("Rx_" + (i + 1));
                }
                // Hyb.AppendHybridShape(NewPoint);
                Hyb.AppendHybridShape(NewShape);
                //  PartID.InWorkObject = NewPoint;
                PartID.InWorkObject = NewShape;
                try
                {
                    PartID.Update();
                }
                catch (Exception)
                {
                    ERR += 1;
                }
                Selection      SetColor = CatDocument.Selection;
                VisPropertySet VSet     = SetColor.VisProperties;
                SetColor.Add(NewShape);
                VSet.SetRealColor(128, 255, 0, 0);
                SetColor.Clear();
            }
            if (ERR > 0)
            {
                MessageBox.Show("共计:" + ERR + "个点创建新参考点失败!");
            }
            Creat3dBall.BackColor = Color.Green;
            ShowCenter();
            progressBar.Value = DataGrid.RowCount;
        }