View Full Version : Extracting Block attributes to Access Table
dmitchell@estesmcclure.co
19th May 2005, 06:33 pm
I would like to extract block attributes from multiple files in a folder and generate a table of these attributes. These is just a start for me. I am using AutoCAD 2004/2005 dual installed.
I would also like to know if there is a way to link multiple text strings to one. Thus if the original is altered then all the other change. This would be used for plan notes. I have look at the sheet manager options and it does not seem to allow for this option but greatly aids in seeveral other areas.
Finally, I guess I should have made more then one post but can you make a block that allows for nested blocks that have seperate insertion puts or if one block is inserted it prompts you if you would like to nest another.
Trying to make life easier.
hendie
19th May 2005, 07:40 pm
and how do you wish to achieve this ? by Vlisp or VBA or VB ?
are you looking to write the code yourself or are you looking for someone to write it for you ?
I know of one ARX module which allows VLisp to communicate with Access but it only exposes a number of methods.... all the code to get and set information in the drawing and the database still has to be written. If memory serves me, the ARX was $250 or so for a licence. I wrote some Vlisp code for testing it and it seemed pretty good.
What do you have so far ?
dmitchell@estesmcclure.co
19th May 2005, 07:52 pm
At this point, I have just done research and know that code can be written and seems to be fairly short. I am trying to figure out the basics so I can write the code myself. This is just the beginning of what I need.
hendie
19th May 2005, 09:23 pm
If you are going to be connecting to Access through AutoCAD & vice versa, I would recommend VBA.. it is possible in Lisp but you have to jump through a lot more hoops.
JAM
20th May 2005, 08:04 am
Hello!
Have the common problem. My task is to export BlockRefernce(BL) attributes to the existing MS Access database(DB).
The Task:
The drawing is created from the template(it is already created by project leader, has the blockreference and all the attributes, so I don't have to worry about this part) or existing template-based drawing is modified. User draws... draws... stops drawing :). He sees two buttons - "Register Drawing", "Update Drawing"
"Register Drawing"
Adds a new record to the database if the one certain BL attribute is empty, else...(still not defined by project leaders). DB table fields values are taken from blockreference attribute values.
"Update Drawing"
Updates the existing DB record(specified by BL certain attribute value)
I have AutoCad 2004 installed, but I am not quite familiar with drawing.
I have some experience in VB6.0, VBA and VB.NET programming.
Are there any useful information about AutoCAD objects(BlockReferrence: Corner_Stamp) and DB connection and coding examples(please no RTFW answers :)).
Is it possible to do in VBA?(it seems to me quite poor with objects and members) or better is VB.NET?
I am not looking forward to Lisp learning :(
Do I have to buy/install additional modules for AutoCad to do my task?
If you are going to be connecting to Access through AutoCAD & vice versa, I would recommend VBA.. it is possible in Lisp but you have to jump through a lot more hoops.
How in VBA? Any literature? Tips where to find it?(theme is quite specific, so I haven't found any luck with Google :))
dmitchell@estesmcclure.co,
I would also like to know if there is a way to link multiple text strings to one.
yes, there is a way to add strings in a usual manner. VBA example:
Sub StrConCat()
Dim a, b, c, d As String
a = "aaa" 'or a= SomeAutoCadObject.SomePropertyValue
b = "bbb"
c = a + b 'simple adding
Result = MsgBox(c, vbOKOnly, "Simple")
d = "Result string: " + Chr(13) + a + Chr(13) + b + Chr(13) + a + " " + b 'coplex adding
Result = MsgBox(d, vbOKOnly, "Complex")
End Sub
At this point, I have just done research and know that code can be written and seems to be fairly short. I am trying to figure out the basics so I can write the code myself. This is just the beginning of what I need.
Any links?
PS. Sorry for my english. :oops:
hendie
20th May 2005, 08:46 am
Jam,
I've added some more information to your post at resourcecad, see http://www.resourcecad.com/forum/viewtopic.php?p=3563#3563
as to the strings question (Jam, I don't think he intended concatenation of strings):
Depending upon how you wish to use the string. ~ you could have the string in modelspace and a viewport in each layout tab focused on the string. That would reflect changes each time the string was changed
Or, if you are talking about multiple strings in modelspace, you could use a reactor so that everytime the main string was edited, it would update all the other relevant strings.
please no RTFW answers
Amazingly, 90% of the code you require is already included in the Help files. Just copy'n'paste, make a few changes and you're most of the way there.
How can you expect to learn if you do not read the documentation ?
JAM
20th May 2005, 11:48 am
:oops:
sorry!
I was just using translated and not full version of help
The original help file contains everything I need endeed.
RTFM rulez :)
JAM
23rd May 2005, 10:56 am
I have a problem again :oops:
My drawing has a BlockReference called "Corner_Stamp_2"(only 1 with such name)
I can get it as a block only. How do I declare a variable to use it as a Blockrefernce object
Sub ATTRIB()
Dim MyBlock As AcadBlock
Dim MyBlocks As AcadBlocks
Dim MyBlockReference As AcadBlockReference
Dim Atts As Variant
Set MyBlocks = ThisDrawing.Blocks
Set MyBlock = MyBlocks.Item("Corner_Stamp_2")
'???????????????????????????????????
'Set MyBlockReference = ???????
'Atts = MyBlockReference.GetAttributes
'???????????????????????????????????
the following declaration doesn't work
Set MyBlockReference = MyBlock.Item("Corner_Stamp_2")
hendie
23rd May 2005, 11:51 am
Since you know the block name, it will be quicker to select that block only. Look into obtaining your block by filtering
Set SSet1 = ThisDrawing.SelectionSets.Add("Tblks")
Dim FilterType(0 To 2) As Integer
Dim FilterData(0 To 2) As Variant
FilterType(0) = 0: FilterData(0) = "INSERT"
FilterType(1) = 2: FilterData(1) = "MY_BLOCK_NAME"
SSet1.Select acSelectionSetAll, , , FilterType, FilterData
If SSet1.Count < 1 Then
MsgBox "Block not found", vbOKOnly, "Sorry..."
Exit Sub
End If
then once you have the selection set, get the block from it and you can get the attributes
hendie
23rd May 2005, 01:31 pm
or you could use something like
Dim blks As AcadBlocks
Set blks = ThisDrawing.Blocks
Dim myblk As String
Dim i As Integer
For i = 0 To blks.Count - 1
myblk = blks.Item(i).Name
If myblk = "MyBlockName" Then
MsgBox "We have just found " & myblk & " !"
Exit Sub
End If
Next i
JAM
23rd May 2005, 01:57 pm
Thank You for attention, but this wasn't exactly what I am trying to do.
I need AcadBlockReference object to get, so that I could use it's GetAttributes method later.
I need
1)To find the Block Reference on the drawing named "Corner_Stamp_2"(I have succeeded only in finding a Block with that name, although BlockReference exists - it is on the drawing, and has a name and properties shown on mouse double-click@)
2)To write Corner_Stamp_2 attributes(tags and values) to the array or other variables(AcadBlockReference.GetAttributes)
3)To use them later to write to database.
I need help with task number 1. I can't believe that it is so complex to get an object from the drawing by it's name :glare:
JAM
23rd May 2005, 03:00 pm
:shock:
Solution Found!!! Thank you all!
Dim MyBlock As AcadBlock
Dim MyBlocks As AcadBlocks
Dim MyBlockReference As AcadBlockReference
Dim Atts As Variant
Public Function SelectMyBlocks(strName As String) As AcadSelectionSet
Dim objSelSet As AcadSelectionSet
Dim objSelCol As AcadSelectionSets
Set objSelCol = ThisDrawing.SelectionSets
For Each objSelSet In objSelCol
If objSelSet.Name = strName Then
objSelSet.Delete
Exit For
End If
Next
Set objSelSet = ThisDrawing.SelectionSets.Add(strName)
Set SelectMyBlocks = objSelSet
End Function
Public Sub GetMyBlockRefAtts()
Dim objSelSet As AcadSelectionSet
Dim objBlkRef As AcadBlockReference
Dim intType(0) As Integer
Dim varDat(0) As Variant
Dim i As Integer
On Error GoTo Err_Control
intType(0) = 0
varDat(0) = "INSERT"
Set objSelSet = SelectMyBlocks("blocks")
objSelSet.Select acSelectionSetAll, FilterType:=intType, _
FilterData:=varDat
For Each MyBlockReference In objSelSet
If MyBlockReference.Name = "Corner_Stamp_2" Then
'MsgBox (MyBlockReference.Name)
Atts = MyBlockReference.GetAttributes
End If
Next MyBlockReference
'For i = LBound(Atts) To UBound(Atts)
'msg = MsgBox(" Tag: " & Atts(i).TagString & " Value: " & Atts(i).TextString, , i)
' Next
Exit_Here:
Exit Sub
Err_Control:
MsgBox Err.Description
Resume Exit_Here
End Sub
Now all I have to do is write the proper TextString to proper DB table field. :)
JAM
27th May 2005, 01:59 pm
The project is now almost passing the testing stage. :). Some minor corrections are still to be done, but there is a problem I am not able to solve yet. Maybe you can give me ideas?
My current Function "GetMyBlockRefAtts("(source code is in the post above)
selects all the block from current drawing. Is it possible to limit it's search to the active layout(the tab is pushed) blocks?
As a result I want Sub GetMyBlockRefAtts() to get attributes only from the current layout tab blockreference named "Corner_Stamp_2'.
I ve been experimenting with Filtering, but no luck yet. They do not provide possibility to filter from within the active layout. I ve tried to do that through Layers, but no luck again, - the layers have non-unique names on each layout.
JAM
30th May 2005, 03:06 pm
I did it!
And the code is much more compact now
Public MyBlockReference As AcadBlockReference
Public Atts As Variant
Public Sub GetMyBlockRefAtts()
Dim nm As String
Dim elem As Object
For Each elem In ThisDrawing.ActiveLayout.Block
With elem
If .EntityName Like "AcDbBlockReference" Then
nm = .Name
If nm Like ("Corner_Stamp_2") Then
Atts = elem.GetAttributes
Exit For
End If
End If
End With
Next
End Sub
Powered by vBulletin™ Version 4.1.2 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.