PDA

View Full Version : Creating a script that creates lines...



zousgr
28th Jul 2006, 03:46 pm
[using AutoCAD 2006]

Hi. This is about my university project and i have some problems.
What i have to do is to insert a raster image at AutoCAD (which is like a small map), and convert it to vector. So the result is a map at a dwg file that the roads are represented from lines.
I've done this part succesfully and now I have a total of 2500+ lines.
What I want to do now is to create a script file (*.scr) that contains the coordinates (StartX, StartY, EndX, EndY) of all 2500 lines so as to load the *.scr file at a new AutoCAD drawing later and to create the initial map.

Copying-pasting 4*2500 8-digit numbers is kinda tiring so i used an autolisp to export the coordinates of every single line to a *.doc file.
As most of you may know the *.scr should contain the data like that (always according to the instructions of my professor):
line
StartX,StartY
EndX,EndY

The problem is that even if i am 100% i do the *.scr perfectly, when i load it at a new AutoCAD drawing this message will appear: Zero length line created at (73.7644, 93.1040)
Specify next point or [Close/Undo]:
Of course the numbers will change depending on which line is first.

Anyway, i initially thought that the autolisp didn't export the coordinates accurately so i took 100 lines and did it by copy-paste at a new *.scr file.
The same message would appear...
The fact is that I compared my whole project with many of my co-students (every student has unique project) and after many many hours i couldn't file a single difference!!
What could my mistake be? I mean, why is AutoCAD recognising all lines as zero-lengthed?

CarlB
28th Jul 2006, 04:46 pm
Do you have the same coordinate twice? for example don't use:

LINE
x1,y1
x2,y2
x2,y2
x3,y3
etc...

because with the 'line' command you just keep entering new coordinates to draw successive line segments.

zousgr
29th Jul 2006, 01:09 am
Do you have the same coordinate twice?

No i don't.

For example: a part of my script file is:
line
71.7654,93.1619
72.6345,93.1619

line
71.7654,91.9462
73.0498,91.9462

line
28.3427,93.5514
27.9787,94.0505

.....etc....

As our professor instructed us to do.
Many of my co-students have done their projects and they did them that way. Only I have this problem.. :(
I also tried at other pcs (faulty installation of my AutoCAD software, who knows?) but the same problem again!!

CarlB
29th Jul 2006, 01:45 am
Something that is often a problem in script files is extra spaces, which act as a return. But I don't see that causing a zero length line.

My guess is you have a running osnap set, such that AutoCAD is snapping to an endpoint or something rather than to the coordinate.

Another way to avoid this problem is to set OSNAPCOORD to 1:

OSNAPCOORD
Type: Integer
Saved in: Registry
Initial value: 0
Controls whether coordinates entered on the command line override running object snaps.

0 Running object snap settings override keyboard coordinate entry
1 Keyboard entry overrides object snap settings
2 Keyboard entry overrides object snap settings except in scripts

zousgr
29th Jul 2006, 02:16 am
Now I understand what you said. Well, you are correct.

This is my mistake:

71.7654,93.1619
72.6345,93.1619

Possibly, the autolisp i used is incorrect.
I used this (http://cadtutor.net/forum/viewtopic.php?t=1785://url) lisp to export the properties.
I used fuccaro's lisp to export these properties but it seems that i did something wrong or the lisp has a minus bug. I mean a line can't have the same StartY and EndY...
So does anyone have a lisp that exports only these four (StartX, StartY, EndX, EndY) coordinates of a line?

Edit: CarlB thanks a lot for your help and immediate answer!

zousgr
29th Jul 2006, 02:26 am
Sorry CarlB
While i was writing you posted your answer and i notice it afterwards.
Well this time you are 100% correct.
It is the OSNAP!!!!
At last. I've been trying everything for days!
But i still don't get why ACAD showed me ''Zero length line created ...'' when i had rhe Endpoint OSNAP command activated. :?
Anyway thanks a lot for your help. You really saved me!

P.S. i feel kinda ridiculous now that i realized that te problem i had for several days could be solved with just a click...

CarlB
29th Jul 2006, 02:26 am
****edit****

Ok, good. Ignore my response below which I wrote before I saw you had success.

You're welcome
-----------------------------------------

No I don't think that's the mistake.

A line can have the same start and end y values, that just means it's horizontal.

Keep looking, check for spaces, turn osnaps off :)

zousgr
30th Jul 2006, 06:02 pm
And one last question I forgot to ask. To create a line the command is:

line
StartX,StartY
EndX,EndY

What are the exact commands to create arcs and circles?

CarlB
31st Jul 2006, 03:50 pm
I think no one answered yet because the question is so basic that it seems you aren't making the effort using AutoCAD to figure it out. But maybe you don't realize that in a script you use the same command sequence as you do on the AutoCAD command line. Try it out yourself, something like;

Circle
Cenx,Ceny
radius


..and for arc, after starting the command there are a few key words to define the following parameters, such as "Start, End, radius". The default is;

Arc
Startx,Starty
Midptx,Midpty
Endptx,Endpty

zousgr
1st Aug 2006, 12:37 am
I think no one answered yet because the question is so basic that it seems you aren't making the effort using AutoCAD to figure it out. But maybe you don't realize that in a script you use the same command sequence as you do on the AutoCAD command line

Indeed i hadn't realized that the sequence is the same. I tried many different combinations with various values to represent an arc (length, radius, startX etc..) but the arc wouldn't be the same as the original one.. I simply didn't know the order of these values! Anyway thanks for the help.