Jump to content

Mtext instand bylayer


CAD

Recommended Posts

Hello Ronjonp,

 

dont know formating but when u double click mtext u can change the color or bylayer. but with properties u can change bylayer but it wont change the color. so i want internal of the mtext bylayer.

 

the HERE

I only need mtext to be bylayer not all object of the drawing. but thx for replying :)

Link to comment
Share on other sites

Hello Ronjonp,

 

I only need mtext to be bylayer not all object of the drawing. but thx for replying :)

 

Grab the code I linked to and replace the _objecttobylayer function with this:

(defun _objecttobylayer	(obj / layer)
 (cond	((eq "AcDbMText" (vlax-get obj 'objectname))
 (vl-catch-all-apply 'vlax-put (list obj 'color 256))
)
 )
)

Link to comment
Share on other sites

Is there not a smaller lisp only for Mtext. this lisp is a risk to my drawing with a wrong move. :)

 

have replace but think i doing it wrong

 

(defun c:DrawingToByLayer

   ;;-----------------------------------------------------------------
   ;;
   ;;  Copyright © 2004 Michael Puckett. All Rights Reserved
   ;;
   ;;-----------------------------------------------------------------
   ;;
   ;;  Forces the entire drawing to "ByLayer" (even xrefs for
   ;;  the lifetime of the session or until an xref reload
   ;;  occurs).
   ;;
   ;;  Forces block definition child entities to layer "0".
   ;;
   ;;  Existing attributes are forced to the same layer the
   ;;  parent block reside on.
   ;;
   ;;  Nominally tested, let me know if you find anything wonky.
   ;;
   ;;  * Use at your own risk. Please test on a dummy dwg *
   ;;
   ;;-----------------------------------------------------------------

   (   /
       _UnLockAllLayers
       _LockLayers
       _ObjectToLayerZero
       _ObjectToByLayer
       _DocumentToByLayer
       _Main
   )

   (defun _UnLockAllLayers ( document / result )
       (vlax-for layer
           (vlax-get-property
               document
              'Layers
           )
           (cond
               (   (eq :vlax-true
                       (vlax-get-property
                           layer
                          'Lock
                       )
                   )
                   (vlax-put-property
                       layer
                      'Lock
                       :vlax-false
                   )
                   (setq result
                       (cons layer
                           result
                       )
                   )
               )
           )
       )
       result
   )

   (defun _LockLayers ( layers )
       (foreach layer layers
           (vlax-put-property
               layer
              'Lock
               :vlax-true
           )
       )
   )

   (defun _ObjectToLayerZero ( object )
       (vlax-put-property object
          'Layer
          "0"
       )
   )

   (defun _objecttobylayer	(obj / layer)
 (cond	((eq "AcDbMText" (vlax-get obj 'objectname))
 (vl-catch-all-apply 'vlax-put (list obj 'color 256))
)
 )
)
       (cond
           (   (and
                   (eq "AcDbBlockReference"
                       (vlax-get
                           obj
                          'ObjectName
                       )
                   )
                   (eq :vlax-true
                       (vlax-get-property
                           obj
                          'HasAttributes
                       )
                   )
               )
               (setq layer (vlax-get-property obj 'Layer))
               (foreach child (vlax-invoke obj 'GetAttributes)
                   (_ObjectToByLayer child)
                   (vlax-put-property child 'Layer layer)
               )
           )
       )
   )

   (defun _DocumentToByLayer ( document )
       (vlax-for block (vlax-get-property document 'Blocks)
           (if 
               (eq :vlax-true
                   (vlax-get-property block
                      'IsLayout
                   )
               )
               (vlax-for object block
                   (_ObjectToByLayer object)
               )
               (vlax-for object block
                   (_ObjectToByLayer object)
                   (_ObjectToLayerZero object)
               )
           )
       )
   )

   (defun _Main ( / document lockedLayers )
       (setq lockedLayers
           (_UnlockAllLayers
               (setq document
                   (vlax-get-property
                       (vlax-get-acad-object)
                      'ActiveDocument
                   )
               )
           )
       )
       (_DocumentToByLayer document)
       (_LockLayers lockedLayers)
       (princ)
   )

   (_Main)

)

Edited by CAD
Link to comment
Share on other sites

(defun c:drawingtobylayer
      ;;-----------------------------------------------------------------
      ;;
      ;;  Copyright © 2004 Michael Puckett. All Rights Reserved
      ;;
      ;;-----------------------------------------------------------------
      ;;
      ;;  Forces the entire drawing to "ByLayer" (even xrefs for
      ;;  the lifetime of the session or until an xref reload
      ;;  occurs).
      ;;
      ;;  Forces block definition child entities to layer "0".
      ;;
      ;;  Existing attributes are forced to the same layer the
      ;;  parent block reside on.
      ;;
      ;;  Nominally tested, let me know if you find anything wonky.
      ;;
      ;;  * Use at your own risk. Please test on a dummy dwg *
      ;;
      ;;-----------------------------------------------------------------
      (/ _unlockalllayers _locklayers _objecttolayerzero _objecttobylayer _documenttobylayer _main)
 (defun _unlockalllayers (document / result)
   (vlax-for layer (vlax-get-property document 'layers)
     (cond ((eq :vlax-true (vlax-get-property layer 'lock))
     (vlax-put-property layer 'lock :vlax-false)
     (setq result (cons layer result))
    )
     )
   )
   result
 )
 (defun _locklayers (layers) (foreach layer layers (vlax-put-property layer 'lock :vlax-true)))
 ;; (defun _objecttolayerzero (object) (vlax-put-property object 'layer "0"))
 (defun _objecttobylayer (obj / layer)
   (cond ((eq "AcDbMText" (vlax-get obj 'objectname))
   (vl-catch-all-apply 'vlax-put (list obj 'color 256))
   (vl-catch-all-apply
     'vlax-put
     (list obj 'textstring (lm:unformat (vla-get-textstring obj) t))
   )
  )
   )
 )
 (defun _documenttobylayer (document)
   (vlax-for block (vlax-get-property document 'blocks)
     (if (eq :vlax-true (vlax-get-property block 'islayout))
(vlax-for object block (_objecttobylayer object))
(vlax-for object block (_objecttobylayer object))
     )
   )
 )
 (defun _main (/ document lockedlayers)
   (setq lockedlayers
   (_unlockalllayers
     (setq document (vlax-get-property (vlax-get-acad-object) 'activedocument))
   )
   )
   (_documenttobylayer document)
   (_locklayers lockedlayers)
   (princ)
 )
 (_main)
)


;;-------------------=={ UnFormat String }==------------------;;
;;                                                            ;;
;;  Returns a string with all MText formatting codes removed. ;;
;;------------------------------------------------------------;;
;;  Author: Lee Mac, Copyright © 2011 - www.lee-mac.com       ;;
;;------------------------------------------------------------;;
;;  Arguments:                                                ;;
;;  str - String to Process                                   ;;
;;  mtx - MText Flag (T if string is for use in MText)        ;;
;;------------------------------------------------------------;;
;;  Returns:  String with formatting codes removed            ;;
;;------------------------------------------------------------;;

(defun lm:unformat (str mtx / _replace rx)
 (defun _replace (new old str)
   (vlax-put-property rx 'pattern old)
   (vlax-invoke rx 'replace str new)
 )
 (if (setq rx (vlax-get-or-create-object "VBScript.RegExp"))
   (progn (setq str
	  (vl-catch-all-apply
	    (function
	      (lambda ()
		(vlax-put-property rx 'global actrue)
		(vlax-put-property rx 'multiline actrue)
		(vlax-put-property rx 'ignorecase acfalse)
		(foreach pair
			 '(("\032" . "\\\\\\\\")
			   (" " . "\\\\P|\\n|\\t")
			   ("$1"
			    .
			    "\\\\(\\\\[ACcFfHLlOopQTW])|\\\\[ACcFfHLlOopQTW][^\\\\;]*;|\\\\[ACcFfHLlOopQTW]"
			   )
			   ("$1$2/$3" . "([^\\\\])\\\\S([^;]*)[/#\\^]([^;]*);")
			   ("$1$2" . "\\\\(\\\\S)|[\\\\](})|}")
			   ("$1" . "[\\\\]({)|{")
			  )
		  (setq str (_replace (car pair) (cdr pair) str))
		)
		(if mtx
		  (_replace "\\\\"
			    "\032"
			    (_replace "\\$1$2$3" "(\\\\[ACcFfHLlOoPpQSTW])|({)|(})" str)
		  )
		  (_replace "\\" "\032" str)
		)
	      )
	    )
	  )
   )
   (vlax-release-object rx)
   (if (null (vl-catch-all-error-p str))
     str
   )
   )
 )
)
(vl-load-com)

Edited by ronjonp
Link to comment
Share on other sites

Hello Ronjonp,

 

i have try Lee mac lisp and load it, but when i type unformat nothing happen?:o

 

;;-------------------=={ UnFormat String }==------------------;;
;;                                                            ;;
;;  Returns a string with all MText formatting codes removed. ;;
;;------------------------------------------------------------;;
;;  Author: Lee Mac, Copyright © 2011 - www.lee-mac.com       ;;
;;------------------------------------------------------------;;
;;  Arguments:                                                ;;
;;  str - String to Process                                   ;;
;;  mtx - MText Flag (T if string is for use in MText)        ;;
;;------------------------------------------------------------;;
;;  Returns:  String with formatting codes removed            ;;
;;------------------------------------------------------------;;

(defun LM:UnFormat ( str mtx / _replace rx )

   (defun _replace ( new old str )
       (vlax-put-property rx 'pattern old)
       (vlax-invoke rx 'replace str new)
   )
   (if (setq rx (vlax-get-or-create-object "VBScript.RegExp"))
       (progn
           (setq str
               (vl-catch-all-apply
                   (function
                       (lambda ( )
                           (vlax-put-property rx 'global     actrue)
                           (vlax-put-property rx 'multiline  actrue)
                           (vlax-put-property rx 'ignorecase acfalse) 
                           (foreach pair
                              '(
                                   ("\032"    . "\\\\\\\\")
                                   (" "       . "\\\\P|\\n|\\t")
                                   ("$1"      . "\\\\(\\\\[ACcFfHLlOopQTW])|\\\\[ACcFfHLlOopQTW][^\\\\;]*;|\\\\[ACcFfHLlOopQTW]")
                                   ("$1$2/$3" . "([^\\\\])\\\\S([^;]*)[/#\\^]([^;]*);")
                                   ("$1$2"    . "\\\\(\\\\S)|[\\\\](})|}")
                                   ("$1"      . "[\\\\]({)|{")
                               )
                               (setq str (_replace (car pair) (cdr pair) str))
                           )
                           (if mtx
                               (_replace "\\\\" "\032" (_replace "\\$1$2$3" "(\\\\[ACcFfHLlOoPpQSTW])|({)|(})" str))
                               (_replace "\\"   "\032" str)
                           )
                       )
                   )
               )
           )
           (vlax-release-object rx)
           (if (null (vl-catch-all-error-p str))
               str
           )
       )
   )
)
(vl-load-com)

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.

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