Solved

AUTOCAD vba paperspace entities

Posted on 2006-11-21
10
2,637 Views
Last Modified: 2010-07-27
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
0
Comment
Question by:PhillO
  • 4
  • 3
  • 3
10 Comments
 
LVL 16

Expert Comment

by:dhsindy
Comment Utility
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
 
LVL 16

Expert Comment

by:dhsindy
Comment Utility
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
 
LVL 16

Assisted Solution

by:dhsindy
dhsindy earned 20 total points
Comment Utility
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
 
LVL 10

Accepted Solution

by:
norrin_radd earned 480 total points
Comment Utility
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
 

Author Comment

by:PhillO
Comment Utility
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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 10

Expert Comment

by:norrin_radd
Comment Utility
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
 

Author Comment

by:PhillO
Comment Utility
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
 
LVL 10

Expert Comment

by:norrin_radd
Comment Utility
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
 

Author Comment

by:PhillO
Comment Utility
Hi Norrin

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

0
 
LVL 10

Expert Comment

by:norrin_radd
Comment Utility
thanks for the points and the grade. glad to help
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Following a number of instances of re-installing Solidworks I thought that it may be a  good idea to detail the procedure that I follow each time to ensure a good stable install. Backup: Backup your system.  It goes without saying that this i…
Our company has proprietary drawing files that we do not give to our customers for final documentation. Our customers now require that we give them these drawings. They understand that they are proprietary and do not require them to be in AutoCAD bu…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now