Jump to content

change width factor of attributed text and single line text


Recommended Posts

Hello all, got a little text style problem over here



Background info:


I am trying to tackle the problem of making a searchable PDF from a drawing with simplex font. From what I have read that is not possible without using OCR, which is unreliable. To work around this I am trying to convert ALL text in a drawing to Arial with width factor = 1, then print to PDF, then undo the changes and leave the font intact (permanently changing the font is not an option here due to standards that I cannot change).



So far, I have made a command that converts all text styles to Arial and width factor=1. Unfortunately, as pointed out in this thread, changing the text style width does not push changes to all text.





The problem:


I am trying to make a lisp routine that forces all text to adopt the width given by their text style (or simply a width of 1, doesn't matter to me). I have tried "REGEN" and "REGENALL"; neither worked. I'm thinking there's a way to do it with the right SSGET filter, but the documentation for SSGET is very confusing to me.



I have attached a drawing to show what I mean. The top text and bottom text both use the same style, yet the top text is narrower. I don't see widthfactor in the quick properties for it; the only way that I know of to change it is changing the text style and then changing it back again. I would like to be able to do it with a single command using lisp.


Any help would be greatly appreciated :)


Edited by aggie_moose
added more info
Link to comment
Share on other sites

According to Lee Mac (which means it's probably right), SSGET cannot search inside of blocks. Predictably, I got something that works for single text, but not block attributes.





However, borrowing heavily from this thread




I made the following code which manually changes single text and block attributes to width = 1 by going inside each block



(defun c:arial ()
(vla-get-textstyles (vla-get-activedocument (vlax-get-acad-object)))
 (vla-SetFont str_text_style "Arial" :vlax-False :vlax-False 0 32)
 (vla-put-width str_text_style 1.0)
 (vla-put-height str_text_style 0.0))
(StripMtext (ssget "x") "FHQW")
(command "regen")
;;start eat program
  CE (getvar "CMDECHO")
  SS (ssget "X" '((0 . "INSERT")))
  CN 0
(setvar "CMDECHO" 0)
(if SS
  (repeat (setq SL (sslength SS))
        SN (ssname SS CN)
        NE (entnext SN)
     (while (and
        (/= (setq EN (cdr (assoc 0 (setq DT (entget NE)))))
        ) ;_ end of /=
        ) ;_ end of and
        (if (= EN "ATTRIB")
              (setq DT (subst (cons 41 1) (assoc 41 DT) DT))
              (entmod DT)
              (entupd SN)
           ) ;_ end of progn
        ) ;_ end of if
        (setq NE (entnext NE))
     ) ;_ end of while
     (setq CN (1+ CN))
     ;;(repeat 25 (princ "\010"))
  ) ;_ end of repeat
      (princ "\nNo input")
(setvar "CMDECHO" CE)
 ;end ate program
(if (setq i -1 ss (ssget "_X" '((0 . "TEXT"))))
 (while (setq ent (ssname ss (setq i (1+ i))))
   (setq elst (entget ent))
   (entmod (subst (cons 41 1.0) (assoc 41 elst) elst))
   (entupd ent)))
(princ (strcat "Total " (itoa CN) " blocks were converted to Arial"))

Unfortunately it is very slow :/



I'm thinking the slowness is due to (ssget "X" '((0 . "INSERT")))



I'm not exactly sure whether that's making a set of every block (which is what I want) or making a set of every single object on the drawing. I suspect it's the latter but I don't know how to fix it.

Link to comment
Share on other sites

You don't have to (ssget "X" '((0 . "INSERT"))) to change the text within blocks.

Try this to change normal blocks (not dynamic blocks):

(setq blocks (vla-get-blocks (vla-get-ActiveDocument (vlax-get-acad-object))))
(vlax-for item blocks
   (if (/= "*" (substr (vla-get-Name item) 1 1))
     (vlax-for item1  (vla-item blocks (vla-get-Name item))
       (if (= "AcDbText" (vla-get-objectname item1))          
    (vla-put-ScaleFactor item1 1.0)
(mapcar '(lambda(x) (vla-put-ScaleFactor (vlax-ename->vla-object x) 1.0))
(vl-remove-if 'listp (mapcar 'cadr (ssnamex (ssget "_X" '((0 . "TEXT")))))))  
(vl-cmdf "regen")

Hope it can help.

Link to comment
Share on other sites

And if dynamic blocks, you use this :

(foreach ent (vl-remove-if 'listp (mapcar 'cadr (ssnamex (ssget "X" '((0 . "INSERT")(66 . 1))))))
 (while (and (setq ent (entnext ent))
      (/= (cdr (assoc 0 (entget ent))) "SEQEND"))
    (if (= "AcDbAttribute" (vla-get-objectname (setq obj (vlax-ename->vla-object ent))))
  (vla-put-ScaleFactor obj 1.0)

Link to comment
Share on other sites

Woo! Looks like your code is good, much better than what I had because I was missing attributed text in blocks with a width overwrite (which apparently accounts for about 90% of the text in our standard title block).






The only change I made was adding



(if (/= nil (ssget "X" '((0 . "INSERT")(66 . 1))) 

...your dynamic block code...


because it was giving an error when there were no blocks in the drawing. Same thing with the mapcar command, I surrounded it with an if statement so it wouldn't bomb out on me.



Now I finally have the ability to batch print drawings with .shx fonts into searchable pdfs! How cool is that?! :excited:

Link to comment
Share on other sites

  • 2 years later...



I am hoping you can help me out. I have the same issue, trying to get searchable PDF files from AutoCAD when the AutoCAD file contains SHX text OR TT text with a Text Width Factor not equal to 1.0 OR the oblique angle not equal to 0. I want to batch convert the files and LEAVE them in the fixed state. We use AutoCAD 2015 and files are stored in Autodesk Vault 2015. We would like to "batch" process the files. I also need to go into blocks that have attributed text like our title blocks. Can you share what you were able to make work please please...:)

Link to comment
Share on other sites

using a script you can open, modify, save and close as many dwg's as you like the script will have a pretty simple 1 line per dwg. The code to put in say Text2-1.lsp is above.


OPEN DWG1 (load "TEXT2-1") save close

OPEN DWG2 (load "TEXT2-1") save close

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...