PDA

View Full Version : autocad (dwg) to excel



shamsam1
05-01-2008, 01:02 AM
how can i export date from autocad (dwg) to excel...help me out guys: pray2:

lucas
05-01-2008, 07:15 AM
Moved so you will get more AutoCAD oriented help.

Is the date mult-line text? Give a few more details please. Also what version of Cad and Excel are you using?

shamsam1
05-01-2008, 09:44 AM
i want to export data like dimensions,layername,text to excel..we are using acutocad 2004 and above and excel 2003 and above.





Moved so you will get more AutoCAD oriented help.

Is the date mult-line text? Give a few more details please. Also what version of Cad and Excel are you using?

Tommy
05-01-2008, 10:24 AM
:hi: Hi shamsam1,

Are you in Autocad or are you in Excel?
I would prefer Autocad myself, it is easier to manipulate Excel from other apps than it is to manipulate Autocad. IMHO

Is the text MText? do you want both the text and mtext? I assume the dimension text is. How do you determine what to export to Excel? Do you export all of it or ....

After you aquire all of this text, layers, and dimensions where do you want to put them and in what type of format?

What are you trying to do?

The more information you can give the better the information you recieve. :yes

shamsam1
05-01-2008, 11:23 PM
i would like to code from vb.6.then open autocad drawing then export all data to excel.
i need a simple program which export all data of dwg to excel.

regards
sam




:hi: Hi shamsam1,

Are you in Autocad or are you in Excel?
I would prefer Autocad myself, it is easier to manipulate Excel from other apps than it is to manipulate Autocad. IMHO

Is the text MText? do you want both the text and mtext? I assume the dimension text is. How do you determine what to export to Excel? Do you export all of it or ....

After you aquire all of this text, layers, and dimensions where do you want to put them and in what type of format?

What are you trying to do?

The more information you can give the better the information you recieve. :yes

shamsam1
05-03-2008, 08:27 PM
:beerchug:
at last i am able to export block attributed details from dwg to excel using vb.6 and autocad2000
if intresed i can share vb.6 code.:bow:

Tommy
05-05-2008, 05:10 PM
No where in any of your posts have you requested attributes. Just all data.

This is a VBA site not a VB6 site.

But yes I would love to see the code.

shamsam1
05-05-2008, 09:41 PM
well in 2 to 3 day i wll be posting the required code.




No where in any of your posts have you requested attributes. Just all data.

This is a VBA site not a VB6 site.

But yes I would love to see the code.

rocheey
05-07-2008, 03:13 AM
is kind of a contradiction.

If you are looking for the very basic properties, which are common to *every* entity, you can use the AcadEntity object.. but short of that, you have to write code specific for every type of entity. Not 'simple' code.

shamsam1
05-07-2008, 04:17 AM
wel i am able to read all block attributes in drawring.using vb.6
but i am more intrested in reading all dimesions value. just got stuck here..:dunno

Tommy
05-07-2008, 06:46 AM
Look for mtext if the dimensions are not associative. Hopefully the dimension text is at least on a "dimension" layer, otherwise the search will be long and hard. Are the drawings in metric or imperial? The Imperial dimensions will be easier to find, otherwise hopefully there will be a designation as in cm/mm. Are you suing a selection set to find the information? Are you just opening the drawing and searching?

shamsam1
05-07-2008, 08:13 PM
dimensison are mtext in my project. also there is seperate layer for dimension .drawminsg are in metric

how to extact all mtext values from dwg.
some sample od vb or vba code will help






Look for mtext if the dimensions are not associative. Hopefully the dimension text is at least on a "dimension" layer, otherwise the search will be long and hard. Are the drawings in metric or imperial? The Imperial dimensions will be easier to find, otherwise hopefully there will be a designation as in cm/mm. Are you suing a selection set to find the information? Are you just opening the drawing and searching?

Tommy
05-09-2008, 06:24 AM
Here is a knowledge base I wrote for dimensions

http://vbaexpress.com/kb/getarticle.php?kb_id=862

HTH

shamsam1
05-10-2008, 01:10 AM
I am using volo view express in my vb6 application. Can any one give me code for zoom window using volo view express in vb6.I have code for zoom extends. Please help me.Its urgent

Tommy
05-10-2008, 07:05 AM
From this point on you will need to post some code to prove to me you are actually know what you are trying to do. You have gone from acad to voloview. from all things in acad to zoom window in volo view. I think you are just ..............

