Visual LISP, AutoLISP and General Customization

Visual LISP, AutoLISP and General Customization

Reply
Distinguished Contributor
warrentdo
Posts: 738
Registered: ‎02-02-2004
Message 1 of 11 (466 Views)

move all 3.5mm text to layer text3.5

466 Views, 10 Replies
09-12-2012 12:22 AM

Hello, We are using autocad 2012.

Is there a way to move all 3.5mm text to layer text3.5 and move all 5mm text to layer text5.

I was hoping in a lisp rather than Qselect.

Any pointer would be great.

Regards

 

Warren.

Distinguished Contributor
phanaem
Posts: 149
Registered: ‎02-06-2007
Message 2 of 11 (460 Views)

Re: move all 3.5mm text to layer text3.5

09-12-2012 12:42 AM in reply to: warrentdo

Try this

(defun C:TEST ( / dmz lay e l)
  (setq dmz (getvar 'dimzin)
        lay (vla-get-layers (vla-get-activedocument (vlax-get-acad-object)))
        )
  (setvar 'dimzin 8)
  (if
    (setq ss (ssget '((0 . "TEXT,MTEXT"))))
    (repeat (setq i (sslength ss))
      (setq e (vlax-ename->vla-object (ssname ss (setq i (1- i))))
            l (strcat "text" (rtos (vla-get-height e) 2)))
      (if (not (tblsearch "Layer" l)) (vla-Add lay l))
      (vla-put-Layer e l)
      )
    )
  (setvar 'dimzin dmz)
  (princ)
  )

 

*Expert Elite*
pbejse
Posts: 2,500
Registered: ‎11-24-2009
Message 3 of 11 (452 Views)

Re: move all 3.5mm text to layer text3.5

09-12-2012 01:17 AM in reply to: warrentdo

warrentdo wrote:

 

Is there a way to move all 3.5mm text to layer text3.5 and move all 5mm text to layer text5.

 


 

another

(defun c:test2 (/ ss f on ob)
    (setq ss (ssget  '((0 . "TEXT,MTEXT"))))
	(repeat (sslength ss)
          	(if (setq f (assoc
                              (cdr (assoc
                                  40 (setq on (entget (setq ob (ssname ss 0))))
                                  )
                                ) '((3.5 "Text3.5")(5.0 "Text5.0"))))
                  	(entmod (subst (cons 8 (cadr f)) (assoc 8 on) on)
                              )
                  )
          (ssdel ob ss)
          )(princ)
  )

 

we may need to add a fuzz value in case where the text height is NOT exactly 3.5 (i.e. 3.502)

 

HTH

 

*Expert Elite*
pbejse
Posts: 2,500
Registered: ‎11-24-2009
Message 4 of 11 (447 Views)

Re: move all 3.5mm text to layer text3.5

09-12-2012 01:50 AM in reply to: pbejse

with fuzz

 

(defun c:test3 (/ ss f on ob lay)
    (setq ss (ssget  '((0 . "TEXT,MTEXT"))))
	(repeat (sslength ss)
          	(setq  f (cdr
                      (assoc 40
                        (setq on (entget (setq ob (ssname ss 0))))
                        )))
		(if (setq lay 
	          	(cond
	                  ((equal f 3.5 0.01)  "Text3.5")
	                  ((equal f 5.0 0.01)   "Text5.0")))
                   
                  	(entmod (subst (cons 8 lay) (assoc 8 on) on)
                              )
                  )
          (ssdel ob ss)
          )(princ)
  )

 

usage:

command: Test3

 

HTH

 

Distinguished Contributor
warrentdo
Posts: 738
Registered: ‎02-02-2004
Message 5 of 11 (445 Views)

Re: move all 3.5mm text to layer text3.5

09-12-2012 01:52 AM in reply to: phanaem

Hello Phanaem and thank you for your help.

 

Ive had a play and just changed             l (strcat "0-" (rtos (vla-get-height e) 2)"TEXT"))

Bow Ive forgot something. this would create a layer 0-3.5text and what I have to create is 0-35text.

All this becasue of a decimal point!! Client requirement.

I love the lisp though.

Cheers

Distinguished Contributor
warrentdo
Posts: 738
Registered: ‎02-02-2004
Message 6 of 11 (442 Views)

Re: move all 3.5mm text to layer text3.5

09-12-2012 01:58 AM in reply to: pbejse

Thats the one.

(defun c:movetextfuzz (/ ss f on ob lay)
    (setq ss (ssget  '((0 . "TEXT,MTEXT"))))
 (repeat (sslength ss)
           (setq  f (cdr
                      (assoc 40
                        (setq on (entget (setq ob (ssname ss 0))))
                        )))
  (if (setq lay
            (cond
                   ((equal f 3.5 0.01)  "0-35TEXT")
                   ((equal f 5.0 0.01)   "0-50TEXT")))
                   ((equal f 7.0 0.01)   "0-70TEXT")))
                  
                   (entmod (subst (cons 8 lay) (assoc 8 on) on)
                              )
                  )
          (ssdel ob ss)
          )(princ)
  )

 

Cheers all.

 

Regards

 

Warren.

*Expert Elite*
Kent1Cooper
Posts: 5,540
Registered: ‎09-13-2004
Message 7 of 11 (421 Views)

Re: move all 3.5mm text to layer text3.5

09-12-2012 05:32 AM in reply to: warrentdo

warrentdo wrote:

....

Is there a way to move all 3.5mm text to layer text3.5 and move all 5mm text to layer text5.

....


If such Text is put into the drawing by some kind of routine or menu item, or is in a Style that has a fixed height, I would think the fuzz factor would not be needed.  What's going to make a piece of Text come out with a height of 3.502?  It's not like checking the length of a Line or something.  If in fact the fuzz factor isn't needed, it can be quite simple:

 

(command

   "_.chprop" (ssget "X" '((0 . "TEXT") (40 . 3.5))) "" "_layer" "text3.5" ""

   "_.chprop" (ssget "X" '((0 . "TEXT") (40 . 5.0))) "" "_layer" "text5" ""

)

Kent Cooper
New Member
robchapman82
Posts: 2
Registered: ‎01-07-2013
Message 8 of 11 (353 Views)

Re: move all 3.5mm text to layer text3.5

01-07-2013 05:19 AM in reply to: warrentdo

Hi all,

 

I tried to butcher the lisps provided to suit my own requirements, but have failed miserably...

 

Rather than searching for a specfic height value, I tried to make the lisp ask me for a content variable.

 

I have a survey dwg with hundreds of spot levels. I'd like to put all text with content "123.84" onto a layer of the same name.

 

Although I could amend the lisp to search for all text of 123.96 through to 124.10, I was hoping to make it a useful tool for the future.

 

Either a lisp that put all text onto a corresponding layer (although this would mean that notes went into layers called "do not scale from this drawing" etc.)

 

...or a lisp that asked me for the content I'd like (123.84), selected all text with that content, and put it onto a layer of the same name.

 

Am I barking up the wrong tree, or could your previous lisp solutions be tweaked to serve my purpose?

 

Many thanks!

Rob

*Expert Elite*
pbejse
Posts: 2,500
Registered: ‎11-24-2009
Message 9 of 11 (340 Views)

Re: move all 3.5mm text to layer text3.5

01-07-2013 06:25 AM in reply to: robchapman82

robchapman82 wrote:

Hi all,

.........

 

...or a lisp that asked me for the content I'd like (123.84), selected all text with that content, and put it onto a layer of the same name.

 

Am I barking up the wrong tree, or could your previous lisp solutions be tweaked to serve my purpose?

 

Many thanks!

Rob


a simple code could  be

 

(defun c:Tolayer ( / num ss i e l)
(while (not (progn
  		(setq num (getstring "\nEnter value to search: "))
  		(if (numberp (read num)) num
                    (and (princ "\n<Invalid number>") nil)))))
(if (setq ss (ssget "_X" (list '(0 . "TEXT")(cons 1 (strcat "*" num "*")))))
		(repeat (setq i (sslength ss))
			(setq e (entget (ssname ss (setq i (1- i))))
                  	      l (assoc -1 e))
                  	 (entmod (list (cons 8 num) l)))
(princ "\nValue not found") )(princ) )

 

O would you rather have the routine select all  string with a valid numerical value  and use a range between x and x. now it would be fun to write a code to do just that

 

 

 

New Member
robchapman82
Posts: 2
Registered: ‎01-07-2013
Message 10 of 11 (334 Views)

Re: move all 3.5mm text to layer text3.5

01-07-2013 06:34 AM in reply to: pbejse

Is that possible?!

 

I didn't even know I wanted that... but now it seems like a perfect idea...!

 

The routine provided worked perfectly. Thanks!

Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.