how to create and use variables in autoCAD

how to create and use variables in autoCAD

joseph_filbert1
New Member New Member
202 Views
9 Replies
Message 1 of 10

how to create and use variables in autoCAD

joseph_filbert1
New Member
New Member

I cannot seem to figure out how to "use" variables in autoCAD. I am very new to the software, but I have some experience with other CAD software (Onshape). Reading through the help file, I found that I can define a user parameter using the parameter manager. However, I'm not sure how to "use" this parameter. For example, I want to create a UCS which is offset from the WCS by some calculated value <0.5*VAR1+(9*0.010+3*0.005)*25.4,0,0>

 

1) Can you use formulas when creating stuff this way?

2) Is there a way to create the variable on the fly?

0 Likes
203 Views
9 Replies
Replies (9)
Message 2 of 10

CodeDing
Advisor
Advisor

@joseph_filbert1 wrote:

1) Can you use formulas when creating stuff this way?


There are ways to dynamically create the position of the UCS. Most notably would probably a Lisp command/function. I do not know of a way to dynamically adjust the UCS position via parameters though (AutoCAD "parameters" are unique entities within the environment, compared to "parameters" often used within programming languages).

 


@joseph_filbert1 wrote:

2) Is there a way to create the variable on the fly?


How do you visualize creating / updating this variable "on-the-fly"? By running a command? Pushing a button? A popup box? Calculated from something in the DWG?

 

Best,

~DD

0 Likes
Message 3 of 10

joseph_filbert1
New Member
New Member

I am unfamiliar with LISP commands, this seems a bit heavy to allow for a variable to be used when setting the origin of a UCS. I would like to be "lazy" and have the required value calculated by autoCAD instead of me. Am I approaching this incorrectly?

 

In other CAD packages if you reference an undefined variable you are given a prompt to define the variable at that moment. Instead of creating the variable ahead of time through the parameter manager.

0 Likes
Message 4 of 10

autoid374ceb4990
Collaborator
Collaborator

So in your example if VAR1 is 10.0 you want the UCS set to 7.667,0,0 ? 

Do any of the other numbers in your equation change or just VAR1?

0 Likes
Message 5 of 10

joseph_filbert1
New Member
New Member

In this example, just VAR1 would be some predefined value. This would apply to other objects that I want to create. Say the starting point of a line, is it possible to use a formula which references a user parameter. Or should I create a random line then impose a formula based geometric constraint afterwards?

0 Likes
Message 6 of 10

DGCSCAD
Collaborator
Collaborator

Dive into "The Basics in a Nutshell" to get a better understanding of how LISP works: https://www.afralisp.net/

 

 

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

paullimapa
Mentor
Mentor

Not sure if what you want can be done but to give you an idea as to what I know here are the steps to get the x, y, z coordinates of the start point of a LINE

You can enter the following at the command prompt:

1) Select the LINE object:

(setq line-entity nil)(while (not line-entity) (princ "\nSelect a Line...") (setq line-entity (ssget "_+.:E:S" '((0 . "LINE")))))

line-entity is the variable that represents the selection set

2) Get the starting point x, y, z coordinates:

(if line-entity (progn (setq line-entity (ssname line-entity 0) ptx (getpropertyvalue line-entity "StartPoint/X") pty (getpropertyvalue line-entity "StartPoint/Y") ptz (getpropertyvalue line-entity "StartPoint/Z"))))

line-entity is the variable that represents the LINE entity which is the first item in the selection set

ptx is the variable that represents the LINE's starting X coordinate

pty is the variable that represents the LINE's starting Y coordinate

ptz is the variable that represents the LINE's starting Z coordinate

3) To use ptx variable like VAR1 for the new X coordinate of the UCS origin location along with pty as the Y coordinate and ptz as the Z coordinate:

(command "_.UCS" "_ZA" (list (+ (* 0.5 ptx) (* (+ (* 9 0.010) (* 3 0.005) 25.4))) pty ptz) "")

 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 8 of 10

Sea-Haven
Mentor
Mentor

Sounds to me that you need to study up a little bit about the UCS command. They can be set using lisp.

 

If you have an object a valid command sequence is  UCS OB pick object say a line at end. You can then run UCS again and set say the slope angle in say the X plane.

SeaHaven_0-1758761141975.png

Another is UCS 3. Which sets 3 points for the UCS. There is multiple ways to set a UCS and you can save current UCS by just that UCS S. Use UCS R to get it back.

 

Dont forget to type PLAN after setting a UCS.

Use UCS W to reset back to world then type PLAN.

 

 

 

0 Likes
Message 9 of 10

leeminardi
Mentor
Mentor

One option is to use quickcalc. Set a constant then use it in an expression.  For example,  in the following I've defines a constant named  var1 and set it to 10.

When typing the expression for a point star with a square bracket. The "10" you see in the expression below was entered by double clicking var1 uder New Category.  

 

leeminardi_0-1758765368249.png

After hitting Enter you get the following:

leeminardi_1-1758765498599.png

You can copy/paste the result of the calculation;  7.667,0 into the prompt line.

 

 

lee.minardi
0 Likes
Message 10 of 10

tramber
Advisor
Advisor

By the way, @leeminardi , this is also possible with the 'CAL function 😁

Old and fun (because you can interact with osnaps) but sometimes very practical, it can store variables through lisp

https://help.autodesk.com/view/ACD/2022/ENU/?guid=GUID-B29F2EF7-12C8-423C-91F5-3852E6AF1514

To explore a little...


EESignature

0 Likes