Otherwise search the net.

shamsam1
05-11-2008, 09:51 PM
here is code to extract block attributes to actocad using vb.6..
but i need to code to extract the dimesions value or mtext without opening outocad..

add reference for autocad and excel




Sub Extract()
Row = 2
col = 1

'Form1.Cls
Dim sheet As Object
Dim shapes As Object
Dim elem As Object
Dim excel As Object
Dim Max As Integer
Dim Min As Integer
Dim NoOfIndices As Integer
Dim excelSheet As Object
Dim RowNum As Integer
Dim Array1 As Variant
Dim Count As Integer
Dim Teller As Integer
Dim Teller1 As Integer
Dim str() As String
Screen.MousePointer = vbHourglass
For i = 0 To List2.ListCount - 1
Text6.Text = i
Text7.Text = List2.List(i)
procOpenDrawing
Set Doc = acad.ActiveDocument
Set mspace = Doc.ModelSpace
RowNum = 1
Dim Header As Boolean
Header = False
Teller = 0
Teller1 = 0
Text1.Text = ""

Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
'Text5.Text = ""
List1.Clear
For Each elem In mspace
With elem
If StrComp(.EntityName, "AcDbBlockReference", 1) = 0 Then
If .HasAttributes Then
Teller = Teller + 1
Array1 = .GetAttributes
' Text1.Text = Text1.Text & vbNewLine & " ****** Read the TAGS ***** " & vbNewLine
' For Count = LBound(Array1) To UBound(Array1)
' If Header = False Then
' If StrComp(Array1(Count).EntityName, "AcDbBlockReference", 1) = 0 Then
' Text1.Text = Text1.Text & Array1(Count).TagString & vbNewLine
' End If
' End If
' Debug.Print
' Next Count
RowNum = RowNum + 1

' Text1.Text = Text1.Text & vbNewLine & " ****** Read the VALUE ***** " & vbNewLine
str1 = ""
For Count = LBound(Array1) To UBound(Array1)
Teller1 = Teller1 + 1
str1 = Array1(Count).tagstring
If str1 = "Materiale" Or str1 = UCase("Materiale") Then
Text2.Text = Text2.Text & Array1(Count).textstring
ElseIf str1 = "BesKrivelse1" Or str1 = UCase("BesKrivelse1") Or _
str1 = "BesKrivelse2" Or str1 = UCase("BesKrivelse2") Or _
str1 = "BesKrivelse3" Or str1 = UCase("BesKrivelse3") Then

Text3.Text = Array1(Count).textstring

If Val(Text3.Text) Then
str = Split(Text3.Text, "x")
For intLoop1 = LBound(str) To UBound(str)
List1.AddItem (Val(str(intLoop1)))
Next intLoop1
End If
ElseIf str1 = "Tegningsnr" Or str1 = UCase("Tegningsnr") Then
Text4.Text = Array1(Count).textstring


ElseIf str1 = "Varenr" Or str1 = UCase("Varenr") Then
Text1.Text = Array1(Count).textstring
End If
Next Count
Debug.Print
Header = True
End If
End If
End With
Next elem



' myexcel.ActiveSheet.Cells(row, col).HorizontalAlignment = xlCenter
'myexcel.ActiveSheet.Cells(row, col).Font.Bold = True
'myexcel.Visible = True
myexcel.ActiveSheet.Cells(Row, col) = Text1.Text
myexcel.ActiveSheet.Cells(Row, col + 1) = Text2.Text
myexcel.ActiveSheet.Cells(Row, col + 3) = List1.List(0)
myexcel.ActiveSheet.Cells(Row, col + 4) = List1.List(1)
myexcel.ActiveSheet.Cells(Row, col + 5) = List1.List(2)
myexcel.ActiveSheet.Cells(Row, col + 6) = Text4.Text
Row = Row + 1
col = 1
Next i
NumberOfAttributes = RowNum - 1
If NumberOfAttributes > 0 Then

Else
MsgBox "No attributes found in the current drawing"
End If
Set acad = Nothing

' Me.SetFocus
Screen.MousePointer = vbNormal

End Sub

EDIT : Added VBA tags Tommy

shamsam1
05-11-2008, 09:51 PM
here is code to extract block attributes to actocad using vb.6..
but i need to code to extract the dimesions value or mtext without opening outocad..

