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

Getting co-ordinates from selection set entities

6 REPLIES 6
Reply
Message 1 of 7
Anonymous
401 Views, 6 Replies

Getting co-ordinates from selection set entities

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

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

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

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

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

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

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

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