当前位置: 首页>>代码示例>>C#>>正文


C# Document.Regenerate方法代码示例

本文整理汇总了C#中Document.Regenerate方法的典型用法代码示例。如果您正苦于以下问题:C# Document.Regenerate方法的具体用法?C# Document.Regenerate怎么用?C# Document.Regenerate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Document的用法示例。


在下文中一共展示了Document.Regenerate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Execute

    public Result Execute(
      ExternalCommandData commandData,
      ref string message,
      ElementSet elements)
    {
      // Get the access to the top most objects. 
      UIApplication rvtUIApp = commandData.Application;
      UIDocument uiDoc = rvtUIApp.ActiveUIDocument;
      _app = rvtUIApp.Application;
      _doc = uiDoc.Document;

      // Select a door on screen. (We'll come back to the selection in the UI Lab later.) 
      Reference r = uiDoc.Selection.PickObject(ObjectType.Element, "Pick a wall, please");
      // We have picked something. 
      Element e = _doc.GetElement(r);

      // (1) element level modification 
      // Modify element's properties, parameters, location. 

      ModifyElementPropertiesWall(e); 
      //ModifyElementPropertiesDoor(e);
      _doc.Regenerate();

      // Select an object on a screen. (We'll come back to the selection in the UI Lab later.) 
      Reference r2 = uiDoc.Selection.PickObject(ObjectType.Element, "Pick another element");
      // We have picked something. 
      Element e2 = _doc.GetElement(r2);

      // (2) you can also use transformation utility to move and rotate. 
      ModifyElementByTransformUtilsMethods(e2);

      return Result.Succeeded;
    }
开发者ID:FlintSable,项目名称:RevitTrainingMaterial,代码行数:33,代码来源:4_ElementModification.cs

示例2: CreateLineStyle

        /// <summary>
        /// Create a new line style using NewSubcategory
        /// </summary>
        void CreateLineStyle(Document doc)
        {
            // Use this to access the current document in a macro.
              //
              //Document doc = this.ActiveUIDocument.Document;

              // Find existing linestyle.  Can also opt to
              // create one with LinePatternElement.Create()

              FilteredElementCollector fec
            = new FilteredElementCollector( doc )
              .OfClass( typeof( LinePatternElement ) );

              LinePatternElement linePatternElem = fec
            .Cast<LinePatternElement>()
            .First<LinePatternElement>( linePattern
              => linePattern.Name == "Long dash" );

              // The new linestyle will be a subcategory
              // of the Lines category

              Categories categories = doc.Settings.Categories;

              Category lineCat = categories.get_Item(
            BuiltInCategory.OST_Lines );

              using( Transaction t = new Transaction( doc ) )
              {
            t.Start( "Create LineStyle" );

            // Add the new linestyle

            Category newLineStyleCat = categories
              .NewSubcategory( lineCat, "New LineStyle" );

            doc.Regenerate();

            // Set the linestyle properties
            // (weight, color, pattern).

            newLineStyleCat.SetLineWeight( 8,
              GraphicsStyleType.Projection );

            newLineStyleCat.LineColor = new Color(
              0xFF, 0x00, 0x00 );

            newLineStyleCat.SetLinePatternId(
              linePatternElem.Id,
              GraphicsStyleType.Projection );

            t.Commit();
              }
        }
开发者ID:jeremytammik,项目名称:the_building_coder_samples,代码行数:56,代码来源:CmdCreateLineStyle.cs

