Select an object on a specific layout

Select an object on a specific layout

Anonymous
Not applicable
365 Views
3 Replies
Message 1 of 4

Select an object on a specific layout

Anonymous
Not applicable
I'm having trouble trying to select a block on a specific paperspace layout.
I thought I had figured it out but the code won't select any blocks. I want
to retrieve a title block on the current layout only. Here is the function
I wrote:

Public Function GetTitleBlock(tsTitleBlockSS As AcadSelectionSet) As Boolean

Dim llTitleBlockFound As Boolean
Dim laDXFCode(3) As Integer
Dim laFilterValue(3) As Variant

On Error GoTo ErrorHandler

GetTitleBlock = True
'
' Get the title block.
'
Set tsTitleBlockSS = ThisDrawing.SelectionSets.Add("TBLK_SS")
If Not tsTitleBlockSS Is Nothing Then
laDXFCode(0) = -4
laFilterValue(0) = " laDXFCode(1) = 410
laFilterValue(1) = ThisDrawing.ActiveLayout.Name
laDXFCode(2) = 2
laFilterValue(2) = "TBLO*"
laDXFCode(3) = -4
laFilterValue(3) = "and>"
tsTitleBlockSS.Select acSelectionSetAll, , , laDXFCode, laFilterValue
If tsTitleBlockSS.Count > 0 Then
Set gbTitleBlockRef = tsTitleBlockSS.Item(0)
If Not gbTitleBlockRef.HasAttributes Then
ShowErrorMessage "No attributes defined in the found title block. "
& _
"Please insert a CRA title block and try again.",
True
GetTitleBlock = False
End If
Else
ShowErrorMessage "Unable to find a CRA standard title block in the
current drawing. " & _
"Please insert a CRA title block and try again.",
True
GetTitleBlock = False
End If
Else
ShowErrorMessage "Unable to create selection set possibly due to low
memory " & _
"or resources. Please close some applications and try
again.", True
GetTitleBlock = False
End If

Exit Function

ErrorHandler:

ShowErrorMessage Err.Description, True
GetTitleBlock = False

End Function

According to AutoDesk's DXF online reference, code 410 is the one for
layouts. All our title blocks here at work (CRA) are named starting with
the string TBLO. When I run this code from my routine in a drawing that has
two paperspace layouts and a title block on each, tsTitleBlockSS.Count
always returns 0.

Any help or suggestions would be greatly appreciated.

Stephen Fletcher
0 Likes
366 Views
3 Replies
Replies (3)
Message 2 of 4

Anonymous
Not applicable
Here's one way to get there from here. Tony Tanzillo clued me in to this
technique. If you want to run the code as is, you'll need to download my
avUtils.dll. Just follow the link below. Otherwise, I've noted the changes
you'll need to make. To test this routine, I placed one instance of the
block "test" in ModelSpace, two in Layout1, and three in Layout2. Even
though that makes six references, this routine will return only the three on
Layout2.

Public Sub test()

Dim fType, fData
Dim ss As AcadSelectionSet, ss2 As AcadSelectionSet
Dim objArray() As AcadEntity, max As Long

' This section only applies if you use avUtils.dll. If not, just
manually
' define two selection sets and your filter variables
Dim obj As VBAX
Set obj = New VBAX
Set ss = obj.CreateSelectionSet
Set ss2 = obj.CreateSelectionSet("ss2")
obj.BuildFilter fType, fData, "0,INSERT,2,TEST"

max = -1
ss.Select acSelectionSetAll, , , fType, fData

For i = 0 To ss.Count - 1
If ThisDrawing.ObjectIdToObject(ss.Item(i).OwnerID).Layout.Name =
"Layout2" Then
max = max + 1
ReDim Preserve objArray(0 To max)
Set objArray(max) = ss.Item(i)
End If
Next

ss2.AddItems objArray
Debug.Print ss2.Count

End Sub

--
Get free software and more at
http://msnhomepages.talkcity.com/protectionfault/foquendo

