.NET

Reply
Contributor
pavan
Posts: 14
Registered: ‎11-30-2005
Message 1 of 6 (124 Views)

how get an entity properties from autocad to .Net Form

124 Views, 5 Replies
03-01-2006 04:01 AM
Hi I had a .net form in which i had a button,
i want to get the length of a line by clicking it from autocad application

this is my code
but it is not working

can any body help me?
Contributor
pavan
Posts: 14
Registered: ‎11-30-2005
Message 2 of 6 (124 Views)

Re: how get an entity properties from autocad to .Net Form

03-01-2006 04:42 AM in reply to: pavan
I am sorry to say that i forgot to mention the details of the error...

I am getting the error like system.NullReferenseError
which says Object has no referce as additional Information.


at the Line

Database Db = HostApplicationServices.WorkingDatabase;
Editor Ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
Distinguished Contributor
Mikko
Posts: 212
Registered: ‎10-03-2003
Message 3 of 6 (124 Views)

Re: how get an entity properties from autocad to .Net Form

03-01-2006 06:27 AM in reply to: pavan
Here is some code in VB.

<CommandMethod("LineLength")> _
Public Shared Sub LineLength()
Dim ed As Editor = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor
Dim db As Database = HostApplicationServices.WorkingDatabase
Dim t As Transaction = db.TransactionManager.StartTransaction()
Dim idArray() As ObjectId = Nothing
Try
Dim res As PromptSelectionResult = ed.GetSelection
If res.Status <> PromptStatus.OK Then
Exit Sub
End If
Dim SS As Autodesk.AutoCAD.EditorInput.SelectionSet = res.Value
idArray = SS.GetObjectIds()
Dim objId As ObjectId
Dim myLine As Line = Nothing
Dim lineStart As Point3d
Dim lineEnd As Point3d
For Each objId In idArray
Dim e As Entity = CType(t.GetObject(objId, OpenMode.ForWrite), Entity)
If e.GetType.Name.ToString() = "Line" Then
myLine = e
lineStart = myLine.StartPoint
lineEnd = myLine.EndPoint
Dim opp As Double = lineEnd.Y - lineStart.Y
Dim adj As Double = lineEnd.X - lineStart.X
MessageBox.Show(Math.Sqrt((opp * opp) + (adj * adj)).ToString)
Else
MessageBox.Show("Not a LINE")
End If
Next
t.Commit()
Catch ex As Exception
MessageBox.Show(ex.ToString)
Finally
t.Dispose()
End Try
End Sub
Active Member
jayapradha
Posts: 7
Registered: ‎02-28-2006
Message 4 of 6 (124 Views)

Re: how get an entity properties from autocad to .Net Form

03-01-2006 10:41 PM in reply to: pavan
Hello Mikko

I had the same problem

In .net form i had button
on button click i call this method " LineLength"

I wrote the same code what u given LineLenth method
But at this line it is giving error

The error is "Object refernec not set to an instantiate an object:
and null refernce exception is occured.

Code:

Dim ed As Editor = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocum

Here it is not recognizing any class like editor, dataBase

using System;
using System.Windows.Forms;
using Autodesk.AutoCAD.Interop;
import Autodesk.AutoCAD.Interop.Common;
import acadApp = Autodesk.AutoCAD.ApplicationServices.Application;
import System.Runtime.InteropServices;
import Autodesk.AutoCAD.Runtime;
import Autodesk.AutoCAD.Geometry;
import Autodesk.AutoCAD.EditorInput;
import Autodesk.AutoCAD.DatabaseServices;

Public Shared Sub LineLength()

Dim ed As Editor = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocum ent.Editor
Dim db As Database = HostApplicationServices.WorkingDatabase
Dim t As Transaction = db.TransactionManager.StartTransaction()
Dim idArray() As ObjectId = Nothing


plese recitfy the problem.


Thanqs in advance.
Contributor
pavan
Posts: 14
Registered: ‎11-30-2005
Message 5 of 6 (124 Views)

Re: how get an entity properties from autocad to .Net Form

03-03-2006 12:59 AM in reply to: pavan
Hi Mikko,

Thanks for responding to my problem, but i am sorry that i am not able to explain you my problem exactly, my problem is that either my code or Your is not working when i am trying to retrieve the Length value from a Button_Click (form's Command Button). if the same code if i put it in a DLL and by using NETLOAD command it is working fine,

once again i am telling you my Problem..

if i press a button (Button Click) on a form..
I want a message box displaying the Length of Line which is Selected in AutoCAD...

I think now you understand this Problem exactly..,

so can anybody help me to solve this issue please...

Thanks in Advance
Pavan Kumar . L
Distinguished Contributor
cgay
Posts: 125
Registered: ‎08-02-2005
Message 6 of 6 (124 Views)

Re: how get an entity properties from autocad to .Net Form

03-03-2006 02:51 PM in reply to: pavan
pavan,

Are you trying to create an EXE or DLL? The managed extensions for autocad only work in a DLL. This means that you need to netload it to get it to work.
If you want a standalone app, you need to ONLY use ComInterop.

C

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

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 to get help installing your software.

Ask the Community