PDA

View Full Version : excel data to draw line in autocad.



yonlih
2010-07-26, 06:14 AM
Dear all,

This is my first post on this forum.
I been using AutoCAD for two yrs and recently was trying to incorporate my calculation with excel to autocad.

my question here is,
I have a set of data in excel consists of two column, x column and y column,
how am i going to do in order my autocad will automatic plot a graph with the x and y value of my excel data sheet.
my idea was to create a button on my excel spreadsheet, when ever i change my parameter that affect my x and y column value, and press the button, it will link to my autocad and a graph will be plotted there.
is this sound possible?

I believe by using autolisp will be much more easier as it will perform the calculation and plotting of graph in autocad itself only, but the reason I create my calculation in an excel spreadsheet is because, some of the autocad users in my company are using autocad LT which not able to perform autolisp program. Therefore, I think to let them have an excel calculation for thier own parameter key in, and pass to some other colleugues who owns autocad which able to run lisp program and generate the graph for them.

I am new to excel marco and also autolisp language, please suggest me if u have any better idea.
Appreciate very much in advance for ur reply.

fixo
2010-07-26, 08:05 PM
Dear all,

This is my first post on this forum.
I been using AutoCAD for two yrs and recently was trying to incorporate my calculation with excel to autocad.

my question here is,
I have a set of data in excel consists of two column, x column and y column,
how am i going to do in order my autocad will automatic plot a graph with the x and y value of my excel data sheet.
my idea was to create a button on my excel spreadsheet, when ever i change my parameter that affect my x and y column value, and press the button, it will link to my autocad and a graph will be plotted there.
is this sound possible?

I believe by using autolisp will be much more easier as it will perform the calculation and plotting of graph in autocad itself only, but the reason I create my calculation in an excel spreadsheet is because, some of the autocad users in my company are using autocad LT which not able to perform autolisp program. Therefore, I think to let them have an excel calculation for thier own parameter key in, and pass to some other colleugues who owns autocad which able to run lisp program and generate the graph for them.

I am new to excel marco and also autolisp language, please suggest me if u have any better idea.
Appreciate very much in advance for ur reply.

Try attached file
Open Autocad drawing
Open Excel file (AutoCAD must be opened)
Select four columns
Press button

~'J'~

yonlih
2010-07-27, 03:05 AM
dear fixo,

thank you so much for your file.
I have just tried, but it return me with this error msg box when i press the button,
please see the attached jpeg.
i still figure it out why, not sure if it because of the autocad version.
I'm using the autocad mechanical 2010.
but some of my colleague are using autocad mechanical 2008 and some are LT.
but i think LT version are not able to do the line plot. correct me if i am wrong.
hopefully you can help to solve this. or giving some guildlines.
Many thanks.

fixo
2010-07-27, 05:11 AM
dear fixo,

thank you so much for your file.
I have just tried, but it return me with this error msg box when i press the button,
please see the attached jpeg.
i still figure it out why, not sure if it because of the autocad version.
I'm using the autocad mechanical 2010.
but some of my colleague are using autocad mechanical 2008 and some are LT.
but i think LT version are not able to do the line plot. correct me if i am wrong.
hopefully you can help to solve this. or giving some guildlines.
Many thanks.
I'm working on A2009 only
You can try open VBA editor (Alt+F11 in Excel)
then go to Tools->References and change AutoCAD XXXX Object Library
on your current version - it would be marked as *MISSING* in there
Unfortunatelly I know nothing about VBA and LT release, sorry

~'J'~

sanrajbhar677632
2011-10-14, 03:53 PM
This is what i am looking for. i picked all references related AutoCAD. i am using AUtoCAD map 2004. i faced this Error Kindly Check it. give me solution friends. Please !



For i = 1 To UBound(lineData, 1) ;gor Error here as "Run time Error 33, type Mismatch

Dim startPt(0 To 2) As Double
Dim endPt(0 To 2) As Double
startPt(0) = CDbl(lineData(i, 1)): startPt(1) = CDbl(lineData(i, 2)): startPt(2) = 0#
endPt(0) = CDbl(lineData(i, 3)): endPt(1) = CDbl(lineData(i, 4)): endPt(2) = 0#
Set oLine = aspace.AddLine(startPt, endPt)
Next i




