Jump to content

Lisp to find and replace text of a certain font.


Recommended Posts

Posted

On some projects we work in Solid Edge, and then translate the drawings to AutoCAD for the customer. When Solid Edge is installed on a machine it installs certain fonts, one of which is a symbols font for Geometric Tolerances. If a customer opens the autocad translation they can't see the geo tol symbols because they don't have the fonts on their machines. Some are ok with us sending them the fonts, others are not. So I'd like to write a lisp that would change the style to use the autocad gdt font, after finding and replacing the text of the solid edge font with the letters that the autocad gdt font uses. This will have to work within blocks and probably mtext. So I would need to be able to find and replace single letters that only occur on a certain text style, so all the letters in the drawing aren't replaced.

Posted

You could select all Text/MText of a certain TextStyle using:

 

(ssget "_X" '((0 . "TEXT,MTEXT") (7 . "YourTextStyleHere")))

 

Or perhaps all Text/MText of a certain style, and all attributed blocks:

 

(ssget "_X"
'(
   (-4 . "<OR")
     (-4 . "<AND")
       (0 . "TEXT,MTEXT")
       (7 . "YourTextStyleHere")
     (-4 . "AND>")
     (-4 . "<AND")
       (0 . "INSERT")
       (66 . 1)
     (-4 . "AND>")
   (-4 . "OR>")
 )
)

Posted

Will the first one work for text within non-attributed blocks?

Posted
Will the first one work for text within non-attributed blocks?

 

No, ssget will only select primary entities, for text entities within blocks you will need to look through and modify the block definition within the block table.

Posted

Now how do I find & replace within the selection set.

Posted

If you wanted to dig through block definitions, this would be how I might approach it:

 

(defun GetBlockEntities ( block / lst )
 (reverse
   (if (setq block (tblobjname "BLOCK" block))
     (while (setq block (entnext block))
       (setq lst (cons block lst))
     )
   )
 )
)

 

Or recursively,

(defun GetBlockEntities ( block )

 (defun EntnextToEnd ( e )
   (if (setq e (entnext e))
     (cons e (EntnextToEnd e))
   )
 )

 (if (setq block (tblobjname "BLOCK" block))
   (EntnextToEnd block)
 )
)

Posted
Now how do I find & replace within the selection set.

 

Well, first you'd have to iterate through the items in the selection set using a loop construct coupled with ssname perhaps.

 

Then, there are many ways to perform the replacement - you could use substr to look through each character individually, or vl-string-subst within a loop to account for all occurrences, or even RegularExpressions using the RegExp object.

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.

Guest
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...