Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Trouble creating wall

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
Anonymous
329 Views, 2 Replies

Trouble creating wall

Anonymous
Not applicable

Hi everyone: I'm trying to make a simple add-in which creates a wall. It compile fine, but it doesn't works. What I'm doing wrong?

Here's the code:

 

Highlight.cs

using System;
using System.Reflection;
using System.Collections.Generic;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using Autodesk.Revit.UI.Selection;
using System.Windows.Media.Imaging;
using System.Windows.Forms;
namespace Walkthrough
{
   /// <remarks>
   /// This application's main class. The class must be Public.
   /// </remarks>
   public class Highlight : IExternalApplication
   {
      // Both OnStartup and OnShutdown must be implemented as public method
      public Result OnStartup(UIControlledApplication application)
      {
        	
      	
      	// Add a new ribbon panel
         RibbonPanel ribbonPanel = application.CreateRibbonPanel("NewRibbonPanel");

         // Create a push button to trigger a command add it to the ribbon panel.
         string thisAssemblyPath = Assembly.GetExecutingAssembly().Location;

        
         PushButtonData buttonData = new PushButtonData("cmdHelloWorld",
            "Hello World", thisAssemblyPath, "Walkthrough.HelloWorld");

         PushButton pushButton = ribbonPanel.AddItem(buttonData) as PushButton;

         
         
         
         // Optionally, other properties may be assigned to the button
         // a) tool-tip
         pushButton.ToolTip = "Say hello to the entire world.";

         // b) large bitmap
         Uri uriImage = new Uri(@"C:\globe.png");
         BitmapImage largeImage = new BitmapImage(uriImage);
         pushButton.LargeImage = largeImage;

         return Result.Succeeded;
      }

      public Result OnShutdown(UIControlledApplication application)
      {
         // nothing to clean up in this simple case
         return Result.Succeeded;
      }
   }
   /// <remarks>
   /// The "HelloWorld" external command. The class must be Public.
   /// </remarks>
[Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
   public class HelloWorld : IExternalCommand
   {
    
   	// The main Execute method (inherited from IExternalCommand) must be public
      public Autodesk.Revit.UI.Result Execute(ExternalCommandData revit,
          ref string message, ElementSet elements)
      {
   		Document doc = revit.Application.ActiveUIDocument.Document;
   		
   		Transaction trans = new Transaction(doc);
        trans.Start("CreationMurAuto");


       //Create line 
        XYZ start = new XYZ(0,0,0);
        XYZ end = new XYZ(100,100,0);
       
        Curve wallLine = Line.CreateBound(start, end);
        Level nivel = Level.Create(doc, 20.0);


		Wall.Create(doc, wallLine, nivel.Id, false);
        
        trans.Dispose();
        return Result.Succeeded;

      }
   }
}

Thank you

0 Likes

Trouble creating wall

Hi everyone: I'm trying to make a simple add-in which creates a wall. It compile fine, but it doesn't works. What I'm doing wrong?

Here's the code:

 

Highlight.cs

using System;
using System.Reflection;
using System.Collections.Generic;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using Autodesk.Revit.UI.Selection;
using System.Windows.Media.Imaging;
using System.Windows.Forms;
namespace Walkthrough
{
   /// <remarks>
   /// This application's main class. The class must be Public.
   /// </remarks>
   public class Highlight : IExternalApplication
   {
      // Both OnStartup and OnShutdown must be implemented as public method
      public Result OnStartup(UIControlledApplication application)
      {
        	
      	
      	// Add a new ribbon panel
         RibbonPanel ribbonPanel = application.CreateRibbonPanel("NewRibbonPanel");

         // Create a push button to trigger a command add it to the ribbon panel.
         string thisAssemblyPath = Assembly.GetExecutingAssembly().Location;

        
         PushButtonData buttonData = new PushButtonData("cmdHelloWorld",
            "Hello World", thisAssemblyPath, "Walkthrough.HelloWorld");

         PushButton pushButton = ribbonPanel.AddItem(buttonData) as PushButton;

         
         
         
         // Optionally, other properties may be assigned to the button
         // a) tool-tip
         pushButton.ToolTip = "Say hello to the entire world.";

         // b) large bitmap
         Uri uriImage = new Uri(@"C:\globe.png");
         BitmapImage largeImage = new BitmapImage(uriImage);
         pushButton.LargeImage = largeImage;

         return Result.Succeeded;
      }

      public Result OnShutdown(UIControlledApplication application)
      {
         // nothing to clean up in this simple case
         return Result.Succeeded;
      }
   }
   /// <remarks>
   /// The "HelloWorld" external command. The class must be Public.
   /// </remarks>
[Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
   public class HelloWorld : IExternalCommand
   {
    
   	// The main Execute method (inherited from IExternalCommand) must be public
      public Autodesk.Revit.UI.Result Execute(ExternalCommandData revit,
          ref string message, ElementSet elements)
      {
   		Document doc = revit.Application.ActiveUIDocument.Document;
   		
   		Transaction trans = new Transaction(doc);
        trans.Start("CreationMurAuto");


       //Create line 
        XYZ start = new XYZ(0,0,0);
        XYZ end = new XYZ(100,100,0);
       
        Curve wallLine = Line.CreateBound(start, end);
        Level nivel = Level.Create(doc, 20.0);


		Wall.Create(doc, wallLine, nivel.Id, false);
        
        trans.Dispose();
        return Result.Succeeded;

      }
   }
}

Thank you

2 REPLIES 2
Message 2 of 3
Revitalizer
in reply to: Anonymous

Revitalizer
Advisor
Advisor
Accepted solution

Hi,

 

"trans.Commit()" is missing.

 

Revitalizer




Rudolf Honke
Software Developer
Mensch und Maschine





0 Likes

Hi,

 

"trans.Commit()" is missing.

 

Revitalizer




Rudolf Honke
Software Developer
Mensch und Maschine





Message 3 of 3
Anonymous
in reply to: Revitalizer

Anonymous
Not applicable

It worked fine! Thanks a lot.

0 Likes

It worked fine! Thanks a lot.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report