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


C# Transaction.Start方法代码示例

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


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

示例1: DuplicateDependent

        //Description: Create 4 Dependent Views for currently active View
        public void DuplicateDependent()
        {
            //setup uidoc and doc for accessing the Revit UI (uidoc and the Model (doc)
            UIDocument uidoc = this.ActiveUIDocument;
            Document doc = uidoc.Document;

            //create a transaction
            using(Transaction t = new Transaction(doc, "Duplicate View 5x"))
            {
            //start the transaction
            t.Start();

            //create a counter for incrementing alphabet
            int i = 0;

            //loop through until you reach 4(change 4 to increase/decreas the before running macro)
            while(i<4)
            {
                //duplicate the currently active view
                ElementId dupViewId=uidoc.ActiveView.Duplicate(ViewDuplicateOption.AsDependent);
                //get the new dependent view
                View dupView = doc.GetElement(dupViewId) as View;
                //use char command to get the Letter A
                char c = (char)(i+65);
                //rename the dependent view to include the original name and the new Area
                dupView.Name = uidoc.ActiveView.Name + " - AREA " + c.ToString();

                //increment the char each loop (A, B, C, etc)
                i++;
            }
            //finalize the transaction
            t.Commit();

            }
        }
开发者ID:jailbirdj,项目名称:create-views-,代码行数:36,代码来源:ThisApplication.cs

示例2: IncrementX

 /// <summary>
 /// adds 1 to X
 /// </summary>
 public void IncrementX()
 {
     Transaction transaction = new Transaction(_dbDoc);
     transaction.Start("Score Update");
     _xScore.Text = X_SCORE_PRE_TEXT + (GetXScore()+1);
     transaction.Commit();
 }
开发者ID:RodH257,项目名称:RevitTicTacToe,代码行数:10,代码来源:ScoreKeeper.cs

示例3: 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(Autodesk.Revit.UI.ExternalCommandData commandData,
                                               ref string message,
                                               ElementSet elements)
        {
            try
            {
                Transaction documentTransaction = new Transaction(commandData.Application.ActiveUIDocument.Document, "Document");
                documentTransaction.Start();
                // Get the application of revit
                Autodesk.Revit.UI.UIApplication revit = commandData.Application;

                // New a real operation class.
                ModelLines deal = new ModelLines(revit);

                // The main deal operation
                deal.Run();
                documentTransaction.Commit();

                // if everything goes well, return succeeded.
                return Autodesk.Revit.UI.Result.Succeeded;
            }
            catch (Exception ex)
            {
                // If any error, give error information and return failed
                message = ex.Message;
                return Autodesk.Revit.UI.Result.Failed;
            }
        }
开发者ID:AMEE,项目名称:revit,代码行数:44,代码来源:Command.cs

示例4: Execute

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

              List<Element> rooms = new List<Element>();
              if( !Util.GetSelectedElementsOrAll(
            rooms, uidoc, typeof( Room ) ) )
              {
            Selection sel = uidoc.Selection;
            message = ( 0 < sel.GetElementIds().Count )
              ? "Please select some room elements."
              : "No room elements found.";
            return Result.Failed;
              }
              using ( Transaction t = new Transaction( doc ) )
              {
            t.Start( "Bump Room Occupancy" );

            foreach ( Room room in rooms )
            {
              BumpOccupancy( room );
            }
            t.Commit();
              }
              return Result.Succeeded;
        }
开发者ID:jeremytammik,项目名称:the_building_coder_samples,代码行数:31,代码来源:CmdSetRoomOccupancy.cs

