.NET

Reply
*Simon
Message 1 of 7 (93 Views)

Getting co-ordinates from selection set entities

93 Views, 6 Replies
05-28-2005 02:30 PM
Hi,

I've been trying to get the co-ordinates of circles in a selection set as
created in the ObjectArx demo code. I have tried every method O can think of
but there doesn't seem to be a method of obtaining the value of the centres.
Code from the demo posted below with notes to indicate what I am trying to
do. I may be missing something obvious here as it should be a simple
process.

Thanks for any ideas.

Simon

Public Sub ssGetFilter()

'Setup

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

'Declare our filter entries this way.

'We build them the same way in ObjectARX.

'DxfCode.Start (equal to 0) - This is for 'Entity Name'

'DxfCode.Color is for ACI color - 1 = Red

Dim values() As TypedValue = { _

New TypedValue(DxfCode.Start, "CIRCLE"), _

New TypedValue(DxfCode.Color, 1) _

}

Dim sfilter As New SelectionFilter(values) ' Create the filter using our
values...

'Set the selection options

Dim SelOpts As New PromptSelectionOptions()

SelOpts.MessageForAdding = "Select Red Circles:"

SelOpts.AllowDuplicates = True

'Make the selection:

Dim res As PromptSelectionResult = ed.GetSelection(SelOpts, sfilter)

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)

ed.WriteMessage((ControlChars.Lf + "You selected: " +
entity.GetType().FullName))

' ********************************************Put something here along the
lines of entity.value or id.value I can't find where the co-ords a re stored



Next id

Finally

myT.Dispose()

End Try

End Sub
*Frank Oquendo
Message 2 of 7 (93 Views)

Re: Getting co-ordinates from selection set entities

05-28-2005 05:50 PM in reply to: *Simon
Simon wrote:

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

If you want the center of a circle, you need to cast the object to a circle.
*Simon
Message 3 of 7 (93 Views)

Re: Getting co-ordinates from selection set entities

05-29-2005 07:05 AM in reply to: *Simon
Thanks Frank. I have tried to do that using this code which I thought would
work but throws an error. I can get other info out such as layer, geometric
extents etc Do you know where I could get a book or some better online code
samples on this as I;m just guessing at the moment and documentation seems
pretty thin on the ground.

Cheers,

Simon

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

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

Dim k

k = Circ.Center

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

End If
















"Frank Oquendo" wrote in message
news:4859625@discussion.autodesk.com...
Simon wrote:

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

If you want the center of a circle, you need to cast the object to a circle.
*Albert Szilvasy
Message 4 of 7 (93 Views)

Re: Getting co-ordinates from selection set entities

05-29-2005 10:46 AM in reply to: *Simon
Can you post a complete example that shows the problem? This is very much
possible and in fact fairly simple to do so I'd like to look at your code to
diagnose the problem.

Albert
"Simon" wrote in message
news:4859602@discussion.autodesk.com...
Hi,

I've been trying to get the co-ordinates of circles in a selection set as
created in the ObjectArx demo code. I have tried every method O can think of
but there doesn't seem to be a method of obtaining the value of the centres.
Code from the demo posted below with notes to indicate what I am trying to
do. I may be missing something obvious here as it should be a simple
process.

Thanks for any ideas.

Simon

Public Sub ssGetFilter()

'Setup

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

'Declare our filter entries this way.

'We build them the same way in ObjectARX.

'DxfCode.Start (equal to 0) - This is for 'Entity Name'

'DxfCode.Color is for ACI color - 1 = Red

Dim values() As TypedValue = { _

New TypedValue(DxfCode.Start, "CIRCLE"), _

New TypedValue(DxfCode.Color, 1) _

}

Dim sfilter As New SelectionFilter(values) ' Create the filter using our
values...

'Set the selection options

Dim SelOpts As New PromptSelectionOptions()

SelOpts.MessageForAdding = "Select Red Circles:"

SelOpts.AllowDuplicates = True

'Make the selection:

Dim res As PromptSelectionResult = ed.GetSelection(SelOpts, sfilter)

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)

ed.WriteMessage((ControlChars.Lf + "You selected: " +
entity.GetType().FullName))

' ********************************************Put something here along the
lines of entity.value or id.value I can't find where the co-ords a re stored



Next id

Finally

myT.Dispose()

End Try

End Sub
*Simon
Message 5 of 7 (93 Views)

Re: Getting co-ordinates from selection set entities

05-29-2005 03:08 PM in reply to: *Simon
Albert,

Here's the code, much of it is as the sample from the sdk. I thought this
would be simple and it probably is once you know how.

Cheers,

Simon

Public Sub ssGetFilter()

'Setup

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

'Declare our filter entries this way.

'We build them the same way in ObjectARX.

'DxfCode.Start (equal to 0) - This is for 'Entity Name'

'DxfCode.Color is for ACI color - 1 = Red

