Layer Change ( only Text )

Layer Change ( only Text )

k005
Advisor Advisor
1,238 Views
20 Replies
Message 1 of 21

Layer Change ( only Text )

k005
Advisor
Advisor

Hello guys;

I want to change the layer named DOOR-WINDOW. But only text objects should be processed.

 

sample:

 

KAPI-PENCERE -----> Kapi-Ebat....bylayer...bylayer...bylayer
Color: 7

 

 

When I select the text object with the window, it performs the operation. Thanks in advance to the helper.

0 Likes
Accepted solutions (3)
1,239 Views
20 Replies
Replies (20)
Message 2 of 21

ВeekeeCZ
Consultant
Consultant

You start... 

0 Likes
Message 3 of 21

pendean
Community Legend
Community Legend
0 Likes
Message 4 of 21

Kent1Cooper
Consultant
Consultant

@k005 wrote:

....

I want to change the layer named DOOR-WINDOW. But only text objects should be processed.

 

sample:

KAPI-PENCERE -----> Kapi-Ebat....bylayer...bylayer...bylayer
Color: 7

 

When I select the text object with the window, it performs the operation. Thanks in advance to the helper.


Do you want to change the Layer itself [your first phrase] or Text object(s)?  Do you want to move Text objects on that Layer into a different Layer ["change the layer" meaning change the layer of the Text, not the layer itself]?  Or do you only want to change their color?

 

KAPI-PENCERE means DOOR-WINDOW in English, so I assume that's the Layer name.  What is Kapi-Ebat [which means Door-Size] for?  Is that the text content of a Text object?  Do you want only Text with that content changed, or all Text on that Layer?

 

Etc.

Kent Cooper, AIA
0 Likes
Message 5 of 21

k005
Advisor
Advisor

I already started... 🙂

0 Likes
Message 6 of 21

k005
Advisor
Advisor

Thanks

0 Likes
Message 7 of 21

k005
Advisor
Advisor

I'm adding a sample dwg right away... wait a minute..

 

-- added

0 Likes
Message 8 of 21

hak_vz
Advisor
Advisor
(defun c:foo (/ ss)
	(setq ss (ssget '((0 . "TEXT")(8 . "KAPI-PENCERE"))))
	(cond 
		((and ss)
			(command "_.chprop" ss "" "LA" "Kapi-Ebat" "")
		)
	)
	(princ)
)

Sorry @k005  but you should be able to write this simple scripts by yourself. Creating selection set with filtering and applying  command function upon selected entities are the basics that any CAD user should know.

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes
Message 9 of 21

k005
Advisor
Advisor

@hak_vz 

 

This code was partially... But not complete..

 

The reason : Lisp code crashes if there is no Kapi-Ebat layer... Otherwise it should create it.

 

Thank you.

0 Likes
Message 10 of 21

hak_vz
Advisor
Advisor

@k005 wrote:

@hak_vz 

 

This code was partially... But not complete..

The reason : Lisp code crashes if there is no Kapi-Ebat layer... Otherwise it should create it.


True. But you should be able to add a line of code that would test if layer exist, and create if it not. Add command line for "-layer" command with option make. Check other consequences of running this command. Attach your code. 

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
Message 11 of 21

ronjonp
Mentor
Mentor
Accepted solution

Give this a try:

(defun c:foo (/ s)
  (if (setq s (ssget ":L" '((0 . "TEXT") (8 . "KAPI-PENCERE"))))
    (foreach e (vl-remove-if 'listp (mapcar 'cadr (ssnamex s)))
      (entmod (append (entget e) '((8 . "Kapi-Ebat"))))
    )
  )
  (princ)
)

 

Message 12 of 21

Kent1Cooper
Consultant
Consultant

@ronjonp wrote:

....

....
      (entmod (append (entget e) '((8 . "Kapi-Ebat"))))
....

Advantage of appending the Layer name to the object's entity data:  It doesn't matter whether the Layer exists -- it will make it if it doesn't [with default color 7 and continuous linetype].

 

Advantage of CHPROP-command approach:  It can change the Layer of all of the selection at once -- no need to step through the selection set one object at a time.  But the Layer needs to exist.

Kent Cooper, AIA
Message 13 of 21

k005
Advisor
Advisor

Like okay. Since we are working in different dwgs, I will either enter the name of the layer to be searched from the keyboard or select the relevant (in the layer to be searched) text.

0 Likes
Message 14 of 21

k005
Advisor
Advisor

 

 

 

(defun c:fo1 (/ s lan)
(setq lan (cdr (assoc 8 (entget(car(entsel))))))
 (princ "\nKatman : ")
  (princ lan)
  (if (setq s (ssget "L:" '((0 . "TEXT") (8 . lan))))
    (foreach e (vl-remove-if 'listp (mapcar 'cadr (ssnamex s)))
      (entmod (append (entget e) '((8 . "Kapi-Ebat")(62 . 7))))
      
    )
  )
  (princ)
)

I get this error

 

error: bad SSGET list value

 

0 Likes
Message 15 of 21

Kent1Cooper
Consultant
Consultant

@k005 wrote:
....
  (if (setq s (ssget "L:" '((0 . "TEXT") (8 . lan))))
....

I get this error

 

error: bad SSGET list value


You have the colon after the L.  Put it before.

Kent Cooper, AIA
0 Likes
Message 16 of 21

ronjonp
Mentor
Mentor
Accepted solution

@k005 wrote:

 

 

 

(defun c:fo1 (/ s lan)
(setq lan (cdr (assoc 8 (entget(car(entsel))))))
 (princ "\nKatman : ")
  (princ lan)
  (if (setq s (ssget "L:" '((0 . "TEXT") (8 . lan))))
    (foreach e (vl-remove-if 'listp (mapcar 'cadr (ssnamex s)))
      (entmod (append (entget e) '((8 . "Kapi-Ebat")(62 . 7))))
      
    )
  )
  (princ)
)

I get this error

 

error: bad SSGET list value

 


Comments in the code below:

(defun c:fo1 (/ s lan)
  ;; RJP selection check .. entget throws an error on a nil value
  (if (and (setq lan (car (entsel)))
	   (setq lan (cdr (assoc 8 (entget lan))))
      )
    (progn (princ "\nKatman : ")
	   (princ lan)
      ;; RJP reformatted ssget call .. please study the differences
	   (if (setq s (ssget ":L" (list '(0 . "TEXT") (cons 8 lan))))
	     ;;(setq s (ssget "L:" '((0 . "TEXT") (8 . lan))))
	     (foreach e	(vl-remove-if 'listp (mapcar 'cadr (ssnamex s)))
	       (entmod (append (entget e) '((8 . "Kapi-Ebat") (62 . 7))))
	     )
	   )
    )
  )
  (princ)
)
Message 17 of 21

k005
Advisor
Advisor

It was very nice. Thank you. 🤗

0 Likes
Message 18 of 21

ronjonp
Mentor
Mentor

@k005 wrote:

It was very nice. Thank you.


You're welcome.

Message 19 of 21

k005
Advisor
Advisor

Is it possible to add a name to it?

 

(setq istenen (getstring t "\nLayer adı giriniz : "))
...


...

(entmod (append (entget e) '((8 . istenen) (62 . 7))))

..?
0 Likes
Message 20 of 21

ronjonp
Mentor
Mentor
Accepted solution
;; Change this
(entmod (append (entget e) '((8 . istenen) (62 . 7))))
;; To this
(entmod (append (entget e) (list (cons 8 istenen) '(62 . 7))))