Results 1 to 5 of 5

Thread: create a loop

  1. #1
    Member
    Join Date
    2002-10
    Posts
    4
    Login to Give a bone
    0

    Default create a loop

    Im pretty green at lisp and I am trying to do something I have never done and have wasted 2 days trying to figure it out.
    the routine I am putting together should label the x axis along the bottom of a rectangle and label the y axis along the left side (eventually around the whole rectanagle). I got it to place the the text and tick at the first locations but am unable to figure out how to get it to count and continue to label.
    I need to create a loop that will add a users entered value "gs" and repeat the code as long as "resultx" is less then p2x and "resulty" is less than "p2y" but controlled separately, so it will run the x direction until condition is met then run in the y direction.

    here is the code I have so far.
    thanks for any help.

    Code:
    (defun C:STPLN (/ p1 p2); [localize more variables?]
    ;establish the start points for grid
      (setq
        p1 (getpoint "\nPick bottom left corner:...")   ;First point
        p1x (car p1)                                    ;X value of bottom left corner
        p1y (cadr p1)                                   ;Y value of bottom left corner
        p2 (getpoint "\nPick top right corner:...")     ;Second point
        p2x (car p1)                                    ;X value of top right corner
        p2y (cadr p1)                                   ;Y value of top right corner
        gs (getint "\nWhat is the grid spacing? ")      ;user enters grid spacing
    
        remainderx (rem p1x gs)                         ; remainder of dividing value by roundfactor
        multiplierx
          (if (zerop remainderx)                        ;if it divides exactly
            (fix (/ p1x gs))                            ;then; keep that quotient
            (1+ (fix (/ p1x gs)))                       ;else, add 1 to rounded-down quotient
          )                                             ;end if & multiplier
        resultx (* gs multiplierx)
        xx (list resultx p1y)                           ;create coord for start point of grid in the x
        	
        remaindery (rem p1y gs)                         ;remainder of dividing value by roundfactor
        multipliery
          (if (zerop remaindery)                        ;if it divides exactly
            (fix (/ p1y gs))                            ;then; keep that quotient
            (1+ (fix (/ p1y gs)))                       ;else, add 1 to rounded-down quotient
          )                                             ;end if & multiplier
        resulty (* gs multipliery)
        yy (list p1x resulty)                           ;create coord for start point of grid in the y
      )                                                 ;end setq
    
    ;;;;begin text and tick location.
    
    (setq t1 "Text Height: <default = ")
    (setq t2 " >: ")
    (setq t3 (getvar "textsize"))
    (setq ht (getreal (strcat t1 (rtos t3 2 2) t2)))
    (if (= ht nil)
    (setq ht t3)
    )
    (setvar "textsize" ht)
    (setq a "N. ")
    (setq b "E. ")
    (setq n (rtos (cadr yy) 2 0))
    (setq e (rtos (car xx) 2 0))
    (setq coord (strcat a n))
    (setq coord2 (strcat b e))
    (setq
      x1 (car xx)                ;gets x coord of starting location in the x
      y1 (cadr xx)               ;gets y coord of starting location in the x
      xx1 (car yy)               ;gets x coord of starting location in the y
      yy1 (cadr yy)              ;gets y coord of starting location in the y
      ht (getvar "TEXTSIZE")
      x2 (- x1 (* ht 0.0))       ;offset in the x
      xx2 (+ xx1 (* ht 1.75))    ;offset in the y
      y2 (- y1 (* ht -1.75))     ;offset in the x
      yy2 (- yy1 (* ht 0.00))    ;offset in the y
       pt2 (list x2 y2)          ;placemnet location for text in the x
       ppt2 (list xx2 yy2)       ;placemnet location for text in the y
       x2 (- x1 (* ht -0.00))    ;starting location of tick in the x
       xx2 (+ xx1 (* ht 1.00))   ;starting location of tick in the y
       y2 (+ y1 (* ht  1.00))    ;ending location of tick in the x
       yy2 (+ yy1 (* ht  0.00))  ;ending location of tick in the x
       p2 (list x2 y2)           ;placemnet location for tick in the x
       pp2 (list xx2 yy2)        ;placemnet location for tick in the y
    )
    ;;;end text and tick location
    ;;;begin plan tick location
    
    (setq
       tickx1 (- resulty (/ t3 2))    ;start verticle tick line x
       tickx2 (+ resulty (/ t3 2))    ;end verticle tick line in the x
       tickbase1 (list resultx tickx1)
       tickbase2 (list resultx tickx2)
       ticky1 (- resultx (/ t3 2))    ;start horizontal tick line y
       ticky2 (+ resultx (/ t3 2))    ;end horizontal tick line in the y
       tickbase3 (list ticky1 resulty)
       tickbase4 (list ticky2 resulty)
    )
    ;;;end plan tick location
    
      (command "text" "mC" pt2 "" "0" coord2 )  ;place starting text in the x
      (command "pline" xx p2 "")                ;place starting tick in the x
      (command "text" "mC" ppt2 "" "90" coord ) ;place starting text in the y
      (command "pline" yy pp2 "")               ;place starting tick in the y
      (command "pline" tickbase1 tickbase2 "")  ;draw starting verticle tick line
      (command "pline" tickbase3 tickbase4 "")  ;draw starting horizontal tick line
    
    
    ;(while
    ;    (or
    ;        (< reslutx p2x)
    ;        (< resluty p2y)
    ;    )
        (if (< reslutx p2x)
            (progn
         (setq resultx (list (+ gs (car xx) p1y)))
            (command "text" "mC" pt2 "" "0" coord2 )  ;place starting text in the x
            (command "pline" xx p2 "")                ;place starting tick in the x
            (command "pline" tickbase1 tickbase2 "")  ;draw starting verticle tick line
            )
        )
    ;    (if (< resluty p2y)
    ;        (progn
    ;     (setq resulty (list p1x (+ gs resulty))
    ;       (command "pline" yy pp2 "")               ;place starting tick in the y
    ;       (command "pline" tickbase1 tickbase2 "")  ;draw starting verticle tick line
    ;       (command "pline" tickbase3 tickbase4 "")  ;draw starting horizontal tick line
    ;        )
    ;    )
    ;)
    
    
    )
    (princ)
    Last edited by buckingmule; 2009-06-03 at 03:17 PM. Reason: Added code tags

  2. #2
    Certifiable AUGI Addict
    Join Date
    2015-11
    Location
    Jo'burg SA
    Posts
    4,512
    Login to Give a bone
    0

    Default Re: create a loop

    I'd advise doing it in 2 loops, 1st doing the X then the Y. E.g.
    Code:
    (while (< reslutx p2x)
      (setq resultx (list (+ gs (car xx) p1y)))
      (command "text" "mC" pt2 "" "0" coord2) ;place starting text in the x
      (command "pline" xx p2 "") ;place starting tick in the x
      (command "pline" tickbase1 tickbase2 "") ;draw starting verticle tick line
    ) ;_ end of if
    Then perform the same type of loop for the Y.

  3. #3
    Member
    Join Date
    2002-10
    Posts
    4
    Login to Give a bone
    0

    Unhappy Re: create a loop

    when I do this the routine get stuck in an endless loop placing the text and tick in the same location instead of adding the user defined number "gs".
    What have I not done to get this to work right.

    thanks for the help

  4. #4
    Member
    Join Date
    2002-10
    Posts
    4
    Login to Give a bone
    0

    Default Re: create a loop

    here is a sample of what I am trying to accomplish.
    Attached Files Attached Files
    Last edited by buckingmule; 2009-06-03 at 03:16 PM.

  5. #5
    I could stop if I wanted to
    Join Date
    2002-08
    Posts
    232
    Login to Give a bone
    0

    Default Re: create a loop

    Can help you?
    Code:
    (defun writ (ta tb det_or / dptx m1 m2 pd ecr ang_or)
    	(setq dptx (* (fix (/ (- (car lmtb) pas) pas)) pas))
    	(while (< dptx (car lmth))
    		(setq m1 (cons dptx (cons (cadr lmtb) '(0.0)))
    		      m2 (cons dptx (cons (cadr lmth) '(0.0)))
    		)
    		(if (zerop det_or)
    			(setq m1 (cons (cadr m1) (cons (car m1) '(0.0)))
    			      m2 (cons (cadr m2) (cons (car m2) '(0.0)))
    			)
    		)
    		(setq pd (inters ta tb m1 m2))
    		(if (/= pd ())
    			(progn
    				(if (zerop det_or)
    					(setq ecr (rtos (cadr pd) 2 0) ang_or (angle ta tb) incl (angtos 0))
    					(setq ecr (rtos (car pd) 2 0) ang_or (rem (+ (/ pi 2) (angle ta tb)) (* 2 pi)) incl (angtos (/ (* 3 pi) 2) (getvar "aunits") 5))
    				)
    				(cond
    					((equal (rem ang_or pi) ang_or)
    						(setq ecr (strcat "  " ecr))
    						(command "_.text" "_justify" "_mleft" "_none" pd htx incl ecr)
    					)
    					(T
    						(setq ecr (strcat ecr "  "))
    						(command "_.text" "_justify" "_mright" "_none" pd htx incl ecr)
    					)
    				)
    			)
    		)
    		(setq dptx (+ dptx pas))
    	)
    )
    ((lambda ( / )
    	(while
    		(null
    			(setq js
    				(ssget "_+.:E:S"
    					(list
    						'(0 . "*POLYLINE")
    						(cons 67 (if (eq (getvar "CVPORT") 1) 1 0))
    						(cons 410 (getvar "CTAB"))
    					)
    				)
    			)
    		)
    	)
    	(initget 7)
    	(setq pas (getint "\nInterval :"))
    	(initget 7)
    	(setq htx (getdist "\nText Heigth: "))
    	(setq ent (entget (ssname js 0)))
    	(cond
    		((= (cdr (assoc 0 ent)) "POLYLINE")
    			(setq vx (entget (entnext (cdar ent))) pt_lst '())
    			(while (= (cdr (assoc 0 vx)) "VERTEX")
    				(setq pt_lst (cons (cdr (assoc 10 vx)) pt_lst))
    				(setq vx (entget (entnext (cdar vx))))
    			)
    			(setq pt_lst (reverse pt_lst))
    		)
    		((= (cdr (assoc 0 ent)) "LWPOLYLINE")
    			(setq nbs (cdr (assoc 90 ent)) cnt 0 pt_lst '())
    			(while (< cnt nbs)
    				(if (= (caar ent) 10)
    					(setq pt_lst (cons (cdar ent) pt_lst) cnt (+ cnt 1))
    				)
    				(setq ent (cdr ent))
    			)
    			(setq pt_lst (reverse pt_lst))
    		)
    	)
    	(setq
    		lmtb
    			(list
    				(apply 'min (mapcar 'car pt_lst))
    				(apply 'min (mapcar 'cadr pt_lst))
    			)
    		lmth
    			(list
    				(apply 'max (mapcar 'car pt_lst))
    				(apply 'max (mapcar 'cadr pt_lst))
    			)
    		i_c -1
    	)
    	(princ "\nWriting X !")
    	(repeat (length pt_lst)
    		(writ (nth (setq i_c (1+ i_c)) pt_lst) (nth (rem (1+ i_c) (length pt_lst)) pt_lst) (/ pi 2))
    	)
    	(princ "\nWriting Y !")
    	(setq
    		lmtb (cons (cadr lmtb) (list (car lmtb)))
    		lmth (cons (cadr lmth) (list (car lmth)))
    		i_c -1
    	)
    	(repeat (length pt_lst)
    		(writ (nth (setq i_c (1+ i_c)) pt_lst) (nth (rem (1+ i_c) (length pt_lst)) pt_lst) 0.0)
    	)
    ))
    Last edited by Bruno.Valsecchi; 2009-06-03 at 03:27 PM.

Similar Threads

  1. 2012: How to create a hydronic primary loop
    By ccenergy in forum Revit MEP - General
    Replies: 1
    Last Post: 2013-01-26, 06:46 PM
  2. End of while loop...
    By marko_ribar in forum AutoLISP
    Replies: 11
    Last Post: 2010-10-20, 07:55 PM
  3. how do i loop this?
    By mgonzales.224492 in forum AutoLISP
    Replies: 2
    Last Post: 2009-07-31, 06:41 PM
  4. Block Insert Array (Loop within a Loop)
    By wpeacock in forum VBA/COM Interop
    Replies: 2
    Last Post: 2005-06-14, 04:24 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •