• Industries
  • Products
  • Buy
  • Services & Support
  • Communities
  • Discussion Groups

    .NET

    Reply
    *Simon

    Getting co-ordinates from selection set entities

    83 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
    Please use plain text.
    *Frank Oquendo

    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.
    Please use plain text.
    *Simon

    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.
    Please use plain text.
    *Albert Szilvasy

    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
    Please use plain text.
    *Simon

    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
    Please use plain text.
    *Albert Szilvasy

    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
    Please use plain text.
    *Simon

    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
    Please use plain text.