Hi,
i have an excel list of Length x Width (2 columns)
2400 50
2340 45
etc
etc
is there a way to DRAW Rectangles from the excel List in AutoCAD? End result i want Rectangles drawn near each other from the Excel List
SInce there are many Rectangles in AutoCAD, it should be done in a way to give a space between each item (i,e first one is drawn in 0,0 coordinate the other one can be drawn, 0,4000) 4 meters away
thanks,
Bedros
Solved! Go to Solution.
Solved by Kent1Cooper. Go to Solution.
This is exactly what I was looking for!
I have a huge amount of rectangle dimensions in Excel that I would like created in autocad. I created a .scr file from the code that was written, and I downloaded the book1 excel file and changed it it a .csv.
However, whenever I run the .scr, I get... well you can see my screenshot.
I've attached a screenshot of the code in my notedpad, as well as the autocad screen when I try to run it. I am a bit new to automation in autocad, so please excuse my ignorance.
This is a LISP, not a Script.
Normal way:
Rename file extension from scr to lsp
load the Lisp by drag&drop or command APPLOAD,
Also prossible but not usual:
Open your SCR file, go to the last char, then press ENTER for a new line,
in the new line write DOIT and press ENTER again.
Save the file.
LSP after loading
Start the new command: DOIT
SCR after loading
Start the new Command: DOIT
(Or if you used my "Option" the Command started after loading automatically)
Sebastian
Hi
I tried this exact lsp which is loaded by autocad but i get stringp nil after I type DOIT.
The DOIT.lsp is saved into D:\DOIT.lsp
I used your last script modified upon my needs:
Quote
(defun C:DOIT (/ source base str X n Y)
(setq
source (open (findfile "D:\CARGO PLANS\Book1.csv") "r")
base '(0 0 0)
); setq
(read-line source); header line [do nothing with it]
(while (setq str (read-line source))
(setq
str (substr str (+ (vl-string-search "," str) 2)); remove line number
X (atof (substr str 1 (setq n (vl-string-search "," str))))
Y (atof (substr str (+ n 2) (1+ (vl-string-search "," str n))))
); setq
(command
"_.rectang" "_none" base "_none" (mapcar '+ base (list X Y))
"_.text"
"_style" "Standard"
"_mc" "_none" (mapcar '+ base (list (/ X 2) (/ Y 2))); midpoint of rectangle
(/ Y 2.0) 0 ; height & rotation
(substr str (+ (vl-string-position 44 str nil T) 2)); content
); command
(setq base (polar base 0 (+ X 5)))
); while
(close source)
(princ)
); defun
Unquote
Thanks for any help.
@Anonymous wrote:
....
I tried this exact lsp which is loaded by autocad but i get stringp nil after I type DOIT.
....
source (open (findfile "D:\CARGO PLANS\Book1.csv") "r")
.....
Filepath subdividers in AutoLisp functions need to be either forward slashes or double backslashes:
source (open (findfile "D:/CARGO PLANS/Book1.csv") "r")
or
source (open (findfile "D:\\CARGO PLANS\\Book1.csv") "r")
Fix that and see whether it works.
@Anonymous , if you're still watching [I didn't catch your message at the time], the same may be the answer to your problem. And @tmwatte , you would need to make the same correction in addition to treating it as an AutoLisp routine rather than a Script.
Hi,
Many thanks. It worked. The only problem with the lisp is that it does not take care of the quantity. If for example you have 14 pcs it draws only one.
at First, after rectangles were drawn, I wanted the QTY and LABEL to appear as TEXT inside the Rectangle - but then it was forgotten, am sure there is a way to do that
From what I observed if I have a lot of rectangulars the text inserted in the rectangular remain quite small. But if I try to insert only a few of them the text gets enlarged up to 205. Standard when opening the autocad is 0.200.
Or the best solution to make it become on multi line text and stick inside the rectangular area (not to get outside the rectangular)
Any way to make it a fix value everytime I execute DOIT function.
Anticipated thanks!
Guys,
can someone paste back the Working Final/Updated Version of the Lisp and the Excel, please?
thanks,
Bedros
Just as a matter of interest Excel can control Autocad so you would draw the rectangs from excel not Acad.
Here is a link to a good tutorial and some sample code that demonstrates drawing objects from excel, its macro code ie VBA. https://www.youtube.com/watch?v=754g0gcGsjY&feature=youtu.be
Public Sub Opendwg()
Dim acadApp As Object
Dim acadDoc As Object
'Check if AutoCAD application is open. If is not opened create a new instance and make it visible.
On Error Resume Next
Set acadApp = GetObject(, "AutoCAD.Application")
If acadApp Is Nothing Then
Set acadApp = CreateObject("AutoCAD.Application")
acadApp.Visible = True
End If
'Check (again) if there is an AutoCAD object.
If acadApp Is Nothing Then
MsgBox "Sorry, it was impossible to start AutoCAD!", vbCritical, "AutoCAD Error"
Exit Sub
End If
On Error GoTo 0
'If there is no active drawing create a new one.
On Error Resume Next
Set acadDoc = acadApp.ActiveDocument
If acadDoc Is Nothing Then
Set acadDoc = acadApp.Documents.Add
End If
On Error GoTo 0
'Check if the active space is paper space and change it to model space.
If acadDoc.ActiveSpace = 0 Then '0 = acPaperSpace in early binding
acadDoc.ActiveSpace = 1 '1 = acModelSpace in early binding
End If
End Sub
Public Sub addline(x1, y1, z1, x2, y2, z2)
' Create the line in model space
'Dim acadApp As Object
'Dim acadDoc As Object
Set acadApp = GetObject(, "AutoCAD.Application")
Set acadDoc = acadApp.ActiveDocument
Dim startpoint(0 To 2) As Double
Dim endpoint(0 To 2) As Double
Dim lineobj As Object
startpoint(0) = x1: startpoint(1) = y1: startpoint(2) = z1
endpoint(0) = x2: endpoint(1) = y2: endpoint(2) = z2
Set lineobj = acadDoc.ModelSpace.addline(startpoint, endpoint)
acadApp.ZoomExtents
End Sub
Public Sub addcirc(x1, y1, z1, rad)
' Create the circle in model space
' Dim acadApp As Object
' Dim acadDoc As Object
Set acadApp = GetObject(, "AutoCAD.Application")
Set acadDoc = acadApp.ActiveDocument
Dim cenpoint(0 To 2) As Double
Dim circobj As Object
cenpoint(0) = x1: cenpoint(1) = y1: cenpoint(2) = z1
Set circobj = acadDoc.ModelSpace.addcircle(cenpoint, rad)
acadApp.ZoomExtents
End Sub
Sub addpoly(cords, col)
' Dim acadApp As Object
' Dim acadDoc As Object
Set acadApp = GetObject(, "AutoCAD.Application")
Set acadDoc = acadApp.ActiveDocument
Dim oPline As Object
' add pline to Modelspace
Set oPline = acadDoc.ModelSpace.AddLightWeightPolyline(cords)
oPline.Color = col
End Sub
Sub alan1()
' This example adds a line in model space
' Define the start and end points for the line
px1 = 1
px2 = 5
py1 = 1
py2 = 5
pz1 = 0
pz2 = 0
Call addline(px1, py1, pz1, px2, py2, pz2)
End Sub
Sub alan2()
px1 = 1
py1 = 1
pz1 = 0
Radius = 8.5
Call addcirc(px1, py1, pz1, Radius)
End Sub
Sub alan3()
'Dim coords(0 To n) As Double
Dim coords(0 To 5) As Double
coords(0) = -6: coords(1) = 1:
coords(2) = 3: coords(3) = 5:
coords(4) = 7.55: coords(5) = 6.25:
col = 1
Call addpoly(coords, col)
End Sub
Can't find what you're looking for? Ask the community or share your knowledge.