LISP newb needs suggestion

Discussion in 'AutoCAD' started by Ozzie, Aug 16, 2004.

  1. Ozzie

    Ozzie Guest

    this post will be completely clear :)

    I will have some blocks in a drawing that their respective layer(s) will populate a list box on macro open (it does this ok). I want to be able to click on any layer in the 1st list box, then the 2nd list box will display the block name that is associated with. When I insert a block into a drawing it takes on the current layer name, but I need the actual block name instead of the current layer name.
     
    Ozzie, Aug 16, 2004
    #1
  2. Ozzie

    john m Guest

    clear as mud

    it sounds like you are wanting to insert a block on a layer with the same
    name as the block?

    populate a list box on macro open (it does this ok). I want to be able to
    click on any layer in the 1st list box, then the 2nd list box will display
    the block name that is associated with. When I insert a block into a drawing
    it takes on the current layer name, but I need the actual block name instead
    of the current layer name.
     
    john m, Aug 19, 2004
    #2
  3. Ozzie

    Ozzie Guest

    Not quite. What I am trying to do is this. After a purge, all that is left sometimes (unfortunately) are a few hidden blocks. My app populates a list box with the layers of these "hidden" blocks. I want to be able to select any layer from the 1st list box and another list box will populate the associated block name with that layer(s) that is/are left over. (I know it sounds a bit weird, but our drawings sometimes do this when we are cleaning them up.) In our drawings if I were to insert a block (ex. name- Fred99) on, lets say, layer L2, Fred99 exists as a block, but when you click on it, the layer manager tells you it is L2. I sure could use some coding help on this one.
     
    Ozzie, Aug 19, 2004
    #3
  4. This is untested theory.
    1. Insert the block.
    2. Explode the block. (Returns array of entities and keeps block)
    3. Delete the block.
    4. Cycle through the array of entities.
    5. Delete the exploded entities.

    Regards - Nathan
     
    Nathan Taylor, Aug 20, 2004
    #4
  5. Ozzie, Could you send a sample dwg...This has got me intrigued...
    sometimes (unfortunately) are a few hidden blocks. My app populates a list
    box with the layers of these "hidden" blocks. I want to be able to select
    any layer from the 1st list box and another list box will populate the
    associated block name with that layer(s) that is/are left over. (I know it
    sounds a bit weird, but our drawings sometimes do this when we are cleaning
    them up.) In our drawings if I were to insert a block (ex. name- Fred99) on,
    lets say, layer L2, Fred99 exists as a block, but when you click on it, the
    layer manager tells you it is L2. I sure could use some coding help on this
    one.
     
    Paul Richardson, Aug 20, 2004
    #5
  6. Ozzie

    Ozzie Guest

    I would, but I cant, property of my work....I guess all I need to know is how can I select a layer in a list box (this layer belongs to a block), then in another list box show the block it is associated with. I fI could get help with that, I would be eternally greatful :)
     
    Ozzie, Aug 20, 2004
    #6
  7. I'm not sure what you are trying to find.

    In the second list box, what do you want to see?
    -- the other block names that have any entities in them that are on the
    layer you picked in the first box? OR
    -- the other block names whose block references are inserted on the layer
    you picked?

    James
     
    James Belshan, Aug 20, 2004
    #7
  8. Ozzie

    Mark Propst Guest

    Ozzie,

    first off, from the subject line i first thought you were looking for a lisp
    solution, but since this is the vba group and you mention listbox i'll
    assume you're looking for a vba solution.

    I'm still confused about what you're trying to do.
    You say you already know how to get the layers in a listbox.
    You know how to select the layer and get it's name.
    So lets ignore that part and figure you already have it under control.

    Starting with the fact that you have a layer name, (lets say "layerX")
    what do you mean by find
    "the block it is associated with"

    "associated with" has no direct meaning as far as autocad goes (at least as
    far as I'm aware) so what exactly (in autocad terms) do you mean?
    do you mean find all block references that are inserted on "layerX" ?
    or
    do you mean find all block definitions in which are contained elements who
    are 'on' "layerX"?
    ie elements whose Layer Property = "LayerX"
    or
    are you possibly meaning that you have block definitions which include
    attributes and therefore also contain (though they are difficult to "see") a
    sequenceend object, and the seqend object is on "LayerX"
    and therefore the layer can't be purged????

    so I guess I'm wondering if your question could be reworded to something
    like this,
    I have a layer that I want to purge, "layerX"
    I've searched all objects in the database and all objects in all blocks in
    the database and none of them have a layer property = "layerX"
    and yet I still can't purge it - I get an error saying that layer is
    referenced and can't be purged.
    What is holding on to that layer, and how can I find it?

    that's my best wild guess as to what your real question is, but I may be way
    off the mark here!
    (i usually am!)
    :)

    hope you solve your dilema, whatever it is.
    Good luck
    Mark




    how can I select a layer in a list box (this layer belongs to a block), then
    in another list box show the block it is associated with. I fI could get
    help with that, I would be eternally greatful :)
     
    Mark Propst, Aug 20, 2004
    #8
  9. Ozzie

    Ozzie Guest

    What I mean is the following. All blocks can have multiple layers. There are a few cases when, after a purge, a few hidden blocks still exist. I have it coded so that after the purge I can populate a list box with all outstanding layers left over ("unpurgable" layers because they belong to hidden blocks. I want to be able to select any layer from that list and have another list box give the user which block (by block name) does this layer belong to. It is convoluted, sorry.
     
    Ozzie, Aug 21, 2004
    #9
  10. Ozzie

    Mark Propst Guest

    not sure what a 'hidden block' is.
    all block definitions are accessible through the blocks collection
    you can filter a selection set for any block you want to erase, erase them,
    then purge them, then purge their layers.
    or you can step through every block in the blocks collection
    then step through every entity in the block definition
    read it's layer to try to find your layer
    (except for attributes and sequends which you need to get from the block
    references themselves.)
    also layers which are frozen in viewports are unpurgable even though empty
    etc
    hth
    Mark

    are a few cases when, after a purge, a few hidden blocks still exist. I have
    it coded so that after the purge I can populate a list box with all
    outstanding layers left over ("unpurgable" layers because they belong to
    hidden blocks. I want to be able to select any layer from that list and have
    another list box give the user which block (by block name) does this layer
    belong to. It is convoluted, sorry.
     
    Mark Propst, Aug 22, 2004
    #10
  11. By cycling through the array of entities you can find out if the layer you are interested in is used in the block. So if you do it for each block in the blocks collection you will find the blocks you are interested in.
    Regards - Nathan
     
    Nathan Taylor, Aug 23, 2004
    #11
  12. After reading another post I realised my first post can simply be done as:
    Public Sub test()
    Dim objBlock As AcadBlock
    Dim objEntity As AcadEntity
    For Each objBlock In ThisDrawing.Blocks
    For Each objEntity In objBlock
    Debug.Print objEntity.Layer
    Next objEntity
    Next objBlock
    End Sub

    Regards - Nathan
     
    Nathan Taylor, Aug 23, 2004
    #12
  13. Ozzie

    Ozzie Guest

    do you have code example of how to do this? tyvm
     
    Ozzie, Aug 23, 2004
    #13
  14. Ozzie

    john m Guest

    now i know what you're refering to.
    this code is from Nathan Taylor's reply earlier
    he shows you how to go thru all the entities in all the block definitions.

    Public Sub test()
    Dim objBlock As AcadBlock
    Dim objEntity As AcadEntity
    For Each objBlock In ThisDrawing.Blocks
    For Each objEntity In objBlock

    Next objEntity
    Next objBlock
    End Sub

    so in the middle of the loop there you just need to say something like
    if objentity.layer = layerSelectedByUserInOtherListBox then
    NewListBox.additem objblock.Name
    end if

    jm
     
    john m, Sep 23, 2004
    #14
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.