Can pass SS variable

Discussion in 'AutoCAD' started by kb, Aug 6, 2004.

  1. kb

    kb Guest

    I am having some difficulty with selecting an object in a drawing, and passing the object from the created selection set to another function that uses the selected object to retrieve the object data.

    You'll note below, I've created a selection set object call objSS, and passed that. It does not see the SS object though. If I change the code in the Object data retreival portion to acadObj (an autocad object), it retreives the OD for every object in the drawing. I need just the seleted entities OD not everything


    'Hide the form
    'Me.Hide
    UserForm1.Hide

    Dim SSetName As String
    Dim objSSet As AcadSelectionSet 'Define sset as a SelectionSet object
    On Error Resume Next
    ' Delete the Selection Set if it Exists
    If Not IsNull(ThisDrawing.SelectionSets.Item("SS2")) Then
    Set objSSet = ThisDrawing.SelectionSets.Item("SS2")
    objSSet.Delete
    End If

    'Set sset to a new selection set named SS2 (the name doesn't matter here)
    Set objSSet = ThisDrawing.SelectionSets.Add("SS2")
    objSSet.SelectOnScreen 'Prompt user to select objects



    ' Selection Set Name
    SSetName = "testList"


    'This is a test box to see if the correct objects were selected
    'Shut off during normal operation
    MsgBox ("Selection set " & objSSet.Name & " contains " & _
    objSSet.count & " items")

    'Get object data of selected object

    Dim acadApp As Object
    Dim amap As AcadMap

    Set acadApp = ThisDrawing.Application
    Set amap = acadApp.GetInterfaceObject("AutoCADMap.Application.2")

    Dim odTables As odTables
    Dim odTable As odTable
    Dim RecordIterator As ODRecords
    Dim odRecord As odRecord
    Dim odValue As ODFieldValue
    Dim msg As String
    Dim acadObj As AcadObject
    Dim i As Integer
    Dim count As Integer


    For Each objSSet In ThisDrawing.ModelSpace
    msg = ""
    ' get the selected object data table and iterator

    Set odTables = amap.Projects(ThisDrawing).odTables

    For i = 0 To odTables.count - 1
    Set odTable = odTables.Item(i)
    Set RecordIterator = odTables.GetODRecords
    Next

    ' initilize iterator on entity
    If RecordIterator.Init(objSSet, False, False) = True Then

    '' oops, that entity has no od attached to specified table
    If RecordIterator.IsDone Then
    msg = msg & "Entity has no data from Object Data Table: " & odTable.Name
    End If

    '' loop through all attached records from specified table
    'Setup a collection to dump the data into.
    Dim colDbaseValues As New Collection
    Do Until RecordIterator.IsDone
    '' get record data
    Set odRecord = RecordIterator.Record
    '' initialize field counter
    count = 0
    '' loop through each od field
    For Each odValue In odRecord
    '' get field name from defs
    msg = msg & odTable.ODFieldDefs.Item(count).Name

    '' and show field value
    Select Case odValue.Type
    Case 0, 1, 2, 3
    msg = msg & " = " & CStr(odValue.Value) & Chr(10)
    Case 4
    msg = msg & " = " & CStr(odValue.Value.X) & "," & CStr(odValue.Value.Y) & "," & CStr(odValue.Value.X) & Chr(10)
    End Select
    count = count + 1
    colDbaseValues.Add odValue.Value
    Next

    '' there may be more records attached
    RecordIterator.Next
    Loop

    '' error getting iterator
    Else
    '' report the bad news
    msg = "Error iterating Object Data Table: " & odTable.Name
    End If

    '' update text box
    MsgBox msg
    Next

    'This is where is calls the other function to populate the database
    'Currenlty used in conjunction with function AddODToDbase

    Set amap = Nothing
    Set acadApp = Nothing
     
    kb, Aug 6, 2004
    #1
  2. kb

    Ed Jobe Guest

    You don't show a name for the function that handles the data, but just add
    an argument to it.

    Function DataHandler ( sset as AcadSelectionset)

    Also, this line appears to do nothing:

    --
    ----
    Ed
    ----
    passing the object from the created selection set to another function that
    uses the selected object to retrieve the object data.
    passed that. It does not see the SS object though. If I change the code in
    the Object data retreival portion to acadObj (an autocad object), it
    retreives the OD for every object in the drawing. I need just the seleted
    entities OD not everything
    CStr(odValue.Value.Y) & "," & CStr(odValue.Value.X) & Chr(10)
     
    Ed Jobe, Aug 6, 2004
    #2
  3. kb

    kb Guest

    I had some garbage in there I guess. I've removed it.

    Also, this line appears to do nothing:
    As for the funtion name, I never included this. It is a button that when clicked does all the below code. So do I have to OD code into a function, then call that?

    Public Sub cmdExecute1_click()

    All the below code is after this
     
    kb, Aug 6, 2004
    #3
  4. kb

    kb Guest

    I figured it out for anyone who needs it.

    I need to define an entity, then change the OD portion of the code to use the selected entity in the selection set.

    Dim addObj As AcadEntity

    For Each addObj In objSSet
     
    kb, Aug 6, 2004
    #4
  5. kb

    Ed Jobe Guest

    If all the code is in the same form's class module, then you can declare a
    public var at the form level and it will have scope for the whole form. Add
    the following to the form's declaration section.

    Private objSSet As AcadSelectionSet

    Then get rid of the Dim statement in your button click.

    --
    ----
    Ed
    ----
    clicked does all the below code. So do I have to OD code into a function,
    then call that?
     
    Ed Jobe, Aug 6, 2004
    #5
  6. kb

    kb Guest

    Will that effect performance, dimensioning a value in the manner I did? I'm just wondering why you do this?
     
    kb, Aug 9, 2004
    #6
  7. kb

    Ed Jobe Guest

    I'm not quite sure I understand your first question. Its ok to have two vars
    for different ss's. What I pointed out is that you dim'd 2 but only used
    one, assigning to it twice. The second never got assigned and hence was
    empty.

    You write it as a function because its a task you do quite often. If the
    question relates to how it works: If you try to create a ss using a name
    that already exists in the collection, it will generate an error. On Error
    Resume Next ignores the error. Since you know why the error occured, the
    Then part of the If statement justs assigns the existing ss object to your
    variable. It uses the object's name rather than assuming a specific index
    because you just can't assume the index will always be the same.

    --
    ----
    Ed
    ----
    I'm just wondering why you do this?
     
    Ed Jobe, Aug 9, 2004
    #7
  8. kb

    kb Guest

    Sorry, I misunderstood your message. Thanks you've explained what I was wondering.

    I'm having HUGE difficulty querying the Database now. I can't get any results. For that matter I can't get a response at all. No errors nothing.

    I need to take the above varirable that I populated in the textbox1, and match it to a record in the database and return the corresponding record in another column called Road_ID.

    Any ideas? I have no idea how to accomplish this.
     
    kb, Aug 9, 2004
    #8
  9. kb

    Ed Jobe Guest

    Have you tried setting a breakpoint in your code and stepping through the
    code and examining the values of variables in the Locals window?

    --
    ----
    Ed
    ----
    results. For that matter I can't get a response at all. No errors nothing.
    match it to a record in the database and return the corresponding record in
    another column called Road_ID.
     
    Ed Jobe, Aug 9, 2004
    #9
  10. kb

    kb Guest

    Yes I have. But for some reason it seems that the value is stuck in the loop. I've created a new collection for the values in that loop so I don't know why the collection isn't getting populated.
     
    kb, Aug 10, 2004
    #10
  11. kb

    Ed Jobe Guest

    If you have a loop that doesn't work properly, then your logic for the loop
    is wrong. If the loop is working ok, but the collection still doesn't get
    populated, then your code to set an item in the collection is wrong. Try
    debugging in break mode again with this info.

    --
    ----
    Ed
    ----
    loop. I've created a new collection for the values in that loop so I don't
    know why the collection isn't getting populated.
     
    Ed Jobe, Aug 10, 2004
    #11
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.