Results 1 to 3 of 3

Thread: 2013: Create line -Run Macro Failed error

  1. #1
    Member
    Join Date
    2013-04
    Posts
    2
    0 Did you find this post helpful? Yes

    Exclamation 2013: Create line -Run Macro Failed error

    Note to Mods: I can only select the 2014 prefix...

    I have recently begun learning how to set up macros in Revit 2013. I can set up a macro easily that will create a TaskDialog box. I then tried to follow numerous tutorials on creating a simple line in Revit. When I run the macro I just get the error below:
    error.JPG
    I have narrowed it down to this bit of code :
    Code:
    SketchPlane planeSF = doc.FamilyCreate.NewSketchPlane(plane);
    The .cs file looks like this :
    /*

    * Revit Macro created by SharpDevelop

    * User: s.bland

    * Date: 25/04/2013

    * Time: 10:06

    *

    * To change this template use Tools | Options | Coding | Edit Standard Headers.

    */

    using System;

    using System.Diagnostics;

    using System.IO;

    using System.Linq;

    using System.Text;

    using System.Collections.Generic;

    using Autodesk.Revit.DB;

    using Autodesk.Revit.DB.Architecture;

    using Autodesk.Revit.DB.Events;

    using Autodesk.Revit.UI.Events;

    using Autodesk.Revit.UI;

    using Autodesk.Revit.UI.Selection;

    using Autodesk.Revit.ApplicationServices;





    namespace TestingModule

    {

    [Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]

    [Autodesk.Revit.UI.Macros.AddInId("A08DF99D-E407-4529-B84A-CB5F57715466")]

    public partial class ThisApplication

    {

    private void Module_Startup(object sender, EventArgs e)

    {



    }



    private void Module_Shutdown(object sender, EventArgs e)

    {



    }



    #region Revit Macros generated code

    private void InternalStartup()

    {

    this.Startup += new System.EventHandler(Module_Startup);

    this.Shutdown += new System.EventHandler(Module_Shutdown);

    }

    #endregion

    public void TestMacro()

    {

    // Begin a series of instructions to Revit

    Transaction trans1 = new Transaction(ActiveUIDocument.Document, "Line");

    trans1.Start();



    // Define the document into which the geometry will be placed

    Document doc = ActiveUIDocument.Document;



    // Revit uses Imperial Feet as its internal definition for length -

    // So provide a conversion variable in order to work in Millimetres:-

    double ftMM = 1 / 304.8;



    // Define two points on the Line - multiply by the conversion variable

    XYZ point01 = new XYZ(); // Defaults to (0.0, 0.0, 0.0) if no values are provided

    XYZ point02 = new XYZ(3000.0, 2400.0, 0.0) * ftMM;



    // Create the Line geometry - 'true' indicates it terminates at the setout points

    Line line01 = doc.Application.Create.NewLine(point01, point02, true);



    // Define the Plane for the Line placement - X-Axis, Y-Axis, Origin

    Plane plane = doc.Application.Create.NewPlane(XYZ.BasisX, XYZ.BasisY, point01);



    // Create a Sketch Plane from this Plane in order to display the Line

    SketchPlane planeSF = doc.FamilyCreate.NewSketchPlane(plane);



    // Display the Line

    ModelLine line01F = doc.FamilyCreate.NewModelCurve(line01, planeSF) as ModelLine;



    // End the series of instructions

    trans1.Commit();



    }

    }

    }

    I hit the same problems when I try to create anything.

    Any ideas?
    Thanks for the help.
    Attached Images Attached Images

  2. #2
    Member
    Join Date
    2012-09
    Posts
    28
    0 Did you find this post helpful? Yes

    Default Re: 2013: Create line -Run Macro Failed error

    What kind of document are you using the macro in?

    I see that you're using doc.FamilyCreate.NewSketchPlane & doc.FamilyCreate.NewModelCurve - these functions only work when used inside Family Documents.

    If this is being used in a regular model, you should use doc.Create.NewSketchPlane and doc.Create.NewModelCurve to accomplish your task.

    You can use the doc.IsFamilyDocument property to determine whether the document is a family document or not.


    On a side note, it's good practice to wrap your transactions in a using block like the following:

    Code:
    using (Transaction trans1 = new Transaction(ActiveUIDocument.Document, "Line"))
    {
    trans1.Start();
    
    //Code Goes Here
    
    trans1.Commit();
    }

  3. #3
    Member
    Join Date
    2013-04
    Posts
    2
    0 Did you find this post helpful? Yes

    Default Re: 2013: Create line -Run Macro Failed error

    That worked great! Thanks

Similar Threads

  1. can't create VSTA MACRO Revit 2013
    By avzalingen811374 in forum Revit - API
    Replies: 0
    Last Post: 2012-09-25, 11:19 AM
  2. Replies: 0
    Last Post: 2012-05-13, 07:57 AM
  3. Replies: 1
    Last Post: 2009-02-27, 12:31 PM
  4. Replies: 2
    Last Post: 2006-06-20, 05:12 PM
  5. Failed to Create object
    By timd in forum AutoCAD General
    Replies: 3
    Last Post: 2004-12-07, 08:36 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •