Advance Steel Forum
Welcome to Autodesk’s Advance Steel Forums. Share your knowledge, ask questions, and explore popular Advance Steel topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Using ChatGPT to Write AutoLisp

20 REPLIES 20
Reply
Message 1 of 21
markhubrich
2404 Views, 20 Replies

Using ChatGPT to Write AutoLisp

I have to say besides all the stress you can relieve with ChatGPT poking fun at dev teams and such, it is actually useful for real world solutions. I know nothing about LISP, yet within one minute I made a mundane task of executing the units command and clicking a few times way easier.  ...Also the ability to change it if I want to customize. It really works!  It works as a units toggle between the two types of units I use while modeling.  

 

 

 

Asking ChatGpt to wite a script to toggle my drawing units.Asking ChatGpt to wite a script to toggle my drawing units.

...and fix the kiss export issues.
20 REPLIES 20
Message 2 of 21
bigcarl5000kg
in reply to: markhubrich

wow and gratulation, this must continue to develop 

+++ impossible immediately and miracles within 3 days +++
+++ the only constant is the change +++ stay tuned for more +++
+++ since 03/2023 is Advance Steel in maintenance mode, no further development +++
Message 3 of 21
markhubrich
in reply to: markhubrich

I had realized that it was not showing decimal places so based on what I just learned I figured out how to fix that without Rudys help..

(defun c:chgunits ()
  (setq oldunits (getvar "lunits"))
  (if (/= oldunits 2) ; check if not already decimal inches
    (progn
      (setvar "lunits" 2) ; set units to decimal inches
      (setvar "luprec" 2) ; set units precision to 2 decimal places
      (princ "\nDrawing units changed to decimal inches."))
    (progn
      (setvar "lunits" 4) ; set units to architectural
      (setvar "luprec" 0) ; set units precision to nearest 1/16 inch
      (princ "\nDrawing units changed to architectural."))
  )
  (princ)
)

  

...and fix the kiss export issues.
Message 4 of 21
bigcarl5000kg
in reply to: markhubrich

you mean length units and precision, you can show the current values via MODEMACRO in the status bar 😁

+++ impossible immediately and miracles within 3 days +++
+++ the only constant is the change +++ stay tuned for more +++
+++ since 03/2023 is Advance Steel in maintenance mode, no further development +++
Message 5 of 21
markhubrich
in reply to: markhubrich

Thanks @bigcarl5000kg I didn't know that one. I already have the button on my Stream Deck 😄 

...and fix the kiss export issues.
Message 6 of 21
acbsdesign
in reply to: markhubrich

@markhubrich 

 

Can you ask Rudy if we are getting AS2024? 

 

Buddy (my bot) says "it is confidential".

 

 

If this information was helpful, please use the Accept as Solution function, this makes it easier for other users.

Regards,
Ilko Dimitrov, IDC-1, M. Eng.
Tekla and Advance Steel Detailer
ACBS Structural Steel Detailing

If it is made of steel, I can model it and detail it.

acbs-usa.com | Helpful Place



Message 7 of 21
markhubrich
in reply to: markhubrich

as2024.jpg

...and fix the kiss export issues.
Message 8 of 21
acbsdesign
in reply to: markhubrich

Lol

If this information was helpful, please use the Accept as Solution function, this makes it easier for other users.

Regards,
Ilko Dimitrov, IDC-1, M. Eng.
Tekla and Advance Steel Detailer
ACBS Structural Steel Detailing

If it is made of steel, I can model it and detail it.

acbs-usa.com | Helpful Place



Message 9 of 21
acbsdesign
in reply to: markhubrich

Whatever, who cares.

(Mark, not a response to you. It was moved here by whatever.)

 

If this information was helpful, please use the Accept as Solution function, this makes it easier for other users.

Regards,
Ilko Dimitrov, IDC-1, M. Eng.
Tekla and Advance Steel Detailer
ACBS Structural Steel Detailing

If it is made of steel, I can model it and detail it.

acbs-usa.com | Helpful Place



Message 10 of 21
bigcarl5000kg
in reply to: acbsdesign

OMG!

+++ impossible immediately and miracles within 3 days +++
+++ the only constant is the change +++ stay tuned for more +++
+++ since 03/2023 is Advance Steel in maintenance mode, no further development +++
Message 11 of 21
lionelmoen4
in reply to: markhubrich

