Change color of last inserted block

Discussion in 'AutoCAD' started by TomV, Mar 17, 2005.

  1. TomV

    TomV Guest

    I've successfully inserted a block into my drawing. Now I want to change the color of the last inserted block (color is set to ByBlock). How do I accomplish this?

    I believe I want to use a selection set "Select" method and mode "acSelectionSetLast":

    objSS.Select acSelectionSetLast

    But then what do I do next?

    Getting my head wrapped around these VB classes and collections of collections of collections gets very confusing.

    Help!!! lol.
     
    TomV, Mar 17, 2005
    #1
  2. TomV

    Jeff Mishler Guest

    How are you inserting the block? What are you using to trigger the color
    change?
     
    Jeff Mishler, Mar 17, 2005
    #2
  3. TomV

    Tom Roberts Guest

    If you have used the InsertBlock method you will have a reference to the new
    BlockReference and you can change its Color property

    Sub InsertBlk()

    Dim BlkRef As AcadBlockReference
    Dim InstPnt As Variant

    InstPnt = ThisDrawing.Utility.GetPoint(, "Pick insertion point")
    Set BlkRef = ThisDrawing.ModelSpace.InsertBlock(InstPnt, "Your_Blk", 1#,
    1#, 1#, 0#)
    BlkRef.Color = acGreen

    End Sub

    --
    Regards
    Tom Roberts
    __________________________
    MechWest Design & Drafting
    Perth, Western Australia
     
    Tom Roberts, Mar 18, 2005
    #3
  4. TomV

    TomV Guest

    Tom - thanks for the help, that worked!

    Ok, that was too dang easy. But, I am confused about something. I use the Intellisense to show me the members as I type. Why doesn't the "color" property show in the list when I type "objBlockRef."? I went ahead and put the ".color" as Tom stated and it does work - even though it didn't show up using Intellisense.

    My code is shown below:

    Private Sub cmdInsertBlock_Click()
    Dim objBlockRef As AcadBlockReference
    Dim varInsertionPoint As Variant
    Dim strFileName As String

    strFileName = "c:\acadwork\other\bubble2.dwg"

    Me.Hide
    With ThisDrawing.Utility
    .InitializeUserInput 1
    varInsertionPoint = .GetPoint(, vbCr & "Pick the insert point: ")
    End With
    On Error Resume Next
    Set objBlockRef = ThisDrawing.ModelSpace.InsertBlock(varInsertionPoint, _
    strFileName, 1, 1, 1, 0)
    If Err Then
    MsgBox "Unable to insert this block"
    Exit Sub
    End If
    objBlockRef.color = acGreen
    objBlockRef.Update

    Me.Show
    End Sub
     
    TomV, Mar 18, 2005
    #4
  5. i guess that you are working with acad2005, the color property in 2005 is supported, but as the
    help says, maybe not supported in future releases.

    - alfred -
     
    Alfred NESWADBA, Mar 18, 2005
    #5
  6. TomV

    TomV Guest

    Thanks Alfred, I now see that the color property is obsolete. Should I be using TrueColor instead? I'd like to go ahead and program it to work with future versions.

    Thanks!
     
    TomV, Mar 19, 2005
    #6
  7. it is supported in acad2006 and i would therefore make a sub/function to set
    the color-property using now ".color" (because it's quicker) and when
    autodesk decides to cancel the color-property you would have to change
    only one sub within all your app's.

    - alfred -
     
    Alfred NESWADBA, Mar 19, 2005
    #7
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.