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

using the lisp to change the attribute tag value of the block

33 REPLIES 33
SOLVED
Reply
Message 1 of 34
toomohdi
7942 Views, 33 Replies

using the lisp to change the attribute tag value of the block

Hi

in attached file i have numbers of block with attribute that has 4 tags 1-code 2- Height( level or Z ) 3-alpha desc 4-point number.

the blocks were inserted in wrong location so i had to move the blocks to correct location so the value of height are not correct i need a lisp to chenge the value of the hieght tag base of insert point of block . appreciate it if sombody can help me. 

33 REPLIES 33
Message 2 of 34
paullimapa
in reply to: toomohdi

Try the attached no error checking lisp function CZ.lsp

 

It will find all blocks matching name CROSS2 and replace the 2nd Attribute which is the Height tag with the Field value that matches with the current inserted Z elevation of the block.

 

Area Object Link | Attribute Modifier | Dwg Setup | Feet-Inch Calculator | Layer Apps | List on Steroids | VP Zoom Scales
Exchange App Store


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 3 of 34
hmsilva
in reply to: toomohdi

Hi toomohdi,

a different approach from the solution provided by Paul Li, just to change the attribute value to the 'z' value from the block insertion point

 

(vl-load-com)
(defun c:demo (/ attlst i obj pt ss val)
  (if (setq ss (ssget "_X" '((0 . "INSERT") (2 . "CROSS2") (66 . 1))))
    (repeat (setq i (sslength ss))
      (setq obj    (vlax-ename->vla-object (ssname ss (setq i (1- i))))
            pt     (vlax-get obj 'InsertionPoint)
            val    (rtos (last pt) 2 3)
            attlst (vlax-invoke obj 'GetAttributes)
      )
      (foreach a attlst
        (if (= (vla-get-TagString a) "Height")
          (vla-put-TextString a val)
        )
      )
    )
  )
  (princ)
)

 

Hope that helps

Henrique

EESignature

Message 4 of 34
3wood
in reply to: toomohdi

Actually you only need to add 100 to all height attributes.

Just try attached ALTEXT.vlx and settings as below, select "2" (the 2nd attribute) to change when it prompts: "hich attribute to be changed (Enter 0 to search attribute tag name): Attribute No.<1>:"

altext.png

 

I also attached the fixed drawing for your information.

Message 5 of 34
toomohdi
in reply to: paullimapa

thanks Paul Li,

the lisp run perfectly but change the height values to ####.

Message 6 of 34
toomohdi
in reply to: hmsilva

Hi Henrique,

 

thanks a lot. your lisp worked just fine.

Message 7 of 34
paullimapa
in reply to: toomohdi

That's strange....what version of AutoCAD are you running and are you running on Windows 7 32bit or 64bit?

 

Area Object Link | Attribute Modifier | Dwg Setup | Feet-Inch Calculator | Layer Apps | List on Steroids | VP Zoom Scales
Exchange App Store


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 8 of 34
toomohdi
in reply to: 3wood

3wood

 

thanks you are right i did chenge location of the blocks by 100 meter in height just to create DWG file for this qustion in my case the value is not consistants so best way is to use insert point of the blocks.thanks a lot for your time .appreciate all.

Message 9 of 34
toomohdi
in reply to: paullimapa

i did try it in autocad 2009 on windows 7 32 bit at home .i would like to be able work with 2015 and win 7 64 bit.is it possible.

Message 10 of 34
paullimapa
in reply to: toomohdi

Try this modified version which checks for 32bit vs 64bit operating system

 

Area Object Link | Attribute Modifier | Dwg Setup | Feet-Inch Calculator | Layer Apps | List on Steroids | VP Zoom Scales
Exchange App Store


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 11 of 34
toomohdi
in reply to: paullimapa

yes now it is working  it just give i digit after dot. 204.2 how can i modify it to give 3 digits after dot.

is it possible to make it select all block on the drawing insted of "CROSS2"i mean edit any type of shape comes in Tag 2. becous most of time we have deferent block in drawing that has to edit.

Message 12 of 34
paullimapa
in reply to: toomohdi

I've modified & placed comments in the code showing:

1. change that allows for selection of all Blocks with Attributes

2. where & how to adjust decimal precision

 

Note: This only works on Blocks with more than 1 Attribute and will always place the Field linking the z insertion point on the 2nd Attribute.  The routine will fail if it runs into a Block with only 1 Attribute

 

Area Object Link | Attribute Modifier | Dwg Setup | Feet-Inch Calculator | Layer Apps | List on Steroids | VP Zoom Scales
Exchange App Store


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 13 of 34
toomohdi
in reply to: hmsilva

is it possible to modify your lisp to select all blocks in drawing no mater what kind of block is in Tag 2 we have,cercle,triangle,ractangle,CROSS1 and ..........

Message 14 of 34
toomohdi
in reply to: paullimapa

Paul Li

thanks alot ,i will try it sunday at work in my office .you have been very helpfull.thanks.

 

Message 15 of 34
paullimapa
in reply to: toomohdi

As I stated previously the current routine will work on all Blocks and will always replace the 2nd Attribute value regardless of the Tag name.

 

 

Area Object Link | Attribute Modifier | Dwg Setup | Feet-Inch Calculator | Layer Apps | List on Steroids | VP Zoom Scales
Exchange App Store


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 16 of 34
paullimapa
in reply to: toomohdi
Message 17 of 34
toomohdi
in reply to: paullimapa

Paul Li

sorry again I noticed that now height Tag is highlighted with white color how can i fix it.

Message 18 of 34
hmsilva
in reply to: toomohdi


@toomohdi wrote:

Hi Henrique,

 

thanks a lot. your lisp worked just fine.


You're welcome, toomohdi

 

Henrique

EESignature

Message 19 of 34
hmsilva
in reply to: paullimapa

Nice code Paul!

 

Cheers

Henrique

EESignature

Message 20 of 34
3wood
in reply to: toomohdi

To set the second attribute to block's Z value, just save following code as a lsp file, then select "Use formula" option in ALTEXT (updated as attached) to use it.

;;; This is an example formula for ALTEXT.vlx
(defun ALTEXT_FORMULA ()
  (if ALTEXT_BLK_ENT
    (rtos (cadddr (assoc 10 ALTEXT_BLK_ENT)) 2 3) ;Refer to rtos usage to change unit mode & precision.
  )
)

 altext_3.png

 

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

Post to forums  

AutoCAD Inside the Factory


Autodesk Design & Make Report