2017-12-05 3 views
1

Ich versuche, ein einfaches Quadrat in AutoCAD mit VBA zu machen, aber wenn ich versuche, meinen Code auszuführen, bekomme ich einen "Out of Range" -Fehler? Jede Hilfe wäre großartig!Autocad VBA - Create Square

Sub box() 
'Link the Exel File to the open CAD File' 
'If no CAD file open it does create one' 
'----------------------------------------------------------------' 
Dim ACAD As AcadApplication 'Create ACAD variable of type AcadApplication 
On Error Resume Next 'This tells VBA to ignore errors 
Set ACAD = GetObject(, "AutoCAD.Application") 'Get a running instance of the class AutoCAD.Application 
On Error GoTo 0 'This tells VBA to go back to NOT ignoring errors 
If ACAD Is Nothing Then 'Check to see if the above worked 
    Set ACAD = New AcadApplication 'Set the ACAD variable to equal a new instance of AutoCAD 
    ACAD.Visible = True 'Once loaded, set AutoCAD® to be visible 
End If 
ACAD.ActiveDocument.Utility.Prompt "Hello from Excel!" 'Print a message to the AutoCAD® command line 

Dim squareObj As Acad3DSolid 
Dim center(0 To 2) As Double 

center(0) = 10 
center(1) = 10 
center(2) = 0 

Set squareObj = ACAD.ActiveDocument.ModelSpace.AddBox(center, 2, 2, 0) 

End Sub 
+0

Sie haben nicht 'center' ... Sie haben' center (0) '... etc – jsotola

+0

Wenn das das Problem ist, dann löschen Sie diesen Beitrag. es ist nicht wirklich jemand anderen Hilfe – jsotola

+2

Das erste Argument ist in Ordnung. Der "Ursprung" (aka 'center') soll ein' Variant (dreibeiniges Array mit zwei Elementen) sein; ' – Profex

Antwort