"Stephen Fletcher" wrote in message
news:87s2ai$a6410@adesknews2.autodesk.com...
> I'm having trouble trying to select a block on a specific paperspace
layout.
> I thought I had figured it out but the code won't select any blocks. I
want
> to retrieve a title block on the current layout only. Here is the
function
> I wrote:
>
>
> Public Function GetTitleBlock(tsTitleBlockSS As AcadSelectionSet) As
Boolean
>
> Dim llTitleBlockFound As Boolean
> Dim laDXFCode(3) As Integer
> Dim laFilterValue(3) As Variant
>
> On Error GoTo ErrorHandler
>
> GetTitleBlock = True
> '
> ' Get the title block.
> '
> Set tsTitleBlockSS = ThisDrawing.SelectionSets.Add("TBLK_SS")
> If Not tsTitleBlockSS Is Nothing Then
> laDXFCode(0) = -4
> laFilterValue(0) = " > laDXFCode(1) = 410
> laFilterValue(1) = ThisDrawing.ActiveLayout.Name
> laDXFCode(2) = 2
> laFilterValue(2) = "TBLO*"
> laDXFCode(3) = -4
> laFilterValue(3) = "and>"
> tsTitleBlockSS.Select acSelectionSetAll, , , laDXFCode, laFilterValue
> If tsTitleBlockSS.Count > 0 Then
> Set gbTitleBlockRef = tsTitleBlockSS.Item(0)
> If Not gbTitleBlockRef.HasAttributes Then
> ShowErrorMessage "No attributes defined in the found title block.
"
> & _
> "Please insert a CRA title block and try again.",
> True
> GetTitleBlock = False
> End If
> Else
> ShowErrorMessage "Unable to find a CRA standard title block in the
> current drawing. " & _
> "Please insert a CRA title block and try again.",
> True
> GetTitleBlock = False
> End If
> Else
> ShowErrorMessage "Unable to create selection set possibly due to low
> memory " & _
> "or resources. Please close some applications and
try
> again.", True
> GetTitleBlock = False
> End If
>
>
> Exit Function
>
> ErrorHandler:
>
> ShowErrorMessage Err.Description, True
> GetTitleBlock = False
>
> End Function
>
>
> According to AutoDesk's DXF online reference, code 410 is the one for
> layouts. All our title blocks here at work (CRA) are named starting with
> the string TBLO. When I run this code from my routine in a drawing that
has
> two paperspace layouts and a title block on each, tsTitleBlockSS.Count
> always returns 0.
>
> Any help or suggestions would be greatly appreciated.
>
> Stephen Fletcher
>
>
0 Likes
Message 3 of 4

Anonymous
Not applicable
That worked!

Thanks.