Dim values() As TypedValue = { _

New TypedValue(DxfCode.Start, "CIRCLE"), _

New TypedValue(DxfCode.Color, 1) _

}

Dim sfilter As New SelectionFilter(values) ' Create the filter using our
values...

'Set the selection options

Dim SelOpts As New PromptSelectionOptions()

SelOpts.MessageForAdding = "Select Red Circles:"

SelOpts.AllowDuplicates = True

'Make the selection:

Dim res As PromptSelectionResult = ed.GetSelection(SelOpts, sfilter)

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)

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

ed.WriteMessage((ControlChars.Lf + "You selected: " +
entity.GetType().FullName))



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

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

Dim k

k = Circ.Center

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

End If

Next id

Finally

myT.Dispose()

End Try

End Sub






"Albert Szilvasy" wrote in message
news:4859720@discussion.autodesk.com...
Can you post a complete example that shows the problem? This is very much
possible and in fact fairly simple to do so I'd like to look at your code to
diagnose the problem.

Albert
"Simon" wrote in message
news:4859602@discussion.autodesk.com...
Hi,

I've been trying to get the co-ordinates of circles in a selection set as
created in the ObjectArx demo code. I have tried every method O can think of
but there doesn't seem to be a method of obtaining the value of the centres.
Code from the demo posted below with notes to indicate what I am trying to
do. I may be missing something obvious here as it should be a simple
process.

Thanks for any ideas.

Simon

Public Sub ssGetFilter()

'Setup

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

'Declare our filter entries this way.

'We build them the same way in ObjectARX.

'DxfCode.Start (equal to 0) - This is for 'Entity Name'

'DxfCode.Color is for ACI color - 1 = Red

Dim values() As TypedValue = { _

New TypedValue(DxfCode.Start, "CIRCLE"), _

New TypedValue(DxfCode.Color, 1) _

}

Dim sfilter As New SelectionFilter(values) ' Create the filter using our
values...

'Set the selection options

Dim SelOpts As New PromptSelectionOptions()

SelOpts.MessageForAdding = "Select Red Circles:"

SelOpts.AllowDuplicates = True

'Make the selection:

Dim res As PromptSelectionResult = ed.GetSelection(SelOpts, sfilter)

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)

ed.WriteMessage((ControlChars.Lf + "You selected: " +
entity.GetType().FullName))

' ********************************************Put something here along the
lines of entity.value or id.value I can't find where the co-ords a re stored



Next id

Finally

myT.Dispose()

End Try

End Sub
*Albert Szilvasy
Message 6 of 7 (93 Views)

Re: Getting co-ordinates from selection set entities

06-01-2005 07:23 PM in reply to: *Simon
The problem is simple: you are trying to cast a Point3d to a String (the
exception thrown actually says that.)

You need to modify this:
------------------
Dim k
k = Circ.Center
ed.WriteMessage((ControlChars.Lf + "CENT " & k))
-----------------
To this:
----------------
Dim k
k = Circ.Center
ed.WriteMessage((ControlChars.Lf + "CENT " & k.ToString()))
-----------
I could've spotted this in first post if I was a bit more versed in VB.

Albert

"Simon" wrote in message
news:4859733@discussion.autodesk.com...
Albert,

Here's the code, much of it is as the sample from the sdk. I thought this
would be simple and it probably is once you know how.

Cheers,

Simon

Public Sub ssGetFilter()

'Setup

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

'Declare our filter entries this way.

'We build them the same way in ObjectARX.

'DxfCode.Start (equal to 0) - This is for 'Entity Name'

'DxfCode.Color is for ACI color - 1 = Red

Dim values() As TypedValue = { _

New TypedValue(DxfCode.Start, "CIRCLE"), _

New TypedValue(DxfCode.Color, 1) _

}

Dim sfilter As New SelectionFilter(values) ' Create the filter using our
values...

'Set the selection options

Dim SelOpts As New PromptSelectionOptions()

SelOpts.MessageForAdding = "Select Red Circles:"

SelOpts.AllowDuplicates = True

'Make the selection:

Dim res As PromptSelectionResult = ed.GetSelection(SelOpts, sfilter)

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)

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

ed.WriteMessage((ControlChars.Lf + "You selected: " +
entity.GetType().FullName))



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

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

Dim k

k = Circ.Center

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

End If

Next id

Finally

myT.Dispose()

End Try

End Sub






"Albert Szilvasy" wrote in message
news:4859720@discussion.autodesk.com...
Can you post a complete example that shows the problem? This is very much
possible and in fact fairly simple to do so I'd like to look at your code to
diagnose the problem.

Albert
"Simon" wrote in message
news:4859602@discussion.autodesk.com...
Hi,

I've been trying to get the co-ordinates of circles in a selection set as
created in the ObjectArx demo code. I have tried every method O can think of
but there doesn't seem to be a method of obtaining the value of the centres.
Code from the demo posted below with notes to indicate what I am trying to
do. I may be missing something obvious here as it should be a simple
process.

