Autolisp to Visual lisp: Design Solutions for Autocad instructor’s Guide Chapter One



Download 210.39 Kb.
Page7/8
Date05.05.2018
Size210.39 Kb.
#47999
1   2   3   4   5   6   7   8

Definitions

Object Oriented Programming – a method of programming in which the actual data used by an application is the major concern instead of the actual process involved to manipulate the data.


ActiveX - Is an outgrowth of two other Microsoft technologies called OLE (Object Linking and Embedding) and COM (Component Object Model).
Event Driven Programming – A program remains idle until the operator performs some action that triggers an event, such as moving a mouse, or pressing a button.
Structured Programming – A method of programming in which all programs are assumed to be interpreted by the computer starting from the beginning of the application and proceeding until it reaches the end. Statements and expressions are executed one after the other following the order in which they are presented.
Class – Is a template used to create an object. Classes are groups of relate objects that share common properties and methods.
Object – Is an individual member of a class or an instance of that class. Objects consists of two primary parts, the properties and methods.
Method – Are the procedures or function used to manipulate the data associated with an object.
Properties – The information regarding the characteristics of an object.
Data – Information consisting of character, number, images, etc. used by a computer program for processing.
Spaghetti Programming – A method of programming in which programs are not written to a set standard, thereby producing applications that are unreliable and difficult to maintain.
Array –
Safe Array –
Encapsulation – a method of ensuring the integrity of an object’s properties from unauthorized or even inappropriate access by letting the object control how data associated with the object is accessed.
Polymorphism – Is when a program treats different objects as if they were identical and each object reacts as it was originally intended.
Object Linking and Embedding – was intended as a means of creating compound documents.
Compound Object Modeling – COM (compound object modeling) provided a means of establishing interaction between software libraries, applications, system software, etc. COM does this by defining a standard by which applications can communicate with one another.
Parent Object – The original object in which an object is created from.
Child Object – An object that is created from other objects.
Inspection Tool – A Visual LISP tool that is used to examine the properties of an object.
Visual Basic – A programming Language developed by Microsoft for the rapid development of Windows based applications.
Visual Basic Application – A version of Visual Basic designed to allow a programmer to develop programs designed for specific applications (Word, Excel, PowerPoint, AutoCAD, etc.).

Variant – Is a variable that can contain different data types.


Wrapper Function – Is a standard function that encapsulates the code used by the application object (the VLA functions in Visual LISP are merely wrapper functions created from the AutoCAD type library)
Collection - Is a grouping of all related AutoCAD objects into categories.

Answers to Review Questions

2. After a wrapper function has been created Visual LISP’s Apropos feature can be used to list the ActiveX wrapper functions that have been.