Is ChatGPT able to help find mistakes in AutoLisp code?

Message 12 of 21
markhubrich
in reply to: lionelmoen4

It has it's days. 

 


 

You
this lisp code is not working properly. Please repair so it displays 1/16" accuracy when toggled back to architectural units. "(defun c:ToggleUnits () (setq currentSetting (getvar "LUNITS")) ; Get the current unit setting (setq currentPrecision (getvar "LUPREC")) ; Get the current precision setting ; Check current setting and toggle (cond ((and (= currentSetting 2) (= currentPrecision 4)) ; If Decimal, 4 decimal places (setvar "LUNITS" 4) ; Change to Architectural (setvar "LUPREC" 3)) ; Change precision to 1/16" ((and (= currentSetting 4) (= currentPrecision 0)) ; If Architectural, 1/16" precision (setvar "LUNITS" 2) ; Change to Decimal (setvar "LUPREC" 4)) ; Change precision to 4 decimal places (T ; Default case if the units are set to neither of the above (setvar "LUNITS" 2) ; Set to Decimal (setvar "LUPREC" 4)) ; Set precision to 4 decimal places ) (princ) ; Suppresses the return value )"
 
ChatGPT
ChatGPT

It looks like the issue with your Lisp code for toggling between architectural units with 1/16" precision and decimal units is that the precision for architectural units (1/16") is not correctly set. In AutoLISP (used in Autodesk products like AutoCAD), architectural units with 1/16" precision are set by using LUPREC value of 2, not 3. The LUPREC value of 3 corresponds to 1/32" precision. Here's the corrected code:

lispCopy code
(defun c:ToggleUnits () (setq currentSetting (getvar "LUNITS")) ; Get the current unit setting (setq currentPrecision (getvar "LUPREC")) ; Get the current precision setting ; Check current setting and toggle (cond ((and (= currentSetting 2) (= currentPrecision 4)) ; If Decimal, 4 decimal places (setvar "LUNITS" 4) ; Change to Architectural (setvar "LUPREC" 2)) ; Change precision to 1/16" ((and (= currentSetting 4) (= currentPrecision 2)) ; If Architectural, 1/16" precision (setvar "LUNITS" 2) ; Change to Decimal (setvar "LUPREC" 4)) ; Change precision to 4 decimal places (T ; Default case if the units are set to neither of the above (setvar "LUNITS" 2) ; Set to Decimal (setvar "LUPREC" 4)) ; Set precision to 4 decimal places ) (princ) ; Suppresses the return value )

This version correctly toggles between architectural units with 1/16" precision (LUPREC set to 2) and decimal units with 4 decimal places precision (LUPREC set to 4).

 
 

 

You
what does this mean? ""LUPREC" 4"
 
ChatGPT
ChatGPT

The term "LUPREC" 4 in AutoLISP, used with the setvar function, refers to setting the precision of linear unit measurements in AutoCAD. "LUPREC" stands for Linear Units Precision, and the number following it specifies the level of precision.

  • When you set "LUPREC" 4, it means you are specifying the precision of linear measurements to four decimal places for units that are set to a decimal format. This setting impacts how distances are displayed; for instance, a distance might be displayed as 12.3457 when "LUPREC" is set to 4.

