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

Retrieve the Geometrical data from AutoCad Objects...

2 REPLIES 2
Reply
Message 1 of 3
Anonymous
347 Views, 2 Replies

Retrieve the Geometrical data from AutoCad Objects...

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...
2 REPLIES 2
Message 2 of 3
Anonymous
in reply to: Anonymous

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...
Message 3 of 3
Anonymous
in reply to: Anonymous

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...

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