Frank Oquendo wrote in message
news:87saa5$a6736@adesknews2.autodesk.com...
> Here's one way to get there from here. Tony Tanzillo clued me in to this
> technique. If you want to run the code as is, you'll need to download my
> avUtils.dll. Just follow the link below. Otherwise, I've noted the changes
> you'll need to make. To test this routine, I placed one instance of the
> block "test" in ModelSpace, two in Layout1, and three in Layout2. Even
> though that makes six references, this routine will return only the three
on
> Layout2.
>
> Public Sub test()
>
> Dim fType, fData
> Dim ss As AcadSelectionSet, ss2 As AcadSelectionSet
> Dim objArray() As AcadEntity, max As Long
>
> ' This section only applies if you use avUtils.dll. If not, just
> manually
> ' define two selection sets and your filter variables
> Dim obj As VBAX
> Set obj = New VBAX
> Set ss = obj.CreateSelectionSet
> Set ss2 = obj.CreateSelectionSet("ss2")
> obj.BuildFilter fType, fData, "0,INSERT,2,TEST"
>
> max = -1
> ss.Select acSelectionSetAll, , , fType, fData
>
> For i = 0 To ss.Count - 1
> If ThisDrawing.ObjectIdToObject(ss.Item(i).OwnerID).Layout.Name =
> "Layout2" Then
> max = max + 1
> ReDim Preserve objArray(0 To max)
> Set objArray(max) = ss.Item(i)
> End If
> Next
>
> ss2.AddItems objArray
> Debug.Print ss2.Count
>
> End Sub
>
>
> --
> Get free software and more at
> http://msnhomepages.talkcity.com/protectionfault/foquendo
>
>
> "Stephen Fletcher" wrote in message
> news:87s2ai$a6410@adesknews2.autodesk.com...
> > I'm having trouble trying to select a block on a specific paperspace
> layout.
> > I thought I had figured it out but the code won't select any blocks. I
> want
> > to retrieve a title block on the current layout only. Here is the
> function
> > I wrote:
> >
> >
> > Public Function GetTitleBlock(tsTitleBlockSS As AcadSelectionSet) As
> Boolean
> >
> > Dim llTitleBlockFound As Boolean
> > Dim laDXFCode(3) As Integer
> > Dim laFilterValue(3) As Variant
> >
> > On Error GoTo ErrorHandler
> >
> > GetTitleBlock = True
> > '
> > ' Get the title block.
> > '
> > Set tsTitleBlockSS = ThisDrawing.SelectionSets.Add("TBLK_SS")
> > If Not tsTitleBlockSS Is Nothing Then
> > laDXFCode(0) = -4
> > laFilterValue(0) = " > > laDXFCode(1) = 410
> > laFilterValue(1) = ThisDrawing.ActiveLayout.Name
> > laDXFCode(2) = 2
> > laFilterValue(2) = "TBLO*"
> > laDXFCode(3) = -4
> > laFilterValue(3) = "and>"
> > tsTitleBlockSS.Select acSelectionSetAll, , , laDXFCode,
laFilterValue
> > If tsTitleBlockSS.Count > 0 Then
> > Set gbTitleBlockRef = tsTitleBlockSS.Item(0)
> > If Not gbTitleBlockRef.HasAttributes Then
> > ShowErrorMessage "No attributes defined in the found title
block.
> "
> > & _
> > "Please insert a CRA title block and try
again.",
> > True
> > GetTitleBlock = False
> > End If
> > Else
> > ShowErrorMessage "Unable to find a CRA standard title block in the
> > current drawing. " & _
> > "Please insert a CRA title block and try again.",
> > True
> > GetTitleBlock = False
> > End If
> > Else
> > ShowErrorMessage "Unable to create selection set possibly due to low
> > memory " & _
> > "or resources. Please close some applications and
> try
> > again.", True
> > GetTitleBlock = False
> > End If
> >
> >
> > Exit Function
> >
> > ErrorHandler:
> >
> > ShowErrorMessage Err.Description, True
> > GetTitleBlock = False
> >
> > End Function
> >
> >
> > According to AutoDesk's DXF online reference, code 410 is the one for
> > layouts. All our title blocks here at work (CRA) are named starting
with
> > the string TBLO. When I run this code from my routine in a drawing that
> has
> > two paperspace layouts and a title block on each, tsTitleBlockSS.Count
> > always returns 0.
> >
> > Any help or suggestions would be greatly appreciated.
> >
> > Stephen Fletcher
> >
> >
>
>
0 Likes
Message 4 of 4

Anonymous
Not applicable
In case you're interested, I added a FilterLayout method to avUtils.dll. You
feed it your selection set and a layout name you want, it'll remove all
objects from your selection set that that don't reside on the specified
layout.

--
Get free software and more at
http://msnhomepages.talkcity.com/protectionfault/foquendo