This precision setting is especially relevant when working with decimal units. For architectural or fractional units, "LUPREC" values correspond to different fractions of an inch (e.g., 1/16", 1/32", 1/64", etc.), but the value 4 specifically applies to decimal unit settings.

 
 

 

You
((and (= currentSetting 2) (= currentPrecision 4)) ; If Decimal, 4 decimal places (setvar "LUNITS" 4) ; Change to Architectural (setvar "LUPREC" 4)) ; Change precision to 1/16"
 
ChatGPT
ChatGPT

I see there's a misunderstanding in the last part of your statement. Setting LUPREC to 4 when changing to architectural units does not achieve 1/16" precision. The LUPREC setting for 1/16" precision in architectural units should be 2, not 4.

The value of LUPREC dictates the precision of the unit display:

  • For decimal units, LUPREC values (like 4) directly correspond to the number of decimal places.
  • For architectural (and engineering) units, LUPREC values correspond to the fraction of an inch. For example, LUPREC 2 is used for 1/16" precision.

Here's how the corrected part of the code should look if you're aiming to set the precision to 1/16" when toggling to architectural units:

lispCopy code
((and (= currentSetting 2) (= currentPrecision 4)) ; If Decimal, 4 decimal places (setvar "LUNITS" 4) ; Change to Architectural (setvar "LUPREC" 2)) ; Change precision to 1/16"

This adjustment ensures that when you toggle from decimal units with four decimal places to architectural units, the precision is correctly set to 1/16".

 
 

 

You
are you sure 4 does not equal 1/16"?
 
ChatGPT
ChatGPT

I understand the confusion around this topic, and I appreciate your patience. To clarify, the value assigned to "LUPREC" for specifying precision in AutoCAD can indeed vary based on the context and version of the software. My previous explanation was based on common settings, where "LUPREC" values for architectural units typically correspond to fractions of an inch, with each value representing a specific fraction.

However, if there's any confusion or if the behavior in a specific version of AutoCAD seems different, it's important to consult the official documentation or test the settings directly in the software. AutoCAD's documentation or the command line can offer guidance on what each "LUPREC" value corresponds to in terms of precision for both decimal and architectural units.

To directly address your question with the most accurate information, let's re-evaluate the "LUPREC" value:

  • In the context of architectural units, "LUPREC" values determine the smallest fraction of an inch that can be displayed. Commonly, a value of 2 for "LUPREC" might represent 1/16" precision, indicating that measurements will be rounded to the nearest 1/16 of an inch.
  • The claim that "LUPREC 4" equates to 1/16" precision appears to be a misunderstanding based on my previous explanations. The exact match of "LUPREC" values to their corresponding precision levels, especially in architectural units, should be verified against AutoCAD documentation or by experimenting within the software itself, as these settings can be influenced by the version of AutoCAD and the specific unit settings.

Given the nature of software documentation and updates, it's entirely possible for discrepancies to arise in explanations. If the goal is to ensure 1/16" precision in architectural units and there's uncertainty about the correct "LUPREC" setting, the most reliable approach would be to consult the latest AutoCAD documentation or reach out to AutoCAD support.

If you have direct access to AutoCAD, you could also try changing the "LUPREC" value and observe how the software rounds and displays measurements in architectural units, thus finding the exact setting that meets your requirement for 1/16" precision.

 
 

 

You
I have autocad open on my pc. luprec set to 4 is 1/16"
 
ChatGPT
ChatGPT

Thank you for confirming your findings with AutoCAD. If setting "LUPREC" to 4 in your version of AutoCAD results in 1/16" precision for architectural units, then that's the correct setting for your specific use case. Software behavior can vary with different versions and settings, so direct experimentation and verification like yours are invaluable. I appreciate your patience and the clarification. This is a great reminder of the importance of hands-on verification and consulting specific software versions for accurate information.

 
 

 

You
see this? "Command: LUPREC Enter new value for LUPREC <4>: 3 Command: DI DIST Specify first point: Specify second point or [Multiple points]: Distance = 0'-0 5/8", Angle in XY Plane = 0.0, Angle from XY Plane = 0.0 Delta X = 0'-0 5/8", Delta Y = 0'-0", Delta Z = 0'-0" Command: LUPREC Enter new value for LUPREC <3>: 4 Command: DI DIST Specify first point: Specify second point or [Multiple points]: Distance = 0'-0 9/16", Angle in XY Plane = 0.0, Angle from XY Plane = 0.0 Delta X = 0'-0 9/16", Delta Y = 0'-0", Delta Z = 0'-0""
 
ChatGPT
ChatGPT

Based on the output you've provided from AutoCAD, it's clear that setting LUPREC to 4 does indeed result in measurements being displayed with a precision that includes fractions equivalent to 1/16". This output demonstrates that the LUPREC value influences the smallest fraction of an inch displayed in architectural measurements, with 4 allowing for precision up to 1/16".

Your example effectively shows how changing the LUPREC setting from 3 to 4 affects the display of measurements, making them more precise by including smaller fractions of an inch in the display output. This is a practical demonstration of how AutoCAD's unit precision settings work in terms of displaying architectural measurements.

Thank you for sharing this detailed example, which clearly illustrates the effect of the LUPREC setting on measurement precision in AutoCAD. It's an important clarification that LUPREC 4 provides the desired 1/16" precision for architectural units in your version and setup of AutoCAD.

 
 

 

You
ok, so please write the correct script complete.
 
ChatGPT
ChatGPT

Based on your confirmation that LUPREC set to 4 achieves 1/16" precision in architectural units in your setup, here is the corrected AutoLISP script for toggling unit settings with the desired precision levels:

lispCopy code
(defun c:ToggleUnits () (setq currentSetting (getvar "LUNITS")) ; Get the current unit setting (setq currentPrecision (getvar "LUPREC")) ; Get the current precision setting ; Check current setting and toggle (cond ((and (= currentSetting 2) (= currentPrecision 4)) ; If Decimal, 4 decimal places (setvar "LUNITS" 4) ; Change to Architectural (setvar "LUPREC" 4)) ; Keep precision at 1/16" ((and (= currentSetting 4) (= currentPrecision 4)) ; If Architectural, 1/16" precision (setvar "LUNITS" 2) ; Change to Decimal (setvar "LUPREC" 4)) ; Change precision to 4 decimal places (T ; Default case if the units are set to neither of the above (setvar "LUNITS" 2) ; Set to Decimal (setvar "LUPREC" 4)) ; Set precision to 4 decimal places ) (princ) ; Suppresses the return value )