I'm working on A2009 only
You can try open VBA editor (Alt+F11 in Excel)
then go to Tools->References and change AutoCAD XXXX Object Library
on your current version - it would be marked as *MISSING* in there
Unfortunatelly I know nothing about VBA and LT release, sorry

~'J'~

fixo
2011-10-15, 07:43 AM
AutoCad drawing must be open at the first, then,
before of you click button, you have just select whole Excel data range,
nothing else
Try again

~'J'~

arazmjo551023
2012-08-12, 08:11 PM
Dear Fixo,

Thank you very much for this useful information, Based on your advise I wanna draw a spline in cad by attached excel coordinate.

Could you please help me?

Thanks

Arash

fixo
2012-08-12, 09:25 PM
Dear Fixo,

Thank you very much for this useful information, Based on your advise I wanna draw a spline in cad by attached excel coordinate.

Could you please help me?

Thanks

Arash

Welcome on board, Arash
I have not worked with splines, anyway I will try to help

Here is my attempt:

Open Excel file, add reference to AutoCAD Type library
then in the Sheet1 add a button, then add code for this button
and save Excel file, better yet to save it in .XLSM format:

Option Explicit

Private Sub CommandButton1_Click()


Dim selRng As Range
Set selRng = Selection

Dim lineData As Variant
lineData = selRng.Value2



Dim acad As AcadApplication
Set acad = GetObject(, "Autocad.Application")
Dim adoc As AcadDocument
Set adoc = acad.ActiveDocument
Dim aspace As AcadBlock
Dim oSpline As AcadSpline
Set aspace = adoc.ActiveLayout.Block

Dim i
ReDim ptarr(0 To (UBound(lineData, 1) * 3) - 1) As Double
Dim n
For i = 1 To UBound(lineData, 1)
ptarr(n) = CDbl(lineData(i, 1)): ptarr(n + 1) = CDbl(lineData(i, 2)): ptarr(n + 2) = 0#
n = n + 3
Next i

Dim startPt(0 To 2) As Double
Dim endPt(0 To 2) As Double
startPt(0) = 0.5: startPt(1) = 0.5: startPt(2) = 0#
endPt(0) = 0.5: endPt(1) = 0.5: endPt(2) = 0#

Set oSpline = aspace.AddSpline(ptarr, startPt, endPt)
'' if you need to draw the closed spline then add this line:
'' oSpline.Closed=True
ZoomAll

Set aspace = Nothing
Set adoc = Nothing
Set acad = Nothing

End Sub

Open any drawing, the go to Excel and select diapazone of
coordinate cells 2 columns as in your example, then press button,
this way it working on my end A2010, MS Office 2007


~'J'~

strawmoped214590
2012-10-27, 09:22 PM
Hi to Everyone,
I looked through posts and i concluded that it is very useful tool in a autocad usage. I have also a question which concern a connection between Excel and AutoCAD. Is there any possibility to generate lines also with line options as thickness, colour and so on?

Thank you in advance for reply.

fixo
2012-10-28, 06:00 AM
Hi, strawmoped,
Welcome on board!
You have to create an Excel file with these datum row by row:
x1, y1, z1, x2, y2, z2, Lineweight as double?, Colrindex as integer
And also what is your Excel version? AutoCAD version?
Let me know about then I will try to write a sample code for you.
But easier yet to hold the data in .CSV file instead, then it would be
retrieved from there more easily, btw

strawmoped214590
2012-10-28, 10:09 AM
I'm working on AUTOCAD 2010 and Excel 2007 version. I'm not sure, but for me it looks more comfortable and automatic to use some executing button in an excel file than saving it as a .CSV file. I thought even it would be nice if excel in first step creates the layers (various thickness, colour and line types) and then in second step generates the lines combined with particular layers.

I'm grateful for your help Fixo.

fixo
2012-10-28, 11:02 AM
Try this Excel file, in the following order
first open drawing, then open Excel file,
open desired spreadsheet and select
data range, then click button,
if this woking good for you, then back
to Excel file and repopulate the range with your
own data
Here you can get it
https://dl.dropbox.com/u/18024145/Drawing_Lines.zip

