Jump to content

Recommended Posts

Posted

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.")
 )
)

 

 

image.thumb.png.109afb74f8bdb5bc797a3d27da8ab718.png

Posted

Try to turn off OSNAP while you run the program...

Just a guess.

Posted

I already turn off snap mode at the beginning of the code.

Posted

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!

  • Thanks 1
Posted

Only the first row of the sample dataset I shared did not work, the remaining rows worked properly as I wanted.

Posted

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. 

Posted (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 by BIGAL
  • Like 1

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...