add reference for autocad and excel




Sub Extract()
Row = 2
col = 1

'Form1.Cls
Dim sheet As Object
Dim shapes As Object
Dim elem As Object
Dim excel As Object
Dim Max As Integer
Dim Min As Integer
Dim NoOfIndices As Integer
Dim excelSheet As Object
Dim RowNum As Integer
Dim Array1 As Variant
Dim Count As Integer
Dim Teller As Integer
Dim Teller1 As Integer
Dim str() As String
Screen.MousePointer = vbHourglass
For i = 0 To List2.ListCount - 1
Text6.Text = i
Text7.Text = List2.List(i)
procOpenDrawing
Set Doc = acad.ActiveDocument
Set mspace = Doc.ModelSpace
RowNum = 1
Dim Header As Boolean
Header = False
Teller = 0
Teller1 = 0
Text1.Text = ""

Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
'Text5.Text = ""
List1.Clear
For Each elem In mspace
With elem
If StrComp(.EntityName, "AcDbBlockReference", 1) = 0 Then
If .HasAttributes Then
Teller = Teller + 1
Array1 = .GetAttributes
' Text1.Text = Text1.Text & vbNewLine & " ****** Read the TAGS ***** " & vbNewLine
' For Count = LBound(Array1) To UBound(Array1)
' If Header = False Then
' If StrComp(Array1(Count).EntityName, "AcDbBlockReference", 1) = 0 Then
' Text1.Text = Text1.Text & Array1(Count).TagString & vbNewLine
' End If
' End If
' Debug.Print
' Next Count
RowNum = RowNum + 1

' Text1.Text = Text1.Text & vbNewLine & " ****** Read the VALUE ***** " & vbNewLine
str1 = ""
For Count = LBound(Array1) To UBound(Array1)
Teller1 = Teller1 + 1
str1 = Array1(Count).tagstring
If str1 = "Materiale" Or str1 = UCase("Materiale") Then
Text2.Text = Text2.Text & Array1(Count).textstring
ElseIf str1 = "BesKrivelse1" Or str1 = UCase("BesKrivelse1") Or _
str1 = "BesKrivelse2" Or str1 = UCase("BesKrivelse2") Or _
str1 = "BesKrivelse3" Or _
str1 = UCase("BesKrivelse3") Then

Text3.Text = Array1(Count).textstring

If Val(Text3.Text) Then
str = Split(Text3.Text, "x")
For intLoop1 = LBound(str) To UBound(str)
List1.AddItem (Val(str(intLoop1)))
Next intLoop1
End If
ElseIf str1 = "Tegningsnr" Or str1 = UCase("Tegningsnr") Then
Text4.Text = Array1(Count).textstring


ElseIf str1 = "Varenr" Or str1 = UCase("Varenr") Then
Text1.Text = Array1(Count).textstring
End If
Next Count
Debug.Print
Header = True
End If
End If
End With
Next elem



' myexcel.ActiveSheet.Cells(row, col).HorizontalAlignment = xlCenter
'myexcel.ActiveSheet.Cells(row, col).Font.Bold = True
'myexcel.Visible = True
myexcel.ActiveSheet.Cells(Row, col) = Text1.Text
myexcel.ActiveSheet.Cells(Row, col + 1) = Text2.Text
myexcel.ActiveSheet.Cells(Row, col + 3) = List1.List(0)
myexcel.ActiveSheet.Cells(Row, col + 4) = List1.List(1)
myexcel.ActiveSheet.Cells(Row, col + 5) = List1.List(2)
myexcel.ActiveSheet.Cells(Row, col + 6) = Text4.Text
Row = Row + 1
col = 1
Next i
NumberOfAttributes = RowNum - 1
If NumberOfAttributes > 0 Then

Else
MsgBox "No attributes found in the current drawing"
End If
Set acad = Nothing

' Me.SetFocus
Screen.MousePointer = vbNormal

End Sub


EDIT: Added VBA tags Tommy

shamsam1
05-11-2008, 09:56 PM
in my second project i am opening dwg drawing without using autocad.

1)i am using volvo viewer
in this i adotn have code or zoom extent
or
2) with using ddvue.ocx

Tommy
05-12-2008, 02:59 PM
http://www.opendwg.org/home

This is the only thing that I know of to do what you are wanting to do without autocad. Now if you are wanting to do something with a dxf file I can help on that, somewhat.

shamsam1
05-12-2008, 06:46 PM
thanks for the assistance..
i have already finished my second project with using ddvue.ocx


i still dotnt have code to extract only dimesnions values from dwg drawings.and export to excel.
i want to extract dimesnions without opening autocad drawings.i have around 5000 dwg drawings.
please help me with a goood vb.6 or macro.my knowlede with lisp is nill...: pray2:

shamsam1
05-13-2008, 10:42 PM
I am using volo view express in my vb6 application. Can any one give me code for zoom window using volo view express in vb6.I have code for zoom extends. Please help me.Its urgent

saranya
05-19-2008, 11:03 PM
Hi,
Can any one help vba code for autocad.I want to extract only the dimensions from autocad drawing and export to excel.Already I have code to capture block attributes.But i dont want to capture from block attributes.I want to capture from drawing only.Some one help me.Its urgent

Tommy
05-21-2008, 11:04 AM
The code below will extract all dimensions except radius, and diameter. Per shamsam1's request. BTW VBA is a subset of VB so this should work in VB with little effort.

So far as getting voloview to do a zoom window, you will have to launch spy++ and write to a file and search the file until you find it. Yes it is a long and difficult process. Good Luck.

Sub WriteDimMeasurement()
Dim ssetA As AcadSelectionSet
Dim gpCode(0) As Integer
Dim dataValue(0) As Variant
Dim I As Long
Dim groupCode() As Integer
Dim dataCode As Variant
gpCode(0) = 0
dataValue(0) = "Dimension"
groupCode = gpCode
dataCode = dataValue
Set ssetA = Aset("DimDelete")
ssetA.Select acSelectionSetAll, , , groupCode, dataCode
On Error Resume Next
For I = ssetA.Count - 1 To 0 Step -1
If ssetA(I).ExtLine1Linetype >= 0 Then
'check for an extension line -
' a leader radius and diameter does not have an
'extension line so it throws an error
If Err.Number > 0 Then
Err.Clear
Else
'place code to write to excel
Debug.Print ssetA(I).Measurement
End If
End If
Next
On Error GoTo 0
ssetA.Delete
Set ssetA = Nothing
End Sub

shamsam1
05-21-2008, 09:46 PM
hi tommy
i get an erro cannt asssing arry to groupCode
1. groupCode = gpCode
Cant assign array to groupcode
2. Set ssetA = Aset("DimDelete")
Aset not defined
What is datatype of Aset?

also Aset not defined.

guide me regarding this

saranya
05-21-2008, 09:48 PM
Hi Tommy,
Thanks for your reply.But while running the code errors are displaying in the following two lines

1. groupCode = gpCode
Cant assign array to groupcode
2. Set ssetA = Aset("DimDelete")
Aset not defined
What is datatype of Aset?

Thanks
Saranya

Tommy
05-22-2008, 04:15 AM
1. groupCode = gpCode
Cant assign array to groupcode
Try


Dim groupCode(0) As Integer
groupCode(0) = gpCode (0)

I don't know why that doesn't work, it works in VB6 and acad 2007 VBA


2.
Forgot a function sorry.

Function Aset(iSSetName As String) As AcadSelectionSet
Dim ssetA As AcadSelectionSet
On Error Resume Next
Set ssetA = ThisDrawing.SelectionSets.Add(iSSetName)
If Err.Number <> 0 Then
Set ssetA = ThisDrawing.SelectionSets(iSSetName)
ssetA.Delete
Set ssetA = ThisDrawing.SelectionSets.Add(iSSetName)
Err.Clear
End If
On Error GoTo 0
Set Aset = ssetA
End Function

saranya
05-24-2008, 12:13 AM
Thank you very much Tommy.It works great.

Saranya

Adonaioc
06-18-2008, 12:45 PM
I would like to be able to do the same thing, i need to export dimensions from an auto cad file into excel so that i can load them from excel into cayman, (a gui client) if its possible i would like to know how.

shamsam1
06-18-2008, 09:38 PM
do u want a lisp program or a vb.6 progam to export
check the earlier post u will get it..

shamsam1
06-19-2008, 12:58 AM
u r requirement still not clear.
u want attributes,block attributes,or dimensions ....


do u want a lisp program or a vb.6 progam to export
check the earlier post u will get it..