TheSwamp
Code Red => VB(A) => Topic started by: ML on April 02, 2007, 09:31:33 AM
-
I am having a little difficulty, In the below example, I am looping through Modelspace and populating my listbox with Block References in the drawing. However, I am not sure how to loop through the entire drawing (paper and modelspace) all at the sametime.
If someone could help me, I'd appreciate it.
Thank you
Mark
For Each Obj In ThisDrawing.ModelSpace
If TypeOf Obj Is AcadBlockReference Then
ListBox1.AddItem (Obj.Name)
End If
Next Obj
-
Are you utilizing a selection set? or have you considered that?
Set objSelCol = objDoc.SelectionSets
For Each objSelSet In objSelCol
If objSelSet.Name = "blk_out" Then
objSelSet.Delete
Exit For
End If
Next objSelSet
Set objSelSet = objSelCol.Add("blk_out")
intType(0) = 0
varData(0) = "INSERT"
objSelSet.Select 5, filtertype:=intType, _
filterdata:=varData
For Each objEnt In objSelSet
-
And if you don't want to use a selection set, which would be the case when working with ObjectDBX, you need to loop through the Layouts collection and then each of their blocks.
For Each oLayout in Doc
For Each oEnt in oLayout.Block
.....
-
Cool. Both approaches make sense.
Thank you :-)
-
Actually, I don't think you can access the blocks collection through Layouts
Mark
-
Actually, I don't think you can access the blocks collection through Layouts
Mark
I don't think that is what Jeff meant.
The "Block" property of a layout object is how you access the block table record that represents that layout.
-
That's correct, Chuck.
Now, if I had inadvertently added an s to the oLayout.Block then that would give an error as Mark thought....but I do try to not make those kind of typing mistakes :-)
-
Oh, I see, that will return the name of the layout (I think)
No what I was looking for was Blockreferences inserted into paper.
The selection set method above would work just fine.
THank you
Mark
-
Mark -
Put this code in a command button on your form and see what happens:
Dim Doc As AcadDocument
Dim oLayout As AcadLayout
Dim oEnt As AcadEntity
Set Doc = ThisDrawing
For Each oLayout In Doc.Layouts
For Each oEnt In oLayout.Block
If TypeOf oEnt Is AcadBlockReference Then
ListBox1.AddItem (oEnt.Name)
End If
Next oEnt
Next oLayout
This will loop through each layout in the drawing and add any block references to the listbox.
This is where Jeff and Chuck were trying to lead you. Each layout in a drawing is, in fact, a block which can contain objects. You can loop through the block and look for objects contained in the block just like looping through modelspace or paperspace.
HTH
Oh, I see, that will return the name of the layout (I think)
No what I was looking for was Blockreferences inserted into paper.
The selection set method above would work just fine.
THank you
Mark
-
This is great information. I finally sort of get it. This is very similar to the way it is done in .NET, if I am not mistaken. Someone please correct me if I am wrong. It is a good thing to understand this, even though it appears to be a bit more complicated, because if you want to eventually move to let's say, VB.NET, you will have to a have a firm understanding in using this approach.
-
Dave
That does make a lot of sense. Thank you very much
I am going to try it then I will post the results.
Mark
-
Dave,
That worked great, exactly what i was looking for
Thank you
Mark
-
Mark,
While any of these methods would work, what Jeff and Chuck were showing you would be a much quicker, more efficient way of doing what you were trying to do. Rather than search through every entity in the drawing looking for blockreferences, they suggested looking through the layouts for the blockreference. much quicker! :-)
-
Yes, I would agree to that and I appreciate the help. However, some might say that the sset method is quicker still. Either way, it works great and it isn't slo at all. I will remember that tip for future reference though
Thank you
-
I was actually advised that this would be a better method: Looping through by objects (Graphical) as opposed to entities which are everything. I have to agree ---->
Mark
Dim Layout As AcadLayout
Dim Obj As Object
For Each Layout In ThisDrawing.Layouts
For Each Obj In Layout.Block
If TypeOf Obj Is AcadBlockReference Then
ListBox1.AddItem (Obj.Name)
End If
Next Obj
Next Layout