示例3: GetMatching3DView

        public static View3D GetMatching3DView(this View view, Document doc)
        {
            ViewFamilyType viewFamilyType = (from v in new FilteredElementCollector(doc).
                 OfClass(typeof(ViewFamilyType)).
                 Cast<ViewFamilyType>()
                 where v.ViewFamily == ViewFamily.ThreeDimensional
                 select v).First();

            View3D view3d = View3D.CreateIsometric(doc, viewFamilyType.Id);

            view3d.Name = view.Name + " 3D temp view";

            ViewBox myviewbox = GetViewBox(view);

            if (myviewbox.bbox == null)
            {
                BoundingBoxXYZ boundingBoxXYZ = new BoundingBoxXYZ();

                boundingBoxXYZ.Min = myviewbox.P1;
                boundingBoxXYZ.Max = myviewbox.P2;
                view3d.SetSectionBox(boundingBoxXYZ);
            }
            else
            {
                view3d.SetSectionBox(myviewbox.bbox);
            }
            view3d.SetOrientation(new ViewOrientation3D(myviewbox.EyePosition, myviewbox.DirectionUp, myviewbox.DirectionView));

            foreach (Category cat in doc.Settings.Categories)
            {
                try
                {
                    if (cat.CategoryType == CategoryType.Model && cat.get_AllowsVisibilityControl(view3d))
                        view3d.SetVisibility(cat, view.GetVisibility(cat));
                }
                catch (System.Exception e) { }

            }

            doc.Regenerate();

            return view3d;
        }
开发者ID:DOCQR,项目名称:revit,代码行数:43,代码来源:ViewBoxFinder.cs

示例4: getViewCoord

        //Get the coordinate of the picked view
        public void getViewCoord(Document doc, string SelectedItem)
        {
            Viewport viewport = null;

            var filterCollector = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Viewports)
                .WhereElementIsNotElementType().ToElements();

            foreach (Element e in filterCollector)
            {
                Viewport vp = e as Viewport;
                string stringViewport = vp.get_Parameter(BuiltInParameter.VIEW_NAME).AsString();

                if (stringViewport == SelectedItem)
                {
                    viewport = vp;
                    leftLower = viewport.GetBoxOutline().MinimumPoint;
                    topRight = viewport.GetBoxOutline().MaximumPoint;
                    center = viewport.GetBoxCenter();

                    doc.Regenerate();
                }
            }
        }
开发者ID:dannysbentley,项目名称:alignviewtosheetcell,代码行数:24,代码来源:ViewLocation.cs

示例5: Execute

        // command main
        //
        public Result Execute(
          ExternalCommandData commandData,
          ref string message,
          ElementSet elements)
        {
            // objects for the top level access
            //
            _app = commandData.Application.Application;
            _doc = commandData.Application.ActiveUIDocument.Document;

            // (0) This command works in the context of family editor only.
            //     We also check if the template is for an appropriate category if needed.
            //     Here we use a Column(i.e., Metric Column.rft) template.
            //     Although there is no specific checking about metric or imperial, our lab only works in metric for now.
            //
            if (!isRightTemplate(BuiltInCategory.OST_Columns))
            {
                Util.ErrorMsg("Please open Metric Column.rft");
                return Result.Failed;
            }
            using (Transaction transaction = new Transaction(_doc))
            {
                try
                {
                    if (transaction.Start("CreateFamily") == TransactionStatus.Started)
                    {
                        // (1.1) add reference planes
                        addReferencePlanes();

                        // (1.2) create a simple extrusion. This time we create a L-shape.
                        Extrusion pSolid = createSolid();
                        _doc.Regenerate();

                        // (2) add alignment
                        addAlignments(pSolid);

                        // (3.1) add parameters
                        addParameters();

                        // (3.2) add dimensions
                        addDimensions();

                        // (3.3) add types
                        addTypes();

                        // test family parameter value modification:
                        //modifyFamilyParamValue();
                        transaction.Commit();
                    }
                    else
                    {
                        TaskDialog.Show("ERROR", "Start transaction failed!");
                        return Result.Failed;
                    }
                }
                catch (Exception ex)
                {
                    TaskDialog.Show("ERROR", ex.ToString());
                    if (transaction.GetStatus() == TransactionStatus.Started)
                        transaction.RollBack();
                    return Result.Failed;
                }
            }
            // finally, return
            return Result.Succeeded;
        }
开发者ID:vnoves,项目名称:RevitTrainingMaterial,代码行数:68,代码来源:2_ColumnLshape.cs