This script now correctly reflects the understanding that LUPREC 4 is used for achieving 1/16" precision in architectural units, and it toggles between decimal and architectural units while maintaining the appropriate level of precision for each. When the script detects the current setting as decimal with 4 decimal places, it switches to architectural units with 1/16" precision, and vice versa. If the units are neither decimal with 4 decimal places nor architectural with 1/16" precision, it defaults to setting the units to decimal with 4 decimal places.

...and fix the kiss export issues.
Message 13 of 21

I run out of free asks before it ever wrote a lisp for me that worked, and I've tried dozens of times

 

Message 14 of 21

@bryan_herronH8R6A What would you like the lisp to do? Maybe I'll give it a shot 🙂

...and fix the kiss export issues.
Message 15 of 21
markhubrich
in reply to: markhubrich

Something I wanted to try for a while...

 

Shared chat with Steely McFeely (chatbot I created) 

...and fix the kiss export issues.
Message 16 of 21
Julio_Soto
in reply to: markhubrich

To do anything complicated with Chat GPT (lisp or VBA) I find I have to ask it to do small things, and then I build up from there. I check the code at every step. Then I piece together what works.  I have yet been able to get anything working from chat GPT with a single prompt.

Message 17 of 21

Here's my latest attempt. Autodesk completely ignores all the pipe network entities when you dynamically hatch the cut or fill in the profile views and hatches right over them when they are in the hatched area. These items should not be hatched through. The goal with this one was to keep the hatch out of the pipe network entities. Ultimately this would be a sysvar instead of a command.

 

ProPipeHatch - 0 being the default, 1 eliminating the hatch inside the pipe network entities, but I suppose if Autodesk would let us select the pipe networks along with the surfaces when we are designating the cut/fill hatching, that would be just as good.

Message 18 of 21
bigcarl5000kg
in reply to: markhubrich

Hi @markhubrich,

 

what did you end up using for your task and with what success?

+++ impossible immediately and miracles within 3 days +++
+++ the only constant is the change +++ stay tuned for more +++
+++ since 03/2023 is Advance Steel in maintenance mode, no further development +++
Message 19 of 21
Julio_Soto
in reply to: bigcarl5000kg

Well here's one. I just wanted a lisp that would chang hatch pattern of all hatches based on user input. This is how the chat went

https://chatgpt.com/share/a3babd7b-46d0-4580-86ae-fb03592f9fd4

 

I had to correct some of the vlax property names as the ones suggested did not exist

Message 20 of 21
markhubrich
in reply to: bigcarl5000kg

Hey @bigcarl5000kg 

I literally just attempted the "place beams by layer" thing this morning. So far it can find all lines that belong to W_12X26 and place a beam along them. I will push this further, but not today. I want to have it populate a line model based on what the layer names are. It will take trial and error but it just might work.

 

Other things in the past, like toggle my units between 4 decimal places and arch 1/16" is very handy. That's about as deep as I went with it for AS. It knows the Python in Grasshopper for Rhino very well. I am generating files in Rhino that I import into AS, but I manually put the beams in.  

...and fix the kiss export issues.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report