Jump to content

Recommended Posts

Posted

I'm found a lisp to change a point Z coord by entmod, but I also want to change the color number. I tried this code:

(defun c:ELEVAZIONE (/ ss i sn pts txt d di e ent)
;;;   ==-- Author : Tharwat Al Shoufi --== 	;;;
;;; Entmod the Z value of Points according	;;;
;;; 	  to the nearest text's value 		;;;
 (if (setq ss (ssget '((0 . "POINT,*TEXT"))))
   (repeat (setq i (sslength ss))
     (setq sn (ssname ss (setq i (1- i))))
     (if (eq (cdr (assoc 0 (entget sn))) "POINT")
       (setq pts (cons (list (cdr (assoc 10 (entget sn))) sn) pts))
       (setq txt (cons (list (cdr (assoc 10 (entget sn))) sn) txt))
     )
   )
 )

 (foreach p pts
   (foreach x txt
     (if (not d)
       (setq d (distance (car p) (car x))
             e (cadr x)
       )
       (if (< (setq di (distance (car p) (car x))) d)
         (setq d di
               e (cadr x)
         )
       )
     )
   )
   (setq d nil)
   


(if (numberp (read (cdr (assoc 1 (entget e)))))
   (progn 
  (entmod
       (subst
         (cons 10
               (list (car (cdr (assoc 10 (setq ent (entget (cadr p))))))
                     (cadr (cdr (assoc 10 ent)))
                     (read (cdr (assoc 1 (entget e))))
			                  )
         )
         (assoc 10 ent)
         ent
       )
  )
	(entmod (subst (cons 62 1) (assoc 62 ent) ent)) ; this is my code
 ))
 )
 (princ "\n Written by Tharwat Al Shoufi")
 (princ)
)

 

but doesn't work. Can someone help me?

Posted

I updated the code this way and it seems to work:

(defun c:ELEVAZIONE (/ ss i sn pts txt d di e ent)
;;;   ==-- Author : Tharwat Al Shoufi --== 	;;;
;;; Entmod the Z value of Points according	;;;
;;; 	  to the nearest text's value 		;;;
 (if (setq ss (ssget '((0 . "POINT,*TEXT"))))
   (repeat (setq i (sslength ss))
     (setq sn (ssname ss (setq i (1- i))))
     (if (eq (cdr (assoc 0 (entget sn))) "POINT")
       (setq pts (cons (list (cdr (assoc 10 (entget sn))) sn) pts))
       (setq txt (cons (list (cdr (assoc 10 (entget sn))) sn) txt))
     )
   )
 )

 (foreach p pts
   (foreach x txt
     (if (not d)
       (setq d (distance (car p) (car x))
             e (cadr x)
       )
       (if (< (setq di (distance (car p) (car x))) d)
         (setq d di
               e (cadr x)
         )
       )
     )
   )
   (setq d nil)
   


(if (numberp (read (cdr (assoc 1 (entget e)))))
   (progn 


(setq elist 
	(subst
         (cons 10
               (list (car (cdr (assoc 10 (setq ent (entget (cadr p))))))
                     (cadr (cdr (assoc 10 ent)))
                     (read (cdr (assoc 1 (entget e))))
				                  )
         )
         (assoc 10 ent)
         ent
       ))
(setq elist (subst (cons 62 1) (assoc 62 elist) elist))


(entmod elist)
 ))


 )
 (princ "\n Fatto!")
 (princ)
)

Posted

You will need to address entities that have color BYLAYER as well

 

[b][color=BLACK]([/color][/b]setq elist [b][color=FUCHSIA]([/color][/b]if [b][color=NAVY]([/color][/b]assoc 62 elist[b][color=NAVY])[/color][/b]
               [b][color=NAVY]([/color][/b]subst [b][color=MAROON]([/color][/b]cons 62 1[b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]assoc 62 elist[b][color=MAROON])[/color][/b] elist[b][color=NAVY])[/color][/b]
               [b][color=NAVY]([/color][/b]append elist [b][color=MAROON]([/color][/b]list [b][color=GREEN]([/color][/b]cons 62 1[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b][b][color=BLACK])[/color][/b]

 

-David

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...