autolisp points in a column

autolisp points in a column

Anonymous
Not applicable
1,022 Views
5 Replies
Message 1 of 6

autolisp points in a column

Anonymous
Not applicable

Here's the elvator pitch. I'm working on a LISP that will select a rectangular area, define points inside that area, open a dialog box that lets you add multiple blocks to a list, and then chronologically places the blocks on the points in the area. I think this will be useful for typical details. This is definitely a project I'm going to work on and off for a while as my reach is currently exceeding my grasp.

 

Currently I'm writing a function that will generate a list of points (p1, p2, p3, etc, quid pro quo...) until a certain point is reached. I've tried using the repeat function but doesn't seem to adjust the numbering (p1 to p2 to p3). Any advice? 

 

;;---FCN FOR POINTS---;;

REPEAT THIS ROW UNTIL IT MATCH THE NUMBER OF COLUMNS

(defun c:4 ()
(getpoint crn1 "n\First corner of rectangular area:")
crn2 (getcorner "n\Second corner of rectangular area:")
(getreal
c "\nEnter number of Columns:" ;SET DEFAULT 4
r "\nEnter number of Rows:" ;SET DEAULT 3
) ;end getreal
(princ)
) ;end function 4

;;---START---;;

(defun grdcol (crn1 crn2 c r /) ;functions sets up the point for the point grid column (grdcol). When inserting the blookcs the main function grabs from here.
(setq
r1 (+ r 1) ; makes it easier to divide amongst the rows. Maybe. Revisit.
r2 (* r1 2) ; distance between to points in column in y direction. Revisit

p1 (list (- (car crn2) (/ (car crn2) r1)) (- (cadr crn2) (/ (cadr crn2) r1))) ;everything in this column will have the same 'x'. 'y' changes.

;WANT TO DO THIS UNTIL y= (+ (cadr crn1) (/ (cadr crn2) r1))

0 Likes
1,023 Views
5 Replies
Replies (5)
Message 2 of 6

Anonymous
Not applicable

an example of what it would look like if I typed each point out, but I'm looking to make it generic.

0 Likes
Message 3 of 6

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

 

For just a start, your variables need to be set in a different way:

....

(defun c:4 ()
(setq

  crn1 (getpoint "n\First corner of rectangular area:")
  crn2 (getcorner crn1 "n\Second corner of rectangular area:")
  c (getint "\nEnter number of Columns:") ;SET DEFAULT 4
  r (getint "\nEnter number of Rows: ") ;SET DEAULT 3
) ;end getreal setq

....

Kent Cooper, AIA
0 Likes
Message 4 of 6

CodeDing
Advisor
Advisor

Even though OP may be a beginner, I still would Highly encourage ALL users to utilize the simple and effective (initget ...) function. It can save a LOT of heartache later in your program flow. We should always assume the user will take a program and put the most ridiculous values in where they shouldn't Lol. Just good practice I believe.

.....
(initget 1) (setq crn1 (getpoint "n\First corner of rectangular area: "))
(while (not (setq crn2 (getcorner crn1 "n\Second corner of rectangular area: ")))
  (prompt "\nMust select a point.")
);while
(setq c (cond
          ((progn (initget 6) (getint "\nEnter number of Columns <4>: ")))
          (4) ;SET DEFAULT 4
        );cond
);setq
(setq r (cond
          ((progn (initget 6) (getint "\nEnter number of Rows <3>: ")))
          (3) ;SET DEFAULT 3
        );cond
);setq
.....

Best,

~DD

0 Likes
Message 5 of 6

Sea-Haven
Mentor
Mentor

You could make 1 list using CONS (ptnum X Y) (Ptnum X Y ) .......... so just add 1 to ptnum and change your Y value.

 

Use this list to write the coulumns. (nth 0 (nth K lst)) is ptnum (nth 1 (nth K lst)) is X and so on.

0 Likes
Message 6 of 6

Sea-Haven
Mentor
Mentor

I use a library dcl for input but would repop open if fail with a test is greater than 4 etc.

 

Thanks Devitg will look into this as an option "Multi getvals.lsp"

 

(defun ah-ans () (setq ans (AH:getvalsm (list "Enter Values" "Cols max 4 " 5 4 "4" "Rows max 3 " 5 4 "3" ))))
(ah-ans)
(if (and (<= (atoi (nth 0 ans)) 4)(<= (atoi (nth 1 ans)) 3))
(princ)
(progn (Alert "maximum values exceeded ")
(ah-ans)
)
)

 

screenshot256.png

0 Likes