示例6: SelectAndPlaceTakeOffFitting

        void SelectAndPlaceTakeOffFitting( Document doc )
        {
            ElementId mainDuctId = ElementId.InvalidElementId;

              // Get DuctType - we need this for its
              // RoutingPreferenceManager. This is how we assign
              // our tap object to be used. This is the settings
              // for the duct object we attach our tap to.

              Duct duct = doc.GetElement( mainDuctId ) as Duct;

              DuctType ductType = duct.DuctType;

              RoutingPreferenceManager routePrefManager
            = ductType.RoutingPreferenceManager;

              // Set Junction Prefernce to Tap.

              routePrefManager.PreferredJunctionType
            = PreferredJunctionType.Tap;

              // For simplicity sake, I remove all previous rules
              // for taps so I can just add what I want here.
              // This will probably vary.

              int initRuleCount = routePrefManager.GetNumberOfRules(
            RoutingPreferenceRuleGroupType.Junctions );

              for( int i = 0; i != initRuleCount; ++i )
              {
            routePrefManager.RemoveRule(
              RoutingPreferenceRuleGroupType.Junctions, 0 );
              }

              // Get FamilySymbol for Tap I want to use.

              FamilySymbol tapSym = null;
              doc.LoadFamilySymbol( "C:/FamilyLocation/MyTap.rfa",
            "MyTap", out tapSym );

              // Symbol needs to be activated before use.

              if( ( !tapSym.IsActive ) && ( tapSym != null ) )
              {
            tapSym.Activate();
            doc.Regenerate();
              }

              // Create Rule that utilizes the Tap. Use the argument
              // MEPPartId = ElementId for the desired FamilySymbol.

              RoutingPreferenceRule newRule
            = new RoutingPreferenceRule( tapSym.Id, "MyTap" );

              routePrefManager.AddRule(
            RoutingPreferenceRuleGroupType.Junctions, newRule );

              // To create a solid tap, we need to use the Revit
              // doc.Create.NewTakeoffFitting routine. For this,
              // we need a connector. If we don't have one, we
              // just create a temporary object with a connector
              // where we want it.

              Connector tmpConn = CreateTemporaryConnectorForTap();

              // Create our tap.

              FamilyInstance tapInst
            = doc.Create.NewTakeoffFitting( tmpConn, duct );
        }
开发者ID:jeremytammik,项目名称:the_building_coder_samples,代码行数:70,代码来源:CmdNewCrossFitting.cs

示例7: GetViewsToDelete

        IList<Element> GetViewsToDelete(Document doc)
        {
            using (Transaction trans = new Transaction(doc))
            {
                // Collect all Views except ViewTemplates
                // Add one drafting view to project before deleting
                // all views because Revit will shut down when last view
                // is deleted from project.

                // Create a new Drafting view
                ViewFamilyType viewFamilyType = new FilteredElementCollector(doc)
                    .OfClass(typeof(ViewFamilyType))
                    .Cast<ViewFamilyType>().First(vft => vft.ViewFamily == ViewFamily.Drafting);

                trans.Start("Delete All Views/Sheets");
                ViewDrafting view = ViewDrafting.Create(doc, viewFamilyType.Id);
                view.ViewName = "TempDraftingView";

                doc.Regenerate();

                // Collect all Views except newly created one
                List<ElementId> exclude = new List<ElementId>();
                exclude.Add(view.Id);

                ExclusionFilter filter = new ExclusionFilter(exclude);
                IList<Element> views = new FilteredElementCollector(doc)
                    .OfClass(typeof(View))
                    .WhereElementIsNotElementType()
                    .WherePasses(filter)
                    .ToElements();

                // Remove all ViewTemplates from views to be deleted
                for (var i = 0; i < views.Count; i++)
                {
                    View v = views[i] as View;
                    if (v.IsTemplate)
                    {
                        views.RemoveAt(i);
                    }
                }
                trans.Commit();
                return views;
            }
        }
开发者ID:mjkkirschner,项目名称:GrimshawTools,代码行数:44,代码来源:DeleteAllViewsSheets.cs

