error 91

error 91

Anonymous
Not applicable
504 Views
2 Replies
Message 1 of 3

error 91

Anonymous
Not applicable

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)

 

Try

CAD_App = GetObject(, "AutoCAD.Application")

CAD_Doc = CAD_App.ActiveDocument

 

Try

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)

 

EndTry

 

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)")

EndIf

EndTry

 

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

 

0 Likes
505 Views
2 Replies
Replies (2)
Message 2 of 3

Alfred.NESWADBA
Consultant
Consultant

Hi,

 

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 -

------------------------------------------------------------------------------------
Alfred NESWADBA
ISH-Solutions GmbH / Ingenieur Studio HOLLAUS
www.ish-solutions.at ... blog.ish-solutions.at ... LinkedIn ... CDay 2026
------------------------------------------------------------------------------------

(not an Autodesk consultant)
0 Likes
Message 3 of 3

norman.yuan
Mentor
Mentor

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:

 

Try

CAD_App = GetObject(, "AutoCAD.Application")

CAD_Doc = CAD_App.ActiveDocument

CAD_Model=CAD_Doc.ModelSpace

...

 

Norman Yuan

Drive CAD With Code

EESignature

0 Likes