Exemple #1
0
        //*****************************CreateSectionPerpendicular()*****************************
        public void CreateSectionPerpendicular(Document doc, UIDocument uidoc)
        {
            // My library
            LibraryGetItems libGet = new LibraryGetItems();

            Element e = libGet.SelectElement(uidoc, doc);

            Wall wall = null;

            if (e != null)
            {
                wall = e as Wall;
            }
            LocationCurve lc             = wall.Location as LocationCurve;
            Transform     curveTransform = lc.Curve.ComputeDerivatives(0.5, true);

            // The transform contains the location curve
            // mid-point and tangent, and we can obtain
            // its normal in the XY plane:

            XYZ origin  = curveTransform.Origin;
            XYZ viewdir = curveTransform.BasisX.Normalize();
            XYZ up      = XYZ.BasisZ;
            XYZ right   = up.CrossProduct(viewdir);

            // Set up view transform, assuming wall's "up"
            // is vertical. For a non-vertical situation
            // such as section through a sloped floor, the
            // surface normal would be needed

            Transform transform = Transform.Identity;

            transform.Origin = origin;
            transform.BasisX = right;
            transform.BasisY = up;
            transform.BasisZ = viewdir;

            BoundingBoxXYZ sectionBox = new BoundingBoxXYZ();

            sectionBox.Transform = transform;

            // Min & Max X values define the section
            // line length on each side of the wall.
            // Max Y is the height of the section box.
            // Max Z (5) is the far clip offset.

            double         d    = wall.WallType.Width;
            BoundingBoxXYZ bb   = wall.get_BoundingBox(null);
            double         minZ = bb.Min.Z;
            double         maxZ = bb.Max.Z;
            double         h    = maxZ - minZ;
            // Z value offset from the current level in view.
            Level  level  = doc.ActiveView.GenLevel;
            double top    = 90 - level.Elevation;
            double bottom = -(level.Elevation + 25);

            sectionBox.Min = new XYZ(-2 * d, bottom, 0);
            sectionBox.Max = new XYZ(2 * d, top, 5);

            ViewFamilyType vft          = viewFamilyType(doc);
            View           viewTemplate = libGet.GetViewTemplate(doc, "Z-ELEV ARCH OFF");
            ViewSection    vs           = null;

            //Create wall section view
            using (Transaction tx = new Transaction(doc))
            {
                try
                {
                    tx.Start("Create Section");
                    vs = ViewSection.CreateSection(doc, vft.Id, sectionBox);
                    doc.Regenerate();
                    tx.Commit();
                }
                catch { }
            }
            using (Transaction t = new Transaction(doc))
            {
                try
                {
                    t.Start("Apply Structural View Template");
                    vs.ViewTemplateId = viewTemplate.Id;
                    vs.Scale          = 24;
                    t.Commit();
                }
                catch { }
            }
        }
Exemple #2
0
        //*****************************CreateSectionStart()*****************************
        public void CreateSectionStart(Document doc, UIDocument uidoc)
        {
            // My library
            LibraryGetItems libGet = new LibraryGetItems();

            Element e = libGet.SelectElement(uidoc, doc);

            Wall wall = null;

            if (e != null)
            {
                wall = e as Wall;
            }

            // Create a BoundingBoxXYZ instance centered on wall
            BoundingBoxXYZ bb     = wall.get_BoundingBox(null);
            double         minZ   = bb.Min.Z;
            double         maxZ   = bb.Max.Z;
            double         h      = maxZ - minZ;
            Level          level  = doc.ActiveView.GenLevel;
            double         top    = 90 - level.Elevation;
            double         bottom = -(level.Elevation + 25);

            LocationCurve lc   = wall.Location as LocationCurve;
            Line          line = lc.Curve as Line;

            XYZ p = line.GetEndPoint(0);
            XYZ q = line.GetEndPoint(1);
            XYZ v = p - q; // p point 0 - q point 1 - view direction up.

            double halfLength = v.GetLength() / 2;
            double offset     = 3; // offset by 3 feet.

            //Max/Min X = Section line Length, Max/Min Y is the height of the section box, Max/Min Z far clip
            XYZ min = new XYZ(-halfLength, bottom, -offset);
            XYZ max = new XYZ(halfLength, top, offset);

            XYZ midpoint = q + 0.5 * v; // q get lower midpoint.
            XYZ walldir  = v.Normalize();
            XYZ up       = XYZ.BasisZ;
            XYZ viewdir  = walldir.CrossProduct(up);

            Transform t = Transform.Identity;

            t.Origin = midpoint;
            t.BasisX = walldir;
            t.BasisY = up;
            t.BasisZ = viewdir;

            BoundingBoxXYZ sectionBox = new BoundingBoxXYZ();

            sectionBox.Transform = t;
            sectionBox.Min       = min; // scope box start
            sectionBox.Max       = max; // scope box end

            ViewFamilyType vft          = viewFamilyType(doc);
            View           viewTemplate = libGet.GetViewTemplate(doc, "Z-ELEV ARCH OFF");
            ViewSection    vs           = null;

            //Create wall section view
            using (Transaction tx = new Transaction(doc))
            {
                try
                {
                    tx.Start("Create Section");
                    vs = ViewSection.CreateSection(doc, vft.Id, sectionBox);
                    tx.Commit();
                }
                catch { }
            }

            using (Transaction tr = new Transaction(doc))
            {
                try
                {
                    tr.Start("Apply Structural View Template");
                    vs.ViewTemplateId = viewTemplate.Id;
                    vs.Scale          = 24;
                    tr.Commit();
                }
                catch { }
            }
        }