DeEng Posted November 26 Posted November 26 Hello, I am trying to write an AutoLISP function to draw arcs based on data from a file. Each line of the file starts with "A", followed by six values representing the start point, end point, and center point of an arc. My goal is to draw the arc using these points and display text annotations for each coordinate on the drawing. However, the code does not work as expected, and I encounter some issues. Here is an example of the data set I am using: A 0 -67.5 8.5 -76 12.75 -63.25 A 86 -76 95.5 -66.5 83.25 -63.75 A 107.5 -28.5 104 -32.5 110.66 -34.8 A 139.5 66 129.5 76 128.25 64.75 A 10.5 76 0 66 12.26 63.63 Here is the code I am working with: ((= firstChar "A") (setq values (parse_values (substr currentLine 2))) (if (= (length values) 6) (progn (setq x1 (atof (nth 0 values))) ; Start X (setq y1 (atof (nth 1 values))) ; Start Y (setq x2 (atof (nth 2 values))) ; End X (setq y2 (atof (nth 3 values))) ; End Y (setq cx (atof (nth 4 values))) ; Center X (setq cy (atof (nth 5 values))) ; Center Y (if (and (/= x1 x2) (/= y1 y2)) (progn (set-layer "PERI") (command "_ARC" (list x1 y1 0.0) (list x2 y2 0.0) (list cx cy 0.0)) (set-layer "DIM") (add-text (strcat "(" (rtos x1 2 1) "," (rtos y1 2 1) ")") x1 y1 3) ; Start (add-text (strcat "(" (rtos x2 2 1) "," (rtos y2 2 1) ")") x2 y2 3) ; End (add-text (strcat "(" (rtos cx 2 1) "," (rtos cy 2 1) ")") cx cy 3) ; Center ) (alert (strcat "Invalid ARC coordinates: " currentLine)) ) ) (alert "Invalid ARC data. Each ARC must have 6 values.") ) ) Quote
fuccaro Posted November 26 Posted November 26 Try to turn off OSNAP while you run the program... Just a guess. Quote
DeEng Posted November 26 Author Posted November 26 I already turn off snap mode at the beginning of the code. Quote
fuccaro Posted November 26 Posted November 26 From what I can see, the arc center and end points are switched. Try to change the COMMAND function: (COMMAND "arc" "c" (list cx cy 0.0) (list x1 y1 0.0) (list x2 y2 0.0)) Or a better approach: try to use ENTMAKE to draw the arc. These days I posted in the Forum a program drawing Arcs using that way. Good luck! 1 Quote
DeEng Posted November 26 Author Posted November 26 Only the first row of the sample dataset I shared did not work, the remaining rows worked properly as I wanted. Quote
Steven P Posted November 26 Posted November 26 Might be wrong, arcs are drawn anti-clockwise (I think, might be clockwise), depends on your start, end and centre whether you get a 'short' arc or a 'long' arc - try swapping the start and end point on the spreadsheet to see if that makes a difference. Generally if some of the LISP is working properly, then it is all working properly but the result is not what the user is expecting from the inputs. Quote
BIGAL Posted November 26 Posted November 26 (edited) If the angle of the arc is alays less than 180 degrees, then use length = rad*angle so you can get angle if its more than 180 use PI in lisp, then reverse the order of the start and end points. Ie erase arc and do again. Its hard to tell what is correct so will leave it to you to test. Edited November 26 by BIGAL 1 Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.