Two part lisp. Create layers with a -text suffix then move all text to new layers.

Two part lisp. Create layers with a -text suffix then move all text to new layers.

LDShaw
Collaborator Collaborator
2,489 Views
23 Replies
Message 1 of 24

Two part lisp. Create layers with a -text suffix then move all text to new layers.

LDShaw
Collaborator
Collaborator

I have a lot of dwg's where I want to separate all the text to it's own layers but leave the other objects where they are.

I know I need to get a list of layers.
create the list with a -text suffix

I've not gotten done commenting it out but here it is. 

 

;; RJP » 2023-05-09 wrote most of this routine. 
;;; DESCRIPTION
;;; 2023-05-09
;;;	add prefix text- to new layers that have text 
;;; Dig into blocks and do the same.
;;;Lonnie
;;;
(defun c:TSP (/ a d la ln pre)

  (vlax-for l (setq la (vla-get-layers (setq d (vla-get-activedocument (vlax-get-acad-object)))))
    (cond ((= -1 (vlax-get l 'lock)) (vlax-put l 'lock 0) (setq a (cons l a))))
  )
  (setq pre "TEXT-")
  (vlax-for b (vla-get-blocks d)
    (if	(= 0 (vlax-get b 'isxref))
      (vlax-for	o b
	(cond ((and (vlax-write-enabled-p o)
		    (vlax-property-available-p o 'textstring)
		    (not (wcmatch (strcase (setq ln (vla-get-layer o))) (strcat pre "*" )))
	       )
	       (entmod (append (entget (vlax-vla-object->ename o)) (list (cons 8 (strcat pre ln)))))
	      )
	)
      )
    )
  )
  (foreach l a (vlax-put l 'lock -1))
  (if (ssget "_X" '((0 . "INSERT") (66 . 1)))
    (command "_.Attsync" "_N" "*")
  )
  (vla-regen d acallviewports)
  (princ)
)

 

 Then I need to gather up the text and move it to the new layer.
This is where I've been running into problem. 




0 Likes
Accepted solutions (4)
2,490 Views
23 Replies
Replies (23)
Message 21 of 24

LDShaw
Collaborator
Collaborator

Works for my needs. As an FYI it takes the attributed Keyed notes and blanks them. It also mirrors some of the blocks text.  Neither issue affects its usefulness to me. 

I've attached a bit of dwg so you can see. 

0 Likes
Message 22 of 24

ronjonp
Mentor
Mentor

@LDShaw wrote:

Works for my needs. As an FYI it takes the attributed Keyed notes and blanks them. It also mirrors some of the blocks text.  Neither issue affects its usefulness to me. 

I've attached a bit of dwg so you can see. 


Take this part out of the code:

  (if (ssget "_X" '((0 . "INSERT") (66 . 1)))
    (command "_.Attsync" "_N" "*")
  )
Message 23 of 24

paullimapa
Mentor
Mentor

since attsyn has side effects, perhaps may have to cycle through all inserted block attributes and change those layers?

(ssget "_X" '((0 . "INSERT") (66 . 1)))

Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 24 of 24

LDShaw
Collaborator
Collaborator

Thank You. 
I will probably keep the attsync as I would rather get cussed for something now than leave an undetonated bomb in the dwg for later disaster. If they really need it I have an old lisp routine that should do the trick. 

 

 

;; RJP » 2023-05-09 wrote most of this routine. 
;;; DESCRIPTION
;;; 2023-05-09
;;;	add prefix text- to new layers that have text 
;;; Dig into blocks and do the same.
;;;Lonnie
;;; Thank goes out to  paullimapa  Kent1Cooper  ronjonp
;;; for the help in making it.
(defun c:TSP (/ a d la ln pre)

  (vlax-for l (setq la (vla-get-layers (setq d (vla-get-activedocument (vlax-get-acad-object)))))
    (cond ((= -1 (vlax-get l 'lock)) (vlax-put l 'lock 0) (setq a (cons l a))))
  )
  (setq pre "TEXT-")
  (vlax-for b (vla-get-blocks d)
    (if	(= 0 (vlax-get b 'isxref))
      (vlax-for	o b
	(cond ((and (vlax-write-enabled-p o)
		    (vlax-property-available-p o 'textstring)
		    (not (wcmatch (strcase (setq ln (vla-get-layer o))) (strcat pre "*" )))
	       )
	       (entmod (append (entget (vlax-vla-object->ename o)) (list (cons 8 (strcat pre ln)))))
	      )
	)
      )
    )
  )
  (foreach l a (vlax-put l 'lock -1))
  (if (ssget "_X" '((0 . "INSERT") (66 . 1)))
    (command "_.Attsync" "_N" "*")
  )
  (vla-regen d acallviewports)
  (princ)
)

 

 

The only little change I have made is putting the text- as a prefix. This way in Revit all the text layers are in the same place. 
I will repost after all comments are written. 

0 Likes