Solved

AUTOCAD vba paperspace entities

Posted on 2006-11-21
10
2,743 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
ID: 17998497
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
ID: 17998541
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
ID: 17998555
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
On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

 
LVL 10

Accepted Solution

by:
norrin_radd earned 480 total points
ID: 18022929
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
ID: 18023314
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
 
LVL 10

Expert Comment

by:norrin_radd
ID: 18023455
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
ID: 18023646
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
ID: 18024978
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
ID: 18025096
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
ID: 18028515
thanks for the points and the grade. glad to help
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

If, like me, you find yourself repeatedly and tediously joining many segments (lines, arcs) in other people's drawings back into polylines that can be used more effectively in Computer Aided Machining and Laser Cutting, then this article is for you!…
The following article will describe how to add/edit a dimension style through AutoCAD VBA. AutoCAD VBA has its quirks and when it comes to dimensions and controlling how they look through VBA.  This is where AutoCAD can be vividly confusing. The…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

730 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