Recalling getpoint / getxxx after changing a variable

Recalling getpoint / getxxx after changing a variable

Anonymous
Not applicable
939 Views
2 Replies
Message 1 of 3

Recalling getpoint / getxxx after changing a variable

Anonymous
Not applicable

Hello to all,

 

I'm facing a small problem of how to go about recalling a Getxxx function once a user definable variable has been changed.

What i'd like is the first point / prompt to be called again after the scale value has been changed by the user but I'm not entirely sure how to go about this.

 

My "SAMPLE" code below (which only partially works).

(NOTE: this is just me playing around with "initget" as I'm still a novice with AutoLISP).

 

(defun c:testfunc ( / *error* *BG:scale scale ans pt1 pt6 )

	(defun *error* ( msg )
		(if (not (wcmatch (strcase msg t) "*break,*cancel*,*exit*"))
			(princ (strcat "\nError: " msg))
		)
		(princ)
	)

	;;	Set up global variable & default value.
	(if	(null *BG:scale)
		(setq *BG:scale 100.0)
	)

	;;	Print current scale at command line before specifying first point.
	(princ (strcat "\nScale = " (rtos *BG:scale)))
	
	(initget "Scale")
	(setq ans (getpoint "\nSpecify first point or [Scale]: "))
	(cond
		(	(= 'list (type ans))
			(setq pt1 ans)
			(setq pt6 (getpoint "\nSpecify second point: "))
		)
		(	(= "Scale" ans)
			(setq scale (getdist (strcat "\nSpecify new scale factor <" (rtos *BG:scale) ">: ")))
			(setq *BG:scale scale)	;;	Then: assign new value.
			(setq scale *BG:scale)	;;	Else: use default value.
			(setq pt6 (getpoint "\nSpecify second point: "))
		)
	)
	
	(entmakex
		(list
			(cons 000 "LINE")
			(cons 010 pt1)		;; First new point.
			(cons 011 pt6)		;; Second new point.
		)
	)
	(princ)
)

If the user chooses to change the scale in the code above, the second point is called after entering the scale value - not what I'm after. I'd like it to recall the first point again (showing the "scale" selection option again - much like an AutoCAD function). 

 

Any susggestions / comments would be welcome. If you do modify the code, please explain with comments whats going on, just for my understanding.

 

Thanks,

Bevan

 

0 Likes
940 Views
2 Replies
Replies (2)
Message 2 of 3

Anonymous
Not applicable

(defun c:testfunc ( / *error* *BG:scale scale ans pt1 pt6 )

 (defun *error* ( msg )
  (if (not (wcmatch (strcase msg t) "*break,*cancel*,*exit*"))
   (princ (strcat "\nError: " msg))
  )
  (princ)
 )

 ;; Set up global variable & default value.
 (if (null *BG:scale)
  (setq *BG:scale 100.0)
 )

 ;; Print current scale at command line before specifying first point.
 (princ (strcat "\nScale = " (rtos *BG:scale)))
 
 (initget "Scale")
 (setq ans (getpoint "\nSpecify first point or [Scale]: "))
 (cond
  ( (= 'list (type ans))
   (setq pt1 ans)
   (setq pt6 (getpoint pt1 "\nSpecify second point: "))
  )
  ( (= "Scale" ans)
   (setq scale (getdist (strcat "\nSpecify new scale factor <" (rtos *BG:scale) ">: ")))
   (setq *BG:scale scale) ;; Then: assign new value.
   (setq scale *BG:scale) ;; Else: use default value
   (initget "Scale")
   
   
   (setq pt1 (getpoint "\n Specify first point or [Scale]: "))
   
   
    (if (= pt1 "Scale")
     (progn
      (while (= pt1 "Scale")
       (progn
        (setq scale (getdist (strcat "\nSpecify new scale factor <" (rtos *BG:scale) ">: ")))
        (setq *BG:scale scale) ;; Then: assign new value.
        (setq scale *BG:scale) ;; Else: use default value
        (initget "Scale")
        
         
          (setq pt1 (getpoint "\n Specify first point or [Scale]: "))
        
       );progn
      );while
 
     );progn
    );if
   (setq pt6 (getpoint pt1 "\n Specify second point: "))
  )
 )
 
 (entmakex
  (list
   (cons 000 "LINE")
   (cons 010 pt1)  ;; First new point.
   (cons 011 pt6)  ;; Second new point.
  )
 )
 (princ)
)

 

 

 

 

I have used while function. It keep on asking the scale factor until the user select the first point.

 

 

 

It may help you.

 

STM

 

0 Likes
Message 3 of 3

ВeekeeCZ
Consultant
Consultant

I do not see a purpose of "Scale". What do you want to scale? What is the purpose of whole program? Insert lines of pre-defined length just by given direction? Or with scale?

 

btw since you have your 'global' variable between localized varibles, then it's not global anymore.

 

And yes, you need to use a loop. Usually

(while (not pt1)

...

)

 

If you 'playing around' (initget), just play little more. Try figure out:

 

(getpoint "\nSpecify first point or [Scale]: ")    ; prevent enter

(getpoint "\nSpecify first point or [Scale]: ")    ; cancel by hit enter

(getpoint "\nSpecify first point or [Scale] <Scale>: ")    ; scale by hit enter or by setting a keyword

(getpoint "\nSpecify first point or <scale>: ")    ; scale just by hit enter

(getpoint "\nSpecify first point or set scale: ")    ; direct setting of scale

0 Likes