.NET

Reply
Active Member
jayapradha
Posts: 7
Registered: ‎02-28-2006
Message 1 of 1 (153 Views)

Get Entity properties

153 Views, 0 Replies
03-02-2006 01:42 AM
Hai

on .net form button is there.
when i click the button i want to get entity from autocad to .net

I call the test method in Button_Click event.

when i click the button
then it gives the error. Object reference not set to instanitate an object. (runtime error) there are no compliation errors.

on NETLOAD test method is working fine.


when i click the button
at this line it is giving the error.
Database Db = HostApplicationServices.WorkingDatabase;
it is not recognize the classes Editor,Database.


the code is below.
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using SampleClasses;
using System.Runtime.InteropServices;
using Microsoft;
using Microsoft.VisualBasic;

using Autodesk.AutoCAD;
using Autodesk.AutoCAD.Interop;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.ApplicationServices;
using acadApp =
Autodesk.AutoCAD.ApplicationServices.Application;
using AcadDB = Autodesk.AutoCAD.DatabaseServices;
using AcadRun = Autodesk.AutoCAD.Runtime;
private void button2_Click(object sender, System.EventArgs e)
{
Microsoft.VisualBasic.Interaction.AppActivate(WindowsApplication1.Form1.cadApp.Caption);
test();
}

public test()
{
object G_OBJ = null;
ObjectId G_OBJID;
Entity G_ENT = null;
Line G_LINE = null;
string G_ENTTYPE = "", s = "", es = "";
try
{
Microsoft.VisualBasic.Interaction.AppActivate(cadApp.Caption);


// Here I am Getting the ERROR --> System.NullReferense Error Additional Info: Object Referense not set to an instance of object
Database Db = HostApplicationServices.WorkingDatabase;


Editor Ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
Transaction Trans = Db.TransactionManager.StartTransaction();
BlockTable bt = (BlockTable)Trans.GetObject(Db.BlockTableId, Autodesk.AutoCAD.DatabaseServices.OpenMode.ForWrite);
BlockTableRecord btr = (BlockTableRecord)Trans.GetObject(bt[BlockTableRecord.ModelSpace],Autodesk.AutoCAD.DatabaseServices.OpenMode.ForWrite);
PromptEntityResult p = Ed.GetEntity("click on an entity");
G_OBJ =(Object) p;
G_OBJID = p.ObjectId;
if(G_OBJID.ToString() != "(0)")
{
G_ENT = (Entity)Trans.GetObject(G_OBJID, Autodesk.AutoCAD.DatabaseServices.OpenMode.ForRead);
G_ENTTYPE = G_ENT.GetType().ToString();
if (G_ENTTYPE == "Autodesk.AutoCAD.DatabaseServices.Line")
{
G_LINE = (Line) G_ENT;
Point3d p0 = G_LINE.StartPoint, p1 = G_LINE.EndPoint;
double dX, dY, Len2D;
dX = (p1.X - p0.X); dY = (p1.Y - p0.Y);
Len2D = Math.Sqrt((dX * dX)+(dY * dY));
s += "\n Length (2D = " + Len2D + ") ";
}
else es += "\n Selected Object is not a Line";
}
}
catch(System.Exception EX){es += "\nErr.. in Get_Object : " + EX.Message.ToString();}
MessageBox.Show(s);
MessageBox.Show(es);
}


What is the problem.
it's urgent.

thanqs in advance
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Need installation help?

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