fixo
2012-10-28, 11:11 AM
Try this Excel file, in the following order
first open drawing, then open Excel file,
open desired spreadsheet and select
data range, then click button,
if this woking good for you, then back
to Excel file and repopulate the range with your
own data
Here you can get it
https://dl.dropbox.com/u/18024145/Drawing_Lines.zip

Or get it from attachment

strawmoped214590
2012-10-28, 01:08 PM
It works, it's amazing. How do You know this all Fixo? Where can I find some tips how to create such a connection between ACAD and Excel? I have much more questions but I don't want to bother you.

fixo
2012-10-28, 05:48 PM
Glad if this working for you,
To be honestly I'm just an old homesitter and
do nothing but make the programs, piece by piece,
day by day, on many languages, its all my life...
Search this forum: Interaction between AutoCAD and Excel,
all 6 parts
Cheers :)

strawmoped214590
2012-10-28, 06:52 PM
I'm only a civil engineering student, so programing is tricky for me.
Respect for your knowledge Fixo. I admire your skills.
I hope, You will help me if the other problems appear.

Thanks.

fixo
2012-10-28, 08:34 PM
Well, if I will be in the good condition,
:)

Darren Allen
2013-02-05, 06:52 PM
Try attached file
Open Autocad drawing
Open Excel file (AutoCAD must be opened)
Select four columns
Press button

~'J'~

I am attempting the same thing. I have selected to four columns and pressed the button, Received "Compile Error: Cannot find project or library." Excel 2007 with ACADm 2012. Please advise, Thank you!

fixo
2013-02-05, 07:34 PM
I am attempting the same thing. I have selected to four columns and pressed the button, Received "Compile Error: Cannot find project or library." Excel 2007 with ACADm 2012. Please advise, Thank you!

Hi Darren, I just tested this one on my AutoCAD 2010,
try to change references on your A2012 Relesase,
then let me know about

soumitramandal83356864
2013-02-15, 05:44 AM
hi fixo ,i have attached the required autocad file here.please see your inbox massage folded..........related massage i have sent to you there

soumitramandal83356864
2013-02-15, 05:48 AM
hi fixo ,i have attached the required autocad file here.

fixo
2013-02-15, 06:37 AM
Hi,
I see in your drawing there are two embedded OLE objects with
"Embedded" status, I don't know entirely how to work
with this object types. Just a guess: maybe you need to create data link
with Excel file instead and work further from this point
But I have not have an experience with this deal as well,
search for VBA datalink on Google or on this forum

Darren Allen
2013-02-15, 01:01 PM
Hi Darren, I just tested this one on my AutoCAD 2010,
try to change references on your A2012 Relesase,
then let me know about

Sorry, it took so long to reply. How do I change the references?

fixo
2013-02-15, 04:09 PM
Hi Allen, See PM
Open project in VBAIDE then go to Tools->References
ans see References wich was marked with yellow ticks,
then change them all relative to your current version

soumitramandal83356864
2013-02-16, 04:26 AM
Thanx u fixo sir for your quick response .....actually i need to say ..i want instant drawing in autocad form canal data put excel. actually there is no need of OLE object in autocad at my end . i added it my sample drawing for ready reference of canal area calculation...thank you once again...

fixo
2013-02-16, 06:08 AM
Then upload a sample Excel sheet with same data,
because I have not have so much time to recreate one from your drawing

soumitramandal83356864
2013-02-16, 05:01 PM
hi fixo sir,thanx again for response from you end,yes i understand your time.i enclosed the excel data file here.........for you.

soumitramandal83356864
2013-02-16, 05:41 PM
i also required to annonate the points in autocad drawing ...

fixo
2013-02-16, 09:48 PM
For the first test you do next
Copy and add this code in AutoCAD VBAIDE (Alt+F11)
in the module
then execute it, but change before all settings and file name
within the code block
See if this code will return all values in AutoCAD command line after