3. In AutoLISP this is done by using the vlax-import-type-library (vlax-import-type-library :tlb-filename filename [ :methods-prefix mprefix :properties-prefix pprefix :constants-prefix cprefix])function.
4. The vlax-invoke-method function provides the developer with a means of calling ActiveX methods
5. Structured programming allowed the developer to create applications in a modular fashion, meaning that the program is broken up into manageable portions. Each portion was defined as a subroutine that can be called by the main program. Structured programming also provided the developer with an avenue for making decisions based upon information that has been tested against a specific condition. Finally, structured programming introduced the concept of loops.
6.
7. The methods are the procedures or functions used to manipulate the data associated with an object. To access the methods associated with an object created by an application other than AutoCAD, the vlax-invoke-method function should be used.
8. ActiveX is a COM based technology.
9. The vlax-get-object function establishes a connection to a currently running instance of an external application. If the application is not currently running or if the vlax-get-object function should return nil, then a connection to the specified application can be created through the AutoLISP function vla-create-object. This function creates a new instance of the target application object, after which it creates a connection to the instance.
10. False, the VLAX-GET-OBJECT just tries to establish a connection where as the VLAX-GET-OR-CREATE-OBJECT attempts to make a connection to the specified application object. If the connection cannot be established, then the function creates an instance of the application and then establishes a connection.
11. False, AutoCAD is an integral part of the AutoLISP programming language and therefore AutoCAD must be running.
12. False, The VL-LOAD-COM function must be loaded before ActiveX controls can be used in an AutoLISP application.
13. By either importing the application’s type library or using AutoLISP to make direct contact with that object’s methods, properties, or constants. When an object’s type library is imported into Visual LISP, AutoCAD automatically generates a set of wrapper functions for the imported features. Once the application object’s library has been imported into Visual LISP, then the wrapper function created can be accessed by the AutoLISP application and Visual LISP’s symbol features. Importing an applications object’s library can be beneficial to the developer; however, it can also have a dramatic impact on the application being developed by incorporating unnecessary methods, properties, and constants, thus adding to the amount of memory required by the application. To circumvent the adverse affects of loading an entire application object’s library, AutoLISP has three functions that allow the developer to access an application’s object without loading the application’s object library. They are vlax-invoke-method (vlax-invoke-method obj method arg [arg...]), vlax-get-property (vlax-get-property object property), and vlax-put-property (vlax-put-property obj property arg).
14. It frees valuable memory.
15. True
16. False, The vlax-import-type-library function allows the developer to specify the prefixes to append to the object’s methods, properties, and constants.
17. True
18. True
19.

(vl-load-com)

(SETQ application (VLAX-GET-ACAD-OBJECT)

;assigns a pointer to the AutoCAD Application

document (VLA-GET-ACTIVEDOCUMENT application)

;Connects to the current active document

modelspace (VLA-GET-MODELSPACE document)

)
20.

(vl-load-com)

(if (equal nil MS-Wordc-wd100Words)

(vlax-import-type-library

:tlb-filename

"C:\\Program Files\\Microsoft Office\\Office\\msword8.olb"

:methods-prefix

"MS-Wordm-"

:properties-prefix

"MS-Wordp-"

:constants-prefix

"MS-Wordc-"

)

)


21.

;;;********************************************************************

;;;

;;; Program Name: VL05.lsp



;;;

;;; Program Purpose: This program allows the user to construct a

;;; simple gear train, from the Pinion Gear RPM,

;;; the gear ratio, the diametral pitch, shaft

;;; diameter, and number of teeth on the pinion

;;; gear. The two gears are constructed as blocks,

;;; and the rpms, number of teeth and gear ratio

;;; of both gears are saved to the newly constructed

;;; entities in the form of extended entity data.

;;;


;;; Program Date: 2/31/99

;;;


;;; Written By: James Kevin Standiford

;;;


;;;********************************************************************

;;;********************************************************************

;;;

;;; Main Program



;;;

;;;********************************************************************