示例5: CreateDimensionElement

        /// <summary>
        /// Create a new dimension element using the given
        /// references and dimension line end points.
        /// This method opens and commits its own transaction,
        /// assuming that no transaction is open yet and manual
        /// transaction mode is being used.
        /// Note that this has only been tested so far using
        /// references to surfaces on planar walls in a plan
        /// view.
        /// </summary>
        public static void CreateDimensionElement(
            View view,
            XYZ p1,
            Reference r1,
            XYZ p2,
            Reference r2)
        {
            Document doc = view.Document;

              ReferenceArray ra = new ReferenceArray();

              ra.Append( r1 );
              ra.Append( r2 );

              Line line = Line.CreateBound( p1, p2 );

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

            Dimension dim = doc.Create.NewDimension(
              view, line, ra );

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

示例6: CreateInstances

        private void CreateInstances(List<FamilySelectorViewModel> ds)
        {
            UpdateFamilySymbolTypes(ds);

            using( var transaction = new Transaction(_creator.RevitDoc.Document, "CreateFamilyInstance"))
            {
                transaction.Start();
                foreach (var vm in ds)
                {
                    foreach (var instanse in vm.DataType.Instances)
                    {
                        var convertedCoords = GetConvertedCoords(instanse);

                        _creator.CreateInstanceInPlace(convertedCoords, vm.SelectedSymbol.Item1);
                    }

                    foreach (var cabel in vm.DataType.CabelInstances)
                    {
                        var convertedCoords = GetConvertedCoords(cabel);
                        var cabelInstance = _creator.CreateInstanceInPlace(convertedCoords, vm.SelectedSymbol.Item1);

                        var lengthParam = cabelInstance.get_Parameter("Length");
                        if (lengthParam != null)
                            lengthParam.Set(Utils.MetersToFeet(cabel.Length));

                        var fromParam = cabelInstance.get_Parameter("From");
                        if (fromParam != null)
                            fromParam.Set(cabel.From);
                    }
                }
                transaction.Commit();
            }
        }
开发者ID:KonbOgonb,项目名称:revit-psElectro-bridge,代码行数:33,代码来源:PSDataImporter.cs

示例7: 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)
        {
            Transaction transaction = new Transaction(commandData.Application.ActiveUIDocument.Document, "External Tool");
            try
            {
                transaction.Start();
                // create a factory to create the corresponding FrameReinMaker
                FrameReinMakerFactory factory = new FrameReinMakerFactory(commandData);

                // Do some data checks, such whether the user select concrete beam or column
                if (!factory.AssertData())
                {
                    message = "Please select a concrete beam or column without reinforcement.";
                    return Autodesk.Revit.UI.Result.Failed;
                }

                // Invoke work() method to create corresponding FrameReinMaker,
                // and create the reinforcement rebars
                factory.work();

                // if everything goes well, return succeeded.
                return Autodesk.Revit.UI.Result.Succeeded;
            }
            catch (Exception ex)
            {
                message = ex.Message;
                return Autodesk.Revit.UI.Result.Failed;
            }
            finally
            {
                transaction.Commit();
            }
        }
开发者ID:AMEE,项目名称:revit,代码行数:50,代码来源:Command.cs

示例8: deleteLinePatterns

        public void deleteLinePatterns(Document doc)
        {
            var collector = new FilteredElementCollector(doc)
                .OfClass(typeof(LinePatternElement)).Where(i => i.Name.StartsWith("IMPORT")).ToList();

            List<ElementId> ids = new List<ElementId>();
            for (int i = 0; i < collector.Count(); i++)
            {
                ids.Add(collector[i].Id);
            }

            using (Transaction t = new Transaction(doc, "Remove Pattern"))
            {
                t.Start();
                try
                {
                    doc.Delete(ids);
                }
                catch (Exception)
                {
                    t.RollBack();
                    return;
                }
                t.Commit();
            }
        }
开发者ID:dannysbentley,项目名称:Delete-Change-Line-Styles,代码行数:26,代码来源:getLines.cs

