Beruflich Dokumente
Kultur Dokumente
AutoCAD VBA
Lecture 2
Prof. Mounir Mabsout
Elsa Sulukdjian
Walid El Asmar
Application Methods
Methods:
Quit: exits drawing and drawing editor.
RunMacro: runs VBA application.
Update: updates the object on the display.
Zoom many methods available for zooming
Application Properties
Properties:
Application Properties
Example
Dim oAcad As AcadApplication
Dim oDoc As AcadDocument
Set oAcad = GetObject(, "AutoCAD.Application")
Set oDoc = oAcad.ActiveDocument
oAcad.Preferences.Display.CursorSize = 5
oAcad.Documents.Open (strDocumentName)
oDoc.Activate
Document Methods
Methods:
Layers
Layers Example
Dim LayFrame As AcadLayer
Set LayFrame = ThisDrawing.Documents.Add(LayFrame)
LayFrame.Color = acBlue
set LayFrame = ThisDrawing.ActiveLayer
For i = 0 To ThisDrawing.Layers.Count 1
If LayFrame = ThisDrawing.Layers.Item(i) Then
Exit For
End If
Next i
ThisDrawing.Layers.Item(i).Linetype = StrLineTypeName
RealToString / StringToReal
AngleToReal /AngleToString
PolarPoint: returns point variant
For i = 1 To Nlines
strNum = .RealToString(i, acDecimal, 0)
dblStPnt(0) = .GetReal("Enter st pnt x for line " + strNum +":")
dblStPnt(1) = .GetReal("Enter st pnt y for line " + strNum +":") : dblStPnt(2)
= 0#
dblEnPnt(0) = .GetReal("Enter End pnt x for line " + strNum +":")
dblEnPnt(1) = .GetReal("Enter End pnt y for line " + strNum +":") :
dblEnPnt(2) = 0#
Set acLine(Nlines - 1) = ThisDrawing.ModelSpace.AddLine(dblStPnt,
dblEnPnt)
Next i
End With
Error Handler
Error Handler
Dim dblPnt(0 To 2) As Double
Dim objSelect As Object
Again:
On Error Resume Next
ThisDrawing.Utility.GetEntity objSelect, dblPnt, "Pick
Object:"
If Err.Number <> 0 Then
Err.Clear
MsgBox "No entity was selected"
GoTo Again
End If
Whats Next
VBA lab
Filtering the selection set
The True Story of PaperSpace