Beispiel #1
0
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            UIApplication uiapp = commandData.Application;
            UIDocument    uidoc = uiapp.ActiveUIDocument;
            Document      doc   = uidoc.Document;

            if (doc.IsFamilyDocument)
            {
                TaskDialog.Show("Error", "This tool only works in Project environment.");

                return(Result.Cancelled);
            }

            Transaction t1 = new Transaction(doc, "Draw Insulation");

            try
            {
                Reference refinsulation = uidoc.Selection.PickObject(ObjectType.Element, new SelectionFilterAnnotation(), "Select Insulation Batting");

                Reference refcurve = uidoc.Selection.PickObject(ObjectType.Element, new SelectionFilterCurve(), "Select Curve");

                DetailCurve insulationdetailcurve = doc.GetElement(refinsulation) as DetailCurve;

                DetailCurve detailcurve = doc.GetElement(refcurve) as DetailCurve;

                double width = insulationdetailcurve.LookupParameter("Insulation Width").AsDouble();

                double ratio = insulationdetailcurve.LookupParameter("Insulation Bulge to Width Ratio (1/x)").AsDouble();

                Curve curve = detailcurve.GeometryCurve;

                t1.Start();

                if (curve is Arc && curve.IsBound)
                {
                    List <Line> lines = SplitArc(curve, width, ratio);

                    foreach (Line l in lines)
                    {
                        DetailCurve newcurve = doc.GetElement(ElementTransformUtils.CopyElement(doc, insulationdetailcurve.Id, new XYZ()).First()) as DetailCurve;
                        newcurve.GeometryCurve = l;
                    }
                }
                if (curve is Line && curve.IsBound)
                {
                    Line        l        = curve as Line;
                    DetailCurve newcurve = doc.GetElement(ElementTransformUtils.CopyElement(doc, insulationdetailcurve.Id, new XYZ()).First()) as DetailCurve;
                    newcurve.GeometryCurve = l;
                }

                t1.Commit();

                return(Result.Succeeded);
            }
            catch (Exception e)
            {
                t1.RollBack();
                return(Result.Cancelled);
            }
        }
Beispiel #2
0
        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            UIApplication uiapp = commandData.Application;
            UIDocument    uidoc = uiapp.ActiveUIDocument;
            Document      doc   = uidoc.Document;

            try
            {
                XYZ origin = uidoc.Selection.PickPoint("Select insertion point");

                double width = 0.2; //feet

                Category c = doc.Settings.Categories.get_Item(BuiltInCategory.OST_Lines);

                CategoryNameMap subcats = c.SubCategories;

                double offset = 0;

                TextNoteOptions options = new TextNoteOptions();
                options.HorizontalAlignment = HorizontalTextAlignment.Left;
                options.TypeId = doc.GetDefaultElementTypeId(ElementTypeGroup.TextNoteType);

                var dict = new SortedDictionary <string, GraphicsStyle>();

                foreach (Category lineStyle in subcats)
                {
                    GraphicsStyle gs = lineStyle.GetGraphicsStyle(GraphicsStyleType.Projection);

                    dict.Add(gs.Name, gs);
                }


                var output = dict.OrderBy(e => e.Key).Select(e => new { graphicStyle = e.Value, linestyleName = e.Key }).ToList();


                using (Transaction t = new Transaction(doc, "Place Lines"))
                {
                    t.Start();

                    //foreach( Line item in ordered) {
                    foreach (var item in output)
                    {
                        //					GraphicsStyle gs = lineStyle.GetGraphicsStyle(GraphicsStyleType.Projection);

                        XYZ newOrigin   = new XYZ(origin.X, origin.Y + offset, 0);
                        XYZ offsetPoint = new XYZ(origin.X + width, origin.Y + offset, 0);

                        Line L1 = Line.CreateBound(newOrigin, offsetPoint);

                        try
                        {
                            TextNote note = TextNote.Create(doc, doc.ActiveView.Id, new XYZ(origin.X - 0.2, origin.Y + offset + 0.01, 0), 0.2, item.linestyleName, options);

                            DetailCurve e = doc.Create.NewDetailCurve(doc.ActiveView, L1);

                            Parameter p = e.LookupParameter("Line Style");

                            p.Set(item.graphicStyle.Id);
                        }
                        catch
                        {
                        }
                        offset -= 0.03;
                    }

                    t.Commit();
                }


                return(Result.Succeeded);
            }
            catch (Exception ex)
            {
                TaskDialog.Show("Error", ex.Message);
                return(Result.Failed);
            }
        }