Equivalent to (getdist ...) in Revit?

Equivalent to (getdist ...) in Revit?

lionel.kai
Advisor Advisor
944 Views
6 Replies
Message 1 of 7

Equivalent to (getdist ...) in Revit?

lionel.kai
Advisor
Advisor

I created a quick-and-dirty Add-in that needs the user to input a distance. However, there doesn't seem to be a ready-made input function in revit - only single-point input (or box). I'm looking for something similar to AutoLISP's getdist or getpoint (that would show a line from the first point as the user is inputting the second point)? Code is below.

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Autodesk.Revit.ApplicationServices;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using Autodesk.Revit.UI.Selection;

namespace MeasSchedRowHt
{
    [Transaction(TransactionMode.Manual)]
    [Regeneration(RegenerationOption.Manual)]

    public class Class1 : IExternalCommand
    {
        static double ScheduleRowHeightToTextSizeRatio = 0.521725; // for Arial
        // ~48/100" row height gives 1/4" text (64/256")

        Result IExternalCommand.Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            //Get application and document objects
            UIApplication uiapp = commandData.Application;
            Document doc = uiapp.ActiveUIDocument.Document;
            View view = doc.ActiveView;

            try
            {
                //User picks 2 corners
                Selection sel = uiapp.ActiveUIDocument.Selection;
                XYZ point1 = sel.PickPoint("Please pick first point to measure from");
                XYZ point2 = sel.PickPoint("Please pick second point to measure to");

                //calculate distance between points
                double distFEET = point1.DistanceTo(point2);
                double textHeightINCHES = distFEET * 12.0 * ScheduleRowHeightToTextSizeRatio;
                double textHeight256ths = textHeightINCHES * 256.0; // assume the text height will be less than 1"

                TaskDialog.Show("Measure Schedule Row Height",
                    "Measured (desired) Schedule Row Height: " + distFEET + " (feet or metric)\r\n" +
                    "\r\n" +
                    "Arial Text Height to use for Spacer Column: " + distFEET * ScheduleRowHeightToTextSizeRatio + " (if metric)\r\n" +
                    "\r\n" +
                    "\r\n" +
                    "Measured (desired) Schedule Row Height: " + distFEET * 12.0 + " (inches, if applicable)\r\n" +
                    "\r\n" +
                    "Arial Text Height to use for Spacer Column: \r\n" +
                    "\t" + textHeightINCHES + " (inches)\r\n" +
                    "\t" + textHeight256ths.ToString("0.0") + "/256\""); // gives 0.0/256"

            }
            //If the user right-clicks or presses Esc, handle the exception
            catch (Autodesk.Revit.Exceptions.OperationCanceledException)
            {
                return Result.Cancelled;
            }
            //Catch other errors
            catch (Exception ex)
            {
                message = ex.Message;
                return Result.Failed;
            }

            return Result.Succeeded;
        }
    }
} 

 


Lionel J. Camara
BIM Manager at KAI Hawaii, Inc. - Structural and Forensic Engineers
Autodesk Certified Professional
0 Likes
Accepted solutions (1)
945 Views
6 Replies
Replies (6)
Message 2 of 7

jeremytammik
Autodesk
Autodesk

Sorry, the Revit API does not offer anything comparable to (getdist ...).

  

You can implement a .NET form asking for a numeric distance. However, it will be pretty hard to display anything useful on the graphics screen matching the current input value.

  

Please be aware that you will have a hard time trying to port code from AutoCAD to Revit one-to-one, since they are such very different animals. Here are a couple of discussions underlining that fact:

  

https://thebuildingcoder.typepad.com/blog/about-the-author.html#5.41

  

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 3 of 7

lionel.kai
Advisor
Advisor
Accepted solution

Thanks for the reply, Jeremy. That's what I was afraid of. It seems that Revit doesn't have many capabilities for smooth user input with add-ins. I'm not actually porting anything from AutoCAD, I am just much more familiar with customization using LISP. In our office almost every AutoCAD Command is customized, but it still feels like AutoCAD. The same cannot be said of Revit however - every customization for Revit is very clunky. And besides, most of our AutoCAD customization had to do with maintaining office standards or drawing faster, but in Revit that's handled by the project settings or custom families, with little capability for improvement otherwise.

 

I made the routine thinking it would make it easier for the drafters to not have to look up the fudge factor relating text height to schedule row height (when formatting revision schedules) - measure a distance, multiply it by a constant, then tell the user.

 

FYI, I've added a wish list item for this:

API: add a PickDist (and/or PickPoint with a starting point) 


Lionel J. Camara
BIM Manager at KAI Hawaii, Inc. - Structural and Forensic Engineers
Autodesk Certified Professional
Message 4 of 7

jeremytammik
Autodesk
Autodesk

Thank you for your appreciation, understanding and wish list item.

 

Yes, Revit sort of insists that you use the built-in native tools and makes it hard to create your own that differ.

 

This also has to do with enforcing the pretty strict BIM paradigm.

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 5 of 7

lionel.kai
Advisor
Advisor

That's one of my major issues with Revit add-ins too - you can't just change a setting and then trigger a native Revit command.

 

So from an "official Autodesk" point of view, how should I be requesting user input in a way that aligns with the "BIM paradigm"? Maybe by having the user select two adjacent parallel lines from the revision schedule grid instead? And then my Add-In could measure the distance between them... Even after more than 10 years using Revit full-time I still tend to think certain ways, such as using detail lines to measure distances because it's often easier than creating a dimension (and snaps better). Maybe I could do that instead? Have the user draw a line, then measure its length and delete it. But that's part of the problem too - I didn't want to spend hours on this relatively simple Add-In. 😞

 

Anyway, I think I am going to just leave it as is. Thanks!


Lionel J. Camara
BIM Manager at KAI Hawaii, Inc. - Structural and Forensic Engineers
Autodesk Certified Professional
0 Likes
Message 6 of 7

BobbyC.Jones
Advocate
Advocate

I too have wished for better user input control.  Maybe one day, right  🙂

 

As for changing a setting and firing a native command, I found the combination of SetDefaultElementTypeId() and PostCommand() very powerful.

--
Bobby C. Jones
0 Likes
Message 7 of 7

jeremytammik
Autodesk
Autodesk

I awfully sorry to admit that I think a bit like you describe too... My first CAD experience was via AutoLISP, in AutoCAD, then ADS (the AutoCAD Development System, a C wrapper around AutoLISP), followed by ARX, which only later became ObjectARX... you can imagine my initial consternation and frustration trying to get to grips with the Revit API back in 2008, which allowed no freedom at all, in comparison...   🙂

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder