Select on Screen filter for specific dynamic block

Select on Screen filter for specific dynamic block

Thomas.Long
Advocate Advocate
3,975 Views
4 Replies
Message 1 of 5

Select on Screen filter for specific dynamic block

Thomas.Long
Advocate
Advocate

I have a dynamic block that is going to go into a number of assemblies along with a multitude of other things. What I would like to do is filter by block name in order to only pick up that specific block. I've found several codes that suggest the way to do it, but when I try to do the same thing it won't allow me to select that block, as if it were filtering it out too.

 

All other parts of this code work except the filter. If I comment the filter out the program runs perfectly. I just need to get it to accept the data correctly and I think its because I'm called off Block Reference for the type to filter by.

 

'Select Information
'\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
    Set oSset = ThisDrawing.PickfirstSelectionSet
    oSset.Clear
    
    Dim fcode(1) As Integer
    Dim fdata(1) As Variant
    
    fcode(0) = 0
    fcode(1) = 2
        
    fdata(0) = "BLOCK REFERENCE"
    fdata(1) = "DYNAMIC BASE CHANNEL"


    oSset.SelectOnScreen fcode, fdata
'\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

 

 

0 Likes
Accepted solutions (1)
3,976 Views
4 Replies
Replies (4)
Message 2 of 5

norman.yuan
Mentor
Mentor
Accepted solution

To set selectionset filter by entity type - block reference, the entity type is not "Block Reference". It is "INSERT". That is, fData(0)="INSERT".

 

Also, if the block to be selected is dynamic block, you cannot be sure all the dynamic block references are selected if you include the block name (block definition's name, actually) in the filter., because a dynamic block reference could be a reference of an annonymous block. which is dynamically generated by AutoCAD when needed.

 

So, in your selection set filter, you should only filter out "INSERT", maybe other thing that could narrow down the selectionset, such as layer, color...but not by block name when the filter target is dynamic block.

 

Then you'll need write code to loop through the selectionset to test each selected block reference by its EffectiveName property to identify the target block reference.

Norman Yuan

Drive CAD With Code

EESignature

Message 3 of 5

Thomas.Long
Advocate
Advocate

Thank you!

 

I'm curious as to why it's labeled insert rather than block reference but I tested it and that worked. It's alright, I don't have to filter it anymore, I'll just tell them they have to avoid the other blocks in the assembly, or else turn them off. There are only a couple other blocks to really worry about so this should work just fine.

0 Likes
Message 4 of 5

jeremye86
Advocate
Advocate

you could use the property effectiveName to get a handle on the specific dynamic block you want.

example below

        FilterData(0) = "INSERT"
        FilterType(0) = 0
        Dim effName As String
        Set oSset = acadDoc.SelectionSets.Add("SS1")
        oSset.Select acSelectionSetAll, FilterType, FilterData
        lngRow = 18
        For Each objInSelect In oSset
            On Error Resume Next
            effName = objInSelect.EffectiveName
            On Error GoTo 0
            If effName = "Dyn_Panel" Then
                BlkAtts = objInSelect.GetAttributes
                .Cells(lngRow, "z").Value = BlkAtts(0).textString   ' pm name
                .Cells(lngRow, "aa").Value = 1
                BlkAtts = objInSelect.GetDynamicBlockProperties
                .Cells(lngRow, "ab").Value = BlkAtts(0).Value  'left len
                .Cells(lngRow, "ac").Value = BlkAtts(2).Value  'right len
                .Cells(lngRow, "ad").Value = BlkAtts(4).Value  ' bottom len
                .Cells(lngRow, "ae").Value = BlkAtts(6).Value  'panel type
                lngRow = lngRow + 1
            End If
        Next objInSelect
0 Likes
Message 5 of 5

Anonymous
Not applicable

 filter_Type = 2 repalce = 100. it is ok

0 Likes