create your own

CAD Programming

78
rate or flag this page

By megamass


CAD Programming


CAD Programming

Most of CAD software in the market allow the CAD programming on them. The use of such language simple and accessible to ordinary users, making it possible to develop applications themselves, so as to accelerate and automate their processes of work.

So you can:

  • Create macro commands, with breaks for entering data;
  • Automating and accelerating processes of project and design;
  • Create and adapt the dialog boxes;
  • Handle the objects of the Software;
  • Make mathematical calculations, involving geometric parameters of objects;
  • Access to the database and search for the design modifications;
  • Working with files;
  • Communicate with other programs.

Touched only two programs that allow cad programming is: AutoCAD and Solidworks.

Programming within the AutoCAD

One of the great advantages of AutoCAD is its flexibility and adaptability to any technical area. The development of specific applications in AutoCAD does not require that you be expert in computer, only to have reasonable knowledge as a user of the program.

There are two different cad programming languages:

  1. AutoLISP, Visual LISP environment and dialogs DCL;
  2. VBA (Visual Basic for Applications) (from the 2000 version).

1. Cad Programming in AutoLISP

The AutoLISP is a programming language inside of AutoCAD, which allows functions from this program, create new functions, operations, entities, etc.. Many "Add-On's" are scheduled in this language. Like any programming language, it is intended that, from data provided by the user (input), give them specific answers, or make one or more transactions (output).

  • Evaluate expressions in Lisp

The interpreter of Lisp is called evaluator. The entire entrance to the Lisp is processed through the evaluator. Everything within the AutoLisp against the assessor returns value as a result.

  • Rate program Lists

If the first element of the list is the name of a subr or a defined function, the subr or function is executed, the rest of the list is used as parameters to the function or subr. If the first element of the list is not a function or subr, you get an error message: "bad function."

  • Develop programmes in AutoLisp - without a cad programming environment

Shall be used while the two programs AutoCAD and a simple text editor (eg Edit or Windows NotePad). It takes the following steps:

  1. Enter in the AutoCAD;
  2. It is called the text editor using the command EDIT;
  3. Edit out the functions that make up the program with a file extension LSP (eg programa1.lsp). -- Save editing and leaves the editor (automatically returning to the AutoCAD); Push-up the file in AutoCAD;
  4. To enforce the functions contained in the file with (name-of-position) or name-of-function.
  • Load cad programming AutoLisp in AutoCAD

At the command line type (load "unit-to-disk: \ \ sub-directory \ \-name promaga-to-extension"), Example:

- Command: (load "c: \ \ trab \ \ programa1.lsp")

AutoLisp in the line of command of AutoCAD

It is possible to assess in terms AutoLisp and functions until the line of command of AutoCAD. This feature is widely used for experimentation and testing.

Example

Programme estimates that the average - media.lsp:

;;; Main Program (defun c: mediatestes () (setq t1 (getreal "\ nNota test-1")) (setq t2 (getreal "\ nNota test-2")) (setq note (sum-and - divides)) (princ "\ = nMedia of tests") (princ note) (principle));; function sum-and-divide (defun sum-and-divide () (/ (+ t1 t2) 3.0))

Load the file media.lsp and perform the function mediatestes:

Command: (load "c: \ \ trab \ \ media.lsp") Command: Note mediatestes test-1: 5.0 Note test-2: 7.0 Media testing = 6.0 Command:

2. Cad Programming in VBA

Microsoft VBA is a programming environment oriented to objects designed to allow for cad programming similar to Visual Basic (VB). The main difference between the VB and VBA is that the VBA flows in AutoCAD. The VBA also provides integration with other applications that use VBA., Such as Microsoft Word and Microsoft Excel.

There are advantages in the fourth cad programming in VBA :

  • The programming environment is easy to learn and use;
  • As the VBA flows in AutoCAD, which means the programs run quickly;
  • The creation of interface is fast and efficient;
  • Projects may be embedded in the actual design or be independent of it.

Charging a project and implement the macro initial

- vbaload [way] \ Pa.dvb-vbarun [way] \ Mod_Inicio_pa

  • Creation of three-dimensional elements:

