Jump to content

Picking the rest of points automatically


Tharwat

Recommended Posts

Hello everyone.

 

(setq points (getint"\n Nos. of X Points: ") ;; <--- any number of points
     Dist (getint"\nLength of Distance: ");; <--- any length
     start (getpoint"\nSpecify the start point:")
     )

(setq pt1........
 pt2..........
  pt3........... and so on

How to create the following points of start point automatically according

to the numbers of points .....?????

 

Many Thanks

 

Tharwat

Link to comment
Share on other sites

In AutoLISP you can create variables at run-time:

 

(setq theIndex 1)
(repeat points
(set (read (strcat "pt" (itoa theIndex))) (getpoint (strcat "\nIndicate point " (itoa theIndex) ": ")))
(setq theIndex (1+ theIndex))
)

 

Regards,

Link to comment
Share on other sites

I'd put them in a list. If you define variables for each point, you'll have a fun time trying to access each.

 

 

eg.

(defun test (/ num dist lst pt)
 (initget 6)
 (if (and (setq num (getint "\nSpecify number of X points: "))
          (not (initget 6))
          (setq dist (getdist "\nSpecify distance: "))
          (car (setq lst (list (getpoint "\nSpecify first point: "))))
     )
   (progn
     (while (> num (length lst))
       (if (setq pt (getpoint
                      (car lst)
                      (strcat "\n"
                              (itoa (- num (length lst)))
                              " point(s) left.\nSpecify next point: "
                      )
                    )
           )
         (grdraw (cadr (setq lst (cons pt lst))) pt 3 1)
       )
     )
     (redraw)
     (reverse lst)
   )
 )
)

Link to comment
Share on other sites

Thanks a lot msasu

 

But I try it with the following code ... and it gives me an error to fixnump ???

(defun c:qq (/ theindex points)
(setq theIndex (getint"\n Nos. of X Points: "))
(repeat points
(set (read (strcat "pt" (itoa theIndex)))
     (getpoint (strcat "\nIndicate point " (itoa theIndex) ": ")))
(setq theIndex (1+ theIndex))
))

 

Any complete example please ?

 

Faithful

Tharwat

Link to comment
Share on other sites

The code should look like:

 

(defun c:qq (/ theindex points)
[color=red](setq points (getint"\n Nos. of X Points: "))[/color]
[color=red](setq theIndex 1)[/color]

(repeat points
 (set (read (strcat "pt" (itoa theIndex)))
       (getpoint (strcat "\nIndicate point " (itoa theIndex) ": ")))
 (setq theIndex (1+ theIndex))
)

[color=red](princ)[/color]
)

 

Regards,

Link to comment
Share on other sites

And for sure the method suggested by @alanjt is much user-friendly (I mean programmer-friendly)...

 

Regards,

Thanks msasu.

Link to comment
Share on other sites

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