Convert text string to custom letters from blocks

Convert text string to custom letters from blocks

rhgrafix
Enthusiast Enthusiast
3,792 Views
42 Replies
Message 1 of 43

Convert text string to custom letters from blocks

rhgrafix
Enthusiast
Enthusiast

Does anyone know of a macro to convert text strings to premade blocks of a home made font? Like A. Werning's 3dtext but much simpler as 2d. Thanks!

0 Likes
Accepted solutions (1)
3,793 Views
42 Replies
Replies (42)
Message 21 of 43

Sea-Haven
Mentor
Mentor
Accepted solution

A start for you.

 

(setq obj (vlax-ename->vla-object (car  (entsel "Pick text"))))
(setq str (vlax-get obj 'textstring))
(setq x 0)
(repeat (strlen str)
(setq char (substr str (setq x (+ x 1)) 1 ))
(cond
((= char "a" )(setq bname "Blocka" wid 1.12))
((= char "b" )(setq bname "Blockb" wid 1.0))
((= char "c" )(setq bname "Blockc" wid 0.85))
((alert (strcat "Character not supported  " char)))
)
(princ (strcat "\n" bname "  " char))
)
0 Likes
Message 22 of 43

rhgrafix
Enthusiast
Enthusiast
When I run it, I get:
error: application is locked and cannot be unloaded.
Thanks
0 Likes
Message 23 of 43

Sea-Haven
Mentor
Mentor

If your text has abc should see "Blocka" "Blockb" etc 

 

Its only a sample and would be intergrated into more code more thought is needed how to handle the sizing of the blocks. 

 

Never seen that error message.

 

(defun c:test ()
(setq obj (vlax-ename->vla-object (car  (entsel "Pick text"))))
(setq str (vlax-get obj 'textstring))
(setq x 0)
(repeat (strlen str)
(setq char (substr str (setq x (+ x 1)) 1 ))
(cond
((= char "a" )(setq bname "Blocka" wid 1.12))
((= char "b" )(setq bname "Blockb" wid 1.0))
((= char "c" )(setq bname "Blockc" wid 0.85))
((alert (strcat "Character not supported  " char)))
)
(princ (strcat "\n" bname "  " char))
)
)
(c:test)

 

0 Likes
Message 24 of 43

ronjonp
Advisor
Advisor

@rhgrafix wrote:
I explained in detail 3 times.

I was trying to help you out. If you explained this 3 times and we're all trying to figure out WTF you want, you need to work on your 'explamanation' skills. 💩

0 Likes
Message 25 of 43

Kent1Cooper
Consultant
Consultant

@ronjonp wrote:

@rhgrafix wrote:
I explained in detail 3 times.

I was trying to help you out. If you explained this 3 times and we're all trying to figure out WTF you want, you need to work on your 'explamanation' skills.


[I dispute the "we're all trying to figure out" part -- speak for yourself.  I understood the explanations quite well.]

Kent Cooper, AIA
0 Likes
Message 26 of 43

ronjonp
Advisor
Advisor

@Kent1Cooper wrote:

@ronjonp wrote:

@rhgrafix wrote:
I explained in detail 3 times.

I was trying to help you out. If you explained this 3 times and we're all trying to figure out WTF you want, you need to work on your 'explamanation' skills.


[I dispute the "we're all trying to figure out" part -- speak for yourself.  I understood the explanations quite well.]


Let me rephrase that .. some of us don't know WTF you want. Better for you @Kent1Cooper ? 😂

0 Likes
Message 27 of 43

rhgrafix
Enthusiast
Enthusiast
Thank you!
0 Likes
Message 28 of 43

ronjonp
Advisor
Advisor

@rhgrafix wrote:
Thank you!

Did you solve your problem? If so care to share the solution/result of your drawing? My apologies .. I missed THIS post which explains what you want to do. FWIW I could not download the lisp by Werning, the link does nothing here. Used a different browser and it worked.

0 Likes
Message 29 of 43

ВeekeeCZ
Consultant
Consultant

Totally agree that there are plenty of information missing, so lots of assumptions needed.

Anyway, here's me humble attempt, see THIS 

It converts just TEXTs, default left justification required.

Blocknames are their ascii. Also make "0" block as dummy if any char missing. 

k is for kerning, it's a constant. Space is 5k.

 

(vl-load-com)

(defun c:LTB ( / xbb k s e d p c a w b)

  (defun xbb (o)
    (vla-getboundingbox (vlax-ename->vla-object o) 'll 'ur)
    (- (car (vlax-safearray->list ur)) (car (vlax-safearray->list ll))))
  
  (setq k 0.1)
  
  (if (setq s (ssget "_:L" '((0 . "TEXT"))))
    (repeat (setq i (sslength s))
      (setq e (ssname s (setq i (1- i)))
	    d (entget e)
	    p (cdr (assoc 10 d))
	    c (cdr (assoc 40 d))
	    a (cdr (assoc 50 d))
	    w (vl-string->list (cdr (assoc 1 d))))
      (foreach l w
	(if (= l 32)
	  (setq p (polar p a (* 5 k)))
	  (progn
	    (if (not (tblsearch "block" (itoa l))) (setq l 0))
	    (setq b (entmakex (list '(0 . "INSERT") (cons 2 (itoa l)) (cons 10 p) (cons 41 c) (cons 42 c) (cons 43 c))))
	    (setq p (polar p a (+ (xbb b) k)))
	    (entmod (append (entget b) (list (cons 50 a)))))))
      (entdel e)))
  (princ)
  )

 

Message 30 of 43

rhgrafix
Enthusiast
Enthusiast

When I run it, nothing happens. It could be that since my Autocad license ran out, I am now using IntelliCAD which runs lisp fine until it sees vla code. Would the block name for each letter be in binary format eg. 'small a' would be 01100001? Or U+0061? I made one of each but I can't so far as to pick the text. Thanks for your help.

0 Likes
Message 31 of 43

Sea-Haven
Mentor
Mentor

Change these two lines in code provided.

 

(setq obj (vlax-ename->vla-object (car  (entsel "\nPick text"))))
(setq str (vlax-get obj 'textstring))


(setq obj (entget (car  (entsel "\nPick text"))))
(setq str (cdr (assoc 1 obj)))

 

0 Likes
Message 32 of 43

rhgrafix
Enthusiast
Enthusiast
I can't tell where 1 line ends and another starts, now I have this which
doesn't add any blocks:

(defun c:tb ()
(vl-load-com)
(setq obj (vlax-ename->vla-object (car (entsel "\nPick text")))) (setq str
(vlax-get obj 'textstring))
(setq obj (entget (car (entsel "\nPick text"))))
(setq str (cdr (assoc 1 obj)))
(setq x 0)
(repeat (strlen str) (setq char (substr str (setq x (+ x 1)) 1 ))
(cond ((= char "a" )(setq bname "Blocka" wid 1.12))
((= char "b" )(setq bname "Blockb" wid 1.0))
((= char "c" )(setq bname "Blockc" wid 0.85))
((alert (strcat "Character not supported " char))) )
(princ (strcat "\n" bname " " char)) )
)
Thanks
0 Likes
Message 33 of 43

Sea-Haven
Mentor
Mentor

I did say "CHANGE" it may be a Language thing, you said no VL code so delete the 2 VL lines and replace as I posted.

 

It wont add any blocks its up to you to provide a lot more info. If the text is 1 unit wide then your block should be also, hence WID factor. 

 

Start point X then add block then X=X+wid for next block point, keep going.

abc

x=0

x=1.12

x=2.12

 

You need to post some blocks so more advice can be supplied.

screenshot335.png

0 Likes
Message 34 of 43

rhgrafix
Enthusiast
Enthusiast

 I understand what change means but your original code was one giant long string so depending on where it word-wraps, line 2 could be anywhere. Here's a screenshot of abcde, the imaginary rectangles are .07"x.1", the kerning is not very important. The goal is to have very simple vector text so when I do laser printing, that is with an actual laser, they are thin crisp, very optimized, for now just as labels, it's functional, not pretty so kerning is not important, but filesize is kind of important with Glowforge, long story. I'm not a programmer so you can lose me easily, I can adjust values and text in a .lsp, not much more. My sample text:

abcde.png

Thanks.

0 Likes
Message 35 of 43

rhgrafix
Enthusiast
Enthusiast

That would work actually.

0 Likes
Message 36 of 43

ВeekeeCZ
Consultant
Consultant

@rhgrafix wrote:

When I run it, nothing happens. Probably no block found. Make "0" as a dummy block at least. It could be that since my Autocad license ran out No, it has nothing to do with that, I am now using IntelliCAD dunno about this which runs lisp fine until it sees vla code. Would the block name for each letter be in binary format eg. 'small a' would be 01100001? Or U+0061? It uses the decimals. See the code, there is 32 for a space. I made one of each but I can't so far as to pick the text. As noted before, it uses a dummo block for chars not found. Thanks for your help.


 

0 Likes
Message 37 of 43

pbejse
Mentor
Mentor

@ВeekeeCZ wrote:

Totally agree that there are plenty of information missing, so lots of assumptions needed.


Ah yes. waht Marcus Penn said

Nice code BTW.

 

0 Likes
Message 38 of 43

ВeekeeCZ
Consultant
Consultant

@pbejse wrote:

@ВeekeeCZ wrote:

Totally agree that there are plenty of information missing, so lots of assumptions needed.


Ah yes. waht Marcus Penn said

Nice code BTW.

 


Thx! Found it!, the reference. The US1 was good, 2... hmm, not sure if I made it to the end. Nonetheless, saw both dubbed. 

0 Likes
Message 39 of 43

ronjonp
Advisor
Advisor

@rhgrafix  Did you try Sean's T2G code? I still think it's perfect for what you doing. Another workaround ( less clean than T2G )... if you use SHX fonts use WMFOUT and WMFIN to create linework from text ... see attached.

0 Likes
Message 40 of 43

rhgrafix
Enthusiast
Enthusiast

I know you're trying to help but those letters are not optimized, the have a billion vertices, it has to be blocks that I make, I don't know how to be more clear. 

0 Likes