Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 01/22/2024 in all areas

  1. Here is my attempt. (defun c:Test (/ int sel ent get ) ;;----------------------------------------------------;; ;; Author : Tharwat Al Choufi ;; ;; website: https://autolispprograms.wordpress.com ;; ;;----------------------------------------------------;; (and (princ "\nSelect Mtexts to remove linebreaks entirely : ") (setq int -1 sel (ssget "_:L" '((0 . "MTEXT")))) (while (setq int (1+ int) ent (ssname sel int)) (entmod (subst (cons 1 (vl-string-translate "\\P" " " (cdr (assoc 1 (setq get (entget ent)))))) (assoc 1 get) get ) ) ) ) (princ) ) (vl-load-com)
    2 points
  2. Also, I did not explain that the application that writes the xlsx file to be read by AutoCAD is not AutoCAD. It is GPS software from another party. It writes out 13(?) decimals to the xlsx file, but I cannot get AutoCAD to read in more than 4 decimal places. Now I am wondering. I only looked at the number of decimal places in the AutoCAD vlisp editor and on the command line. Turns out I'm an idiot. If I do (RTOS Lat 2 13) of the latitude read in by AutoCAD, all the decimal digits are there. AutoCAD only returns the 1st four to the display. Having started lisp at v10 286, I'm pretty embarrassed to admit how many years I've know this. My sincere apologies for wasting your collective time.
    1 point
  3. @Tharwat Are you sure? I tested your exact original code, and it left behind a "P" where every line break was. Am I missing something? Just did it again to be sure. That's why I did the 2nd post afterwards.
    1 point
  4. Why didn't you say so before!! While we are taking out the line breaks adjusting the mtext width is able to be done at the same time The methods use above are using "entmod" to adjust the text, also in the entity definition is the code 41 which is the mtext width code something like: (if (= (cdr (assoc 41) 0) will find out if they are 0 width, and we can set a nominal width or calculate a width according to the font and number of characters used in each line I am going out this evening but might have a look at this later
    1 point
  5. You're in double luck.... I created a a similar routine in the same thread as pkenewell, an alternative method. Likewise, the same text length limit applies - can adjust these if that becomes an issue (for most things, 256 characters is usually enough except a notes block of text) (defun c:TxtRemCR ( / MySS SSCountMyEnt MyEntGet Mytext TextList OrderList NewText n acount) ; txt remove carriage returns ;;Sub Functions: ;;Starting with LM: Refer to Lee Macs website (defun LM:str->lst ( str del / pos ) (if (setq pos (vl-string-search del str)) (cons (substr str 1 pos) (LM:str->lst (substr str (+ pos 1 (strlen del))) del)) (list str) ) ) (defun LM:lst->str ( lst del ) (if (cdr lst) (strcat (car lst) del (LM:lst->str (cdr lst) del)) (car lst) ) ) (princ "\nSelect MText") ;; Note in command line "Select text" (setq MySS (ssget '((0 . "MTEXT")))) ;; Select objects with a selection set, filtered to 'MTEXT' entity type (setq SSCount 0) ;; Just a counter set to 0 (while (< SSCount (sslength MySS)) ;; loop through length or selection set using SSCount (setq MyEnt (ssname MySS SSCount)) ;; get the nth item in the selection set entity name (setq MyEntGet (entget MyEnt)) ;; get the entity definition from the above (setq MyText (cdr (assoc 1 MyEntGet))) ;; get the text from the entity (first 256 characters) (setq TextList (LM:str->lst MyText "\n")) ;; Convert the text string to a list, deliminator \n (new line) (setq MyEntGet (subst (cons 1 (LM:lst->str TextList " ")) (assoc 1 MyEntGet) MyEntGet)) (entmod MyEntGet) ;; Modify the text (setq SSCount (+ SSCount 1)) ) ; end while ); end function
    1 point
  6. @jim78b OOPS - I made a slight change to the routine above. Re-copy it from the post. I realized it changes everything to color 200, rather than changing everything inside blocks to ByBlock. corrected.
    1 point
  7. @Highvoltage You're in luck. I just created a very similar routine for another poster. In addition to the problem with (vl-string-subst), one of other the problems with using DXF is sometimes the mtext string is separated into multiple DXF codes if the text is more than 250 chars. The additional codes use DXF code 3 instead of 1. It's better to get the full text string using ActiveX and parsing it. Try the following instead: (defun c:mbch (/ _StrParse d obj ss tls txt) (vl-load-com) (vla-StartUndoMark (setq d (vla-get-activedocument (vlax-get-acad-object)))) (defun _StrParse (str del / pos) (if (and str del) (if (setq pos (vl-string-search del str)) (cons (substr str 1 pos) (_StrParse (substr str (+ pos 1 (strlen del))) del)) (list str) ) ) ) (princ "\nSelect MTEXT Objects: ") (if (setq ss (ssget '((0 . "MTEXT")))) (repeat (setq n (sslength ss)) (setq obj (vlax-ename->vla-object (ssname ss (setq n (1- n)))) txt (vla-get-textstring obj) tls (_strparse txt "\\P") ) (if (> (length tls) 1) (setq txt (apply 'strcat (cons (car tls)(mapcar '(lambda (x)(strcat " " x)) (cdr tls)))) obj (vla-put-textstring obj txt) ) ) ) ) (redraw) (vla-endundomark d) (princ) )
    1 point
  8. @pkenewell Please don't use my codes with yours nor modifying them.
    0 points
×
×
  • Create New...