"Stephen Fletcher" wrote in message
news:87snje$ci829@adesknews2.autodesk.com...
> That worked!
>
> Thanks.
>
> Frank Oquendo wrote in message
> news:87saa5$a6736@adesknews2.autodesk.com...
> > Here's one way to get there from here. Tony Tanzillo clued me in to this
> > technique. If you want to run the code as is, you'll need to download my
> > avUtils.dll. Just follow the link below. Otherwise, I've noted the
changes
> > you'll need to make. To test this routine, I placed one instance of the
> > block "test" in ModelSpace, two in Layout1, and three in Layout2. Even
> > though that makes six references, this routine will return only the
three
> on
> > Layout2.
> >
> > Public Sub test()
> >
> > Dim fType, fData
> > Dim ss As AcadSelectionSet, ss2 As AcadSelectionSet
> > Dim objArray() As AcadEntity, max As Long
> >
> > ' This section only applies if you use avUtils.dll. If not, just
> > manually
> > ' define two selection sets and your filter variables
> > Dim obj As VBAX
> > Set obj = New VBAX
> > Set ss = obj.CreateSelectionSet
> > Set ss2 = obj.CreateSelectionSet("ss2")
> > obj.BuildFilter fType, fData, "0,INSERT,2,TEST"
> >
> > max = -1
> > ss.Select acSelectionSetAll, , , fType, fData
> >
> > For i = 0 To ss.Count - 1
> > If ThisDrawing.ObjectIdToObject(ss.Item(i).OwnerID).Layout.Name
=
> > "Layout2" Then
> > max = max + 1
> > ReDim Preserve objArray(0 To max)
> > Set objArray(max) = ss.Item(i)
> > End If
> > Next
> >
> > ss2.AddItems objArray
> > Debug.Print ss2.Count
> >
> > End Sub
> >
> >
> > --
> > Get free software and more at
> > http://msnhomepages.talkcity.com/protectionfault/foquendo
> >
> >
> > "Stephen Fletcher" wrote in message
> > news:87s2ai$a6410@adesknews2.autodesk.com...
> > > I'm having trouble trying to select a block on a specific paperspace
> > layout.
> > > I thought I had figured it out but the code won't select any blocks.
I
> > want
> > > to retrieve a title block on the current layout only. Here is the
> > function
> > > I wrote:
> > >
> > >
> > > Public Function GetTitleBlock(tsTitleBlockSS As AcadSelectionSet) As
> > Boolean
> > >
> > > Dim llTitleBlockFound As Boolean
> > > Dim laDXFCode(3) As Integer
> > > Dim laFilterValue(3) As Variant
> > >
> > > On Error GoTo ErrorHandler
> > >
> > > GetTitleBlock = True
> > > '
> > > ' Get the title block.
> > > '
> > > Set tsTitleBlockSS = ThisDrawing.SelectionSets.Add("TBLK_SS")
> > > If Not tsTitleBlockSS Is Nothing Then
> > > laDXFCode(0) = -4
> > > laFilterValue(0) = " > > > laDXFCode(1) = 410
> > > laFilterValue(1) = ThisDrawing.ActiveLayout.Name
> > > laDXFCode(2) = 2
> > > laFilterValue(2) = "TBLO*"
> > > laDXFCode(3) = -4
> > > laFilterValue(3) = "and>"
> > > tsTitleBlockSS.Select acSelectionSetAll, , , laDXFCode,
> laFilterValue
> > > If tsTitleBlockSS.Count > 0 Then
> > > Set gbTitleBlockRef = tsTitleBlockSS.Item(0)
> > > If Not gbTitleBlockRef.HasAttributes Then
> > > ShowErrorMessage "No attributes defined in the found title
> block.
> > "
> > > & _
> > > "Please insert a CRA title block and try
> again.",
> > > True
> > > GetTitleBlock = False
> > > End If
> > > Else
> > > ShowErrorMessage "Unable to find a CRA standard title block in
the
> > > current drawing. " & _
> > > "Please insert a CRA title block and try
again.",
> > > True
> > > GetTitleBlock = False
> > > End If
> > > Else
> > > ShowErrorMessage "Unable to create selection set possibly due to
low
> > > memory " & _
> > > "or resources. Please close some applications
and
> > try
> > > again.", True
> > > GetTitleBlock = False
> > > End If
> > >
> > >
> > > Exit Function
> > >
> > > ErrorHandler:
> > >
> > > ShowErrorMessage Err.Description, True
> > > GetTitleBlock = False
> > >
> > > End Function
> > >
> > >
> > > According to AutoDesk's DXF online reference, code 410 is the one for
> > > layouts. All our title blocks here at work (CRA) are named starting
> with
> > > the string TBLO. When I run this code from my routine in a drawing
that
> > has
> > > two paperspace layouts and a title block on each,
tsTitleBlockSS.Count
> > > always returns 0.
> > >
> > > Any help or suggestions would be greatly appreciated.
> > >
> > > Stephen Fletcher
> > >
> > >
> >
> >
>
>
0 Likes