Announcements
Notice: Upload of PDF documents is currently unavailable across the Community due to an ongoing issue.

Microsoft CoPilot AI can write AutoLisp coding

Microsoft CoPilot AI can write AutoLisp coding

chlaksavery
Observer Observer
9,124 Views
9 Replies
Message 1 of 10

Microsoft CoPilot AI can write AutoLisp coding

chlaksavery
Observer
Observer

It's not perfect. Sometimes theses a back and forth to correct and error check. But the AI will try to fix the code until it does work.

Last thing I tried was asking it to write code to convert all survey figures to polylines at a zero elevation.

Took a few fixes, but eventually worked. Now it's a Button Macro. https://omegle.onl/

9,125 Views
9 Replies
Replies (9)
Message 2 of 10

kczerwonka
Advocate
Advocate

Never thought of doing that. That's cool!

0 Likes
Message 3 of 10

Kent1Cooper
Consultant
Consultant

There have been numerous Topics raised here based on problems with AI-generated AutoLisp code [more commonly from ChatGPT] that was really way off -- using assumed but non-existent function names, supplying incorrect arguments, etc.  I guess we should assume that AI will get better at it over time, but so far....

Kent Cooper, AIA
0 Likes
Message 4 of 10

CodeDing
Mentor
Mentor

@chlaksavery ,

 

I have personally found recently that Claude.ai is better at writing code than ChatGPT. Might be worth looking into.

 

Also, I created a SF2 command to do the exact thing you requested (converting Survey Figures). You can get it from this post here:

https://forums.autodesk.com/t5/civil-3d-forum/database-processing-feature-lines-instead-of-survey-fi... 

 

Best,

~DD

0 Likes
Message 5 of 10

DGCSCAD
Advisor
Advisor

After seeing this thread, I took a crack at having it emulate a no-frills version of ACAD's native Find And Replace Text. A few tweaks later and it's getting there, but it's still a WIP:

 

(defun c:FART (/ ss find replace);Find And Replace Text
  (setq find (getstring "\nEnter the text to find: "))
  (setq replace (getstring "\nEnter the replacement text: "))
  (setq ss (ssget '((0 . "TEXT,MTEXT,DIMENSION,ACAD_TABLE"))))
  (if ss
    (progn
      (vlax-for obj (vla-get-ActiveSelectionSet (vla-get-ActiveDocument (vlax-get-acad-object)))
(princ "\n")
(princ (vla-get-ObjectName obj))
        (cond
          ((= (vla-get-ObjectName obj) "AcDbText")
           (while (vl-string-search find (vla-get-TextString obj))
             (vla-put-TextString obj (vl-string-subst replace find (vla-get-TextString obj)))))
          ((= (vla-get-ObjectName obj) "AcDbMText")
           (while (vl-string-search find (vla-get-TextString obj))
             (vla-put-TextString obj (vl-string-subst replace find (vla-get-TextString obj)))))
          ((= (vla-get-ObjectName obj) "AcDbRotatedDimension")
           ;(if (vl-string-search find (vla-get-TextOverride obj))
           (while (vl-string-search find (vla-get-TextOverride obj))
             (vla-put-TextOverride obj (vl-string-subst replace find (vla-get-TextOverride obj)))))
          ((= (vla-get-ObjectName obj) "AcDbTable")
           ;(let ((rowCount (vla-get-Rows obj))
                 ;(colCount (vla-get-Columns obj)))

		(setq colCount (vlax-get-property obj 'Columns))
		(setq rowCount (vlax-get-property obj 'rows))

             (repeat rowCount
               (setq row (1- rowCount))
               (repeat colCount
                 (setq col (1- colCount))
                 (setq cellText (vla-gettext obj row col))
                 (while (vl-string-search find cellText)
                   (setq cellText (vl-string-subst replace find cellText))
                   (vla-SetText obj row col cellText))
                 (setq colCount (1- colCount)))
               (setq rowCount (1- rowCount)))));)
        )
      (princ "\nText replacement completed.")
    )
    (princ "\nNo matching text found.")
  )
  (princ)
)

 

I had it add MLeaders, but that was full of made-up function definitions. I'll be trying a different approach.

AutoCad 2018 (full)
Win 11 Pro
0 Likes
Message 6 of 10

gbattinPH5TG
Advocate
Advocate
What a great command for a tool. LOL
Have AI add a prompt at the end that says (princ "\nFART has finished successfully.")
Message 7 of 10

Sea-Haven
Mentor
Mentor

For anyone with Copilot make sure last 2 words are "Autocad lisp", but it can struggle on some tasks.

0 Likes
Message 8 of 10

SamBensonL4GSH
Participant
Participant

I know that you can add knowledge sources to Microsoft Co-Pilot, does anyone have any good ones that they've used for theirs or would recommend?

0 Likes
Message 9 of 10

Kent1Cooper
Consultant
Consultant

@SamBensonL4GSH wrote:

I know that you can add knowledge sources to Microsoft Co-Pilot, does anyone have any good ones that they've used for theirs or would recommend?


[Is it possible to embed the entire AutoLisp Reference in there as a "knowledge source," so it won't make up functions, use incorrect arguments, etc.?]

Kent Cooper, AIA
0 Likes
Message 10 of 10

CodeDing
Mentor
Mentor

@Kent1Cooper ,

 

I've tried. It makes it better, but still often confuses functions from Common Lisp as useable for AutoLisp. But I have noticed that as these newer AI models come out they do get much better at writing AutoLISP.

 

~DD

0 Likes