Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Lecture 1
Prof. Mounir Mabsout Elsa Sulukdjian Walid El Asmar
Object ARX:
ObjectARX programming environment provides an objectoriented C++ application programming interface.
VBA vs AutoLISP
AutoLISP runs from command line or menu system. VBA is more powerful in terms of userinteraction and dialog box interfaces. VBA is also more powerful in linking to other Windows programs, I.e. opening applications, exchanging data.
VBA vs VB
VBA is run from inside the AutoCAD memory pool; thus, the communication is faster. At runtime, VB does not take the monopole of the AutoCAD activity, I.e. you can still manipulate a drawing using the ADS while the VB runs. VB is more powerful in terms of database manipulation. VBA does not have a form load procedure while VB does, I.e. forms need to be re-initialized in VBA. VBA is a subset of VB. Not all controls and properties found in VB are available in VBA.
Getting Started
The VBA IDE is accessed through the AutoCAD Tools menu Macro Visual Basic Editor, or Alt+F11. Main Features:
Project Explorer: tree diagram showing modules, forms and AutoCAD Objects in use. Properties Window. User Form Windows. Code Window. Object Browser: tree structure display used to shop for any AutoCAD/VBA object or method (bala TVA).
VBA IDE
Example: Object Line (acLine) Properties Coordinates of start point Method Set [] StartPoint used to change those coordinates.
Tree structure that shows the hierarchy of objects in the application. Made of: collections of objects and objects. The AutoCAD Application is at the base of the trunk. Ascending procedure required to access an entity.
Preferences Collections Objects Paper Space Model Space
Block
BlockS
Block
Other Collections
Document
Document
After declaration, each entity has to be assigned a certain location in the Object Model, in order to be manipulated:
Dim Circ as AcadCircle set Circ = ThisDrawing.ModelSpace.Addcircle()
It is required to trace this location in an ascending manner, I.e from the trunk up to the concerned branch. Later, any entity can be manipulated either directly by its reference name, or by retracing its location:
Circ.Color = acBlue
or
ThisDrawing.ModelSpace.Item(0).Color = acBlue
About ThisDrawing
ThisDrawing is a reference name for the active document in the application. Although the AutoCAD Application is closer in level to the roots of the Object Model, it can be manipulated from the active document, I.e:
ThisDrawing.Application
etc
This is not really in contradiction with the regular procedure, for Application in this case is a not really the AutoCAD Application, but only a pointer to it.
Application Pointer
Points to
Sample Code:
Dim oAcad as AcadApplication Dim oDocument AcadDocument Dim oPref as AcadPreferences Set oAcad = GetObject( , AutoCAD.Application) set oDocument = oAcad.ActiveDocument set oPref = oAcad.Preferences
Equivalent Syntaxes:
oDocument. ThisDrawing. oAcad. ThisDrawing.Application. oPref. ThisDrawing.Application.Preferences.
A Collection Object is a set of things all collected into one object. The Collection Object provides a mechanism by which several items, data, or other objects, can be linked together & referenced as a singular item: a Selection Set. A Selection Set can contain any number of entity objects, of any type (lines, blocks, etc.) referencing even more objects. Generally, 3 methods are associated with collections, providing the basic functions needed to Add, Remove or Access items in a collection.
In the AutoCAD drawing object model, the storage place for all selection sets is called Selection Sets Collection. Selection Sets are referenced by name (string type) inside the collection.
Note: The AddItems() method requires that we supply an array of object references, and it will not accept just one single object.
Retrieving selection set members is done using an offset value into the selection set. The 1st member of the selection is at an offset of 0 & the last member is at an offset of (number of objects in the set 1). When iterating through a selection set, the easiest programming strategy is to use the For-Each-Next loop structure. The item() method is best if you know exactly where the object to be manipulated resides.
The following program will get the entity type and layer of the 1st object in the entity list. It will then change the layers of matching entity types in the remainder of the selection set.
Dim MatchIt As Object Dim Ent As Object Set MatchIt = S2.Item(0) For each Ent in S2 If ((MatchIt.EntityType = Ent.EntityType))_ And (MatchIt.Layer <> Ent.Layer)) Then Ent.Layer = MatchIt.Layer Ent.Update End If Next End
Methods:
Clear: clears the selection set (selection set still exists). Delete: deletes the selection set from the collection, linkage to the set is broken, and any reference to the set will result in an error. Erase: deletes the items from the drawing. Selection set still exists but without any entity objects in it. Highlight: highlights the objects in the set (to show the operator what items have been selected) RemoveItems: removes one or more entity objects from the selection set (objects are still on the drawing though). Update: regenerates the entity objects on the screen.
Count: Number of entity objects in the selection set. Name: Name of the selection set.
Properties:
Whats Next