Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

Attribute Exstact "Weight Of Materials"

Status
Not open for further replies.

Sinbad41

Industrial
Mar 9, 2003
2
This is my first post so Hello everybody

A friend in the Formwork industry has showed me that AutoCAD has ability of to extract attributes using the ATTEXT to a text file, which in turn can be opened in Excel and Access. This is great until the drawing contains say 10 or more block files each inserted say 50 times.

So I have attempted to write some VBA code and I’m failing miserably. I don’t have the syntax knowledge to get it to work.

From reading other peoples code am I right in thinking you must firstly find and count the blocks in the drawing and then ask the blocks for their attributes or do I include the code in the middle of the count loop???????

This all sound like I know what I’m talking about.
I assure you I don’t I have only little VB and AutoCAD knowledge

The main goal is to calculate the total weight (Attribute Value) of the blocks in the Drawing, export these block files into Excel, showing block totals and weight totals, a sort of bill of materials but using weights.

See possible output below(sorry about the underscores its the only way i could set it out)

(B_ Name)(Total Blocks)(Ref Num)(B_Weight)(Total B_Weight)
Nut_________50________01_______10g_________500g
Bolt_________75________02_______25g________1875g
Washer_____100________03________5g_________500g

Totals______225____________________________2875g

(There could be over 50 different blocks and weight values in a drawing)

The block name and the number of times it occurs in the drawing and total weights are important. These values will be used to calculate the size of lorry required for delivery.

Se below some code that I have attempted………

Public excelApp As Object
Public wkbObj As Object
Public shtObj As Object
Dim gtotal As Integer

Sub CommandButton1_Click()
Dim a, b, blocktotal, count As Integer
Dim blockname As String
Dim ent As Object

blocktotal = ThisDrawing.Blocks.count
For a = 0 To blocktotal - 1
blockname = ThisDrawing.Blocks.Item(a).Name
If Not Mid$(blockname, 1, 1) = "*" Then ListBox1.AddItem blockname
Next a
For a = 0 To ListBox1.ListCount - 1
blockname = ListBox1.List(a): blocktotal = 0
For b = 0 To ThisDrawing.ModelSpace.count - 1
Set ent = ThisDrawing.ModelSpace.Item(b)
If ent.EntityType = acBlockReference And ent.Name = blockname Then blocktotal = blocktotal + 1
Next b

ListBox2.AddItem blocktotal
gtotal = gtotal + blocktotal

'Do I include GetAttribute code? Selection sets? Here?
'or after the next as a separate for loop?

Next a

ListBox3.AddItem gtotal
End Sub

Sub CommandButton2_Click()
On Error Resume Next
Set excelApp = GetObject(, "Excel.Application")
If Err <> 0 Then
Err.Clear
Set excelApp = CreateObject(&quot;Excel.Application&quot;)
If Err <> 0 Then
MsgBox &quot;Could not start Excel!&quot;, vbExclamation
End
End If
End If

excelApp.Visible = True
Set wbkObj = excelApp.Workbooks.Add
Set shtObj = wbkObj.Worksheets(1)
shtObj.Name = &quot;Block Name & Count&quot;

Dim a, b, blocktotal As Integer
Dim blockname As String

b = 2
For a = 0 To ListBox1.ListCount - 1
blockname = ListBox1.List(a)
blocktotal = ListBox2.List(a)
shtObj.Cells(b, 1).Value = blockname
shtObj.Cells(b, 2).Value = blocktotal

b = b + 1

Next a

b = b + 1

shtObj.Cells(1, 1).columnwidth = 12
shtObj.Cells(1, 1).Value = &quot;Blocks&quot;
shtObj.Cells(1, 1).Font.Bold = True

shtObj.Cells(1, 2).columnwidth = 8
shtObj.Cells(1, 2).Value = &quot;Number&quot;
shtObj.Cells(1, 2).Font.Bold = True

shtObj.Cells(b, 1).Value = &quot;Grand Total=&quot;
shtObj.Cells(b, 1).Font.Bold = True

shtObj.Cells(b, 2).Value = gtotal

End Sub

Sub CommandButton3_Click()
End
End Sub



Private Sub UserForm_Click()

End Sub
 
Replies continue below

Recommended for you

I have limited ability with VB. When I need to figure out weights of a 3D drawing in autocad, I check the volume of that object and multiply the object density. That procedure is a lot faster than writing the program. One of my night student was able to do exactly that when I had him lay rebar in a continuous footing in 3D.
 
The blocks are all parts of a hire firms stock, (construction) all individual parts like a support stanchion down to the smallest part like a nut or bolt.
They all share common attributes:
Name, Part Number, Description and Weight

This is what i have now

userform.gif


This what i'm trying to acheive

userform01.gif
Any help would be most appreciated :)
 
Hi,
Not knowing how much you know about VBA, it is probably quicker to create a selection set of blockRefs with attributes. Once you have the selection set, you can iterate of the info from each &quot;object&quot; and build you list.

Go here:


Great bunch of guys who can help here too.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor