.NET

.NET

Reply
*Anders Pettersson
Message 1 of 3 (140 Views)

Retrieve the Geometrical data from AutoCad Objects...

140 Views, 2 Replies
06-08-2005 01:46 AM
I've made some arx-programs for AutoCad 2002 so I'm not really new in this
topic. My first goal for my first ".NET-ARX" in C# is to traverse the
current document and retrieve all objects geometrical data, no matter which
type they are. Do you now any way of getting the geometrical data form the
objects in C#.



If you have any tip of where to expand my knowledge in ".NET-ARX" I'm really
grateful...
*Simon
Message 2 of 3 (140 Views)

Re: Retrieve the Geometrical data from AutoCad Objects...

06-08-2005 05:25 AM in reply to: *Anders Pettersson
Here is some vb code that selects objects then filters out the text &
circles. It should give you an idea of how to get the data you are after
using C#

Public Sub GetAll()

Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor



'Set the selection options

Dim SelOpts As New PromptSelectionOptions

SelOpts.MessageForAdding = "Select Objects:"

SelOpts.AllowDuplicates = True

'Make the selection:

Dim res As PromptSelectionResult = ed.GetSelection()

If Not res.Status = PromptStatus.OK Then Return

Dim SS As Autodesk.AutoCAD.EditorInput.SelectionSet = res.Value

Dim idarray As ObjectId() = SS.GetObjectIds()

Dim db As Database = Application.DocumentManager.MdiActiveDocument.Database

Dim tm As Autodesk.AutoCAD.DatabaseServices.TransactionManager =
db.TransactionManager

'start a transaction

Dim myT As Transaction = tm.StartTransaction()

Try

Dim id As ObjectId

For Each id In idarray

Dim entity As Entity = tm.GetObject(id, OpenMode.ForRead, True)







If TypeOf entity Is Autodesk.AutoCAD.DatabaseServices.DBText Then

' DBTEXT Origin = bottom left

TextBox1.Text += "DBTEXT FOUND " & vbCrLf

Dim Txt As Autodesk.AutoCAD.DatabaseServices.DBText = entity

Dim k

TxtFound = TxtFound + 1

k = Txt.TextString

TextBox1.Text += "STRING " & k.ToString & vbCrLf

TextFnd(1, TxtFound) = k.tostring

k = Txt.Position

TextBox1.Text += "POSITION " & vbCrLf & k.ToString & vbCrLf & vbCrLf

Dim Spl

Spl = Mid(k.tostring, 2, Len(k.tostring) - 2)

TextBox1.Text += "SPLIT" & Spl & vbCrLf

Dim sa() As String

sa = Split(Spl, ",", -1)

TextFnd(0, TxtFound) = TxtFound

TextFnd(2, TxtFound) = sa(0)

TextFnd(3, TxtFound) = sa(1)







End If









If TypeOf entity Is Autodesk.AutoCAD.DatabaseServices.MText Then

TextBox1.Text += "*MTEXT FOUND " & vbCrLf

Dim Txt As Autodesk.AutoCAD.DatabaseServices.MText = entity

TxtFound = TxtFound + 1

Dim k

'k = Txt.Id

'TextBox1.Text += "ID " & k.ToString & vbCrLf

k = Txt.Contents

TextBox1.Text += "Contents " & k.ToString & vbCrLf & vbCrLf

TextFnd(1, TxtFound) = k.tostring



k = Txt.Location

TextBox1.Text += "Location " & k.ToString & vbCrLf

Dim Spl

Spl = Mid(k.tostring, 2, Len(k.tostring) - 2)

TextBox1.Text += "SPLIT" & Spl & vbCrLf

Dim sa() As String

sa = Split(Spl, ",", -1)

TextFnd(0, TxtFound) = TxtFound

TextFnd(2, TxtFound) = sa(0)

TextFnd(3, TxtFound) = sa(1)



End If





If TypeOf entity Is Autodesk.AutoCAD.DatabaseServices.Circle Then

TextBox1.Text += "CIRCLE FOUND " & vbCrLf

Dim Circ As Autodesk.AutoCAD.DatabaseServices.Circle = entity

Dim k

k = Circ.Center

ed.WriteMessage((ControlChars.Lf + "CENT " & k.ToString))

TextBox1.Text += "Centre " & k.ToString & vbCrLf & vbCrLf

Dim Spl

Spl = Mid(k.tostring, 2, Len(k.tostring) - 2)

TextBox1.Text += "SPLIT" & Spl & vbCrLf

Dim sa() As String

sa = Split(Spl, ",", -1)

CircFound = CircFound + 1

CircCen(0, CircFound) = CircFound

CircCen(1, CircFound) = sa(0)

CircCen(2, CircFound) = sa(1)

End If

Next id

Finally

myT.Dispose()

End Try

TextBox1.Text += "Text " & TxtFound & vbCrLf

TextBox1.Text += "Circles " & CircFound & vbCrLf

End Sub





"Anders Pettersson" wrote in message
news:4868384@discussion.autodesk.com...
I've made some arx-programs for AutoCad 2002 so I'm not really new in this
topic. My first goal for my first ".NET-ARX" in C# is to traverse the
current document and retrieve all objects geometrical data, no matter which
type they are. Do you now any way of getting the geometrical data form the
objects in C#.



If you have any tip of where to expand my knowledge in ".NET-ARX" I'm really
grateful...
New Member
d00ape
Posts: 2
Registered: ‎06-08-2005
Message 3 of 3 (140 Views)

Re: Retrieve the Geometrical data from AutoCad Objects...

06-09-2005 01:36 AM in reply to: *Anders Pettersson
Thanks I'll try that sample!
Do you now any way of getting the geometrical data for objects...
At this point all want to accomplish is to retrieve the polygon points that all objects in an dwg-file. Maybe it's not an arx I should do for this purpose...
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.