Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Find and replace multileader text with LISP

19 REPLIES 19
Reply
Message 1 of 20
bdsmls
5821 Views, 19 Replies

Find and replace multileader text with LISP

I'm looking for a lisp routine that can find and replace multileader text.

I want to replace "T." with "T+" and "B." with "B+".

All the multileaders are on layers with a suffix of "-elev".

Any help will be greatly appreciated.

 

Thanks in advance,

Larry

19 REPLIES 19
Message 2 of 20
pbejse
in reply to: bdsmls


@bdsmls wrote:

I'm looking for a lisp routine that can find and replace multileader text.

I want to replace "T." with "T+" and "B." with "B+".

All the multileaders are on layers with a suffix of "-elev".

Any help will be greatly appreciated.

 

Thanks in advance,

Larry


command:  _find
     
settings....
Text types
Dimension/Leader text

 
Why the need for lisp codes?

 

Anyway, since i'm replying.

 

(defun c:REpME  (/ sel e)
      (setq sel (ssget "_X" '((0 . "MULTILEADER")(8 . "*-elev"))))
      (repeat (sslength sel)
            (setq e (vlax-ename->vla-object (ssname sel 0)))
            (vla-put-textstring
                  e
                  (vl-string-translate
                        "B.T."
                        "B+T+"
                        (vla-get-textstring e)))
            (ssdel (ssname sel 0) sel)
            )
      )

 

HTH

Message 3 of 20
pbejse
in reply to: pbejse

Scratch the previous post

 

This is more specific:

 

(defun c:REpME  (/ sel e)
      (if (setq sel (ssget '((0 . "MULTILEADER")(8 . "*-elev"))))
	      (repeat (sslength sel)
	            (setq e (vlax-ename->vla-object (ssname sel 0))
	                   str (vla-get-textstring e))
	            (if (setq f	 
		            (cond
		            	((wcmatch str "*B.*") (list "B." "B+"))
			        ((wcmatch str "*T.*") (list "T." "T+"))))
			(vla-put-textstring e
	                (vl-string-subst (cadr f)(car f) str) )
	                		
	                                )
	            (ssdel (ssname sel 0) sel)
	            )
          )
          (princ)
      )

 

 

Message 4 of 20
bdsmls
in reply to: bdsmls

That's what i was looking for. Thanks for your help.

 

Larry

Message 5 of 20
alanjt_
in reply to: pbejse

@pbejse: FYI, wcmatch IS case sensitive.

Message 6 of 20
pbejse
in reply to: alanjt_

You are absolutely right.. my mistake Smiley Wink

 

Thanks Alanjt.....

Message 7 of 20
bbarkman.jedson
in reply to: bdsmls

Would this work if a block with an attribute is embedded in the multileader?

Message 8 of 20
pbejse
in reply to: bbarkman.jedson


@bbarkman.jedson wrote:

Would this work if a block with an attribute is embedded in the multileader?


Yes i think its possible, what do you have in mind? 

Message 9 of 20
bbarkman.jedson
in reply to: pbejse

Our revision tag is a block embedded in a multileader with the one attribute (REVNUM). I am prompting the user for the current revision letter/number (so the routine knows which values to look for) and the desired revision. I'd like to check the current value from the user against what's in the multileader. If there's a match, change it. If not, do nothing. In the same routine I'm also looking at regular blocks via the attribute name. That way if a block or multileader with that block is inserted they all get checked. When the attribute tag name is found the routine proceeds accordingly. This works fine with regular blocks. The only thing missing is the "if" action for multileaders. They get changed no matter what, which means a revision tag could be altered when it shouldn't. The current code is attached. Much of it was provided by Lee McDonnell.
Message 10 of 20
bbarkman.jedson
in reply to: bdsmls

Here's the code.

Message 11 of 20
pbejse
in reply to: bbarkman.jedson

Sounds simple enough, before anything elseI notice the program name is Revup, Does that mean if i change all 4 to 5, the existing 5 will remain as 5 or be bump-up to 6 and so on?

Message 12 of 20
pbejse
in reply to: pbejse

Well, cant wait for you to reply. its getting pretty late here.

but if its just changing one value to another

 

(defun c:Revup ( / aDoc source SVal Mle MleD AT2Edit)
(defun _CheckMl (Tag ent / a)
      (vlax-for  itm  ent
            (if (and (eq (vla-get-Objectname itm)
                         "AcDbAttributeDefinition")
                     (eq (vla-get-TagString
                               itm) Tag))
                  (setq a (vla-get-ObjectID itm))))
      		a
      	)
       (setq aDoc (vla-get-ActiveDocument (vlax-get-acad-object)))
	(if (and
		(setq ssmldrs (ssget "X" '((0 . "MULTILEADER"))))
		(setq oldval (strcase (getstring "\nEnter current value: ")))
		(setq newval (strcase (getstring "\nEnter new value: ")))
	  	)
	  (repeat (setq i (sslength ssmldrs))
		(if (and (= (vla-get-ContentType
	                  (setq Mle  (vlax-ename->vla-object (ssname ssmldrs (setq i (1- i))))))  1)
                          (setq MleD (vla-item (vla-get-blocks  Adoc)
                                                (vla-get-ContentBlockName Mle)))
                          (setq AT2Edit (_CheckMl "REVNUM" MleD))
			  (eq (vla-GetBlockAttributeValue  Mle AT2Edit) oldval)
			 ) 
			  (vla-SetBlockAttributeValue  Mle  AT2Edit newval)
                         )
                   )(vla-regen aDoc acActiveViewport )
             )
        (princ)
       )
(vl-load-com)
(princ)

 HTH

 

 

Message 13 of 20
bbarkman.jedson
in reply to: pbejse

RevUp is just what I chose to call the command. When run, the first prompt is "Enter Current Value:" Second prompt is "Enter New Value:" Example: User enters "A" for current value and "0" for new value. Command will look at blocks and multileaders for the attribute named REVNUM. If it finds that attribute, it looks at its value. If the current value in the attribute is A, it is changed to 0. (That way other revisions the user does not wish to change will be left alone.) This works fine for blocks. For multileaders, it works if the value exists (in this case "A"), but if the value does not exist it gets changed anyway. I only want to change attribute values if there is a match between what's currently in the attribute and what the user enters for "current value." It's too bad that the usual functions can't reach inside a multileader containing a block without bending over backwards in the code. Does that help?
Message 14 of 20
bbarkman.jedson
in reply to: pbejse

Thanks, gave it a quick run. Unfortunately, it changed all mleaders regardless.
Message 15 of 20
pbejse
in reply to: bbarkman.jedson

Works fine here. post a sample drawing with the mleader.

 

Make sure you run the code i posted [post # 12]

Better yet rename the defun to something else

 

Anyhoo. try this 

 

(defun c:RevOne ( / aDoc source SVal Mle MleD AT2Edit)
(defun _CheckMl (Tag ent / a)
      (vlax-for  itm  ent
            (if (and (eq (vla-get-Objectname itm)
                         "AcDbAttributeDefinition")
                     (eq (vla-get-TagString
                               itm) Tag))
                  (setq a (vla-get-ObjectID itm))))
      		a
      	)
       (setq aDoc (vla-get-ActiveDocument (vlax-get-acad-object)))
	(if (and
		(setq ssmldrs (ssget "X" '((0 . "MULTILEADER"))))
		(setq oldval (strcase (getstring "\nEnter current value: ")))
		(setq newval (strcase (getstring "\nEnter new value: ")))
	  	)
	  (repeat (setq i (sslength ssmldrs))
		(if (and (= (vla-get-ContentType
	                  (setq Mle  (vlax-ename->vla-object (ssname ssmldrs (setq i (1- i))))))  1)
                          (setq MleD (vla-item (vla-get-blocks  Adoc)
                                                (vla-get-ContentBlockName Mle)))
                          (setq AT2Edit (_CheckMl "REVNUM" MleD))
			  (eq (strcase (vla-GetBlockAttributeValue  Mle AT2Edit)) oldval)
			 ) 
			  (vla-SetBlockAttributeValue  Mle  AT2Edit newval)
                         )
                   )(vla-regen aDoc acActiveViewport )
             )
        (princ)
       )
(vl-load-com)
(princ)

 

command:RevOne

BTW: are you using a 64bit OS?

Message 16 of 20
urix
in reply to: bbarkman.jedson

Hi- Could anyone tell me how to FIND and REPLACE texts contents of Multileader.
I am trying to change key notes for “M-A” to “M-1”.
The usual “_find” command does not pick up these attributes.
Tried using Revup.lsp but says it is invalid as it needs to be inserted.
Please advice!
Message 17 of 20
nabsterhema
in reply to: pbejse

i have adifferent related problem i want to remove certain part of mleder text and i have a lips to do that but in mtext not mleader and i wonder if you can help me with that, the detail problem is as follow 

I am working on AutoCad plant 3d and it generates isometric drawing contains mleader with coordinates as shown in the sample dwg attached.

I want to remove the lines contains "E XXXXX , N XXXX" From MLEADER the problem is that the lisp cannot see the Mleader text only sees any apply on mtext so it there is away to made this lisp work on mleader 

thanks for your time , the lisp and sample dwg is attached.

Message 18 of 20
eavilad3rd
in reply to: pbejse

Hi Sir, I'd been trying to use this code but It didn't work both MLEADER and ATTRIBUTE, I'm currently using AutoCAD 2018 64bit, lisp is working no error because of it asks me for current value and replaced value then after I press enter nothing happen. Pls, help thank you.

Message 19 of 20
devitg
in reply to: nabsterhema

As I can see , MTEXT , surrounded by the magenta circle DO NOT belong to a MLEADER. Neither the mleader have any text 

See result from vlax-dump for mleader 

 

SELECCIONE LA ENTIDAD  ; IAcadMLeader: AutoCAD Multi-Leader Interface
; Property values:
;   Application (RO) = #<VLA-OBJECT IAcadApplication 00000001401151a8>
;   ArrowheadBlock = ""
;   ArrowheadSize = 2.5
;   ArrowheadType = 0
;   BlockConnectionType = 0
;   BlockScale = 1.0
;   ContentBlockName = ""
;   ContentBlockType = 6
;   ContentType = 0
;   Document (RO) = #<VLA-OBJECT IAcadDocument 00000000342b27e8>
;   DogLegged = -1
;   DoglegLength = 3.06186
;   EntityTransparency = "ByLayer"
;   Handle (RO) = "74D4"
;   HasExtensionDictionary (RO) = 0
;   Hyperlinks (RO) = #<VLA-OBJECT IAcadHyperlinks 000000003cb6e368>
;   LandingGap = 2.0
;   Layer = "Annotation"
;   LeaderCount (RO) = 1
;   LeaderLineColor = #<VLA-OBJECT IAcadAcCmColor 000000003cb6e420>
;   LeaderLinetype = "ByBlock"
;   LeaderLineWeight = -2
;   LeaderType = 1
;   Linetype = "ByLayer"
;   LinetypeScale = 1.0
;   Lineweight = -1
;   Material = "ByLayer"
;   ObjectID (RO) = 44
;   ObjectName (RO) = "AcDbMLeader"
;   OwnerID (RO) = 43
;   PlotStyleName = "ByLayer"
;   ScaleFactor = 1.0
;   StyleName = "AdskIso"
;   TextAttachmentDirection = 0
;   TextBackgroundFill = Ocurrió una excepción
;   TextBottomAttachmentType = 0
;   TextDirection = Ocurrió una excepción
;   TextFrameDisplay = 0
;   TextHeight = 4.0
;   TextJustify = Ocurrió una excepción
;   TextLeftAttachmentType = 1
;   TextLineSpacingDistance = Ocurrió una excepción
;   TextLineSpacingFactor = Ocurrió una excepción
;   TextLineSpacingStyle = Ocurrió una excepción
;   TextRightAttachmentType = 1
;   TextRotation = Ocurrió una excepción
;   TextString = Ocurrió una excepción
;   TextStyleName = Ocurrió una excepción
;   TextTopAttachmentType = 0
;   TextWidth = Ocurrió una excepción
;   TrueColor = #<VLA-OBJECT IAcadAcCmColor 000000003cb6e900>
;   Visible = -1

Note that all TEXT related property  say AN EXCEPTION OCCUR.

Your mleader style have no content

 
 

Modify Multileader Style AdskIso.jpg

 

and the MTEX is just a MTEXT 

 

SELECCIONE LA ENTIDAD  ; IAcadMText: AutoCAD MText Interface
; Property values:
;   Application (RO) = #<VLA-OBJECT IAcadApplication 00000001401151a8>
;   AttachmentPoint = 7
;   BackgroundFill = -1
;   Document (RO) = #<VLA-OBJECT IAcadDocument 00000000342b27e8>
;   DrawingDirection = 5
;   EntityTransparency = "ByLayer"
;   Handle (RO) = "74E6"
;   HasExtensionDictionary (RO) = 0
;   Height = 2.5
;   Hyperlinks (RO) = #<VLA-OBJECT IAcadHyperlinks 000000003cd63868>
;   InsertionPoint = (127.0 61.0 -1.35003e-13)
;   Layer = "Annotation"
;   LineSpacingDistance = 4.16667
;   LineSpacingFactor = 1.0
;   LineSpacingStyle = 1
;   Linetype = "ByLayer"
;   LinetypeScale = 1.0
;   Lineweight = -1
;   Material = "ByLayer"
;   Normal = (0.0 0.0 1.0)
;   ObjectID (RO) = 46
;   ObjectName (RO) = "AcDbMText"
;   OwnerID (RO) = 43
;   PlotStyleName = "ByLayer"
;   Rotation = 0.0
;   StyleName = "AdskIsoAnnotation"
;   TextString = "CONT'D ON\n1\"-AMP-980-0368-SS\nW 13116\nN 23303\nEL +8044"
;   TrueColor = #<VLA-OBJECT IAcadAcCmColor 000000003cd64c40>
;   Visible = -1
;   Width = 0.0

Hope it help to clear it . 

 

 

 

 

 

 

Message 20 of 20

Hi! Just wondering if you ended finding a solution to use this lisp with a multileader. Thanks!

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost