Posts: 17
Registered: ‎03-15-2008
Message 1 of 3 (163 Views)

error 91

163 Views, 2 Replies
03-09-2014 02:35 PM

Hi! I'm not sure if I should publish this post here, but I'm trying to do something between Excel and Autocad with VSTO and Autocad type library and all this with vb.net


This is part of my code:


Dim PTRange, XRange, YRange, ZRange, CDRange, HTRange As Excel.Range

Dim North, Easte, Elevation As Double

Dim BlockName As String = "UTM"

Dim PtXYZ As Double()

Dim ValScale, ARotation As Double

ValScale = Convert.ToDouble(1)

ARotation = Convert.ToDouble(0)



CAD_App = GetObject(, "AutoCAD.Application")

CAD_Doc = CAD_App.ActiveDocument



For I AsInt16 = Fila To FilaEnd

'PTRange = XlSheet_GetValues.Cells(I, 1)

'Punto = PTRange.Value

YRange = XlSheet_GetValues.Cells(I, 2)

North = Convert.ToDouble(YRange.Value)

XRange = XlSheet_GetValues.Cells(I, 3)

Easte = Convert.ToDouble(XRange.Value)

ZRange = XlSheet_GetValues.Cells(I, 4)

Elevation = Convert.ToDouble(ZRange.Value)

'Cota = ZRange.Value

'CDRange = XlSheet_GetValues.Cells(I, 5)

'Descripcion = CDRange.Value


PtXYZ = NewDouble() {Este, Norte, Elevation}

'PtXYZ(0) = Este : PtXYZ(1) = Norte : PtXYZ(2) = Elevation


Dim Acad_BlockInsert As AcadBlockReference


'CAD_Model.InsertBlock(PtXYZ, BlockName, ValScale, ValScale, ValScale, ARotation)

Acad_BlockInsert = CAD_Model.InsertBlock(PtXYZ, BlockName, ValScale, ValScale, ValScale, ARotation) ' HERE IS THE PROBLEM

'If Acad_BlockInsert.HasAttributes Then

'ArrayATT = Acad_BlockInsert.GetAttributes



Next I

Catch ex AsException

' I got this error number 91 and it meant that object reference not set to an instance of an object

MsgBox("Error número " & Err.Number & vbNewLine & "Descripción del Error: " & Err.Description)




Catch ex AsException

If Err.Number = 429 Then

MsgBox("AutoCAD no se encuentra activada o el programa no esta instalado en el EQUIPO", MsgBoxStyle.Critical, "ERROR DE CONEXION (EXCEL - AUTOCAD)")




So, I can't insert the block because I got the err.number 91.

I would like to know if there will be some way to sort it out , or It's not posible to create this kind of connection between Excel and AutoCAD with VB.NET


I'll appreciate any help


*Expert Elite*
Posts: 9,607
Registered: ‎06-29-2007
Message 2 of 3 (135 Views)

Re: error 91

03-10-2014 02:44 AM in reply to: luisibad



does a block named "UTM" exist in the current drawing?

Does the exception occure in the first loop or in any further loop?

Have you verified the variable-content for insertion-point?


- alfred -

Ingenieur Studio HOLLAUS ... www.hollaus.at
*Expert Elite*
Posts: 1,064
Registered: ‎04-27-2009
Message 3 of 3 (122 Views)

Re: error 91

03-10-2014 06:59 AM in reply to: luisibad

It is obviously that you did not show enough code to find the cause of the error, because the error is occured at


Acad_BlockInsert = CAD_Model.InsertBlock(PtXYZ, BlockName, ValScale, ValScale, ValScale, ARotation)


and the error seems to indicate the object CAD_Model (which I assume is the MOdelSpace of active drawing) is Nothing.


Your code did not show how/where it is declare. But since the AutoCAD.Application is just instantiated in the shown code, and logically, CAD_Model variable can only be assigned to an valid AcadModelSpace object after that, which can not be seen in your code. Thus, the error says exactly what is wrong: CAD_Model is not assigned.


If the current drawing is the target drawing, the code shouyld be like this:



CAD_App = GetObject(, "AutoCAD.Application")

CAD_Doc = CAD_App.ActiveDocument




Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.