Setting block entities?

Setting block entities?

Anonymous
Not applicable
228 Views
3 Replies
Message 1 of 4

Setting block entities?

Anonymous
Not applicable
I want to run a sub using 2 options; 1. by selecting the object or 2. by
looping through the drawing blocks.
I can't figure out the correct syntax for this in order to get both options
to work. The Getentity utility doesn't work if I try to use an AcadBlock
instead of an AcadEntity. Also If I don't set oBlk as a block then I can't
loop through the drawing blocks.

Private Sub Panel()
InsertPanel
End Sub

Private Sub Panels()
Dim oBlk As AcadBlock
For Each oBlk In ThisDrawing.Blocks
InsertPanel oBlk
Next oBlk
End Sub

Private Sub InsertPanel(Optional oBlk As AcadBlock)
Dim oEnt As AcadEntity
Dim Pnt As Variant
On Error Resume Next
If oBlk Is Nothing Then
ThisDrawing.Utility.GetEntity oEnt, Pnt, "Select Panel to update: "

'I can't seem to set the oEnt variable
Else: Set oEnt = oBlk
End If

Debug.Print oEnt.Name
End Sub
0 Likes
229 Views
3 Replies
Replies (3)
Message 2 of 4

Anonymous
Not applicable
do you mean to be using blockreference rather than block?

"GARYNTX" wrote in message
news:0C9B0E829B3CCB4C27CD494FD5874399@in.WebX.maYIadrTaRb...
> I want to run a sub using 2 options; 1. by selecting the object or 2. by
> looping through the drawing blocks.
> I can't figure out the correct syntax for this in order to get both
options
> to work. The Getentity utility doesn't work if I try to use an AcadBlock
> instead of an AcadEntity. Also If I don't set oBlk as a block then I can't
> loop through the drawing blocks.
>
> Private Sub Panel()
> InsertPanel
> End Sub
>
> Private Sub Panels()
> Dim oBlk As AcadBlock
> For Each oBlk In ThisDrawing.Blocks
> InsertPanel oBlk
> Next oBlk
> End Sub
>
> Private Sub InsertPanel(Optional oBlk As AcadBlock)
> Dim oEnt As AcadEntity
> Dim Pnt As Variant
> On Error Resume Next
> If oBlk Is Nothing Then
> ThisDrawing.Utility.GetEntity oEnt, Pnt, "Select Panel to update: "
>
> 'I can't seem to set the oEnt variable
> Else: Set oEnt = oBlk
> End If
>
> Debug.Print oEnt.Name
> End Sub
>
>
0 Likes
Message 3 of 4

Anonymous
Not applicable
I see what you mean. I am actually going to use the blockreference at first.
So I take it I will have to loop through every entity in modelspace and
paperspace to get each block reference?
0 Likes
Message 4 of 4

Anonymous
Not applicable
A couple of suggestions, first you are definitely heading in the right
direction by pulling the common functionality out of the Panel and Panels
subs and putting that into it's own function.

Second, make the InsertPanel sub a function, even if it only returns a
boolean indicating success or failure of the operation. You don't have to
use the return value if you don't need, but it's invaluable when you find
that your entire application crashes in the event that this functions fails.
You may also want to consider a new name for the function. I think that
InsertPanel is a great function name, but perhaps not for this particular
function. What is it exactly that this function is doing and to what is it
doing it to?

Third, your real error isn't syntactical, it's in the architecture of your
design. If a function requires an argument to perform it's operations, then
ensure that all procedures that call the function provide that argument. In
general, functions should be passed all of the data that they will need and
should not have to go get data that was not supplied.

To apply that to this particular situation, place the burden of collecting
data from the user and supplying the appropriate arguments to the
InsertPanel function on the Panel sub.

'**Warning - not tested**
Private Sub Panel()
Dim oEnt As AcadEntity
Dim Pnt As Variant
Dim oBlkRef as AcadBlockReference

ThisDrawing.Utility.GetEntity oEnt, Pnt, "Select Panel to update: "

If Typeof oEnt Is AcadBlockReference Then
Set oBlkRef = oEnt
Call InsertPanel (ThisDrawing.Blocks(oBlkRef.Name))
End If
End Sub

This way, you can use the same InsertPanel function for both the Panel and
the Panels subs, not to mention any future code that you may write.
--
Bobby C. Jones
www.acadx.com
0 Likes