Tag: .net

  • Jigging with SHIFT, CTRL and Mouse Wheel Functionality (AutoCAD .net API)

    If writing software then make it easy for your users.
    User Input is critical. You gotta make the user experience amazing.

    Any AutoCAD programmer knows that things which an algorithm may take a million years and infinite computational power to do can sometimes be easily done by a human being instantly. In the same way it is sometimes much easier to give a human being the ability to choose: then you can get an optimum result without complex algorithms.

    This post is a code snipped of how you can utilise the CTRL + SHIFT + Mouse Wheel (up/down) mechanisms in order to produce different desired results when operating a custom jig.

    Here is the code:

     

    So when the appropriate user input happens, then the jig can respond accordingly. Yes it’s true – the OOP purists will say: “you’re passing a concrete type in there” – I can always change it later if I want.

  • Comparing Lines – IEqualityComparer (AutoCAD .net)

    It’s not very often that I write something on the Autocad .net API, so here’s something which you, I suppose, will need one day:

     

    If you want to compare two lines, with a tolerance, in a collection then you’d need a LineComparer. The MSDN guide says that one should inherit from EqualityComparer, so unquestioningly, I did their bidding. The results are as below.

    Take careful note of the Hashcode. You want lines that are similar – and are within the tolerance to return the same hashcode. If they are outside the tolerance then the chances of two different lines returning the same hashcode is minimal.

    Lines are equal if their start and ends points are equal (or vice versa). They are also more or less equal if they return the same hash code. In such cases, then the equals method is run.

  • Introducing AcCoreConsole

    AcCoreConsole is AutoDesk’s brand new toy. It is basically a command line version of AutoCAD. It has no “User Interface”. That means that if you are a user, there are no menus to click on. No buttons. Nothing. You have to do everything via text. Via command line, like it was in the very beginning.

    You cannot see lines.

    What is the benefit of this you ask? Well it allows for super fast batch processing.

    Please watch my screencast for a very brief introduction to this new technology. I will provide another video of the batch processing power of this babey.

     

    https://knowledge.autodesk.com/community/screencast/d6ef5929-4208-443d-8b53-eca0c637328a

    I hope you learn something.

     

    Ben

  • Writing Clear Tests

    A very rudimentary but fundamental tip: When you are testing something, it is absolutely paramount that you have a crystal clear idea in your mind of exactly what you are testing.

    If you want to ensure that there are 4 tyres on your car, before you start out from your garage, you must check for exactly that:

    • are there four tyres on my car?

    If you test for something else:

    • are there tyres on my car?

    Then you may win some of the time, but other times you will get confusing and conflicting results.  What if somebody adds 3 tyres, but omits one tyre? Obviously this car will have a lot of problems going forward (pun intended), and you will wonder why all of a sudden your tests are all passing but the car is failing?

    What is going on? And it will not be immediately obvious what is going on. Because the mind can deceive, and while the eyes see, they may yet be blind. You’ll be spending a loooooooooooot of time trying to debug that one little glitch. Save yourself the headache, especially if you’re looking at the code 6 months later.

     

    So it is a very simple, but very powerful tip:

    • be very specific and clear in your mind as to exactly what you are testing for.