.NET

Reply
Contributor
luisibad
Posts: 17
Registered: ‎03-15-2008
Message 1 of 3 (149 Views)

error 91

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

 

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

 

*Expert Elite*
Alfred.NESWADBA
Posts: 8,982
Registered: ‎06-29-2007
Message 2 of 3 (121 Views)

Re: error 91

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

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
Ingenieur Studio HOLLAUS ... www.hollaus.at
-------------------------------------------------------------------------
*Expert Elite*
norman.yuan
Posts: 987
Registered: ‎04-27-2009
Message 3 of 3 (108 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:

 

Try

CAD_App = GetObject(, "AutoCAD.Application")

CAD_Doc = CAD_App.ActiveDocument

CAD_Model=CAD_Doc.ModelSpace

...

 

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.