'Set the dimensions and create the wall in left center space model (0) = 0: center (1) = 0: center (2) = 0 = length Largura_cabina width = Espessura_parede height = Altura_cabina September Parede_Esquerda = ThisDrawing.ModelSpace.AddBox ( center, length, width, height)

  • Copy of elements:

'Copy the hole, setting the botoneira Dim copia_furo The Acad3DSolid September copia_furo = Furos_Placa_Botoneira.Copy () Dim point1 (0 to 2) The Double Dim point2 (0 to 2) The Double point1 (0) = 0: point1 (1) = 0: point1 (2) = 0 point2 (0) = 0: point2 (1) = 0: point2 (2) = 180 copia_furo.Move point1, point2

  • Treatment of Layers:

'Treatment of layers (of the cabin trim)

If Form_cabina.Cxcbo_cabina.Text = "INOX" Then Dim LayerInox The AcadLayer September LayerInox = ThisDrawing.Layers.Add (INOX) ThisDrawing.ActiveLayer = 253 = LayerInox LayerInox.Color

End If

  • Working with Microsoft Access

'Search of the model guides the chassis of the cab of the lift in the database Dim Guiascab The Recordset Dim Pesqguias The String Pesqguias = "SELECT Guia_cabina FROM WHERE Lifts Load ='" & Form_ascensor.Cxcbo_carga & " '" September Guiascab = MyDb.OpenRecordset (Pesqguias) = Guiascab Guides! Guia_cabina Guiascab.Close A_in_guias = Inserir_texto_Mod_tabela_alinhado_centro (Guides, 733.4, 513)

"Add a box of combinations from a table of the database Dim Design The Recordset September MyDb = OpenDatabase (" c: \ Draft \ Pac.mdb ") Cxcbo_Projectista.Clear September Design MyDb.OpenRecordset = (" Projectistas ") While Not Projectista.EOF

Cxcbo_Projectista.AddItem Projectista.Fields ( "Design"). Projectista.MoveNext Value

Wend Projectista.Close If Cxcbo_Projectista.ListCount> 0 Then

Cxcbo_Projectista.ListIndex = 0 End If

  • Working with Microsoft Excel

'Insert in the spreadsheet Pac.xls the listing of materials of the lift sub

Mod_insert_excel () Dim Excel2 The Excel.Application Dim ExcelWorkbook2 The Object September Excel2 = New Excel.Application September ExcelWorkbook2 = Excel.Workbooks.Open ( "c: \ Project \ Pac.xls ") in September MyDb = OpenDatabase (" c: \ Draft \ Pac.mdb ") ... Worksheets ( "imagine"). Cells (39, 17). ... Value = Largchapa Worksheets ( "imagine"). Cells (10, 2). Value = Form_cliente.Cxtxt_ref_empresa Worksheets ( "imagine"). Cells (12, 2). ... Value = Form_ascensor.Cxtxt_pisos ExcelWorkbook2.SaveAs "C: \ Draft \ Xls \" Form_cliente.Cxtxt_ref_empresa & & "" Excel2.Application.Quit End Sub

ONLINE BOOK STORE

AutoCAD 2008 For Dummies (For Dummies (Computers)) AutoCAD 2008 For Dummies (For Dummies (Computers))
Price: $13.55
List Price: $24.99
Expert CAD Management: The Complete Guide Expert CAD Management: The Complete Guide
Price: $17.59
List Price: $49.99
Visual Lisp: A Guide to Artful Programming (Autodesk's Programmer) Visual Lisp: A Guide to Artful Programming (Autodesk's Programmer)
Price: $69.99
List Price: $83.95
Lisp in Small Pieces Lisp in Small Pieces
Price: $77.69
List Price: $95.00
AutoCAD 2008 and AutoCAD LT 2008 Bible AutoCAD 2008 and AutoCAD LT 2008 Bible
Price: $25.94
List Price: $49.99

Comments

RSS for comments on this Hub

No comments yet.

Submit a Comment

Members and Guests

Sign in or sign up and post using a hubpages account.


optional


  • No HTML is allowed in comments, but URLs will be hyperlinked
  • Comments are not for promoting your hubs or other sites

working