?
Solved

AUTOCAD vba paperspace entities

Posted on 2006-11-21
10
Medium Priority
?
2,848 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 80 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
Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

 
LVL 10

Accepted Solution

by:
norrin_radd earned 1920 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

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…
In this article, we will see the basic design consideration while designing a Multi-tenant web application in a simple manner. Though, many frameworks are available in the market to develop a multi - tenant application, but do they provide data, cod…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

764 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