Edit lisp help

Edit lisp help

chan230984
Advocate Advocate
1,349 Views
14 Replies
Message 1 of 15

Edit lisp help

chan230984
Advocate
Advocate

Hi all,

I'm looking for some help editing a lisp

I have Lisp and I want some help.
After Command asks Next level Position, I want to select object of the all circle.
And get results as in the picture

thanks !

Untitled.png

 

(defun LM:UnFormat ( str mtx / _replace rx )
(defun _replace ( new old str )
(vlax-put-property rx 'pattern old)
(vlax-invoke rx 'replace str new)
)
(if (setq rx (vlax-get-or-create-object "VBScript.RegExp"))
(progn
(setq str
(vl-catch-all-apply
(function
(lambda ( )
(vlax-put-property rx 'global actrue)
(vlax-put-property rx 'multiline actrue)
(vlax-put-property rx 'ignorecase acfalse)
(foreach pair
'(
("\032" . "\\\\\\\\")
(" " . "\\\\P|\\n|\\t")
("$1" . "\\\\(\\\\[ACcFfHLlOopQTW])|\\\\[ACcFfHLlOopQTW][^\\\\;]*;|\\\\[ACcFfHLlOopQTW]")
("$1$2/$3" . "([^\\\\])\\\\S([^;]*)[/#\\^]([^;]*);")
("$1$2" . "\\\\(\\\\S)|[\\\\](})|}")
("$1" . "[\\\\]({)|{")
)
(setq str (_replace (car pair) (cdr pair) str))
)
(if mtx
(_replace "\\\\" "\032" (_replace "\\$1$2$3" "(\\\\[ACcFfHLlOoPpQSTW])|({)|(})" str))
(_replace "\\" "\032" str)
)
)
)
)
)
(vlax-release-object rx)
(if (null (vl-catch-all-error-p str))
str
)
)
)
)
(vl-load-com)
(defun c:chm ( / level p0 p1)
(setvar "cmdecho" 0)
(command "._undo" "_begin")
(if (and (setq level (atof (LM:UnFormat (cdr (assoc 1 (entget (car (entsel "\nFirst level: "))))) nil)))
(setq p1 (getpoint "\nSpecify first level position: "))
)
(progn
(setq p0 p1)
(command "._leader" p1 "@0.65<45" "" (strcat "EL=" (rtos level 2 3)) "")

(while (setq p1 (getpoint "\nSpecify next level position: "))
(command "._leader" p1 "@0.65<45" "" (strcat "EL=" (rtos (+ level (- (cadr p1) (cadr p0))) 2 3)) "")
)
); progn
); if
(command "._undo" "_end")
(setvar "cmdecho" 1)
(princ)
)

0 Likes
Accepted solutions (2)
1,350 Views
14 Replies
Replies (14)
Message 2 of 15

pbejse
Mentor
Mentor

@chan230984 wrote:


After Command asks Next level Position, I want to select the object of the circle.


 

How is that different from selecting the center of the circle ?

That appears to be working fine @chan230984 

 

0 Likes
Message 3 of 15

chan230984
Advocate
Advocate

@pbejse 

I have a lot of circles
And it will make my work faster If I select all circle, just one click.

0 Likes
Message 4 of 15

chan230984
Advocate
Advocate

@pbejse  I typed it wrong

select all circle not a circle

0 Likes
Message 5 of 15

pbejse
Mentor
Mentor
Accepted solution

@chan230984 wrote:

@pbejse 

I have a lot of circles
And it will make my work faster If I select all circle, just one click.


You want to select mulitple cirlces?

 

(defun c:chm ( / level p0 p1)
(setvar "cmdecho" 0)
(command "._undo" "_begin")
(if (and (setq level (atof (LM:UnFormat (cdr (assoc 1 (entget (car (entsel "\nFirst level: "))))) nil)))
         (setq p1 (getpoint "\nSpecify first level position: "))
	 (null 
	   (command "._leader" p1 "@0.65<45" "" (strcat "EL=" (rtos level 2 3)) "")
	   )
	 (princ "\nSelect Circle object for Next level position: ")
	 (setq circles (setq on (ssget  '((0 . "Circle")))))
    )
      	(repeat (setq i (sslength circles))
	  (setq p0 p1)
		(setq p1 (cdr (assoc 10 (entget (ssname circles (setq i (1- i)))))))
			(command "._leader" p1 "@0.65<45" "" (strcat "EL=" (rtos (+ level (- (cadr p1) (cadr p0))) 2 3)) "")
	) 
); if
(command "._undo" "_end")
(setvar "cmdecho" 1)
(princ)
)

 

 

0 Likes
Message 6 of 15

chan230984
Advocate
Advocate

@pbejse 

Hi friend, Please Edit this Lisp again Because something wrong

thank you !

 

Untitled.png

0 Likes
Message 7 of 15

Kent1Cooper
Consultant
Consultant

I suspect this much:

....
  (repeat (setq i (sslength circles))
    (setq p0 p1)
    (setq p1 (cdr (assoc 10 (entget (ssname circles (setq i (1- i)))))))
    (command "._leader" p1 "@0.65<45" ""
      (strcat "EL=" (rtos (+ level (- (cadr p1) (cadr p0))) 2 3))
      ""
    )
....

should be more like this:

....
  (repeat (setq i (sslength circles))
    ;;;;; (setq p0 p1) ; not needed -- all in relation to 'level' value, not previous Circle
    (setq p1 (cdr (assoc 10 (entget (ssname circles (setq i (1- i)))))))
    (command "._leader" p1 "@0.65<45" "" (strcat "EL=" (rtos (+ level (- (cadr p1) level)) 2 3)) "")
.... 

Kent Cooper, AIA
0 Likes
Message 8 of 15

chan230984
Advocate
Advocate

@Kent1Cooper 

Not yet

 

Untitled.jpg

0 Likes
Message 9 of 15

pbejse
Mentor
Mentor

Is it all good now? 

0 Likes
Message 10 of 15

chan230984
Advocate
Advocate

@pbejse 

not

 

Untitled.png

0 Likes
Message 11 of 15

pbejse
Mentor
Mentor

@chan230984 wrote:

@pbejse 

not


Remind me again what the lisp code is about? can you please post the equivalent drawing sample of the imaghe you posted and show the "correct" results.

 

 

 

0 Likes
Message 12 of 15

chan230984
Advocate
Advocate

@pbejse 

Sorry I am not good an English

Please see Picture Below

 

Untitled.png

0 Likes
Message 13 of 15

pbejse
Mentor
Mentor
Accepted solution
(defun c:chm ( / level p0 p1)
(setvar "cmdecho" 0)
(command "._undo" "_begin")
(if (and (setq level (atof (LM:UnFormat (cdr (assoc 1 (entget (car (entsel "\nFirst level: "))))) nil)))
         (setq p1 (getpoint "\nSpecify first level position: "))
	 (null 
	   (command "._leader" p1 "@0.65<45" "" (strcat "EL=" (rtos level 2 3)) "")
	   )
	 (princ "\nSelect Circle object for Next level position: ")
	 (setq p0 p1 circles (setq on (ssget  '((0 . "Circle")))))
    )
      	(repeat (setq i (sslength circles))
		(setq p1 (cdr (assoc 10 (entget (ssname circles (setq i (1- i)))))))
			(command "._leader" p1 "@0.65<45" "" (strcat "EL=" (rtos (+ level (- (cadr p1) (cadr p0))) 2 3)) "")
	) 
); if
(command "._undo" "_end")
(setvar "cmdecho" 1)
(princ)
)

HTH 

Message 14 of 15

chan230984
Advocate
Advocate

@pbejse 

thanks again! you are a good man

0 Likes
Message 15 of 15

pbejse
Mentor
Mentor

@chan230984 wrote:

@pbejse 

thanks again! you are a good man


Good for you, You are welcome.

 

0 Likes