Jump to content

Recommended Posts

Posted

My English is not so good, but i will try my best.

I've created a LISP for creating a square with desired area. So if you want a 100sqm, you can just a pick a point and type 100 to make a 10 by 10 square. 

 

(defun c:ats(/)
  (setq a1 (getpoint "\nStart point: "))
  (setq ar (getreal "\nSquare area: "))
  (setq artd (sqrt ar))
  (setq a2 (polar a1 (angtof "0" 0) artd))
  (setq a3 (polar a2 (angtof "90" 0) artd))
  (setq a4 (polar a3 (angtof "180" 0) artd))
  (setq a5 (polar a4 (angtof "270" 0) artd))
  (command "pline" a1 a2 a3 a4 a5 a1 "")
)

Here's the code I've written.

 

It works fine, but it doesn't give me the same result when I change zoom levels. Although It works on less magnified levels, in wider views, it becomes a single line or in other cases, a triangle.

It's my first time writing any kind of code and I've got no one around me that knows how to code 😕 Hope you guys could help me.

 

PS. I just started learning LISP like 8 hours ago but I would appreciate if any of you computer genies could help these problems as well.

My final intention was to create a lisp that has following functions:

1. Makes a square based on starting point and its area.

2. Continuously make different squares that starts from base square area, increasing its size by fixed increment value.

3. All Squares made should be away from each other by equal distance.

4. All Squares made have its area as a text in the center of itself. 

 

It would be great if you could edit my LISP or just point me in the right direction.

 

Thank you.

Posted

This should fix it

 

(defun c:ats( / a1 a2 a3 a4 oldsnap)
(setq oldsnap (getvar 'osmode))
(setvar 'osmode 0)
  (setq a1 (getpoint "\nStart point: "))
  (setq ar (getreal "\nSquare area: "))
  (setq artd (sqrt ar))
  (setq a2 (polar a1 (angtof "0" 0) artd))
  (setq a3 (polar a2 (angtof "90" 0) artd))
  (setq a4 (polar a3 (angtof "180" 0) artd))
  (setq a5 (polar a4 (angtof "270" 0) artd))
  (command "pline" a1 a2 a3 a4 a5 a1 "")
(setvar 'osmode oldsnap)
(princ)
)

 

Can also use RECTANG command  

 

(setq a1 (getpoint "\nStart point: "))
(setq ar (sqrt (getreal "\nSquare area: ")))
(setq a2  (mapcar '+ a1 (list ar ar 0.0) ))
(command "rectang" a1 a2)

 

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