(DEFUN c:gear (/ rpm number_teeth

gear_ratio dia_pitch shaft_dia PT

pitch_dia gear_teeth gear_out Pinion_out

gear_rpm dist pt_x pt_y

pinion gear shaft_pinion

Shaft_gear lastent exdata1 newent1

exdata newent

)

(vl-load-com)



(SETQ application (VLAX-GET-ACAD-OBJECT)

document (VLA-GET-ACTIVEDOCUMENT application)

modelspace (VLA-GET-MODELSPACE document)

rpm (GETREAL "\nEnter RPM of Pinion Gear : ")

number_teeth (GETREAL "\nEnter Number of Teeth : ")

gear_ratio (/ 1 (GETREAL "\nEnter Gear Ratio : "))

dia_pitch (GETREAL "\nEnter Diametral Pitch : ")

shaft_dia (GETREAL "\nEnter Shaft Diameter : ")

PT (GETPOINT "\nSelect Point : ")

;;;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

;;; Calculates the pitch diameter, number of teeth on the gear,

;;; the outside diameter of the gear the outside diameter of the

;;; pinion, the distance between the pinion and the gear and the

;;; position of the gear

;;;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

pitch_dia (/ number_teeth dia_pitch)

gear_teeth (* gear_ratio number_teeth)

gear_out (+ pitch_dia (* 2 (/ 1 (/ gear_teeth pitch_dia))))

pinion_out (+ pitch_dia (* 2 (/ 1 (/ number_teeth pitch_dia))))

gear_rpm (* gear_ratio rpm)

dist (+ (* 0.5 pinion_out) (* 0.5 gear_out))

pt_x (+ dist (CAR pt))

pt_y (CADR pt)

)

;;; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~



;;; Begins the construction of the pinion block

;;; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

(VLA-ADDCIRCLE

modelspace

(VLAX-3d-Point pt)

(/ pinion_out 2)

)

(setq lastent (entget (entlast)))



;;;;;; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

;;;;;; Modifies the entity created by attaching XDATA

;;;;;; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

(regapp "pinion")

(setq exdata1

(LIST


(LIST "pinion"

(CONS 1000 (STRCAT "Pinion's RPM " (RTOS rpm)))

(CONS 1041 gear_ratio)

(CONS 1042 number_teeth)

)

)

)



(setq newent1

(append lastent (list (append '(-3) exdata1)))

)

(entmod newent1)



(VLA-ADDCIRCLE

modelspace

(VLAX-3d-Point (LIST pt_x pt_y))

(/ gear_out 2.0)

)

;;;;;; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~



;;;;;; Modifies the entity created by attaching XDATA

;;;;;; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

(setq lastent (entget (entlast)))

(regapp "gear")

(setq exdata

(LIST


(LIST "gear"

(CONS 1000 (STRCAT "Mating Gear's RPM " (RTOS rpm)))

(CONS 1041 gear_ratio)

(CONS 1042 gear_teeth)

)

)

)



(setq newent

(append lastent (list (append '(-3) exdata)))

)

(entmod newent)



(VLA-ADDCIRCLE

modelspace

(VLAX-3d-Point pt)

(/ shaft_dia 2.0)

)

(VLA-ADDCIRCLE



modelspace

(VLAX-3d-Point (LIST pt_x pt_y))

(/ shaft_dia 2.0)

)

(princ)



)
22.

;;;*******************************************************************

;;; Program Name: ActiveXSeries.lsp

;;; Program Purpose: Calculate the voltage drop for a group of

;;; resistors, equivalent resistance,

;;; Total Current

;;;

;;; Programmed By: James Kevin Standiford



;;; Date: 3/21/2000

;;;********************************************************************

(defun c:series (/ volt l_length)

(setvar "cmdecho" 0)

;;;***~~~~~~New~~~~~~***~~~~~~~NEW~~~~~~~~***~~~~~~~~NEW~~~~~~

(vl-load-com)

(if (equal nil MS-Wordc-wd100Words)

(vlax-import-type-library

:tlb-filename

"C:\\Program Files\\Microsoft Office\\Office\\msword8.olb"

:methods-prefix

"MS-Wordm-"

:properties-prefix

"MS-Wordp-"

:constants-prefix

"MS-Wordc-"

)

)

(setq MS-Word (vlax-get-or-create-object "Word.Application.8"))



(vla-put-visible MS-Word :vlax-true)

(setq documents (vla-get-documents MS-Word)

new-document (MS-Wordm-add documents)

paragraphs (MS-Wordp-get-paragraphs new-document)

page (MS-Wordp-get-last paragraphs)

range (MS-Wordp-get-range page)

res (ssget "x" (list (cons 0 "insert") (cons 2 "resistor")))

)

;;;***~~END New~~~~~~***~~~END NEW~~~~~~~~***~~~~END NEW~~~~~~



(if (/= res nil)

(progn


(setq rcnt 0

volt (getreal "\nEnter voltage : ")

l_length (sslength res)

ent (entget

(entnext (cdr (assoc -1 (entget (ssname res rcnt)))))

)

r_list (list (atof (cdr (assoc 1 ent))))



ent_name_list (list

(cdr


(assoc -1

(entget (entnext (cdr (assoc -1 ent))))

)

)

)



r_num

(list


(cdr

(assoc


1

(entget


(entnext

(cdr


(assoc

-1

(entget (entnext (cdr (assoc -1 ent)))



)

)

)



)

)

)



)

)

rcnt (1+ rcnt)



)

(while (< rcnt l_length)

(setq

ent (entget



(entnext (cdr (assoc -1 (entget (ssname res rcnt)))))

)

r_list



(append r_list

(list (atof (cdr (assoc 1 ent))))

)

ent_name_list



(append

ent_name_list

(list (cdr

(assoc


-1

(entget (entnext (cdr (assoc -1 ent)))

)

)

)



)

)

r_num



(append

r_num


(list

(cdr


(assoc

1

(entget



(entnext

(cdr (assoc

-1

(entget


(entnext

(cdr (assoc -1 ent))

)

)

)



)

)

)



)

)

)



)

rcnt (1+ rcnt)

)

)

(setq list_cnt (- (length r_list) 1)



eq_res

(nth 0 r_list)

l_cnt 1

)

(while (<= l_cnt list_cnt)



(setq resistor (nth l_cnt r_list))

(if (/= resistor nil)

(setq eq_res

(+ eq_res resistor)

)

)

(setq l_cnt (1+ l_cnt))



)

(setq name (GETVAR "dwgname")

length_string (STRLEN name)

name_truncated (SUBSTR name 1 (- length_string 3))

result_file (open (STRCAT (getvar "dwgprefix")

name_truncated

".RLT"

)

"a"



)

amperage (/ volt eq_res)

)

(princ "\n" result_file)



(setq string

(strcat


(princ

(strcat


"\nThe equivalent resistance for the circuit on Drawing : "

(getvar "dwgname")

" is "

(rtos eq_res)



" ohms"

)

result_file



)

(princ


(strcat "\nThe voltage for this circuit is " (rtos volt))

result_file

)

(princ (strcat "\nThe total current for this circuit is "



(rtos amperage)

" amps"


)

result_file

)

)

)



(setq l_cnt 0)

(while (<= l_cnt list_cnt)

(setq

string (strcat



string

(princ (strcat

"\nThe voltage drop for resistor "

(nth l_cnt r_num)

" is "

(setq g (rtos (* (nth l_cnt r_list)



amperage

)

)



)

;;;~~~~~~~~~~~~NEW~~~~~~~~~~~~~~~~NEW~~~~~~~~~~~~~~~NEW~~~~~~~~

" volts it resistance is "

(rtos (nth l_cnt r_list))

" OHMS The Current for this resistor is "

(RTOS amperage)

" AMPS"

;;;~~~~~~~END~~NEW~~~~~~~~~~~END~~NEW~~~~~~~~~~END~~NEW~~~~~



)
result_file

)

)



)

(setq resistor_ent (nth l_cnt ent_name_list)

entg (entget resistor_ent)

entg (subst (cons 1 g) (assoc 1 (entget resistor_ent)) entg)

)

(entupd (cdr (assoc -1 (entmod entg))))



(setq l_cnt (1+ l_cnt))

)

;;;***~~~~~~New~~~~~~***~~~~~~~NEW~~~~~~~~***~~~~~~~~NEW~~~~~~



(MS-Wordm-InsertAfter range string)

;;;***~~END New~~~~~~***~~~END NEW~~~~~~~~***~~~~END NEW~~~~~~

(alert string)

(close result_file)

(command "modemacro"

(strcat "The voltage used for this circuit was "

(rtos volt)

" volts"


)

)

(princ)



)

)

(if (= res nil)



(alert "No Resistors Found : ")

)

(princ)



)

(princ "\nEnter series to start program :")

(princ)

Chapter Ten





Download 210.39 Kb.

Share with your friends:
1   2   3   4   5   6   7   8




The database is protected by copyright ©ininet.org 2024
send message

    Main page