Category: Autocad .Net API

This documents the work I’ve done on the Autocad API.

I will be posting code and helpful methods which you might find of use.

Thank you!

  • How to do some simple projections via AutoCAD’s .net API

    How to do some simple projections via AutoCAD’s .net API

    Projections via AutoCAD’s .net API can be confusing. You need to specify a direction, and a plane, upon which you can project a point to. It can be confusing unless it’s clearly spelled out with an example: see below.:

    // insert the usual references
    
    
    Document doc = Application.DocumentManager.MdiActiveDocument;
    Database db = doc.Database;
    
    using (Transaction tr = db.TransactionManager.StartTransaction())
    {
        BlockTable blockTable = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
        BlockTableRecord modelSpace = tr.GetObject(blockTable[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
    
        // the original originalLine
        using (Line originalLine = new Line(Point3d.Origin, new Point3d(5, 5, 0)))
        {
            modelSpace.AppendEntity(originalLine);
            tr.AddNewlyCreatedDBObject(originalLine, true);
    
            // but we want to project it ONTO a plane.
            Plane plane = new Plane(Point3d.Origin,  new Vector3d(0,1,0));
    
            // project the originalLine onto a plane.
            Matrix3d projection = Matrix3d.Projection(plane, - Vector3d.YAxis);                            
    
            Line projectedLine = new Line(originalLine.StartPoint.TransformBy(projection), originalLine.EndPoint.Project(plane, -1 * Vector3d.YAxis));
            plane.Dispose();
    
    
            modelSpace.AppendEntity(projectedLine);
            tr.AddNewlyCreatedDBObject(projectedLine, true);                            
        }
    
        tr.Commit();
    }
  • IntelliCad based Tools to support Material Take-off

    You don’t need to spend $30,000 p/a on Tekla licenses. You can estimate steel based on IntelliCad based software. Here’s some software I wrote to make this happen:

     

    How to Model Beams on Intellicad based software from Tek1 on Vimeo.

     

     

    Demo: Create beam and Create Beam Lines from Tek1 on Vimeo.

  • Getting Ordered Intersection Points of a Line along a Particular Direction (Part II)

    This part II of a two part post. Please see part one here.

    We’re moving forward with the next set of requirements. Once we have the intersection points we need to do the following:

    Notice how these lines are staggered (in terms of their offset from the main line) and how the colours are alternating?
    Notice how these lines are staggered (in terms of their offset from the main line) and how the colours are alternating?

    1. Create lines out of them, and then
    2. Offset them from the main line, and staggered them by a specified amount
    3. and color every alternating line a certain color.

    The code to do so is as follows. Hopefully it will be pretty self explanatory:

  • Getting Ordered Intersection Points of a Line along a Particular Direction

    It seems to be a common problem: getting intersection points along a line.

    This is what we want:

    We want the ordered points.
    Notice how the points are nicely ordered, from the start point of the picked line?

    Here’s how I solved it:

  • Ordering Lines using Linq (AutoCAD .net API)

    This is a simple example of how Linq can be used to filter, map and order a set of lines.

    The code is pretty self-explanatory. It is a useful example which can be used to springboard towards further, more sophisticated use-cases according to your own requirements.

     

     

  • How to get help on Autocad command without wasting anyone’s time

    Help on Autocad commands are right there at the command line. However, too many times new users ask questions. Not just new users, experienced users as well get used to some way of working and  stay there without checking out the full documentation. This video show where the command is available

    https://youtu.be/3bEKW40A8SA

  • LineDirectionJigger (AutoCAD .net API Jig code)

    Many times, over my career in using AutoCAD, I’ve had this requirement: given a particular input vector, I’ve wanted to a jig a line perpendicular to it, within my code.

    Accordingly, I have written a little class which I call the LineDirectionJigger: basically it restricts users to select one direction or another. For the sake of completeness I”m posting everything, but you will want to focus on the calling class (i.e. the getViewDirection() method) and the server, which is of course the LineDirectionJigger class.

    You can see a demo of this jig starting at about 1:26 in this video here.

    And here is the code:

  • Precast Efficiency Tool: Efficiently Create Elevation Drawings

    Demo:

    Command: Marking Plan To Elevation from Tek1 on Vimeo.

    What does this command do?

    It quickly and easily allows you to create elevation drawings given a certain marking plan view of a panel. You need to first: (i) select the applicable panel lines, then (ii) you need to select a view direction. The way you select a view direction is by selecting a panel line which is perpendicular to the view direction, and using the resulting jig to select the direction you want to view the panel. (iii) Then, you must use a bounding box to select any applicable grid lines you need. (iv) use the resulting jig to position the panel lines where you want.

     Benefits of this command:

    1. Reduces Errors and
    2. Improves Efficiency.