示例8: Execute

    // command main
    //
    public Result Execute(
      ExternalCommandData commandData,
      ref string message,
      ElementSet elements)
    {
      // objects for the top level access
      //
      _app = commandData.Application.Application;
      _doc = commandData.Application.ActiveUIDocument.Document;

      // (0) This command works in the context of family editor only.
      //     We also check if the template is for an appropriate category if needed.
      //     Here we use a Column(i.e., Metric Column.rft) template.
      //     Although there is no specific checking about metric or imperial, our lab only works in metric for now.
      //
      if (!isRightTemplate(BuiltInCategory.OST_Columns))
      {
        Util.ErrorMsg("Please open Metric Column.rft");
        return Result.Failed;
      }

      // (1.1) add reference planes
      addReferencePlanes();

      // (1.2) create a simple extrusion. We create a L-shape extrusion.
      Extrusion pSolid = createSolid();
      _doc.Regenerate();

      // (2) add alignment
      addAlignments(pSolid);

      // (3.1) add parameters
      addParameters();

      // (3.2) add dimensions
      addDimensions();

      // (3.3) add types
      addTypes();

      // (4.1) add formulas
      addFormulas();

      // (4.2) add materials
      addMaterials(pSolid);

      // (5.1) add visibilities
      addLineObjects();
      changeVisibility(pSolid);

      // finally return
      return Result.Succeeded;
    }
开发者ID:FlintSable,项目名称:RevitTrainingMaterial,代码行数:55,代码来源:4_ColumnVisibility.cs

示例9: Execute

        // command main
        //
        public Result Execute(
          ExternalCommandData commandData,
          ref string message,
          ElementSet elements)
        {
            // objects for the top level access
            //
            _app = commandData.Application.Application;
            _doc = commandData.Application.ActiveUIDocument.Document;

            // (0) This command works in the context of family editor only.
            //     We also check if the template is for an appropriate category if needed.
            //     Here we use a Column(i.e., Metric Column.rft) template.
            //     Although there is no specific checking about metric or imperial, our lab only works in metric for now.
            //
            if (!isRightTemplate(BuiltInCategory.OST_Columns))
            {
                Util.ErrorMsg("Please open Metric Column.rft");
                return Result.Failed;
            }

            using (Transaction transaction = new Transaction(_doc))
            {
                try
                {
                    if (transaction.Start("CreateFamily") == TransactionStatus.Started)
                    {
                        // (1) create a simple extrusion. just a simple box for now.
                        Extrusion pSolid = createSolid();

                        // We need to regenerate so that we can build on this new geometry
                        _doc.Regenerate();

                        // try this:
                        // if you comment addAlignment and addTypes calls below and execute only up to here,
                        // you will see the column's top will not follow the upper level.

                        // (2) add alignment
                        addAlignments(pSolid);

                        // try this: at each stage of adding a function here, you should be able to see the result in UI.

                        // (3) add types
                        addTypes();
                        transaction.Commit();
                    }
                    else
                    {
                        TaskDialog.Show("ERROR", "Start transaction failed!");
                        return Result.Failed;
                    }
                }
                catch (Exception ex)
                {
                    TaskDialog.Show("ERROR", ex.ToString());
                    if (transaction.GetStatus() == TransactionStatus.Started)
                        transaction.RollBack();
                    return Result.Failed;
                }
            }
            // finally, return
            return Result.Succeeded;
        }
开发者ID:vnoves,项目名称:RevitTrainingMaterial,代码行数:65,代码来源:1_ColumnRectangle.cs

示例10: CreateWalls

    /// <summary>
    /// Create walls with a rectangular profile from two coner points. 
    /// </summary>
    public static List<Wall> CreateWalls(Document rvtDoc, XYZ pt1, XYZ pt2)
    {
      // Set the lower-left (x1, y1) and upper-right (x2, y2) corners of a house. 
      double x1 = pt1.X;
      double x2 = pt2.X;
      if (pt1.X > pt2.X)
      {
        x1 = pt2.X;
        x2 = pt1.X;
      }

      double y1 = pt1.Y;
      double y2 = pt2.Y;
      if (pt1.Y > pt2.X)
      {
        y1 = pt2.Y;
        y2 = pt1.Y;
      }

      // Set four corner of walls from two croner point.
      // 5th point is for combenience to loop through.  
      List<XYZ> pts = new List<XYZ>(5);
      pts.Add(new XYZ(x1, y1, pt1.Z));
      pts.Add(new XYZ(x2, y1, pt1.Z));
      pts.Add(new XYZ(x2, y2, pt1.Z));
      pts.Add(new XYZ(x1, y2, pt1.Z));
      pts.Add(pts[0]);

      // Get the levels we want to work on. 
      // Note: hard coding for simplicity. Modify here you use a different template. 
      Level level1 = ElementFiltering.FindElement(rvtDoc, typeof(Level), "Level 1", null) as Level;
      if (level1 == null)
      {
        TaskDialog.Show(
          "Create walls", "Cannot find (Level 1). Maybe you use a different template? Try with DefaultMetric.rte."
        );
        return null;
      }

      Level level2 = ElementFiltering.FindElement(rvtDoc, typeof(Level), "Level 2", null) as Level;
      if (level2 == null)
      {
        TaskDialog.Show(
          "Create walls", "Cannot find (Level 2). Maybe you use a different template? Try with DefaultMetric.rte."
        );
        return null;
      }

      // Flag for structural wall or not. 
      bool isStructural = false;

      // Save walls we create. 
      List<Wall> walls = new List<Wall>(4);

      // Loop through list of points and define four walls. 
      for (int i = 0; i <= 3; i++)
      {
        // define a base curve from two points. 
        Line baseCurve = Line.CreateBound(pts[i], pts[i + 1]);
        // create a wall using the one of overloaded methods. 
        //Wall aWall = rvtDoc.Create.NewWall(baseCurve, level1, isStructural); // 2012
        Wall aWall = Wall.Create(rvtDoc, baseCurve, level1.Id, isStructural); // since 2013
        // set the Top Constraint to Level 2 
        aWall.get_Parameter(BuiltInParameter.WALL_HEIGHT_TYPE).Set(level2.Id);
        // save the wall.
        walls.Add(aWall);
      }
      // This is important. we need these lines to have shrinkwrap working. 
      rvtDoc.Regenerate();
      rvtDoc.AutoJoinElements();

      return walls;

    }
开发者ID:vnoves,项目名称:RevitTrainingMaterial,代码行数:77,代码来源:5_ModelCreationExport.cs

示例11: OpeningElementOpenings

    private static void OpeningElementOpenings(
        Document doc, double minOpeningValue)
    {
      FilteredElementCollector openingCollector =
          new FilteredElementCollector(doc);
      openingCollector.OfClass(typeof(Opening));

      // Get the IList for the collector - we cannot delete
      // elements using a collector iterator
      IList<Element> openings =
          openingCollector.ToList<Element>();

      foreach (Opening open in openings)
      {
        // Open the host wall
        Wall wall = open.Host as Wall;
        if (wall == null) continue; //safety

        // Get the original area to compare
        double previousArea = wall.get_Parameter(
            BuiltInParameter.HOST_AREA_COMPUTED).AsDouble();

        // Delete the wall opening
        doc.Delete(open);
        doc.Regenerate();

        // Get the new area to compare
        double newArea = wall.get_Parameter(
            BuiltInParameter.HOST_AREA_COMPUTED).AsDouble();

        // So the instance opening equals:
        double instanceAreaOnTheWall =
            (newArea - previousArea);

        if (instanceAreaOnTheWall <= minOpeningValue)
          AddWallArea(wall.Id, instanceAreaOnTheWall, 0.0);
        else
          AddWallArea(wall.Id, 0.0, instanceAreaOnTheWall);
      }
    }
开发者ID:augustogoncalves,项目名称:PIOTM-WallOpeningArea,代码行数:40,代码来源:WallAreaFunctions.cs

