Results 1 to 2 of 2

Thread: Macro Manager does not like code

  1. #1
    Member
    Join Date
    2005-12
    Posts
    44
    Login to Give a bone
    0

    Default Macro Manager does not like code

    I have included a partial piece of my code that basically just draws a line on a plot sheet. It passes when i do the F5 (debugger) but when i get out of the API and try to run it in Macro Manager the Run button is deactivated. This is a test run for another macro that i am trying to put together. I am on 2011 and using windows xp x64. I'm guessing Macro Manager does not like something in the code but i cannot tell what it is??

    Code:
    using XYZ = Autodesk.Revit.Geometry.XYZ;
    using LINE = Autodesk.Revit.Geometry.Line;
    
    UIAPPLICATION app = m_doc.Application;
    
    //declare variables
    double x1 = (5.0);
    double y1 = (5.0);
    double z =  (0.0);
    double x2 = (7.0);
    double y2 = (5.0);
                           
    //create object
    XYZ point1 = app.Application.Create.NewXYZ(x1, y1, z);   //takes doubles
    XYZ point2 = app.Application.Create.NewXYZ(x2, y2, z);
    
    //Create Line
    LINE line = app.Application.Create.NewLineBound(point1, point2);

  2. #2
    100 Club
    Join Date
    2007-10
    Location
    Brisbane
    Posts
    138
    Login to Give a bone
    0

    Default Re: Macro Manager does not like code

    It looks like there's a couple of things happening here from what I can tell.
    First off, the Revit.Geometry namespace is no longer used in Revit 2011. You should only need to reference:

    using Autodesk.Revit.DB;
    using Autodesk.Revit.UI;

    Then in the actual code, here's what I used in my VSTA macro:
    Code:
          public void DrawLine()
            {
                Document doc = this.Document;
                UIApplication app = this.Application;
    
                //Create the Points
                double x1 = 5.0;
                double y1 = 5.0;
                double z = 0.0;
                double x2 = 117.0;
                double y2 = 115.0;
                XYZ point1 = app.Application.Create.NewXYZ(x1, y1, z);
                XYZ point2 = app.Application.Create.NewXYZ(x2, y2, z);
    
                //Create line
                Line line = app.Application.Create.NewLineBound(point1, point2);
                DetailCurve detailCurve = doc.Create.NewDetailCurve(doc.ActiveView, line);
    
                TaskDialog.Show("Done", "Line Created");
            }
    What you can do is create a new module in VSTA macro manager, then click CreateMacro and call it DrawLine, then just insert the code from above. What this should do, is draw a long line on the active sheet/view (I edited your distances to make it a bit more noticeable, feel free to change it back). The main thing that differs from your code is that I've added the following line:

    DetailCurve detailCurve = doc.Create.NewDetailCurve(doc.ActiveView, line);

    It's a little confusing, you have to create a Line, which doesn't actually display anything - it's simply a way of representing some Geometry. Then, we tell Revit we want to create a detail line that matches this geometry by creating a 'DetailCurve'.

Similar Threads

  1. CP222-2: Autodesk Revit VSTA: Writing Your First Macro An Introduction to the Macro Manager
    By Autodesk University in forum Customization and Programming
    Replies: 0
    Last Post: 2014-12-01, 02:12 AM
  2. Replies: 0
    Last Post: 2012-04-27, 03:20 AM
  3. Revit Architecture 2009 VSTA Macro Manager Bug?
    By FWSchreck in forum Revit - API
    Replies: 1
    Last Post: 2009-03-27, 05:22 PM
  4. Macro Manager bugs
    By drodrigues in forum Revit - API
    Replies: 0
    Last Post: 2009-02-11, 06:12 PM
  5. Execute Command Macro Code programmatically
    By autocad.wishlist1734 in forum AutoCAD Wish List
    Replies: 0
    Last Post: 2007-09-18, 01:52 PM

Posting Permissions

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