+ Reply to Thread
Results 1 to 8 of 8
  1. #1
    Super Member Tyke's Avatar
    Computer Details
    Tyke's Computer Details
    Operating System:
    Windows 7 - 64 bit, Vista and XP Pro
    Computer:
    HP Z400 Workstation
    CPU:
    Intel(R) Xeon(R) CPU W3530 @ 2.80GHz
    RAM:
    8 GB
    Graphics:
    Nvidia Quadro 600 1GB DDR3
    Primary Storage:
    2x 500GB HDD RAID 1 and Western Digital 2TB NAS RAID 1
    Secondary Storage:
    Lacie external HDD 2TB Raid Level 1
    Monitor:
    Samsung SyncMaster P2770HD, 2443 and 193T
    Discipline
    Multi-disciplinary
    Tyke's Discipline Details
    Occupation
    Surveyor, programmer, civil engineer
    Discipline
    Multi-disciplinary
    Details
    Surveying and civil engineering. As built utilities surveys and data maintenance in GIS systems. Building surveys, measured and laser scanning. Setting out of all civil works. Control and settlement surveys. Programming in AutoCAD, MicroStation, Geograf and stand alone applications for all uses.
    Using
    Civil 3D 2013
    Join Date
    Jun 2006
    Location
    Saxony, Germany
    Posts
    858

    Default Stripping block attributes

    Registered forum members do not see this ad.

    I have a VBA routine which strips all of the attributes from all of the blocks in a drawing, see following code:

    Code:
        Dim oEnt As AcadEntity
        Dim i As Integer
        
        ' get all blocks in drawing
        Set colBlocks = ThisDrawing.Blocks
        
        ' iterate each block and remove all of the attribute definitions
        For Each objBlock In colBlocks
            For Each oEnt In objBlock
                If oEnt.ObjectName = "AcDbAttributeDefinition" Then
                    oEnt.Delete
                End If
            Next oEnt
    
            ThisDrawing.SendCommand "_ATTSYNC" & vbCr & "NAME" & vbCr & objBlock.Name & vbCr
    
        Next objBlock
        
        ' iterate each block reference and remove its attribute references
        For Each oEnt In ThisDrawing.ModelSpace
            If TypeOf oEnt Is AcadBlockReference Then
                Set objBlockRef = oEnt
                If objBlockRef.HasAttributes Then
                    varAttribs = objBlockRef.GetAttributes
                    For i = LBound(varAttribs) To UBound(varAttribs)
                        varAttribs(i).Delete
                    Next i
                End If
            End If
            
        Next oEnt
        
        ThisDrawing.Regen acAllViewports
        ThisDrawing.PurgeAll
    This part works fine, but when I run a further routine in which I select a single block on screen, I test to see if the block has any attributes and depending on the result I display the appropriate form. At this point none of the blocks have any attribute references or definitions and I have confirmed this by checking the properties panel after selecting a block and by using the block editor. I have used the following code to check for any attributes:

    Code:
            ' check if block already has some attributes
            ' and then show the appropriate form
            If objBlockRef.HasAttributes = True Then
                frmAppend.Show
                Me.Hide
            Else
                frmAddAtts.Show
                frmAddAtts.cbxFirstAttName.SetFocus
                Me.Hide
            End If
    After executing the line in red it always evaluates to True even though there are no attributes.

    Even if I quit the macro, do something else and then restart the macro, it still always evaluates to True.

    What am I doing wrong?

    If I save the drawing nothing changes, but if I close and reopen the drawing the test for arributes evaluates as False, as it should.
    Last edited by Tyke; 25th Jul 2012 at 10:35 am. Reason: Extra information added
    Engage brain before mouth

    "The German who types with a Yorkshire accent" - Dave Broada 2o1o

  2. #2
    Luminous Being dbroada's Avatar
    Computer Details
    dbroada's Computer Details
    Operating System:
    XP Pro
    Computer:
    Dell
    CPU:
    Intel Xeon 2.13GHz
    RAM:
    2GB
    Graphics:
    NVIDA Quadro FX 580
    Monitor:
    DELL 23" & SAMSUNG 21"
    Discipline
    Electro/Mech
    dbroada's Discipline Details
    Occupation
    Design Engineer
    Discipline
    Electro/Mech
    Using
    Electrical 2013
    Join Date
    Nov 2005
    Location
    Sussex, UK
    Posts
    5,061

    Default

    I can't answer this (even if I wasn't at home) but could this have something to do with ATTSYNC? You can manually delete all the attributes in a block but its not until you ATTSYNC the block that the attributes disappear from the existing blocks. As I say, no idea but may be worth exploring until somebody more clued up than me arrives.

    ----------------------------------

    and of course I have now looked a bit closer and see you already ATTSYNC. Maybe you do it at the wrong time
    "That's it. It's one thing for a ghost to terrorize my children, but quite another for him to play my Theremin." Homer Simpson

    Dave

  3. #3
    Super Member Tyke's Avatar
    Computer Details
    Tyke's Computer Details
    Operating System:
    Windows 7 - 64 bit, Vista and XP Pro
    Computer:
    HP Z400 Workstation
    CPU:
    Intel(R) Xeon(R) CPU W3530 @ 2.80GHz
    RAM:
    8 GB
    Graphics:
    Nvidia Quadro 600 1GB DDR3
    Primary Storage:
    2x 500GB HDD RAID 1 and Western Digital 2TB NAS RAID 1
    Secondary Storage:
    Lacie external HDD 2TB Raid Level 1
    Monitor:
    Samsung SyncMaster P2770HD, 2443 and 193T
    Discipline
    Multi-disciplinary
    Tyke's Discipline Details
    Occupation
    Surveyor, programmer, civil engineer
    Discipline
    Multi-disciplinary
    Details
    Surveying and civil engineering. As built utilities surveys and data maintenance in GIS systems. Building surveys, measured and laser scanning. Setting out of all civil works. Control and settlement surveys. Programming in AutoCAD, MicroStation, Geograf and stand alone applications for all uses.
    Using
    Civil 3D 2013
    Join Date
    Jun 2006
    Location
    Saxony, Germany
    Posts
    858

    Default

    Quote Originally Posted by dbroada View Post
    I can't answer this (even if I wasn't at home) but could this have something to do with ATTSYNC? You can manually delete all the attributes in a block but its not until you ATTSYNC the block that the attributes disappear from the existing blocks. As I say, no idea but may be worth exploring until somebody more clued up than me arrives.
    Thanks Dave, I already tried that, programatically and directly in AutoCAD, but it didn't achieve anything
    Engage brain before mouth

    "The German who types with a Yorkshire accent" - Dave Broada 2o1o

  4. #4
    Full Member
    Discipline
    Electrical
    btraemoore's Discipline Details
    Occupation
    Electrical Designer
    Discipline
    Electrical
    Using
    Electrical 2012
    Join Date
    Apr 2012
    Location
    Houston
    Posts
    55

    Default

    are you trying strip the attributes and then repopulate them with a user form? Im a little confused as to the goal your trying to achieve.
    Last edited by btraemoore; 25th Jul 2012 at 03:27 pm.

  5. #5
    Full Member
    Discipline
    Electrical
    btraemoore's Discipline Details
    Occupation
    Electrical Designer
    Discipline
    Electrical
    Using
    Electrical 2012
    Join Date
    Apr 2012
    Location
    Houston
    Posts
    55

    Default

    try this and see if you can get it to do what you want.

    i like to use selection sets, so attached to the bottom is a sub that deletes all selection sets before running the code. (good for debugging)

    When I was debugging I did notice that it kept verifying that it DID have attributes, but when you request anything from the attribute it canceled out because there were none. my guess is that because of the type of block it is programmed to say " hey guy, I have attributes" when in all actuality it doesn't because we just deleted them all. I don't know how to fix that problem but by adding 5 lines of code, the problem can be dealt with. Good food for thought on the main problem though, we can learn something from it.



    Code:
    Sub NameOfYourChoice()
    
        SS_delete 1
        
        Dim gpCode(0) As Integer
        Dim dataValue(0) As Variant
        Dim SS_Example As AcadSelectionSet
        Dim i As Integer
       
        Set SS_Example = ThisDrawing.SelectionSets.Add("SS_Example")
            gpCode(0) = 0: dataValue(0) = "INSERT"
           
        SS_Example.Select acSelectionSetAll, , , gpCode, dataValue
       
        Dim Cur_Blk As AcadEntity
        Dim Blk_Atts() As AcadAttributeReference
        Dim Cur_Att As AcadAttributeReference
        Dim n As Integer
    
        For i = 0 To SS_Example.Count - 1
            Set Cur_Blk = SS_Example.Item(i)
            Blk_Atts = Cur_Blk.GetAttributes
    
            For n = 0 To UBound(Blk_Atts)
                Set Cur_Att = Blk_Atts(n)
                
                Cur_Att.Delete
            Next n
        Next i
        
        Dim Att As Variant
        Application.Update
        For Each Item In SS_Example
            If Item.HasAttributes Then
                Blk_Atts = Item.GetAttributes
                For Each Att In Blk_Atts
                    If Att.TagString <> Empty Then
                        frmAppend.Show
                        frmAddAtts.Hide
                    Else
                        frmAddAtts.Show
                        frmAddAtts.cbxFirstAttName.SetFocus
                        frmAddAtts.Hide
                   End If
                Next
            End If
        Next
        Application.Update
    
    End Sub
    '-----------------------------------------------------------------
    
    Sub SS_delete(x As Byte)
        If ThisDrawing.SelectionSets.Count > 0 Then
        Dim i As Integer
            On Error Resume Next
            For i = 0 To ThisDrawing.SelectionSets.Count - 1
                ThisDrawing.SelectionSets.Item(i).Delete
            Next i
            On Error GoTo 0
        End If
    End Sub
    Last edited by btraemoore; 25th Jul 2012 at 04:07 pm. Reason: updated opinion

  6. #6
    Super Member Tyke's Avatar
    Computer Details
    Tyke's Computer Details
    Operating System:
    Windows 7 - 64 bit, Vista and XP Pro
    Computer:
    HP Z400 Workstation
    CPU:
    Intel(R) Xeon(R) CPU W3530 @ 2.80GHz
    RAM:
    8 GB
    Graphics:
    Nvidia Quadro 600 1GB DDR3
    Primary Storage:
    2x 500GB HDD RAID 1 and Western Digital 2TB NAS RAID 1
    Secondary Storage:
    Lacie external HDD 2TB Raid Level 1
    Monitor:
    Samsung SyncMaster P2770HD, 2443 and 193T
    Discipline
    Multi-disciplinary
    Tyke's Discipline Details
    Occupation
    Surveyor, programmer, civil engineer
    Discipline
    Multi-disciplinary
    Details
    Surveying and civil engineering. As built utilities surveys and data maintenance in GIS systems. Building surveys, measured and laser scanning. Setting out of all civil works. Control and settlement surveys. Programming in AutoCAD, MicroStation, Geograf and stand alone applications for all uses.
    Using
    Civil 3D 2013
    Join Date
    Jun 2006
    Location
    Saxony, Germany
    Posts
    858

    Default

    I'm wanting to completely strip the attributes and not repopulate them, and that I can do. When the attributes have been stripped there is an option to add new attribute(s) to a block, but the block is recognised as still having attributes, even though there aren't any there. This is just part of a larger program where amongst other things attributes can be added to blocks without any attributes and appended to blocks that already have attributes. One of the options in this program is to strip all of the attributes from all of the blocks and it was during testing that I found this problem.
    Engage brain before mouth

    "The German who types with a Yorkshire accent" - Dave Broada 2o1o

  7. #7
    Full Member
    Discipline
    Electrical
    btraemoore's Discipline Details
    Occupation
    Electrical Designer
    Discipline
    Electrical
    Using
    Electrical 2012
    Join Date
    Apr 2012
    Location
    Houston
    Posts
    55

    Default

    okay cool, so you got the problem worked out?

    i realized what you were doing when i was debugging, the code i posted should fix it.

  8. #8
    Super Member Tyke's Avatar
    Computer Details
    Tyke's Computer Details
    Operating System:
    Windows 7 - 64 bit, Vista and XP Pro
    Computer:
    HP Z400 Workstation
    CPU:
    Intel(R) Xeon(R) CPU W3530 @ 2.80GHz
    RAM:
    8 GB
    Graphics:
    Nvidia Quadro 600 1GB DDR3
    Primary Storage:
    2x 500GB HDD RAID 1 and Western Digital 2TB NAS RAID 1
    Secondary Storage:
    Lacie external HDD 2TB Raid Level 1
    Monitor:
    Samsung SyncMaster P2770HD, 2443 and 193T
    Discipline
    Multi-disciplinary
    Tyke's Discipline Details
    Occupation
    Surveyor, programmer, civil engineer
    Discipline
    Multi-disciplinary
    Details
    Surveying and civil engineering. As built utilities surveys and data maintenance in GIS systems. Building surveys, measured and laser scanning. Setting out of all civil works. Control and settlement surveys. Programming in AutoCAD, MicroStation, Geograf and stand alone applications for all uses.
    Using
    Civil 3D 2013
    Join Date
    Jun 2006
    Location
    Saxony, Germany
    Posts
    858

    Default

    Registered forum members do not see this ad.

    Sorry I didn't get back sooner but I was out of the office all day yesterday.

    Thanks for the code Trae, but unfortunately it didn't fix the problem.

    When debugging I saw that when a block doesn't have any attributes and when .HasAttributes is queried and it says the block does have some attributes, that the upper bound for the attributes returned is -1. I used this value (< 0 really) when looping the attributes and managed with a little bit of tweaking to get the correct form to show. I used my code to strip the attributes and then the following code for showing the appropriate form:

    Code:
            ' check if block already has some attributes
            ' and then show the appropriate form
            
            Dim Blk_Atts() As AcadAttributeReference
            Dim Att           As Variant
            Dim Item         As Variant
                   
            If objBlockRef.HasAttributes = True Then
                Blk_Atts = objBlockRef.GetAttributes
                Item = UBound(Blk_Atts)
                
                'If Att.TagString <> Empty Then
                If Item < 0 Then
                     frmAddAtts.Show
                     frmAddAtts.cbxFirstAttName.SetFocus
                     Me.Hide
                Else
                     frmAppend.Show
                     Me.Hide
                End If
                   
            Else
                frmAddAtts.Show
                frmAddAtts.cbxFirstAttName.SetFocus
                Me.Hide
            End If
    I realize its just a work around and doesn't really solve the problem but I would still like to be able to strip the attributes and get a correct response from the .HasAttributes query.

    Thanks for your time and effort, it is appreciated. If I get to solve the problem I'll get back to you on it.
    Engage brain before mouth

    "The German who types with a Yorkshire accent" - Dave Broada 2o1o

Similar Threads

  1. Rotate block with attributes = messed attributes
    By diego gr in forum AutoCAD 2D Drafting, Object Properties & Interface
    Replies: 5
    Last Post: 23rd Jan 2012, 07:34 pm
  2. Object Data (OD) attributes to Block attributes
    By mpozauko in forum AutoLISP, Visual LISP & DCL
    Replies: 2
    Last Post: 6th Jan 2012, 01:08 pm
  3. Block Attributes, Creating Attributes
    By CADLee in forum AutoCAD 2D Drafting, Object Properties & Interface
    Replies: 2
    Last Post: 3rd Jan 2012, 06:40 pm
  4. Replace block and its attributes with new block and attributes
    By SPACECADET in forum AutoCAD Drawing Management & Output
    Replies: 9
    Last Post: 11th Feb 2011, 03:10 pm
  5. Stripping Quotation Marks from a Variable
    By Razoo in forum AutoLISP, Visual LISP & DCL
    Replies: 18
    Last Post: 9th Dec 2009, 05:28 pm

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts