AUTOCAD vba paperspace entities

I want to cycle through drawings layouts to get block names for a vba program

how do access say a titleblock  block for example that is in a layout?

Phill
PhillOAsked:
Who is Participating?
 
norrin_raddCommented:
not sure if this will help you much but here is some code that i use to get my layout names in a listbox:

'*********
Public Sub getLayouts()
Dim layoutObj As AcadLayout
Dim layoutname As String
Dim addlayouts

howManylays = ThisDrawing.Layouts.Count
'MsgBox howManylays
layoutlist.Clear
layoutlist.AddItem ("Model")
For Each layoutObj In ThisDrawing.Layouts

If layoutObj.NAME <> ("Model") Then


layoutlist.AddItem (layoutObj.NAME)
'MsgBox layoutObj.Name
Else
End If

Next

End Sub
'*********

here is a piece of code that I use to edit a datestamp block in current layout or modelspace, this will not work by itself its just a segment of a bigger project.:

'***********
If ThisDrawing.GetVariable("Ctab") = "Model" Then

'Dim BlkRef As AcadBlockReference
    For Each obj In ThisDrawing.ModelSpace
            If TypeOf obj Is AcadBlockReference Then
            Set blkref = obj
                If blkref.HasAttributes Then
                    AttArray = blkref.GetAttributes
                   For i = LBound(AttArray) To UBound(AttArray)
                    If AttArray(i).TagString = "DATESTAMP" Then
                        AttArray(i).textString = ".." & partialdwgname & " " & Now & " by " & who
                    End If
                    Next i
                   
                End If
        End If
    Next
 Else
 
    For Each obj In ThisDrawing.paperspace
            If TypeOf obj Is AcadBlockReference Then
            Set blkref = obj
                If blkref.HasAttributes Then
                    AttArray = blkref.GetAttributes
                    For i = LBound(AttArray) To UBound(AttArray)
                    If AttArray(i).TagString = "DATESTAMP" Then
                        AttArray(i).textString = partialdwgname & " " & Now & " by " & who  '_
                       
                    End If
                    Next i
                   
                End If
        End If
    Next
'********
you may be able to piece something together from this.
sorry I couldnt put it together a little smoother, kinda snowed under right now.
good luck
0
 
dhsindyRetired considering supplemental income.Commented:
All block names available in any layout or model space.  At the command line type the word block; then a ?; then, and *.  Keep hitting the enter key until done.

Also, if you turn of file logging on the format tab, everything that scrolls across will be saved in it (an ASCII file).  Which of course you can cut, paste, and edit.
0
 
dhsindyRetired considering supplemental income.Commented:
I meant turn ON logging - I think thats on the FORMAT/OPEN AND SAVE tab on the lower left.  Also, in the BLOCK command you can use the standard AutoCAD wildcards:

@ = alphebetic character;
# = numeric character;
? = a single character wildcard; and,
* = multiple character wildcard.
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
dhsindyRetired considering supplemental income.Commented:
AutoCAD only writes the block once in the file.  Every other occurance is just a copy, rotate, scale of the original.  That is why it is available in any view.
0
 
PhillOAuthor Commented:
Hi Norrin

According to the autocad vba docs ( as I understand it) ThisDrawing.paperspace refers only to the active layout. So to get through all the paperspace layouts I have to  do some thing like

    ThisDrawing.Utility.GetEntity blk, pnt, "Select block:"
   
    If blk.entityType = acBlockReference Then
        BlockName = blk.Name
        For Each layout In ThisDrawing.layouts
            For Each ent In layout.block
                If ent.entityType = acBlockReference Then
                    If ent.Name = BlockName Then ent.Delete
                End If
            Next
        Next
    End If

Is that right or have I misread it


BTW this code allows a user to to select a block and delete every reference to it... that's all it does. It actually works but I'm not sure if the methodology is correct
0
 
norrin_raddCommented:
that looks good to me. if "that's all it does" (pretty powerful if you ask me ;)) and it works the way it is to delete every reference then it should work to edit them or get the names or whatever you want to do to them. just replace the "If ent.Name = BlockName Then ent.Delete" part with what you want to do.

looks good and I think youre right about thisdrawing.paperspace .
0
 
PhillOAuthor Commented:
I'm not sure what you mean by "(pretty powerful if you ask me ;))

Ultimately it can be used for other things as well like replacing blocks etc.
0
 
norrin_raddCommented:
when I said "(pretty powerful if you ask me ;))" I thought you were downplaying that routine is all.

anyway, did my code help you at all or did you get it on your own? i was trying to get something worked up earlier but never got to it. looks like you got the idea.
0
 
PhillOAuthor Commented:
Hi Norrin

Yes thankyou, your code did help. In fact it help solve a couple of other issues as well

0
 
norrin_raddCommented:
thanks for the points and the grade. glad to help
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.