示例12: Execute

        /// <summary>
        /// Implement this method as an external command for Revit.
        /// </summary>
        /// <param name="commandData">An object that is passed to the external application 
        /// which contains data related to the command, 
        /// such as the application object and active view.</param>
        /// <param name="message">A message that can be set by the external application 
        /// which will be displayed if a failure or cancellation is returned by 
        /// the external command.</param>
        /// <param name="elements">A set of elements to which the external application 
        /// can add elements that are to be highlighted in case of failure or cancellation.</param>
        /// <returns>Return the status of the external command. 
        /// A result of Succeeded means that the API external method functioned as expected. 
        /// Cancelled can be used to signify that the user cancelled the external operation 
        /// at some point. Failure should be returned if the application is unable to proceed with 
        /// the operation.</returns>
        public Autodesk.Revit.UI.Result Execute(ExternalCommandData commandData,
        ref string message, Autodesk.Revit.DB.ElementSet elements)
        {
            m_revitApp = commandData.Application.Application;
            m_doc = commandData.Application.ActiveUIDocument.Document;

            Level level1 = GetLevel();
            if (level1 == null)
            {
                throw new Exception("[ERROR] Failed to get level 1");
            }

            try
            {
                //
                // Post a warning and resolve it in FailurePreproccessor
                try
                {
                    Transaction transaction = new Transaction(m_doc, "Warning_FailurePreproccessor");
                    FailureHandlingOptions options = transaction.GetFailureHandlingOptions();
                    FailurePreproccessor preproccessor = new FailurePreproccessor();
                    options.SetFailuresPreprocessor(preproccessor);
                    transaction.SetFailureHandlingOptions(options);
                    transaction.Start();
                    FailureMessage fm = new FailureMessage(m_idWarning);
                    m_doc.PostFailure(fm);
                    transaction.Commit();
                }
                catch (System.Exception)
                {
                    message = "Failed to commit transaction Warning_FailurePreproccessor";
                    return Result.Failed;
                }

                //
                // Dismiss the overlapped wall warning in FailurePreproccessor
                try
                {
                    Transaction transaction = new Transaction(m_doc, "Warning_FailurePreproccessor_OverlappedWall");
                    FailureHandlingOptions options = transaction.GetFailureHandlingOptions();
                    FailurePreproccessor preproccessor = new FailurePreproccessor();
                    options.SetFailuresPreprocessor(preproccessor);
                    transaction.SetFailureHandlingOptions(options);
                    transaction.Start();

                    Line line = m_revitApp.Create.NewLineBound(new XYZ(-10, 0, 0), new XYZ(-20, 0, 0));
                    Wall wall1 = m_doc.Create.NewWall(line, level1, false);
                    Wall wall2 = m_doc.Create.NewWall(line, level1, false);
                    m_doc.Regenerate();

                    transaction.Commit();
                }
                catch (System.Exception)
                {
                    message = "Failed to commit transaction Warning_FailurePreproccessor_OverlappedWall";
                    return Result.Failed;
                }

                //
                // Post an error and resolve it in FailuresProcessingEvent
                try
                {
                    m_revitApp.FailuresProcessing += new EventHandler<Autodesk.Revit.DB.Events.FailuresProcessingEventArgs>(FailuresProcessing);
                    Transaction transaction = new Transaction(m_doc, "Error_FailuresProcessingEvent");
                    transaction.Start();

                    Line line = m_revitApp.Create.NewLineBound(new XYZ(0, 10, 0), new XYZ(20, 10, 0));
                    Wall wall = m_doc.Create.NewWall(line, level1, false);
                    m_doc.Regenerate();

                    FailureMessage fm = new FailureMessage(m_idError);
                    FailureResolution fr = DeleteElements.Create(m_doc, wall.Id);
                    fm.AddResolution(FailureResolutionType.DeleteElements, fr);
                    m_doc.PostFailure(fm);
                    transaction.Commit();
                }
                catch (System.Exception)
                {
                    message = "Failed to commit transaction Error_FailuresProcessingEvent";
                    return Result.Failed;
                }

                //
                // Post an error and resolve it in FailuresProcessor
//.........这里部分代码省略.........
开发者ID:AMEE,项目名称:revit,代码行数:101,代码来源:Command.cs

示例13: CreateFaceWalls

        static void CreateFaceWalls(
            Document doc)
        {
            Application app = doc.Application;

              Document massDoc = app.NewFamilyDocument(
            _conceptual_mass_template_path );

              CreateMassExtrusion( massDoc );

              //if( File.Exists( _family_path ) )
              //  File.Delete( _family_path );

              SaveAsOptions opt = new SaveAsOptions();
              opt.OverwriteExistingFile = true;

              massDoc.SaveAs( _family_path, opt );

              using( Transaction tx = new Transaction( doc ) )
              {
            tx.Start( "Create FaceWall" );

            if( !doc.LoadFamily( _family_path ) )
              throw new Exception( "DID NOT LOAD FAMILY" );

            Family family = new FilteredElementCollector( doc )
              .OfClass( typeof( Family ) )
              .Where<Element>( x => x.Name.Equals( _family_name ) )
              .Cast<Family>()
              .FirstOrDefault();

            FamilySymbol fs = doc.GetElement(
              family.GetFamilySymbolIds().First<ElementId>() )
            as FamilySymbol;

            // Create a family instance

            Level level = doc.ActiveView.GenLevel;

            FamilyInstance fi = doc.Create.NewFamilyInstance(
              XYZ.Zero, fs, level, StructuralType.NonStructural );

            doc.Regenerate(); // required to generate the geometry!

            // Determine wall type.

            WallType wallType = new FilteredElementCollector( doc )
              .OfClass( typeof( WallType ) )
              .Cast<WallType>()
              .Where<WallType>( x => FaceWall.IsWallTypeValidForFaceWall( doc, x.Id ) )
              .FirstOrDefault();

            // Retrieve mass element geometry.

            Options options = app.Create.NewGeometryOptions();
            options.ComputeReferences = true;

            //options.View = doc.ActiveView; // conceptual mass is not visible in default view

            GeometryElement geo = fi.get_Geometry( options );

            // Create a sloped wall from the geometry.

            foreach( GeometryObject obj in geo )
            {
              Solid solid = obj as Solid;

              if( null != solid )
              {
            foreach( Face f in solid.Faces )
            {
              Debug.Assert( null != f.Reference,
                "we asked for references, didn't we?" );

              PlanarFace pf = f as PlanarFace;

              if( null != pf )
              {
                XYZ v = pf.FaceNormal;

                // Errors:
                //
                // Could not create a face wall.
                //
                // Caused by using ActiveView.Level
                // instead of ActiveView.GenLevel.
                //
                // This reference cannot be applied to a face wall.
                //
                // Caused by using this on a horizontal face.

                if( !Util.IsVertical( v ) )
                {
                  FaceWall.Create(
                    doc, wallType.Id,
                    WallLocationLine.CoreCenterline,
                    f.Reference );
                }
              }
            }
//.........这里部分代码省略.........
开发者ID:sridharbaldava,项目名称:the_building_coder_samples,代码行数:101,代码来源:CmdFaceWall.cs

示例14: AddRoof

    /// <summary>
    /// Add a roof over the rectangular profile of the walls we created earlier.
    /// </summary>

    public static void AddRoof(Document rvtDoc, List<Wall> walls)
    {
      // Hard coding the roof type we will use. 
      // e.g., "Basic Roof: Generic - 400mm"  
      const string roofFamilyName = "Basic Roof";
      const string roofTypeName = Util.Constant.RoofTypeName;
      const string roofFamilyAndTypeName = roofFamilyName + ": " + roofTypeName;

      // Find the roof type
      RoofType roofType =
        ElementFiltering.FindFamilyType(
          rvtDoc, typeof(RoofType), roofFamilyName, roofTypeName, null
        ) as RoofType;
      if (roofType == null)
      {
        TaskDialog.Show(
          "Add roof", "Cannot find (" + roofFamilyAndTypeName +
          "). Maybe you use a different template? Try with DefaultMetric.rte.");
      }

      // Wall thickness to adjust the footprint of the walls
      // to the outer most lines. 
      // Note: this may not be the best way. 
      // but we will live with this for this exercise. 
      //Dim wallThickness As Double = _
      //walls(0).WallType.CompoundStructure.Layers.Item(0).Thickness() ' 2011
      double wallThickness = walls[0].WallType.GetCompoundStructure().GetLayers()[0].Width;
      // 2012
      double dt = wallThickness / 2.0;
      List<XYZ> dts = new List<XYZ>(5);
      dts.Add(new XYZ(-dt, -dt, 0.0));
      dts.Add(new XYZ(dt, -dt, 0.0));
      dts.Add(new XYZ(dt, dt, 0.0));
      dts.Add(new XYZ(-dt, dt, 0.0));
      dts.Add(dts[0]);

      // Set the profile from four walls 
      CurveArray footPrint = new CurveArray();
      for (int i = 0; i <= 3; i++)
      {
        LocationCurve locCurve = (LocationCurve)walls[i].Location;
        XYZ pt1 = locCurve.Curve.GetEndPoint(0) + dts[i];
        XYZ pt2 = locCurve.Curve.GetEndPoint(1) + dts[i + 1];
        Line line = Line.CreateBound(pt1, pt2);
        footPrint.Append(line);
      }

      // Get the level2 from the wall
      ElementId idLevel2 = walls[0].get_Parameter(BuiltInParameter.WALL_HEIGHT_TYPE).AsElementId();

      //Level level2 = (Level)_doc.get_Element(idLevel2); // 2012
        Level level2 = rvtDoc.GetElement(idLevel2) as Level; // since 2013

      // Footprint to morel curve mapping  
      ModelCurveArray mapping = new ModelCurveArray();

      // Create a roof.
      FootPrintRoof aRoof = rvtDoc.Create.NewFootPrintRoof(footPrint, level2, roofType, out mapping);

      //  Set the slope 
      foreach (ModelCurve modelCurve in mapping)
      {
        aRoof.set_DefinesSlope(modelCurve, true);
        aRoof.set_SlopeAngle(modelCurve, 0.5);
      }

      // Added. 
      rvtDoc.Regenerate();
      rvtDoc.AutoJoinElements();
    }
开发者ID:FlintSable,项目名称:RevitTrainingMaterial,代码行数:74,代码来源:5_ModelCreationExport.cs

示例15: Execute

        /// <summary>
        /// Implement this method as an external command for Revit.
        /// </summary>
        /// <param name="commandData">An object that is passed to the external application 
        /// which contains data related to the command, 
        /// such as the application object and active view.</param>
        /// <param name="message">A message that can be set by the external application 
        /// which will be displayed if a failure or cancellation is returned by 
        /// the external command.</param>
        /// <param name="elements">A set of elements to which the external application 
        /// can add elements that are to be highlighted in case of failure or cancellation.</param>
        /// <returns>Return the status of the external command. 
        /// A result of Succeeded means that the API external method functioned as expected. 
        /// Cancelled can be used to signify that the user cancelled the external operation 
        /// at some point. Failure should be returned if the application is unable to proceed with 
        /// the operation.</returns>
        public virtual Autodesk.Revit.UI.Result Execute(ExternalCommandData commandData
          , ref string message, Autodesk.Revit.DB.ElementSet elements)
        {
            m_revitApp = commandData.Application.Application;
             m_revitDoc = commandData.Application.ActiveUIDocument.Document;
             Transaction transaction = new Transaction(m_revitDoc, "ManipulateForm");

             try
             {
            transaction.Start();

            // Create a loft form
            Form form = CreateLoft();
            m_revitDoc.Regenerate();
            // Add profile to the loft form
            int profileIndex = AddProfile(form);
            m_revitDoc.Regenerate();
            // Move the edges on added profile
            MoveEdgesOnProfile(form, profileIndex);
            m_revitDoc.Regenerate();
            // Move the added profile
            MoveProfile(form, profileIndex);
            m_revitDoc.Regenerate();
            // Move the vertex on bottom profile
            MoveVertexesOnBottomProfile(form);
            m_revitDoc.Regenerate();
            // Add edge to the loft form
            Reference edgeReference = AddEdge(form);
            m_revitDoc.Regenerate();
            // Move the added edge
            Autodesk.Revit.DB.XYZ offset = new Autodesk.Revit.DB.XYZ (0, -40, 0);
            MoveSubElement(form, edgeReference, offset);
            m_revitDoc.Regenerate();
            // Move the vertex on added profile
            MoveVertexesOnAddedProfile(form, profileIndex);
            m_revitDoc.Regenerate();

            transaction.Commit();
             }
             catch (Exception ex)
             {
            message = ex.Message;
            transaction.RollBack();
            return Autodesk.Revit.UI.Result.Failed;
             }

             return Autodesk.Revit.UI.Result.Succeeded;
        }
开发者ID:AMEE,项目名称:revit,代码行数:64,代码来源:Command.cs


注:本文中的Document.Regenerate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。