示例9: Execute

        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            UIApplication app = commandData.Application;
              Document doc = app.ActiveUIDocument.Document;

              using ( Transaction t = new Transaction( doc ) )
              {
            t.Start( "Create Shared Parameter" );
            Category cat;
            int i = 0;

            // create instance parameters:

            foreach ( BuiltInCategory target in targets )
            {
              cat = GetCategory( doc, target );
              if ( null != cat )
              {
            CreateSharedParameter( doc, cat, ++i, false );
              }
            }

            // create a type parameter:

            cat = GetCategory( doc, BuiltInCategory.OST_Walls );
            CreateSharedParameter( doc, cat, ++i, true );
            t.Commit();
              }
              return Result.Succeeded;
        }
开发者ID:jeremytammik,项目名称:the_building_coder_samples,代码行数:33,代码来源:CmdCreateSharedParams.cs

示例10: 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(Autodesk.Revit.UI.ExternalCommandData commandData,
            ref string message, Autodesk.Revit.DB.ElementSet elements)
        {
            Transaction newTran = null;
            try
            {
                if (null == commandData)
                {
                    throw new ArgumentNullException("commandData");
                }

                Document doc = commandData.Application.ActiveUIDocument.Document;
                ViewsMgr view = new ViewsMgr(doc);

                newTran = new Transaction(doc);
                newTran.Start("AllViews_Sample");

                AllViewsForm dlg = new AllViewsForm(view);

                if (dlg.ShowDialog() == DialogResult.OK)
                {
                    view.GenerateSheet(doc);
                }
                newTran.Commit();

                return Autodesk.Revit.UI.Result.Succeeded;
            }
            catch (Exception e)
            {
                message = e.Message;
                if ((newTran != null) && newTran.HasStarted() && !newTran.HasEnded())
                    newTran.RollBack();
                return Autodesk.Revit.UI.Result.Failed;
            }
        }
开发者ID:AMEE,项目名称:revit,代码行数:51,代码来源:AllViews.cs

示例11: Execute

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

              Transaction tx = new Transaction( doc,
            "Extract Part Atom" );

              tx.Start();

              string familyFilePath
            = "C:/Documents and Settings/All Users"
            + "/Application Data/Autodesk/RAC 2011"
            + "/Metric Library/Doors/M_Double-Flush.rfa";

              string xmlPath = "C:/tmp/ExtractPartAtom.xml";

              app.ExtractPartAtomFromFamilyFile(
            familyFilePath, xmlPath );

              tx.Commit();

              return Result.Succeeded;
        }
开发者ID:jeremytammik,项目名称:the_building_coder_samples,代码行数:29,代码来源:CmdPartAtom.cs

示例12: AddFamilyParameterAndType

        /// <summary>
        /// Ask the user to open a revit family template and then add FamilyTypes and FamilyParameters
        /// to it. Say the user opens a Door template, he can then save the family as a new door family and load
        /// it into a new project for use.
        /// </summary>
        public void AddFamilyParameterAndType()
        {
            Document doc;

             OpenFileDialog openFileDialog = new OpenFileDialog();
             openFileDialog.Title = "Select family document";
             openFileDialog.Filter = "RFT Files (*.rft)|*.rft";

             if (openFileDialog.ShowDialog() == DialogResult.OK)
             {
            doc = m_revitApp.Application.NewFamilyDocument(openFileDialog.FileName);
             }
             else
            return;

             using( Transaction transaction = new Transaction( m_revitApp.ActiveUIDocument.Document ) )
             {
               transaction.Start( "AddFamilyParameterAndType" );

               if( doc.IsFamilyDocument )
               { // has to be a family document to be able to use the Family Manager.

             FamilyManager famMgr = doc.FamilyManager;

             //Add a family param.
             FamilyParameter famParam = famMgr.AddParameter( "RevitLookup_Param", BuiltInParameterGroup.PG_TITLE, ParameterType.Text, false );
             famMgr.Set( famParam, "Default text." );

             //Create a couple of new family types. Note that we can set different values for the param
             //in different family types.

             FamilyType newFamType = famMgr.NewType( "RevitLookup_Type1" );
             famMgr.CurrentType = newFamType;

             if( newFamType.HasValue( famParam ) )
             {
               famMgr.Set( famParam, "Text1." );
             }

             FamilyType newFamType1 = famMgr.NewType( "RevitLookup_Type2" );
             famMgr.CurrentType = newFamType;

             if( newFamType.HasValue( famParam ) )
             {
               famMgr.Set( famParam, "Text2." );
             }

             famMgr.MakeType( famParam );

             if( ( famParam != null ) && ( newFamType != null ) )
             {
               MessageBox.Show( "New family types/params added successfully.", "RevitLookup", MessageBoxButtons.OK, MessageBoxIcon.Information );
             }
             else
               MessageBox.Show( "Family types/params addition failed.", "RevitLookup", MessageBoxButtons.OK, MessageBoxIcon.Error );
               }

               transaction.Commit();
             }
        }
