Selection Set - Removing Blocks with a certain name

Discussion in 'AutoCAD' started by thenov, Oct 11, 2004.

  1. thenov

    thenov Guest

    I am writing an event (reactor) for the erase command. I want to take away the ability for the user to erase certain blocks. I am trying to automatically remove these blocks from a selection set in my erase event. I can't seem to figure this out. How do I automatically remove certain block names from a selection set so they can not be erased. Any Ideas?
     
    thenov, Oct 11, 2004
    #1
  2. thenov

    TomD Guest

    the ability for the user to erase certain blocks. I am trying to
    automatically remove these blocks from a selection set in my erase event. I
    can't seem to figure this out. How do I automatically remove certain block
    names from a selection set so they can not be erased. Any Ideas?

    With a filter, using the NOT key? I'm not certain of the actual code, but
    it should be fairly straight forward.

    Maybe something like the following:

    dim vCod(3) as Integer, vVal(3) as Variant
    vCod(0) = -4: vVal(0) = "<NOT"
    vCod(1) = 0: vVal(1) = "INSERT"
    vCod(2) = 2: vVal(2) = "YourBlockName"
    vCod(3) = -4: vVal(3) = "NOT>"
    WARNING! I did NOT test this and I'm not even sure if it would work, but I
    think the idea is workable.HTH
     
    TomD, Oct 11, 2004
    #2
  3. thenov

    Ed Jobe Guest

    Assuming you were monitoring for the Erase command via the BeginCommand
    event, you would have to get the selection set for the command in progress
    using ThisDrawing.ActiveSelectionSet. Since this is readonly, you wouldn't
    be able to alter the selection set. But if you find the blocks in the active
    selection set, you could try canceling the command with:
    SendKeys "{ESC}" & "{ESC}"

    You might want to prompt the user with info as to why their action wasn't
    successful.


    --
    ----
    Ed
    ----
    the ability for the user to erase certain blocks. I am trying to
    automatically remove these blocks from a selection set in my erase event. I
    can't seem to figure this out. How do I automatically remove certain block
    names from a selection set so they can not be erased. Any Ideas?
     
    Ed Jobe, Oct 11, 2004
    #3
  4. Is it read only as in a pointer to a constant object or read only as in
    cannot be assigned to?
     
    Frank Oquendo, Oct 11, 2004
    #4
  5. thenov

    Ed Jobe Guest

    I did some tests, here's what I found.
    TEST1 - this does not error, but also does not alter the ss that is passed
    to the erase command so it has no effect.
    Private Sub Doc_BeginCommand(ByVal CommandName As String)
    Dim ss As AcadSelectionSet
    If CommandName = "ERASE" Then
    ThisDrawing.ActiveSelectionSet.Clear
    ThisDrawing.Utility.Prompt "You are not allowed to erase these
    items."
    End If
    End Sub

    TEST2 - This only works if the obects are not selected first. In which case,
    you can't test for a block.
    Private Sub Doc_BeginCommand(ByVal CommandName As String)
    Dim ss As AcadSelectionSet
    If CommandName = "ERASE" Then
    SendKeys "{ESC}" & "{ESC}"
    ThisDrawing.Utility.Prompt "You are not allowed to erase these
    items."
    End If
    End Sub
     
    Ed Jobe, Oct 11, 2004
    #5
  6. thenov

    thenov Guest

    Great Idea!. However I was NOT able to get it to work. Is the syntax of the not operator shown correctly in your snippet? Also why the value of -4? Thanks!
     
    thenov, Oct 11, 2004
    #6
  7. thenov

    thenov Guest

    So there is NO Solution?
     
    thenov, Oct 11, 2004
    #7
  8. thenov

    Ed Jobe Guest

    Ed Jobe, Oct 11, 2004
    #8
  9. thenov

    TomD Guest

    the not operator shown correctly in your snippet? Also why the value of -4?
    Thanks!

    It may well be incorrect. I haven't done too much logial testing with
    filters in VBA. I'm about 85% sure the idea will work, just not sure of the
    code.

    Looking at a sample in Joe Sutphin's book, though not exactly like your
    situation, would seem to say that it should be more like this:

    <AND
    <NOT
    INSERT
    NOT>
    <NOT
    YourBlockName
    NOT>
    AND>

    If that's not sensible enough, repost and I'll rewrite the whole thing.
     
    TomD, Oct 11, 2004
    #9
  10. thenov

    thenov Guest

    Thanks for your help but I am still a little confused. When you get a minute could you please post the snippet. Thanks Again.
     
    thenov, Oct 11, 2004
    #10
  11. thenov

    Ed Jobe Guest

    The -4 is a dxf code that allows you to mark the start and end of logical
    grouping. However, even if you were to creat a selection set without the
    blocks, you still have the problem of preventing their deletion.

    --
    ----
    Ed
    ----
    minute could you please post the snippet. Thanks Again.
     
    Ed Jobe, Oct 11, 2004
    #11
  12. thenov

    Ed Jobe Guest

    I think your best bet is to redefine the ERASE command. I threw this
    together real quick. It doesn't set any sysvars like cmdecho or check the
    pickfirst ss, but should give you an idea. I used lisp because it will make
    it easier to redefine using acad.lsp.
    (defun c:erase1 ( / ss)
    (setq ss (ssget '(
    (-4 . "<NOT")
    (-4 . "<AND")
    (0 . "INSERT")
    (2 . "block1");if more than 1 blk "block1,block2"
    (-4 . "AND>")
    (-4 . "NOT>")
    )

    )
    )
    (command "erase" ss "")
    )
     
    Ed Jobe, Oct 11, 2004
    #12
  13. thenov

    thenov Guest

    Thanks Ed! This did the trick.
     
    thenov, Oct 11, 2004
    #13
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.