Trouble getting with Block attributes iCAD 7.2: SOLVED

The VBA forum deals with IntelliCAD 2000 VBA (Visual Basic for Applications) issues.

Moderator: CMS Inc

Post Reply
Accuright
Valued Contributor
Posts: 47
Joined: Thu Jul 26, 2012 2:19 pm

Trouble getting with Block attributes iCAD 7.2: SOLVED

Post by Accuright » Thu Oct 11, 2012 8:14 am

This snippet of code is for a parking space counter for land surveying. It goes through and counts the times a special handicapped symbol is placed. That part is easy. One instance of the block is one space. Regular parking spaces are counted by looking at the block, which has one attribute for the amount of parking spaces, and retrieving the textstring for that attribute.

It appears that calling the line

Code: Select all

MsgBox " OUTPUT : " & varAtts.Item(0).textString
results in no action. No message box is displayed. I've tried using an index of 1, but as per earlier posts from valued contributors, all selection sets are zero-based now in IntelliCAD. Using an index of 1 doesn't seem to make any difference. If I comment out the variable part of that message box, it is displayed.

Does anyone know the proper method or more details on working with the GetAttributes property? All the examples I've found seem to match the methods I've used.

Code: Select all

For i = 0 To (entcount - 1)
        Set objEntity = ThisWorkspace.ActiveDocument.ModelSpace.Item(i)
        If objEntity.EntityType = vicBlockInsert And objEntity.Layer = "TRAFFIC" Then
            Set objBlockRef = objEntity
            BLOCKNAME = objBlockRef.Name
            If BLOCKNAME = "HANDICAP" Then HCOUNT = HCOUNT + 1
            If BLOCKNAME = "PARKING SPACES" Then
                MsgBox objBlockRef.GetAttributes.count 'Returns 1 which is correct
                Set varAtts = objBlockRef.GetAttributes
                'PROBLEM: THIS IS RETURNING NOTHING TO THE VARIABLE!
                    MsgBox " OUTPUT : " & varAtts.Item(0).textString
                'PCOUNT = PCOUNT + val(varAtts)
            End If
        End If
    Next i
[/code]
Last edited by Accuright on Mon Oct 29, 2012 10:54 am, edited 1 time in total.
Accuright
Valued Contributor
Posts: 47
Joined: Thu Jul 26, 2012 2:19 pm

RESOLVED

Post by Accuright » Mon Oct 29, 2012 10:53 am

I resolved this issue, here are the details:

I starting trying to go deeper into the BlockInsert entity, to try and parse through it's individual entities. The only option I had of doing this was to explode the block. That's not right, since we can't leave the blocks exploded...

Instead of setting a pointer to ObjBlockRef.GetAttributes, I used a For Each loop to go through each Attribute in ObjBlockRef.GetAttributes. This method allows the vba to pull the textstring out of each attribute.

Now the code writes as follows:

Code: Select all

    entcount = ThisWorkspace.ActiveDocument.ModelSpace.count
        
    For i = 0 To (entcount - 1)
        Set objEntity = ThisWorkspace.ActiveDocument.ModelSpace.Item(i)
        If objEntity.EntityType = vicBlockInsert And objEntity.Layer = "TRAFFIC" Then
            Set objBlockRef = objEntity
            BLOCKNAME = objBlockRef.Name
            
            If LCase(BLOCKNAME) = LCase("HC") Or LCase(BLOCKNAME) = LCase("HANDICAP") Then HCOUNT = HCOUNT + 1
            If LCase(BLOCKNAME) = LCase("PS") Or LCase(BLOCKNAME) = LCase("PARKING SPACES") Then
                For Each objAttrib In objBlockRef.GetAttributes
                    ps = objAttrib.textString
                    PCOUNT = PCOUNT + Val(ps)
                Next objAttrib
            End If
        End If
    Next i
Post Reply