Replace text with block and transfer value to scale X

Replace text with block and transfer value to scale X

Anonymous
Not applicable
1,161 Views
11 Replies
Message 1 of 12

Replace text with block and transfer value to scale X

Anonymous
Not applicable

Hi. Anyone can help me?

 

I need to replace text objects with a block, get the value from text and apply it on the X scale (including negative values).

 

Thank you

0 Likes
Accepted solutions (1)
1,162 Views
11 Replies
Replies (11)
Message 2 of 12

natasha.l
Alumni
Alumni

Hello @Anonymous, 

 

Can you provide us with an example of what you are trying to accomplish for some more clarity? 

Take a look at this video some of the functionality you are looking for maybe demonstrated. 

 

Thank you. 

0 Likes
Message 3 of 12

Anonymous
Not applicable

Hi.

 

I dont know how to clarify more. I want to create a block on each text with a specific x scale, which is the string value, plus a factor (im ok with that because i can manipulate the text values).  The link for the video does not work.

 

Thanks

0 Likes
Message 4 of 12

ara_neresesian
Collaborator
Collaborator

HI

PLEASE MAKE A SAMPLE AND SEND IT.

WE CAN HELP YOU BETTER

 

WHAT I UNDERSTAND IS LIKE THIS  PICTURECapture.JPG

AM I RIGHT?

 

Message 5 of 12

Anonymous
Not applicable

Hi

Exactly! Your capture reflect what i want.

 

Here is my sample.

 

in fact i will need 2 blocks, but i can easily handle it. 

 

0 Likes
Message 6 of 12

Moshe-A
Mentor
Mentor
Accepted solution

@Anonymous  hi,

 

check this lisp. wrap the following codes line in text file call it apsc.lsp and appload it.

 

enjoy

moshe

 

 

(vl-load-com)

; apply scale

(defun c:apsc (/ get_block_name askString net_digits ; local functions
	         default ss elist sx)

 (defun get_block_name (def / flag blk)

  (while (not flag) 
   (if (eq (setq blk (getstring (strcat "\nBlock name <" def ">: "))) "")
    (setq blk def)
   )

   (if (null (tblsearch "block" blk))
    (progn
     (vlr-beep-reaction)
     (prompt (strcat "\nBlock " blk " is not exist.")) 
    ); progn
    (setq flag t) 
   ); if
  ); while

  blk 
 ); get_block_name

  
 ; return only digits 
 (defun net_digits (str / i ch num)
  (setq i 1 ch (substr str i 1) num "")
  (while (/= ch "")
   (if (or
	 (eq ch ".") 
	 (eq ch "+")
         (eq ch "-")
         (and
	  (>= (ascii ch) 48)
	  (<= (ascii ch) 57)
         )
       )
    (setq num (strcat num ch))
   ); if

   (setq i (1+ i) ch (substr str i 1))
  ); while  

  num ; return
 ); net_digits


 (setvar "cmdecho" 0)
 (command "._undo" "_begin")

 ; set default 
 (if (eq (getvar "users5") "")
  (setq default (setvar "users5" "1"))
  (setq default (getvar "users5"))
 )
  
 (if (and
       (setvar "users5" (setq bname (get_block_name default)))
       (setq ss (ssget '((0 . "?text"))))
     )
   (foreach ename (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss)))
    (setq elist (entget ename))

    (if (setq sx (atof (net_digits (cdr (assoc '1 elist)))))
     (command "._insert" bname "_none" (cdr (assoc '10 elist)) sx 1 0)
    ) 
   ); foreach
 ); if

 (command "._undo" "_end")
 (setvar "cmdecho" 1)
  
 (princ)
)

0 Likes
Message 7 of 12

Anonymous
Not applicable

Yeah, it worked! I only have problems with zero values, but i can easily replace them.

 

Thank you very much!

 

 

0 Likes
Message 8 of 12

Anonymous
Not applicable

in that case it should draw nothing or apply a small value.

0 Likes
Message 9 of 12

Moshe-A
Mentor
Mentor

@Anonymous ,

 

replace this:

 

    (if (setq sx (atof (net_digits (cdr (assoc '1 elist)))))
     (command "._insert" bname "_none" (cdr (assoc '10 elist)) sx 1 0)
    ) 

 

with this ...to skip insert the block when text value is 0.00

 

    (if (and
	  (setq sx (atof (net_digits (cdr (assoc '1 elist)))))
	  (/= (rtos sx 2 2) "0.00")
	)
     (command "._insert" bname "_none" (cdr (assoc '10 elist)) sx 1 0)
    ) 

 

 

0 Likes
Message 10 of 12

Anonymous
Not applicable

For some reason didn't work.

 

"Value must be nonzero.
; error: Function cancelled

0 Likes
Message 11 of 12

Moshe-A
Mentor
Mentor

@Anonymous ,

 

sorry (you are right)

 

replace this line:

(/= (rtos sx 2 2) "0.00")

 with this line:

(/= sx 0)
0 Likes
Message 12 of 12

Anonymous
Not applicable

It worked!

Thank you!!!

 

Final Code:

(vl-load-com)

; apply scale

(defun c:apsc (/ get_block_name askString net_digits ; local functions
	         default ss elist sx)

 (defun get_block_name (def / flag blk)

  (while (not flag) 
   (if (eq (setq blk (getstring (strcat "\nBlock name <" def ">: "))) "")
    (setq blk def)
   )

   (if (null (tblsearch "block" blk))
    (progn
     (vlr-beep-reaction)
     (prompt (strcat "\nBlock " blk " is not exist.")) 
    ); progn
    (setq flag t) 
   ); if
  ); while

  blk 
 ); get_block_name

  
 ; return only digits 
 (defun net_digits (str / i ch num)
  (setq i 1 ch (substr str i 1) num "")
  (while (/= ch "")
   (if (or
	 (eq ch ".") 
	 (eq ch "+")
         (eq ch "-")
         (and
	  (>= (ascii ch) 48)
	  (<= (ascii ch) 57)
         )
       )
    (setq num (strcat num ch))
   ); if

   (setq i (1+ i) ch (substr str i 1))
  ); while  

  num ; return
 ); net_digits


 (setvar "cmdecho" 0)
 (command "._undo" "_begin")

 ; set default 
 (if (eq (getvar "users5") "")
  (setq default (setvar "users5" "1"))
  (setq default (getvar "users5"))
 )
  
 (if (and
       (setvar "users5" (setq bname (get_block_name default)))
       (setq ss (ssget '((0 . "?text"))))
     )
   (foreach ename (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss)))
    (setq elist (entget ename))

    (if (and
	  (setq sx (atof (net_digits (cdr (assoc '1 elist)))))
	  (/= sx 0)
	)
     (command "._insert" bname "_none" (cdr (assoc '10 elist)) sx 1 0)
    ) 
   ); foreach
 ); if

 (command "._undo" "_end")
 (setvar "cmdecho" 1)
  
 (princ)
)
0 Likes