Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

AtoCAD, Access and VBA 2

Status
Not open for further replies.

PZero

IS-IT--Management
Jan 16, 2006
28
GB
I have a drawing with several tabs. Each tab is named to match a record in my database, i.e. tab “R001” and record “R001”. The layout of each tab contains several blocks, each with several attributes. Each attribute’s tag is named to match a field name in my database, i.e. tag “FLOOR_AREA” and field “FLOOR_AREA”.

I am trying to put together a VBA app that will determine the current tab name and change the values of the attributes based on the related database record. This information does not need to be saved in the drawing, in fact it would be preferable to have the data accessed ‘on-the-fly’ so that the data viewed is the most recent.

I have hardly any VBA experience so I'm struggling a bit. I've learned quite a lot today, but still really have no clue on where to start with the code. I'm assuming it should be fairly basic, but I could be very wrong.

Thanks,
Chris
 
Hi PZero,

After a little experimenting - you are right the 410 code doesn't work. However, in your case since you have a paperspace tab active already, this will work:

Code:
BuildFilter intData, varData, -4, "<and", _
                                  0, "INSERT", _
                                  2, "TitleBlock", _
                                  67, 0, _
                                -4, "and>"

Just remember, it will only select the blocks named "TitleBlock" in paperspace on the ACTIVE LAYOUT only - it won't work in batch mode per se. If you need that, you'll need to walk the collection of tabs, set each one current, and then run the selection set.

HTH
Todd
 
Thanks Todd, but it doesn't work. If set to 0 it won't select anything (nothing in model space), and if set to 1 it still selects the block on the first layout rather than the current layout.

After looking around I think whats needed is a routine of some sort to filter the selection set. Something like;

[ol][li]Send selection set to array[/li]
[li]Purge blocks not on the current layout from the array[/li]
[li]Import attributes to the remaining block in the array[/li][/ol]

Would something like that work?
 
I posted on another forum and this was one of the replies;

Code:
Dim Id As Long
Dim b As AcadBlockReference
Id = ThisDrawing.PaperSpace.ObjectID
For Each b In ssTitleBlock
Debug.Print b.OwnerID
If b.OwnerID = Id Then
yadayada

Is that workable?
 
Hi PZero,

You are correct it won't select anything in modelspace with a code 67 . 0 - your first layout is usually model space. I tried the response you received from another forum before I posted the above code and the OwnerID returned for block references (inserted blocks) is the block table record. So, no, it's not workable.

You may need to have some user interaction, or if your intial selection set count is zero, change the filter criteria and re-run the selection set again.

HTH
Todd
 
Does it help that I know that there will be only one block on each layout that we are trying to update? So there will be several layouts, 001, 002, 03, etv, but each layout will have one block called for example, 'TitleBlock'. Is there no way of identifying that? For example 'ThisDrawing.ActiveLayout.Block("TitleBlock")' and the update the attributes of that block?
 
Hi PZero,

Currently (at least up 2007) there is not. You would need to use uniquely named blocks. There may be a way in 2008.

HTH
Todd
 
What about removing blocks from the selectionset that aren't on the current layout? Is that a possibility?
 
Thanks for all your help Todd.

I gave on on layout filtering in the end and instead decided to create a new layer named the same as the layout on which the block resides to filter by. A bit messier than I wanted but it does the job.

Chris.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top