示例#1
0
        public void Execute(UIApplication app)
        {
            Document   doc        = app.ActiveUIDocument.Document;
            ModelCurve modelCurve = doc.GetElement(pForm.Controllor.pModel.curve_id) as ModelCurve;

            //拿到用户画的线段
            Curve thecurve = modelCurve.GeometryCurve;


            //拿到用户选中的梁类型

            FamilySymbol familySymbol = null;

            familySymbol = pForm.Controllor.pModel.BeamSymbols[pForm.cbox_Beamsymbols.SelectedIndex];


            //拿到用户选择的标高
            Level thepickedlevel = null;

            thepickedlevel = pForm.Controllor.pModel.levels[pForm.cbox_levels.SelectedIndex];

            ElementId eleid = pForm.Controllor.pModel.curve_id;

            TaskDialog.Show("ss", "成功点击了提交按钮" + eleid.ToString());
            Element    ele           = doc.GetElement(pForm.Controllor.pModel.face_reference.ElementId);
            PlanarFace thepickedface = ele.GetGeometryObjectFromReference(pForm.Controllor.pModel.face_reference) as PlanarFace;

            TaskDialog.Show("ss", thepickedface.ToString());
            //拿到模型线到楼板的投影线
            Curve curve_projection = FindFacecurve(thecurve, thepickedface);



            //创建梁
            using (Transaction tr = new Transaction(doc))
            {
                TaskDialog.Show("ss", "正在尝试进行事务处理");
                tr.Start("Create beam");
                if (familySymbol == null)
                {
                    tr.Commit();
                }
                if (!familySymbol.IsActive)
                {
                    familySymbol.Activate();
                }
                doc.Create.NewFamilyInstance(curve_projection, familySymbol, thepickedlevel, Autodesk.Revit.DB.Structure.StructuralType.Beam);

                tr.Commit();
            }
        }