.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

how get an entity properties from autocad to .Net Form

5 REPLIES 5
Reply
Message 1 of 6
pavan
518 Views, 5 Replies

how get an entity properties from autocad to .Net Form

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?
5 REPLIES 5
Message 2 of 6
pavan
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;
Message 3 of 6
Mikko
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
Message 4 of 6
jayapradha
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.
Message 5 of 6
pavan
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
Message 6 of 6
cgay
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

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost