Jump to content

Custom array ?


chavlji

Recommended Posts

Hello

Does anyone has lisp procedure for array where i should only select

1. number of itterations

2. start point

3. end point

And it would distribute selected items from start point to end point with n/distance spacing.

 

Autocad's default array only accepts number of itterations and spacing between them...

Link to comment
Share on other sites

Following example SHOULD work, but has some strange error...

If I select some random point (that is not OSNAPed) it works superb.

But try select second point as INTERSECTION point of some 3rd line and OTRACK line, it does not work right. Every items are placed correct except last one. This one is always placed on the midpoint of the line!!!

 

Why it that so?

 

Please it is driving me crazy...

 

; Jan Spacing Tool

(prompt "\n ca: Jan Spacing tool")
(defun c:ST ()
 (setvar "cmdecho" 0)
 
 (setq OBJ (ssget))
 (if (or (= N nil) (< N 2)) (setq N 2))
 
 (setq N (getint "\nItterations <2>:"))
 
 (setq T1 (getpoint "\nStart point "))
 (setq T2 (getpoint "\nEnd point\n"))
 
 (setq X (car T1))
 (setq Y (cadr T1))
 (setq X2 (car T2))
 (setq Y2 (cadr T2))
 ;(PRINC (- Y2 Y))
 ;(foreach msg (list "\n" X "," Y "") (princ msg))
 ;(foreach msg (list "\n" X2 "," Y2 "") (princ msg))
 
 (initget 1 "Div Mult")
 (setq Tip (getkword "\nDistance < Div, Mult > "))

 (initget 1 "Middle Border")
 (setq Center (getkword "\nEnd point is < Middle, Border > "))
 ;(PRINC (- Y2 Y))
 (if (= Center "Border")
     (progn
   (setq TBorder (getpoint "\nIzberi robno tocko "))
   (setq X2 (- X2 (- (car TBorder) X) ) )
   (setq Y2 (- Y2 (- (cadr TBorder) Y) ) )
     )
   )
 
 (PRINC (- Y2 Y))
 (if (= Tip "Div")
     (progn
   (setq DX (/ (- X2 X) (- N 1) ) )
       (setq DY (/ (- Y2 Y) (- N 1) ) )
     )
     (progn
       (setq DX (- X2 X) )
       (setq DY (- Y2 Y) )
     )
   )
 
 (command "_CopyBase" T1 OBJ "")
 (setq i 1)
 (while (< i N)
       (setq TI (list (+ X (* DX i)) (+ Y (* DY i)) ) )
   (command "_PasteClip" TI)
       (PRINC (cadr TI))
       (setq i (+ i 1))
   )
 (foreach msg (list "\nItterated " (- N 1 ) "x on distance DX=" DX ", DY=" DY) (princ msg))
)

Link to comment
Share on other sites

Then the only other thing I would advise is that you save the previous osmode setting before changing it to 0 and restore it when the program is terminated.

Link to comment
Share on other sites

Something like this:

 

(setq olderr *error* *error errtrap)
(defun errtrap    (msg)
 (if oldvars (mapcar 'setvar vlst oldvars))
 (setq *error* olderr)
 (princ))

(setq vlst    (list "CMDECHO" "CLAYER" "OSMODE" "DIMSCALE") ; list altered variables here.
     oldvars (mapcar 'getvar vlst))

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