Welcome to CADVANTAGE’s No Nonsense, Quick Start, Step by Step tutorial for Shape Programming in AutoCAD .

This tutorial is part of the CAD-CAM @ Home scheme currently available in the city of Aurangabad in India.

The tutorial is a Goodwill Gesture for all AutoCAD users who take pains to go out of way and learn new things.

To learn more about computers in general and CAD CAM CAE in particular as detailed below, you may enroll for the
CAD++ [ CAD @ Home ] program at :

CADVANTAGE ( where AutoCAD is taught FREE )
C 2 - 6, N 7, CIDCO,
Opp. Onkar Gas, Behind Swamikripa STD,
Aurangabad 431003
India
Ph : 0240 - 480767
Email : CadGuruCool@yahoo.com
Webpage : www.geocities.com/CadGuruCool



Shape Programming in AutoCAD


Step 1

What is a Shape file ?

AutoCAD Shape file is an ASCII file with extension .shp

The files are created using a text editor like notepad and must be compiled before they can be used in a drawing.

When a shape file is compiled, a new file is created.

The new file is given the original filename plus the extension .shx

The shx file is the file used by AutoCAD in a drawing session.


Unlike blocks, shapes have a smaller memory footprint

Step 2

What goes inside a Shape file ?

Shape files contain only basic drawing entities like lines and arcs.

They are similar to blocks, in that their purpose is to simplify the process of repeating a set of entities with varying scales. However, shapes have certain advantages over blocks :

  • Shapes are faster to insert and regenerate on screen.
  • They are more memory-efficient.
  • Shapes take less space on disk as part of a drawing than blocks (see figure in step 1).




  • .
    Step 3

    We will use Notepad to write the Shape file.

    Click the Start button and select Run.
    Step 4

    A dilaog box will appear.

    Type notepad.

    Click OK or press Enter on the keyboard.

    Step 5

    The general procedure for shapes will be:

  • Write the shape description file using notepad.
  • Save the file with a .shp extension.
  • Use the AutoCAD compile command to compile the .shp to a .shx file.
  • Use the AutoCAD load command to load the .shx file.
  • Use the AutoCAD shape command to insert the shape.



  • Step 6

    As shown in figure on the right, the shape file consists of two parts :

  • The Header part on line 1
  • The Numerical Description part on subsequent lines.

  • Step 7

    In the header part, * signals the begining of the first shape in file and then the shape number ie. 1

    Total 255 shapes can be defined in a single .shp file but the total number of characters (including spaces) in the file should not exceed 2000 and maximum characters that are allowed on a single line are 127.

    The next number 8 is the total number of numerical description elements in line 2. This number is normally added after completing the shape definition.

    The last one is the shape name which is always in uppercase. Shape name in lowercase is ignored during compilation.


    .
    Step 8

    As discussed in Step 2, a shape file consists of lines and arcs. But these lines and arcs are not defined as we do in AutoCAD.

    In Shapes, lines can be drawn along 16 standard angles as shown in figure on the right.

    Also, the number system is Hexadecimal.
    Unlike in the decimal system, where the base for counting cycle is 10, in hexadecimal system, the base is 16.

    Here, 10 is written as A, 11 is written as B and so on.
    After it reaches F (for 15), it continues with number 10. Number 10 in hexadecimal notation, therefore, has the same value as 16 in decimal notation.


    AutoCAD Shape file standard angles
    Step 9

    Similarly, arcs are defined as 8 standard Octant arcs.

    You can draw any arc out of these 8 arcs or their multiples.



    AutoCAD Shape file standard octant arcs.

    Step 10

    We want to draw the resistance shape as shown in figure.

    The header line will be as shown in figure.

  • The * indicates the begining of a new shape.
  • The next number 1 is the shape number. The number can be between 1 to 255 but should not repeat for another shape definition in the same file.
  • The next number is the number of shape description elements that are to follow.
    Since we haven't got any idea about the probable number of elements, we put an x temporarily. After the description is complete, we will change it to 8 as shown in figure.
    You can count the number of elements in the second line begining with 020 till the terminating 0 and check if they are 8.

  • The last is the shape name which is always in uppercase. Shape names in lowercase are ignored during compilation.




  • Step 11

    On the second line, numerical description elements are written.

    The first element is defined as 020, where :

  • The first 0 denotes hexadecimal system
  • The next number 2 is the length of the element.
  • The third number 0 is the standard shape angle as discussed in step 8.


  • Similarly, the next inclined element is drawn 2 units at Standard Shape Angle of 3 and so on.

    The last element is 0 which denotes the end of shape definition.

    Now count the total number of elements and replace the x in the header line with this number.

    Don't forget to press Enter < Carraige Return > after the second line.

    Step 12

    To use this shape, save the file as resis.shp in notepad.

    Switch to AutoCAD and issue the compile command at the Command: prompt and select the resis.shp file.

    If there are no errors, AutoCAD will give the following message

    Compiling shape/font description file
    Compilation successful.
    Output file C:\My Documents\Tutorials\Shape\resis.shx
    contains 51 bytes.

    A new compiled file resis.shx is created.

    Type load at the AutoCAD Command: prompt and select the resis.shx file to load the shape.

    Type shape at the Command: prompt and enter the name resis to insert the resistance shape.







    Step 13

    Next, we want to draw the milled slot shape as shown in figure.

    The header line will be as shown in figure.

    If you want to define the shape in the same file as the resistor shape, then the header line will be :

    * 2 , 9 , SLOT





    .

    Step 14

    The milled slot has two lines and two arcs.

    As discussed in Step 9, there are 8 standard shape arcs called octant arcs.

    To draw a 90 degree arc in anti-clockwise direction as shown in figure, the shape element definition will be :

    00A,1,022

    where :

  • The element 00A is a signal element in hexadecimal notation indicating an octant arc description is to follow.
  • The next element 1 is the radius of the arc.
  • The 0 in 022 is again the hexadecimal notation similar to the first element in line description.
  • The first 2 in 022 indicates that the arc begining value ie. the octant arc 2 as shown in figure.
  • The last 2 in 022 are the total octant arcs to span. Here, the arc spans 2 octant arcs.


  • For a clockwise arc, the number will be -022 ie. negative.

    Step 15

    Coming to the milled slot, the first element is the bottom line.

    The line is along the standard shape angle 0 and length 2. It is written as 020

    Next is the arc on the right that goes anti-clockwise from the end of the first line.

    To begin an arc, use 00A which is called signal element.

    Next is the radius of the arc ie. 1





    Step 16

    The arc begins at octant 6 and spans 4 octant arcs as shown in figure on the right.

    The description element for this arc will be 064 where,

    The 0 is for hexadecimal notation,

    6 is the octant number for begining arc and 4 are the total octant arcs spanned.

    Similarly, the next two elements are defined.

    Every shape description ends with a 0

    Shape description should not end with the cursor on the last line with characters, but on a blank line.
    Press Enter at the keyboard for a Carraige Return.

    Now, count the number of numerical elements in the shape description part and type it in the header part. In this case it is 9.

    Save the file in notepad as slot.shp and execute the compile, load and shape commands in AutoCAD to use the shape as explained in Step 12.




    Step 17

    Want to dig deeper
    into Shapes ?

    Call CADVANTAGE Now !!! Ph : 0240 - 480767 in Aurangabad.



    Dig deep till you reach the other side of the globe - only at CADVANTAGE