Anuncios

The Autodesk Community Forums has a new look. Read more about what's changed on the Community Announcements board.

Ask for distance and store it and add distance in text with a certain height - Modify LISP

cool.stuff
Advocate

Ask for distance and store it and add distance in text with a certain height - Modify LISP

cool.stuff
Advocate
Advocate

Hi!! :cara_con_una_leve_sonrisa:


New year community!! :cara_con_una_leve_sonrisa:


I've found this lisp:


;Use this command to measure the distance between two points while applying a Combined Scale Factor
;Be sure to copy this lisp to your job folder, and set your CSF as required. Do not change CSF outside of job folder.
;Ahmed F. 2017
(defun c:DM ()
(setq TD 0)
(setq x1 (getpoint "\nSelect First Point: "))
(setq x2 (getpoint x1 "\nSelect Second Point: "))
(prompt
(strcat
(rtos (distance x1 x2))
(rtos (setq TD (+ TD (/(distance x1 x2) 0.12345))))
)
)
(prompt (strcat "\nTotal Distance = " (rtos TD)))
(princ)
)


It measures a distance and divide it by the factor 0.12345.


I would like to know if anyone could help me and change the lisp to do the following things please:
- Asks for the factor and store it in a variable. Later, if the user wants, if could set the factor again (like the fillet radius);
- Add a text with the TD value, which would be placed in the 2nd point (it would be possible to define the text height, as the factor?);


Many many thanks!!! :cara_con_una_leve_sonrisa:

0 Me gusta
Responder
Soluciones aceptadas (2)
890 Vistas
7 Respuestas
Respuestas (7)

ВeekeeCZ
Consultant
Consultant

Not really sure why your code works with "total distance"... this not make sense to me.

But try this code?

 

(defun c:TextDist (/ done p1 p2)
  
  (or *TD-Scale* (setq *TD-Scale* 1.))
  (or *TD-Height* (setq *TD-Height* 1.))
  
  (while (progn
	   (setq done nil)
	   (while (not done)
	     (princ (strcat "Current setting:  Scale " (rtos *TD-Scale*) "  Height " (rtos *TD-Height*)))
	     (initget "Scale Height")
	     (setq p1 (getpoint "\nSpecify a point or [Scale/Height]: "))
	     
	     (cond ((= p1 "Scale") 	(initget 3) (setq *TD-Scale* (getdist "\nScale factor: ")))
		   ((= p1 "Height") 	(initget 3) (setq *TD-Scale* (getdist "\nText height: ")))
		   ((setq done T))))
	   p1)
    
    (if (setq p2 (getpoint p1 "\nSecond point: "))
      (entmake (list (cons 0 "TEXT")
		     (cons 10 (trans p2 1 0))
		     (cons 7 (getvar 'textstyle))
		     (cons 40 *TD-Height*)
		     (cons 1 (rtos (/ (distance p1 p2) *TD-Scale*)))
		     (cons 50 (angle '(0 0 0) (getvar 'ucsxdir)))
		     ))))
  (princ)
  )

 

cool.stuff
Advocate
Advocate

Works like a charm!!! :cara_con_una_leve_sonrisa:

 

Many many thanks!! :cara_con_una_leve_sonrisa:

 

 

 

(please change this line to make the code run clear :cara_con_una_leve_sonrisa:

 

		   ((= p1 "Height") 	(initget 3) (setq *TD-Height* (getdist "\nText height: "))

 There is "TD-Scale" and it should be "TD-Height"!!!  )

 

Many thanks!! :cara_con_una_leve_sonrisa:

ВeekeeCZ
Consultant
Consultant
Solución aceptada

Ouch, thanks. Unfortunately, 30 min edit time has expired.

 

(defun c:TextDist (/ done p1 p2)
  
  (or *TD-Scale* (setq *TD-Scale* 1.))
  (or *TD-Height* (setq *TD-Height* 1.))
  
  (while (progn
	   (setq done nil)
	   (while (not done)
	     (princ (strcat "Current setting:  Scale " (rtos *TD-Scale*) "  Height " (rtos *TD-Height*)))
	     (initget "Scale Height")
	     (setq p1 (getpoint "\nSpecify a point or [Scale/Height]: "))
	     
	     (cond ((= p1 "Scale") 	(initget 3) (setq *TD-Scale* (getdist "\nScale factor: ")))
		   ((= p1 "Height") 	(initget 3) (setq *TD-Height* (getdist "\nText height: ")))
		   ((setq done T))))
	   p1)
    
    (if (setq p2 (getpoint p1 "\nSecond point: "))
      (entmake (list (cons 0 "TEXT")
		     (cons 10 (trans p2 1 0))
		     (cons 7 (getvar 'textstyle))
		     (cons 40 *TD-Height*)
		     (cons 1 (rtos (/ (distance p1 p2) *TD-Scale*)))
		     (cons 50 (angle '(0 0 0) (getvar 'ucsxdir)))
		     ))))
  (princ)
  )

 

cool.stuff
Advocate
Advocate

Can I ask you a little modification?

 

It is possible that this code would offset a line/polyline? For instance, I would define a factor, just like the code you've written, and then the lisp would ask the real distance to offset. Then, the offset woudl be given by the distance times the factor, please?

 

Many many thanks and sorry to push my luck..

0 Me gusta

ВeekeeCZ
Consultant
Consultant
Solución aceptada

Well, a bit confused by your saying "modification"... As I understand your task, you basically want another function that has nothing to do with the previous task but the scale factor. If I am right, try the following code. If not, elaborate on the issue more.

 

(defun c:FOffset (/ done flg osd)
  
  (or *TD-Scale* (setq *TD-Scale* 1.)) ;; set defaul value
  (or *FO-Dist*  (setq *FO-Dist* 1.))
  (setq osd (getvar 'offsetdist))
  
  (while (not done)
    (princ (strcat "Current settings:  Scale " (rtos *TD-Scale*)))
    (initget "Scale Through Erase Layer")
    (setq flg (getdist (strcat "\nSpecify offset distance or [Scale/Through/Erase/Layer] <" (rtos *FO-Dist*) ">: ")))
    (if (= flg "Scale")
      (progn
	(initget 3) (setq *TD-Scale* (getdist "\nScale factor: ")))
      (setq done T)))

  (if (numberp flg)
    (command "_.offset" (* (setq *FO-Dist* flg) *TD-Scale*))
    (progn
      (setvar 'offsetdist (* *FO-Dist* *TD-Scale*))
      (command "_.offset" flg)))
  (while (> (getvar 'cmdactive) 0) (command pause))
  (setvar 'offsetdist osd)
  (princ)
  )

 

Notes:

- the scale factor would be the same for both routines. *TD-Scale* (rename yourself if not)

- only from the first prompt Specify offset distance or [Scale/Through/Erase/Layer] you can specify a Scale. If you pick any other option it will turn into the regular offset command (with distance already scaled). That means, if pick eg. "Layer" ... then after layer setting you will get back to "Specify offset distance or [Through/Erase/Layer] <20.000>:" prompt, now distance is already scaled (both set and prompted).

Good luck.

 

cool.stuff
Advocate
Advocate

Many many thanks!! :cara_con_una_leve_sonrisa:

 

I'll test it later, but sounds great!! :cara_con_una_leve_sonrisa:

 

Many thanks!

0 Me gusta

cool.stuff
Advocate
Advocate

Many many thanks!!! :cara_con_una_leve_sonrisa:

 

Works perfectly!!! :cara_con_una_leve_sonrisa:

0 Me gusta