Option Explicit
' Notes:
' 1. requires settings: Tools -> Options -> General tab -> Error trapping field -> check "Break on Unhandled errors"
' 2. requires reference to Microsoft Excel XX.0 Object Library
Function IsExcelRunning() As Boolean
Dim xlApp As Excel.Application
On Error Resume Next
Set xlApp = GetObject(, "Excel.Application")
IsExcelRunning = (Err.Number = 0)
Set xlApp = Nothing
Err.Clear
End Function

Sub ReadExcelRange()
' To read data from specific Excel range
Dim xlApp As Excel.Application
Dim blnIsOK As Boolean
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
blnIsOK = IsExcelRunning()
If blnIsOK Then
Set xlApp = GetObject(, "Excel.Application")
Else
Set xlApp = CreateObject("Excel.Application")
xlApp.Visible = True
xlApp.UserControl = True
End If
Dim xlFileName As String
' set full path of your Excel file here:
xlFileName = "C:\MyFolder\MyFile.xlsx"
xlApp.Application.ScreenUpdating = False
' open file for read
Set xlBook = xlApp.Workbooks.Open(xlFileName)
Set xlSheet = xlBook.Worksheets("Sheet1") ' desired sheet name , same if use xlBook.Worksheets(1)
xlSheet.Activate
Dim xlrange As Excel.Range
Set xlrange = xlSheet.Range("A1:F25")
xlrange.Select
Dim cols As Long
Dim rows As Long
cols = xlrange.Columns.Count
rows = xlrange.rows.Count
Dim rangeValue As Variant
rangeValue = xlrange.Value2

' clean up memory
xlBook.Close False
Set xlBook = Nothing
xlApp.Quit
Set xlApp = Nothing
DoEvents
' go to Autocad then
Dim i, j
For i = 1 To rows
For j = 1 To cols
' read cell data separatelly just for test
ThisDrawing.Utility.Prompt vbLf & CStr(rangeValue(i, j))
Next
Next
End Sub

soumitramandal83356864
2013-02-17, 03:19 AM
Very very Good morning & thank u fixo sir, i am trying this........i will be back later

fixo
2013-02-19, 09:49 AM
Here is other part of code,
I have not have a time to go further, so
you have to add your other flowers in there by yourself
Rename file to .bas extension before

soumitramandal83356864
2013-02-21, 05:04 PM
Thank You Sir...............

fixo
2013-03-23, 12:02 PM
You're welcome,
Cheers :)

dcraingenieros369034
2013-04-10, 02:03 AM
Hi,

If i have an excel file with database of steel shapes, its possible this file automatic load, when execute a .dvb file, when i started AutoCAD???

thanks!!

sahil26_mujawar403238
2013-07-23, 08:50 AM
Dear Sir,

I am new here, actually i want to draw a graph in autocad that should work automatically if we change a value.
I am attaching an autocad drawing file showing the graph profile and i want it exactly in that way but should work automatically even if a small value in x or y axis is changed

please help me out

fixo
2013-07-23, 08:56 AM
Welcome on board, craingenieros,
Please search for this question on this forum or take a look at this thread:
http://www.cadtutor.net/forum/showthread.php?80427-Automatically-Load-dvb-file-when-Autocad-start
Hth

fixo
2013-07-23, 09:01 AM
Hi Sahil, welcome on board,
unfortunately I can't help with it, sorry,
it's too difficult for my poor vba programming skills
Perhaps somebody else lead you to right direction,

sahil26_mujawar403238
2013-07-23, 09:28 AM
ANY WAY THANK FOR THE REPLY

BUT IF U GET ANY INFO ABT THIS DO LET ME KNOW
THANKS AGAIN

Regards

Sahil

fixo
2013-07-23, 10:10 AM
Okay, Sahill
Will do if I've find a solution,
Cheers :)

shashidharga451041
2013-11-30, 03:14 AM
Hi friends,
I'm a new member to this forum. I've Map dwg file with polylines representing roads. I've the road improvements data in excel Ex., Name of road, length of improvements made and year of improvements. I've these data for last five years. Is it possible to highlight the improvement details of roads by different colors using excel data. I'm using acad map 2013 excel 2010. If I manually do this it will take a lot of time. Please help. Thanx in advance.
Regards,
Shashi