Thanks for any ideas.

Simon

Public Sub ssGetFilter()

'Setup

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

'Declare our filter entries this way.

'We build them the same way in ObjectARX.

'DxfCode.Start (equal to 0) - This is for 'Entity Name'

'DxfCode.Color is for ACI color - 1 = Red

Dim values() As TypedValue = { _

New TypedValue(DxfCode.Start, "CIRCLE"), _

New TypedValue(DxfCode.Color, 1) _

}

Dim sfilter As New SelectionFilter(values) ' Create the filter using our
values...

'Set the selection options

Dim SelOpts As New PromptSelectionOptions()

SelOpts.MessageForAdding = "Select Red Circles:"

SelOpts.AllowDuplicates = True

'Make the selection:

Dim res As PromptSelectionResult = ed.GetSelection(SelOpts, sfilter)

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)

ed.WriteMessage((ControlChars.Lf + "You selected: " +
entity.GetType().FullName))

' ********************************************Put something here along the
lines of entity.value or id.value I can't find where the co-ords a re stored



Next id

Finally

myT.Dispose()

End Try

End Sub
*Simon
Message 7 of 7 (93 Views)

Re: Getting co-ordinates from selection set entities

06-01-2005 11:37 PM in reply to: *Simon
Albert,

Thanks for that. I had thought to do that but .ToString doesn't come up in
intellisense so I didn't try it. If you type it in it works fine. Thanks
very much.

Simon


"Albert Szilvasy" wrote in message
news:4862797@discussion.autodesk.com...
The problem is simple: you are trying to cast a Point3d to a String (the
exception thrown actually says that.)

You need to modify this:
------------------
Dim k
k = Circ.Center
ed.WriteMessage((ControlChars.Lf + "CENT " & k))
-----------------
To this:
----------------
Dim k
k = Circ.Center
ed.WriteMessage((ControlChars.Lf + "CENT " & k.ToString()))
-----------
I could've spotted this in first post if I was a bit more versed in VB.

Albert

"Simon" wrote in message
news:4859733@discussion.autodesk.com...
Albert,

Here's the code, much of it is as the sample from the sdk. I thought this
would be simple and it probably is once you know how.

Cheers,

Simon

Public Sub ssGetFilter()

'Setup

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

'Declare our filter entries this way.

'We build them the same way in ObjectARX.

'DxfCode.Start (equal to 0) - This is for 'Entity Name'

'DxfCode.Color is for ACI color - 1 = Red

Dim values() As TypedValue = { _

New TypedValue(DxfCode.Start, "CIRCLE"), _

New TypedValue(DxfCode.Color, 1) _

}

Dim sfilter As New SelectionFilter(values) ' Create the filter using our
values...

'Set the selection options

Dim SelOpts As New PromptSelectionOptions()

SelOpts.MessageForAdding = "Select Red Circles:"

SelOpts.AllowDuplicates = True

'Make the selection:

Dim res As PromptSelectionResult = ed.GetSelection(SelOpts, sfilter)

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)

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

ed.WriteMessage((ControlChars.Lf + "You selected: " +
entity.GetType().FullName))



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

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

Dim k

k = Circ.Center

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

End If

Next id

Finally

myT.Dispose()

End Try

End Sub






"Albert Szilvasy" wrote in message
news:4859720@discussion.autodesk.com...
Can you post a complete example that shows the problem? This is very much
possible and in fact fairly simple to do so I'd like to look at your code to
diagnose the problem.

Albert
"Simon" wrote in message
news:4859602@discussion.autodesk.com...
Hi,

I've been trying to get the co-ordinates of circles in a selection set as
created in the ObjectArx demo code. I have tried every method O can think of
but there doesn't seem to be a method of obtaining the value of the centres.
Code from the demo posted below with notes to indicate what I am trying to
do. I may be missing something obvious here as it should be a simple
process.

Thanks for any ideas.

Simon

Public Sub ssGetFilter()

'Setup

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

'Declare our filter entries this way.

'We build them the same way in ObjectARX.

'DxfCode.Start (equal to 0) - This is for 'Entity Name'

'DxfCode.Color is for ACI color - 1 = Red

Dim values() As TypedValue = { _

New TypedValue(DxfCode.Start, "CIRCLE"), _

New TypedValue(DxfCode.Color, 1) _

}

Dim sfilter As New SelectionFilter(values) ' Create the filter using our
values...

'Set the selection options

Dim SelOpts As New PromptSelectionOptions()

SelOpts.MessageForAdding = "Select Red Circles:"

SelOpts.AllowDuplicates = True

'Make the selection:

Dim res As PromptSelectionResult = ed.GetSelection(SelOpts, sfilter)

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)

ed.WriteMessage((ControlChars.Lf + "You selected: " +
entity.GetType().FullName))

' ********************************************Put something here along the
lines of entity.value or id.value I can't find where the co-ords a re stored



Next id

Finally

myT.Dispose()

End Try

End Sub

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