manirpg Posted June 1, 2010 Share Posted June 1, 2010 Please some one help me is there any lisp for convert attribute definition(not block attribute) to text or mtext Quote Link to comment Share on other sites More sharing options...
David Bethel Posted June 1, 2010 Share Posted June 1, 2010 Here's an old one that should do the trick: ;======================================================================= ; Atd2Text.Lsp Feb 28, 2003 ; Change ATTDEF To Text Using Tag Name As Text Value ;================== Start Program ====================================== (princ "\nCopyright (C) 2003, Fabricated Designs, Inc.") (princ "\nLoading Atd2Text v1.1 ") (setq a2t_ nil lsp_file "Atd2Text") ;================== Macros ============================================= (defun PDot ()(princ ".")) (PDot);++++++++++++ Set Modes & Error ++++++++++++++++++++++++++++++++++ (defun a2t_smd () (SetUndo) (setq olderr *error* *error* (lambda (e) (while (> (getvar "CMDACTIVE") 0) (command)) (and (/= e "quit / exit abort") (princ (strcat "\nError: *** " e " *** "))) (command "_.UNDO" "_END" "_.U") (a2t_rmd)) a2t_var '(("CMDECHO" . 0) ("MENUECHO" . 0) ("MENUCTL" . 0) ("MACROTRACE" . 0) ("OSMODE" . 0) ("SORTENTS" . 119) ("BLIPMODE" . 0) ("MODEMACRO" . ".") ("SNAPMODE" . 0) ("UCSICON" . 1) ("ORTHOMODE" . 0) ("GRIDMODE" . 0) ("ELEVATION" . 0) ("THICKNESS" . 0) ("HIGHLIGHT" . 0) ("REGENMODE" . 1) ("CECOLOR" . "BYLAYER") ("CELTYPE" . "BYLAYER"))) (foreach v a2t_var (setq a2t_rst (cons (cons (car v) (getvar (car v))) a2t_rst)) (setvar (car v) (cdr v))) (princ (strcat (getvar "PLATFORM") " Release " (ver) " - Convert ATTDEF to TEXT ....\n")) (princ)) (PDot);++++++++++++ Return Modes & Error +++++++++++++++++++++++++++++++ (defun a2t_rmd () (setq *error* olderr) (foreach v a2t_rst (setvar (car v) (cdr v))) (command "_.UNDO" "_END") (prin1)) (PDot);++++++++++++ Set And Start An Undo Group ++++++++++++++++++++++++ (defun SetUndo () (and (zerop (getvar "UNDOCTL")) (command "_.UNDO" "_ALL")) (and (= (logand (getvar "UNDOCTL") 2) 2) (command "_.UNDO" "_CONTROL" "_ALL")) (and (= (logand (getvar "UNDOCTL") 8) (command "_.UNDO" "_END")) (command "_.UNDO" "_GROUP")) (PDot);************ Main Program *************************************** (defun a2t_ (/ olderr a2t_var a2t_rst st tc ss en ed i) (a2t_smd) (initget 1 "Tag Default Prompt") (setq st (getkword "\nMake Text Show ATTDEF -> Default/Prompt/Tag: ")) (cond ((= st "Tag") (setq tc 2)) ((= st "Prompt") (setq tc 3)) ((= st "Default") (setq tc 1))) (while (not ss) (setq ss (ssget '((0 . "ATTDEF"))))) (setq i (sslength ss)) (princ (strcat "\nChanging " (rtos i 2 0) " ATTDEFs to TEXT\n")) (while (not (minusp (setq i (1- i)))) (princ (strcat "\r" (rtos i 2 0) " ")) (setq en (ssname ss i) ed (entget en)) (entdel en) (entmake (list (cons 0 "TEXT") (cons 1 (cdr (assoc tc ed))) (assoc 7 ed) (assoc 8 ed) (assoc 10 ed) (assoc 11 ed) (if (assoc 39 ed) (assoc 39 ed) (cons 39 0.0)) (assoc 40 ed) (assoc 41 ed) (assoc 50 ed) (assoc 51 ed) (if (assoc 62 ed) (assoc 62 ed) (cons 62 256)) (assoc 71 ed) (assoc 72 ed) (cons 73 (cdr (assoc 74 ed))) (assoc 210 ed)))) (a2t_rmd)) (PDot);************ Load Program *************************************** (defun C:Atd2Text () (a2t_)) (if a2t_ (princ "\nAtd2Text Loaded\n")) (prin1) ;|================== End Program ======================================= -David Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted June 1, 2010 Share Posted June 1, 2010 Not trying to step on your toes David, but this should account for MText AttDefs also: (defun c:AttDef2Text ( / ss ) ;; © Lee Mac ~ 01.06.10 (vl-load-com) (if (setq ss (ssget "_:L" '((0 . "ATTDEF")))) ( (lambda ( i / e o ) (while (setq e (ssname ss (setq i (1+ i)))) (if ( (if (and (vlax-property-available-p (setq o (vlax-ename->vla-object e)) 'MTextAttribute) (eq :vlax-true (vla-get-MTextAttribute o))) MAttDef2MText AttDef2Text ) (entget e) ) (entdel e) ) ) ) -1 ) ) (princ) ) (defun AttDef2Text ( eLst / dx74 dx2 ) ;; © Lee Mac ~ 01.06.10 (setq dx74 (cdr (assoc 74 eLst)) dx2 (cdr (assoc 2 eLst))) (entmake (append '( (0 . "TEXT") ) (RemovePairs '(0 100 1 2 3 73 74 70 280) eLst) (list (cons 73 dx74) (cons 1 dx2) ) ) ) ) (defun MAttDef2MText ( eLst ) ;; © Lee Mac ~ 01.06.10 (entmake (append '( (0 . "MTEXT") (100 . "AcDbEntity") (100 . "AcDbMText") ) (RemoveFirstPairs '(40 50 41 7 71 72 71 72 73 10 11 11 210) (RemovePairs '(-1 102 330 360 5 0 100 101 1 2 3 42 43 51 74 70 280) eLst) ) (list (cons 1 (cdr (assoc 2 eLst)))) ) ) ) (defun RemoveFirstPairs ( pairs lst ) ;; © Lee Mac (defun foo ( pair lst ) (if lst (if (eq pair (caar lst)) (cdr lst) (cons (car lst) (foo pair (cdr lst))) ) ) ) (foreach pair pairs (setq lst (foo pair lst)) ) lst ) (defun RemovePairs ( pairs lst ) ;; © Lee Mac (vl-remove-if (function (lambda ( pair ) (vl-position (car pair) pairs) ) ) lst ) ) Quote Link to comment Share on other sites More sharing options...
David Bethel Posted June 1, 2010 Share Posted June 1, 2010 Lee, Not a problem. The OP is a bit vague. -David Quote Link to comment Share on other sites More sharing options...
manirpg Posted June 4, 2010 Author Share Posted June 4, 2010 Dear friends, David & Lee , Both of the codes working fine and amezing..................... Thanks lot.............:D:D:D mani Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted June 4, 2010 Share Posted June 4, 2010 You're welcome Quote Link to comment Share on other sites More sharing options...
WindowsIHateYou Posted July 11, 2014 Share Posted July 11, 2014 I tried that (post #3) and got the error as follows: ; error: no function definition: REMOVEPAIRS I tried #2 also, and it worked, but wouldn't retain the attribute values. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted July 12, 2014 Share Posted July 12, 2014 Did you copy all of the code in my post? Quote Link to comment Share on other sites More sharing options...
WindowsIHateYou Posted July 16, 2014 Share Posted July 16, 2014 Did you copy all of the code in my post? S.O.B. "Select all" in browser wouldn't stay in quote box. So I highlighted "all", but apparently "all" doesn't include the last parenthesis. Hence, once again, my username. Works fine now. Thanks Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted July 17, 2014 Share Posted July 17, 2014 You're welcome Quote Link to comment Share on other sites More sharing options...
reynaldomalasaga Posted February 23, 2017 Share Posted February 23, 2017 Is This code of yours David Bethel , will function even if the attribute is on block already ? sorry for my English :( Quote Link to comment Share on other sites More sharing options...
David Bethel Posted February 23, 2017 Share Posted February 23, 2017 In short, 'No' The original request was to convert the ATTDEF. Not the ATTRIBute. It can be done but certain criteria would have to be established. Is the block to be exploded or just have the ATTRIBUTEs stripped out ? Are all of the properties to be retained as is or match the insert A fairly complex operation. -David Quote Link to comment Share on other sites More sharing options...
reynaldomalasaga Posted February 24, 2017 Share Posted February 24, 2017 In short, 'No' The original request was to convert the ATTDEF. Not the ATTRIBute. It can be done but certain criteria would have to be established. Is the block to be exploded or just have the ATTRIBUTEs stripped out ? Are all of the properties to be retained as is or match the insert A fairly complex operation. -David Thank u sr. For your rply.. can you help me sir.. i need a code that will convert Attributes to mtext that the *block will not exploded *all of the properties to be retained as is. i have some code her .. but their is some error.. heheeheheheh Quote Link to comment Share on other sites More sharing options...
David Bethel Posted February 24, 2017 Share Posted February 24, 2017 I'm sorry bit I know next to nothing about MTEXT. I have programs that can convert regular TEXT ATTRIBute to regular TEXT. I'm afraid if either are MTEXT style entities, it would fail or crash. Hopefully someone can jump in a help out. I'll post what I have in a bit. -David Quote Link to comment Share on other sites More sharing options...
David Bethel Posted February 24, 2017 Share Posted February 24, 2017 This is pretty dangerous stuff. Please make backups of your original files To convert standard TEXT ATTRIButes into independent TEXT entities and set the ATTRIB to "" : [b][color=BLACK]([/color][/b]defun c:att2txt [b][color=FUCHSIA]([/color][/b]/ ss i en an ad av td[b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]defun remove [b][color=NAVY]([/color][/b]expr lst[b][color=NAVY])[/color][/b][color=#8b4513];;;TonyT or VNesterowski[/color] [b][color=NAVY]([/color][/b]apply 'append [b][color=MAROON]([/color][/b]subst nil [b][color=GREEN]([/color][/b]list expr[b][color=GREEN])[/color][/b] [b][color=GREEN]([/color][/b]mapcar 'list lst[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]and [b][color=NAVY]([/color][/b]princ [color=#2f4f4f]"\nSelect ATTRIBute INSERTs"[/color][b][color=NAVY])[/color][/b] [b][color=NAVY]([/color][/b]setq ss [b][color=MAROON]([/color][/b]ssget [b][color=GREEN]([/color][/b]list [b][color=BLUE]([/color][/b]cons 0 [color=#2f4f4f]"INSERT"[/color][b][color=BLUE])[/color][/b] [b][color=BLUE]([/color][/b]cons 66 1[b][color=BLUE])[/color][/b] [b][color=BLUE]([/color][/b]cons 70 0[b][color=BLUE])[/color][/b] [b][color=BLUE]([/color][/b]cons 71 0[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b] [b][color=NAVY]([/color][/b]setq i 0[b][color=NAVY])[/color][/b] [b][color=NAVY]([/color][/b]while [b][color=MAROON]([/color][/b]setq en [b][color=GREEN]([/color][/b]ssname ss i[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]setq an [b][color=GREEN]([/color][/b]entnext en[b][color=GREEN])[/color][/b] ad [b][color=GREEN]([/color][/b]entget an[b][color=GREEN])[/color][/b] av [b][color=GREEN]([/color][/b]cdr [b][color=BLUE]([/color][/b]assoc 1 ad[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]while [b][color=GREEN]([/color][/b]= [color=#2f4f4f]"ATTRIB"[/color] [b][color=BLUE]([/color][/b]cdr [b][color=RED]([/color][/b]assoc 0 ad[b][color=RED])[/color][/b][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b] [b][color=GREEN]([/color][/b]entmod [b][color=BLUE]([/color][/b]subst [b][color=RED]([/color][/b]cons 1 [color=#2f4f4f]""[/color][b][color=RED])[/color][/b] [b][color=RED]([/color][/b]assoc 1 ad[b][color=RED])[/color][/b] ad[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b] [b][color=GREEN]([/color][/b]setq td ad[b][color=GREEN])[/color][/b] [b][color=GREEN]([/color][/b]setq td [b][color=BLUE]([/color][/b]remove [b][color=RED]([/color][/b]assoc 2 td[b][color=RED])[/color][/b] td[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b] [b][color=GREEN]([/color][/b]setq td [b][color=BLUE]([/color][/b]remove [b][color=RED]([/color][/b]assoc 70 td[b][color=RED])[/color][/b] td[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b] [b][color=GREEN]([/color][/b]setq td [b][color=BLUE]([/color][/b]subst [b][color=RED]([/color][/b]cons 1 av[b][color=RED])[/color][/b] [b][color=RED]([/color][/b]assoc 1 td[b][color=RED])[/color][/b] td[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b] [b][color=GREEN]([/color][/b]setq td [b][color=BLUE]([/color][/b]subst [b][color=RED]([/color][/b]cons 0 [color=#2f4f4f]"TEXT"[/color][b][color=RED])[/color][/b] [b][color=RED]([/color][/b]assoc 0 td[b][color=RED])[/color][/b] td[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b] [b][color=GREEN]([/color][/b]setq td [b][color=BLUE]([/color][/b]subst [b][color=RED]([/color][/b]cons 73 [b][color=PURPLE]([/color][/b]cdr [b][color=TEAL]([/color][/b]assoc 74 td[b][color=TEAL])[/color][/b][b][color=PURPLE])[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b]assoc 74 td[b][color=RED])[/color][/b] td[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b] [b][color=GREEN]([/color][/b]entmake td[b][color=GREEN])[/color][/b] [b][color=GREEN]([/color][/b]setq an [b][color=BLUE]([/color][/b]entnext an[b][color=BLUE])[/color][/b] ad [b][color=BLUE]([/color][/b]entget an[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]entupd en[b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]setq i [b][color=GREEN]([/color][/b]1+ i[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]command [color=#2f4f4f]"_.REGENALL"[/color][b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]prin1[b][color=FUCHSIA])[/color][/b][b][color=BLACK])[/color][/b] MTEXT is not taken into account ( 'cause I know nothing about them ) The BLOCK definition is not modified, only the INSERT data Good Luck -David Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.