开发者ID:jeremytammik,项目名称:RevitLookup,代码行数:65,代码来源:TestDocument.cs

示例13: TestOne

        public void TestOne()
        {
            using (var t = new Transaction(DocumentManager.Instance.CurrentDBDocument))
            {
                if (t.Start("Test one.") == TransactionStatus.Started)
                {
                    //create a reference point
                    var pt = DocumentManager.Instance.CurrentDBDocument.FamilyCreate.NewReferencePoint(new XYZ(5, 5, 5));

                    if (t.Commit() != TransactionStatus.Committed)
                    {
                        t.RollBack();
                    }
                }
                else
                {
                    throw new Exception("Transaction could not be started.");
                }
            }

            //verify that the point was created
            var collector = new FilteredElementCollector(DocumentManager.Instance.CurrentDBDocument);
            collector.OfClass(typeof (ReferencePoint));

            Assert.AreEqual(1, collector.ToElements().Count);
        }
开发者ID:algobasket,项目名称:Dynamo,代码行数:26,代码来源:TestExamples.cs

示例14: Execute

        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            Document doc = commandData.Application
            .ActiveUIDocument.Document;

              FilteredElementCollector collector
            = new FilteredElementCollector( doc );

              collector.OfClass( typeof( Level ) );
              Level level = collector.FirstElement() as Level;

              Transaction t = new Transaction( doc );

              t.Start( "Create unbounded room" );

              FailureHandlingOptions failOpt
            = t.GetFailureHandlingOptions();

              failOpt.SetFailuresPreprocessor(
            new RoomWarningSwallower() );

              t.SetFailureHandlingOptions( failOpt );

              doc.Create.NewRoom( level, new UV( 0, 0 ) );

              t.Commit();

              return Result.Succeeded;
        }
开发者ID:jeremytammik,项目名称:the_building_coder_samples,代码行数:32,代码来源:CmdPreprocessFailure.cs

示例15: updateDoor

        //third exervise put into a user interface
        public static void updateDoor(Document doc, UIDocument uidoc)
        {
            //creates a Collection of the doors as FamilyInstances
            var doorColl = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Doors)
                .OfClass(typeof(FamilyInstance));

            //Uses linq queries to select the door that have a ToRoom Value
            IEnumerable<FamilyInstance> doors =
                from FamilyInstance f in doorColl
                where f.ToRoom != null
                select f;

            //Start the transaction CRITICAL without transactions Revit cannot update
            using (Transaction t = new Transaction(doc, "Door Data Update"))
            {
                //Starts the transction
                t.Start();
                //goes through each door based on the filter above
                foreach (FamilyInstance e in doors)
                {
                    //gets the ToRoom number as a string
                    string doorToRoom = e.ToRoom.Number.ToString();
                    //updates the comments parameter to the ToRoom value
                    e.get_Parameter(BuiltInParameter.ALL_MODEL_INSTANCE_COMMENTS).Set(doorToRoom);
                }
                //Commits the changes to the Revit File
                t.Commit();
            }
        }
开发者ID:Gytaco,项目名称:RevitAPI,代码行数:30,代码来源:examplecommands.cs


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