View Full Version : Adding a "Layout" filter when getting a selection
kyheulon
25-08-2004, 04:07 PM
I'm new to the forum and VBA, so thanks for any help. I can create a selection set by getting ALL the blocks by name. But I want to get is just the block references in the current layout and put that in the SS. How can I add the "filtering" for objects in the current Layout.
Thanks,
Eddie
25-08-2004, 11:47 PM
8) Can you post your code so we see what the code is doing ?
It may help us help you.
kyheulon
27-08-2004, 09:42 PM
Here's the code... It finds all the blockreferences in all the layouts. I just want the blockreference in the current layout. Thanks,
Public Sub AttrGet()
Dim oSSet As AcadSelectionSet, iGroup(0 To 1) As Integer, vData(0 To 1) As Variant
Dim oBlkRef As AcadBlockReference
Dim vAttribs As Variant, vAttrib As Variant
Dim sAttrib As String
Set oSSet = ThisDrawing.SelectionSets.Add("SSGet2")
iGroup(0) = 0: vData(0) = "INSERT"
iGroup(1) = 2: vData(1) = "SHT-INFO"
oSSet.Select acSelectionSetAll, , , iGroup, vData
For Each oBlkRef In oSSet
If oBlkRef.HasAttributes Then
vAttribs = oBlkRef.GetAttributes
For Each vAttrib In vAttribs
If vAttrib.TagString = "SHEET-NO" Then
sAttrib = vAttrib.TextString
vAttrib.TextString = "Test"
End If
Next vAttrib
End If 'oBlkRef.HasAttributes
Next oBlkRef
oSSet.Delete
Set oSSet = Nothing
Set oBlkRef = Nothing
End Sub
TCARPENTER
30-08-2004, 04:18 PM
The code you have is doing what it should, selecting any entity which is a block. Switch your code to look like this and it should work:
Dim ...iGroup(0 To 3) As Integer, vData(0 To 3) As Variant
iGroup(0) = -4: vData(0) = "<and"
iGroup(1) = 0: vData(1) = "INSERT"
iGroup(2) = 2: vData(2) = "SHT-INFO"
iGroup(3) = -4: vData(3) = "and>"
HTH
Todd
kyheulon
31-08-2004, 12:21 PM
I added the code that you gave and it didn't change the outcome of the macro. It still puts in the selection set all the blockreferences in all the layouts, not the blockreference(s) in the current layout. If you have any other ideas let me know. Thanks!
YosSa
31-08-2004, 12:24 PM
ThisDrawing.ActiveLayout .................
kyheulon
31-08-2004, 12:31 PM
ThisDrawing.ActiveLayout??? Where do you want me to use this? In the line where I set the selection set? This doesn't work.
YosSa
31-08-2004, 12:33 PM
you could use it in in a if statement ...
if thisdrawing.activelayout = "paper" then ...
Just throwing in some options ....
Dont get mad :)
TCARPENTER
31-08-2004, 04:30 PM
kyheulon,
Sorry, I misunderstood what you were looking for. You won't be able to build a filter for selecting the blocks in the particular layout you're looking for. You'll need to parse each entity in the current layout. If I understand correctly, you are trying to locate a specific block within the current or active layout. With that in mind, your code should look something like this:
Public Sub AttrGet()
Dim oBlkRef As AcadBlockReference
Dim vAttribs As Variant, vAttrib As Variant
Dim sAttrib As String
Dim oEnt As AcadEntity
' Parse each entity in the current space - if the block you are
' looking for should always be in paperspace use ThisDrawing.PaperSpace.
' If its model space, use ThisDrawing.ModelSpace.
' If it can be in any space, you'll need to walk the entire collection of layouts.
'
For Each oEnt In ThisDrawing.PaperSpace
' Check if the current entity is an inserted block or not.
'
If oEnt.ObjectName = "AcDbBlockReference" Then
Set oBlkRef = oEnt
' Now check the block for the correct block.
'
If oBlkRef.Name = "SHT-INFO" Then
' Check the block for attributes.
'
If oBlkRef.HasAttributes Then
vAttribs = oBlkRef.GetAttributes
For Each vAttrib In vAttribs
If vAttrib.TagString = "SHEET-NO" Then
sAttrib = vAttrib.TextString
vAttrib.TextString = "Test"
End If
Next vAttrib
' If looking for only one instance to update, then exit the sub,
' otherwise continue on.
'
Exit Sub ' Comment this out (or delete it) if looking for more than one instance.
End If 'oBlkRef.HasAttributes
End If 'oBlkRef.Name = "SHT-INFO"
End If ' oEnt.ObjectName = "AcDbBlockReference"
Next oEnt
Set oEnt = Nothing
Set oBlkRef = Nothing
End Sub
It's not as elegant as using filters but its the about the only way to get done what you need.
HTH
Todd
sschevers
23-09-2004, 09:45 AM
You can use the filter option
dim curLayoutName as string
curLayoutName = thisdrawing.activelayout.Name
Dim ...iGroup(0 To 4) As Integer, vData(0 To 4) As Variant
iGroup(0) = -4: vData(0) = "<and"
iGroup(1) = 0: vData(1) = "INSERT"
iGroup(2) = 2: vData(2) = "SHT-INFO"
iGroup(3) = 410 :vData(3)= curlayoutName
iGroup(4) = -4: vData(4) = "and>"
this will do the job
Phil Brogan
05-01-2005, 05:07 PM
You can use the filter option
dim curLayoutName as string
curLayoutName = thisdrawing.activelayout.Name
Dim ...iGroup(0 To 4) As Integer, vData(0 To 4) As Variant
iGroup(0) = -4: vData(0) = "<and"
iGroup(1) = 0: vData(1) = "INSERT"
iGroup(2) = 2: vData(2) = "SHT-INFO"
iGroup(3) = 410 :vData(3)= curlayoutName
iGroup(4) = -4: vData(4) = "and>"
Did anybody actually TRY this? The group code 410 has always worked in LISP when filtering sets on the basis of the associated Layout, but the object.select method returns an empty set when 410 is included as one of the filters in VBA.
Anybody?
this will do the job
TCARPENTER
05-01-2005, 05:47 PM
Phil,
I have tried this in the past and had no luck, and since reading you post, I did try it again just for grins and still no luck. Maybe sschevers is on a more recent release than you and I are, I'm still on 2002.
HTH
Todd
Phil Brogan
05-01-2005, 06:02 PM
It's good to know I'm not going nuts.
I think the problem is likely that we [all] have progressed to R2002 or better, rather than being behind in our revs. I think that R2002 and later now handles Layout associations differently than was done previously.
In examining the DXF file, there is some correlation between a block object and its Layout, but the correlation is indirect, and I haven't been able to figure out what it is, much less relate it to something in VBA I can use.
Thanks,
Phil
sschevers
06-01-2005, 08:11 AM
:oops: :oops: :oops:
having a lisp background also I assumed the filter option would work in VBA also. In the past I used the filter option 67 ( the code for model or paperspace) en that worked fine. So I thougth 410 would work also.
Maybe make a function in lisp and call it via sendcommand (not the best option i know) en store the data in one of the uservars.(Don't know if it's possible to store objects or entities in the uservars.) If you use the sendcommand make a smalle function like
sub selset
ThisDrawing.SendCommand "lispfunction"
end sub
An other option is to use the reference to the vlisp enviroment.
see the link below
http://www.augi.com/publications/hotnews.asp?page=578
never tried it but mabey it's an option
vBulletin® v3.7.3, Copyright ©2000-2009, Jelsoft Enterprises Ltd.