Lisp TXT to ATT (help to modify)

Lisp TXT to ATT (help to modify)

Edwin.Saez
Advisor Advisor
5,941 Views
18 Replies
Message 1 of 19

Lisp TXT to ATT (help to modify)

Edwin.Saez
Advisor
Advisor

hi everyone!

 

I found the following Lee Mac routine, and I need you to help me modify it.
lisp converts the text to attributes.

 

- I need them to be able to convert texts that are inside the block, without having to enter the block.
- when they are already converted, they are assigned the default property "Multiples Lines".
- The default text of the ATT, should not have "_" between texts.

 

Thanks for the help

 

;; Txt2Att  ( Lee Mac )
;; Converts Single-line Text to Attribute Definition

(defun c:txt2att ( / StringSubst RemovePairs ss ent eLst str dx73 )
  (vl-load-com)
  ;; Lee Mac  ~  27.04.10

  (defun StringSubst ( new pat str )
    (while (vl-string-search pat str)
      (setq str (vl-string-subst new pat str))
    )
    str
  )

  (defun RemovePairs ( lst pairs )
    (vl-remove-if
      (function
        (lambda ( pair )
          (vl-position (car pair) pairs)
        )
      )
      lst
    )
  )

  (if (setq ss (ssget "_:L" '((0 . "TEXT"))))
    
    ( (lambda ( i )
        
        (while (setq ent (ssname ss (setq i (1+ i))))
          (setq eLst (entget ent)
                str  (StringSubst "_" " " (cdr (assoc 1 eLst)))
                dx73 (cdr (assoc 73 eLst)))

          (setq eLst (RemovePairs eLst '( 0 100 1 73 )))

          (if (entmake (append '( (0 . "ATTDEF") ) eLst (list (cons 70    0)
                                                              (cons 74 dx73)
                                                              (cons 1   str)
                                                              (cons 2   str)
                                                              (cons 3   str))))
            (entdel ent)
          )
        )
      )
      -1
    )
  )

  (princ))

Edwin Saez


LinkedIn / AutoCAD Certified Professional


EESignature


 


Si mi respuesta fue una solución para usted, por favor seleccione "Aceptar Solución", para que también sirva a otro usuarios.

0 Likes
Accepted solutions (1)
5,942 Views
18 Replies
Replies (18)
Message 2 of 19

pbejse
Mentor
Mentor

@Edwin.Saez.Jamanca wrote:

hi everyone!

 

I found the following Lee Mac routine, and I need you to help me modify it.
lisp converts the text to attributes.

 

- I need them to be able to convert texts that are inside the block, without having to enter the block.
- when they are already converted, they are assigned the default property "Multiples Lines".
- The default text of the ATT, should not have "_" between texts.

 

Thanks for the helP


 

Easier to REDEFINE a block Edwin. Once you modify one of the instances of the block the rest will follow. Have the UPDATED block at the ready, include the block onto your Tool palette and you're done.

 

 

redefine.png 

- Not sure what that means

 

- off topic -

I remember a month or so ago, I was blasted by giving the same suggestion Smiley Very Happy

 

 

0 Likes
Message 3 of 19

Edwin.Saez
Advisor
Advisor

@pbejse,

 

THANKS FOR ANSWERING,
WHAT HAPPENS IS THAT I HAVE 100 DIFFERENT BLOCKS HAVING TEXTS WITHIN THE BLOCK, AND THAT I WANT THAT TEXTS TO BE ATTRIBUTED, NOT TO ENTER INTO EVERY BLOCK AND CREATE A NEW ATTRIBUTE.

Edwin Saez


LinkedIn / AutoCAD Certified Professional


EESignature


 


Si mi respuesta fue una solución para usted, por favor seleccione "Aceptar Solución", para que también sirva a otro usuarios.

0 Likes
Message 4 of 19

pbejse
Mentor
Mentor

@Edwin.Saez.Jamanca wrote:

@pbejse,

 

THANKS FOR ANSWERING,
WHAT HAPPENS IS THAT I HAVE 100 DIFFERENT BLOCKS HAVING TEXTS WITHIN THE BLOCK, AND THAT I WANT THAT TEXTS TO BE ATTRIBUTED, NOT TO ENTER INTO EVERY BLOCK AND CREATE A NEW ATTRIBUTE.


Wow. Deja Vu and All caps at that.

 

TEXTS - plural , each one will be converted to multiline attribtue or combined all text ito one multiline attribute?

 

Can you post a sample block?

 

 

0 Likes
Message 5 of 19

Edwin.Saez
Advisor
Advisor

I attached a dwg example of the blocks.

there are 2 types of blocks:

 

- blocks that have single line text (text)
- blocks that have multi-line text (Mtext)

 

lisp should work for both options.
similar to the lisp of lee mac, but without having to enter the block editor, and that convert to attribute the texts.
in the case of texts of several lines (Mtext) must combine all the Mtext, in one multiline attribute.

 

Thanks for the help @pbejse.

Edwin Saez


LinkedIn / AutoCAD Certified Professional


EESignature


 


Si mi respuesta fue una solución para usted, por favor seleccione "Aceptar Solución", para que también sirva a otro usuarios.

0 Likes
Message 6 of 19

pbejse
Mentor
Mentor

Both strings on blocks are MTEXT.

 

Are you saying if the MTEXT is just one line convert it to an attribute and more than one then convert it to a MultiLine attribute?

 

Or convert MTEXT to multiline attribute regardless? and if it's a TEXT entity just a regular attribute?

 

What you need to show is a BEFORE and AFTER so there would be no confusion.

 

 

 

 

 

0 Likes
Message 7 of 19

Edwin.Saez
Advisor
Advisor

pbejse escribió:

Both strings on blocks are MTEXT.


if I know, but lisp should work for text and Mtext, since other blocks are with text


 

Are you saying if the MTEXT is just one line convert it to an attribute and more than one then convert it to a MultiLine attribute?


if, the text make it an attribute.
mtext that is also a single attribute. Only the content of the mtext is in separate line; this should be a single attribute.

Edwin Saez


LinkedIn / AutoCAD Certified Professional


EESignature


 


Si mi respuesta fue una solución para usted, por favor seleccione "Aceptar Solución", para que también sirva a otro usuarios.

0 Likes
Message 8 of 19

Edwin.Saez
Advisor
Advisor

@pbejse,

 

Attached dwg, with the blocks as they are now, and how they should be.

Edwin Saez


LinkedIn / AutoCAD Certified Professional


EESignature


 


Si mi respuesta fue una solución para usted, por favor seleccione "Aceptar Solución", para que también sirva a otro usuarios.

0 Likes
Message 9 of 19

pbejse
Mentor
Mentor

Ok, before I begin, The blocks to be processed have only one item of either a MTEXT or a TEXT? There are no blocks that have multiple text/mtext entity, and by that, I mean more than one text/mtext object not string lines. Correct?

 

 

 

0 Likes
Message 10 of 19

jackshield
Collaborator
Collaborator
i cannot think of any native autocad solutions. you can redefine the block, but getting the new attribute to absorb the existing text value may not be possible. the lisp routine might work if blocks are exploded, if you can live without the blocks
0 Likes
Message 11 of 19

pbejse
Mentor
Mentor

Command: TXT2MATT

 

HTH

Message 12 of 19

Edwin.Saez
Advisor
Advisor

Patrick,

 

It works very well.

the only thing I want you to add is that all attributes have the property of multiple lines.

 

thanks Smiley Happy

Edwin Saez


LinkedIn / AutoCAD Certified Professional


EESignature


 


Si mi respuesta fue una solución para usted, por favor seleccione "Aceptar Solución", para que también sirva a otro usuarios.

0 Likes
Message 13 of 19

pbejse
Mentor
Mentor
Accepted solution

@Edwin.Saez.Jamanca wrote:

Patrick,

 

It works very well.

the only thing I want you to add is that all attributes have the property of multiple lines.

 

thanks Smiley Happy


Thought you wanted single attributes for single lines.

 

Try the quick mod [ txtAll2Matt.lsp ] 

 

HTH

 

Message 14 of 19

Edwin.Saez
Advisor
Advisor

@pbejse,

 

is perfect for me
a question, could the boundary width "0" the attribute?

 

thanks always for the help!

you are a crackSmiley Happy

Edwin Saez


LinkedIn / AutoCAD Certified Professional


EESignature


 


Si mi respuesta fue una solución para usted, por favor seleccione "Aceptar Solución", para que también sirva a otro usuarios.

0 Likes
Message 15 of 19

pbejse
Mentor
Mentor

@Edwin.Saez.Jamanca wrote:

@pbejse,

 

is perfect for me
a question, could the boundary width "0" the attribute?

 

thanks always for the help!

you are a crack Smiley Happy


Yes, just get rid of this line

 

....
(vla-put-MTextBoundaryWidth NewMultilineAttribute (vlax-get (Cdr f) 'width))
...

BUT more coding would be needed to add the //P per line based on the existing STRING content. 

 

Not sure if that's a good thing Smiley Very Happy

 

We'll continue tomorrow edwin, 

 

Cheers

 

Message 16 of 19

Edwin.Saez
Advisor
Advisor

@pbejse,

 


 

 

BUT more coding would be needed to add the //P per line based on the existing STRING content. 

  


This is what I need...Smiley Embarassed

 

thanks Patrick! you are a genious!! Smiley Happy

 

Edwin Saez


LinkedIn / AutoCAD Certified Professional


EESignature


 


Si mi respuesta fue una solución para usted, por favor seleccione "Aceptar Solución", para que también sirva a otro usuarios.

0 Likes
Message 17 of 19

pbejse
Mentor
Mentor

@Edwin.Saez.Jamanca wrote:

 


 BUT more coding would be needed to add the //P per line based on the existing STRING content. 

  

This is what I need...Smiley Embarassed  


Not a big fan of "//P" myself. so I'm not really in agreement with your request there edwin. I think you're better off with the mtext width as it was before it was converted to Multiline Attribute.

 

But really that's just me stalling. Smiley Very Happy

 

 

0 Likes
Message 18 of 19

Edwin.Saez
Advisor
Advisor

@pbejse,

 

thanks for answering patrick.


what happens is that I do not like to see the attribute grips when it has a width width other than 0. That's why I wanted the value to be kept at 0, and depending on the content of the existing text, you can do a line break , just as you mentioned it. Smiley Frustrated

Anyway, I appreciate your help. 🙂

Edwin Saez


LinkedIn / AutoCAD Certified Professional


EESignature


 


Si mi respuesta fue una solución para usted, por favor seleccione "Aceptar Solución", para que también sirva a otro usuarios.

0 Likes
Message 19 of 19

jackshield
Collaborator
Collaborator
Did this resolve the issue of retaining the text value defined in block?
0 Likes