1 Attachment(s)
Change attribute textstyle within block
Hi All
I am trying to create a lisp routine to change the attribute textstyle within a block and there are a multiple of different block to be changed within the same drawing.
This is also to be applied to many drawings to bring them into line with the updated CAD standards.
I have attached what I have so far, but it does not loop through the blocks.
Any help appreciated.
Re: Change attribute textstyle within block
We need to loop through the blocks, and through the inserts to change all attributes style.
As a 'demo'
Code:
(vl-load-com)
(defun c:demo (/ atts i obj ss)
(or adoc (setq adoc (vla-get-activedocument (vlax-get-acad-object))))
(vlax-for blks (vla-get-blocks adoc)
(if (= :vlax-false (vla-get-isxref blks))
(vlax-for blk blks
(if (= (vla-get-objectname blk) "AcDbAttributeDefinition")
(vla-put-stylename blk "MyStyleName")
)
)
)
)
(if (setq ss (ssget "X" '((0 . "INSERT") (66 . 1))))
(repeat (setq i (sslength ss))
(setq obj (vlax-ename->vla-object (ssname ss (setq i (1- i))))
atts (vlax-invoke obj 'getattributes)
)
(foreach att atts
(vla-put-stylename att "MyStyleName")
)
)
)
(vla-regen adoc acallviewports)
(princ)
)
Hope this helps,
henrique
1 Attachment(s)
Re: Change attribute textstyle within block
Hi Henrique
Sorry for the delay in responding, but I have been side tracked by another project.
Thank for the reply, yes this works excellent.
Another question, I have to check the current text styles and then use a condition statement to change the style to the new value.
Are you able to help?
I have attached a sample of the cond statement.
regards
Steve
Re: Change attribute textstyle within block
Hi Steve,
if we use 'strcase' function when we set 'ts', the return will be in uppercase...
The 'ht' variable is a real number???
Code:
(cond
((= ts "TXT-13") (setq newval "13-TEXT"))
((= ts "TXT-18") (setq newval "18-TEXT"))
((= ts "TXT-25") (setq newval "25-TEXT"))
((= ts "TXT-35") (setq newval "35-TEXT"))
((= ts "TXT-5") (setq newval "5-TEXT"))
((= ts "TXT-7") (setq newval "7-TEXT"))
((and (= ts "ROMANS") (vl-position ht '(1.3 2.6 6.5 13.0 26.0 32.5 65.0 130.0)))
(setq newval "13-TEXT")
)
((and (= ts "ROMANS") (vl-position ht '(1.8 3.6 9.0 18.0 36.0 45.0 90.0 180.0)))
(setq newval "18-TEXT")
)
((and (= ts "ROMANS") (= ht 250.0))
(setq newval "25-TEXT")
)
((and (= ts "ROMANS") (vl-position ht '(3.5 7.0 17.5 35.0 70.0 87.5 175.0 350.0)))
(setq newval "35-TEXT")
)
((and (= ts "ROMANS") (vl-position ht '(5.0 10.0 25.0 50.0 100.0 125.0 250.0 500.0)))
(setq newval "5-TEXT")
)
;if none of the above conditions is true, and ts= ROMANS, change to "7-TEXT"
((= ts "ROMANS") (setq newval "7-TEXT"))
) ;end cond
Henrique
2 Attachment(s)
Re: Change attribute textstyle within block
Hi Henrique
Attached is current program, but I am having trouble associating variables for the fist part, BLOCKS.
I an been able to convert the ActiveX name to a lisp name and set variable "nam", but I am unable to extract any text variables from this "block" object.
The lower section, attribute definition, seems to work.
Any help appreciated.
Regards
Steve
- - - Updated - - -
Hi Henrique
Also I have attached a sample drawing I am using.
It is a block with attributes imbedded.
1 Attachment(s)
Re: Change attribute textstyle within block
Good Luck!
I recommend using 'filter to select blocks :)
Re: Change attribute textstyle within block
Thanks a bunch this is just what I need, would it be possible though to be able to select multiple entities when actually changing the "textstyle" instead of just the 1 ?
1 Attachment(s)
Re: Change attribute textstyle within block
Code:
(DEFUN C:CAS (/ BS BSL CT NOFUV NOFNU LP NE NEL NEAET NEA NEAS OFNU NNEL)
(PROMPT "\n*CHANGE ATTRIBUTE STYLE* ")
(PROMPT "\nSelect block with attributes to change: ")
(SETQ BS (SSGET '((-4 . "<AND") (0 . "INSERT") (66 . 1) (-4 . "AND>")) ))
(SETQ BSL (SSLENGTH BS))
(SETQ CT (- BSL 1))
(SETQ NOFUV (GETSTRING "\nNew attribute style: "))
(SETQ LP 1)
(WHILE LP
(SETQ NE (SSNAME BS CT))
(SETQ CT2 0)
(SETQ LP2 1)
(WHILE LP2
(SETQ NE (ENTNEXT NE))
(SETQ NEL (ENTGET NE))
(SETQ NEAET (CDR (ASSOC 0 NEL)))
(SETQ NEA (ASSOC 7 NEL))
(SETQ NEAS (CDR NEA))
(IF (= NEAET "ATTRIB")
(PROGN
(IF (/= NEA NIL)
(PROGN
(SETQ NOFNU (CONS 7 NOFUV))
(SETQ OFNU NEA)
(SETQ NNEL (SUBST NOFNU OFNU NEL))
(ENTMOD NNEL)
(ENTUPD NE)
));END PROGN/IF NEA
));END PROGN/IF NEAET
(IF (= NEAET "SEQEND") (SETQ LP2 NIL))
);END WHILE LP2
(SETQ CT (- CT 1))
(IF (< CT 0) (SETQ LP NIL))
);END WHILE LP
(PRINC)
);END CAS
Re: Change attribute textstyle within block
Quote:
Originally Posted by
aaronic_abacus
Code:
(DEFUN C:CAS (/ BS BSL CT NOFUV NOFNU LP NE NEL NEAET NEA NEAS OFNU NNEL)
(PROMPT "\n*CHANGE ATTRIBUTE STYLE* ")
(PROMPT "\nSelect block with attributes to change: ")
(SETQ BS (SSGET '((-4 . "<AND") (0 . "INSERT") (66 . 1) (-4 . "AND>")) ))
(SETQ BSL (SSLENGTH BS))
(SETQ CT (- BSL 1))
(SETQ NOFUV (GETSTRING "\nNew attribute style: "))
(SETQ LP 1)
(WHILE LP
(SETQ NE (SSNAME BS CT))
(SETQ CT2 0)
(SETQ LP2 1)
(WHILE LP2
(SETQ NE (ENTNEXT NE))
(SETQ NEL (ENTGET NE))
(SETQ NEAET (CDR (ASSOC 0 NEL)))
(SETQ NEA (ASSOC 7 NEL))
(SETQ NEAS (CDR NEA))
(IF (= NEAET "ATTRIB")
(PROGN
(IF (/= NEA NIL)
(PROGN
(SETQ NOFNU (CONS 7 NOFUV))
(SETQ OFNU NEA)
(SETQ NNEL (SUBST NOFNU OFNU NEL))
(ENTMOD NNEL)
(ENTUPD NE)
));END PROGN/IF NEA
));END PROGN/IF NEAET
(IF (= NEAET "SEQEND") (SETQ LP2 NIL))
);END WHILE LP2
(SETQ CT (- CT 1))
(IF (< CT 0) (SETQ LP NIL))
);END WHILE LP
(PRINC)
);END CAS
Hey there.. I see you're not new here, ;)
please remember to use "code tags" when posting code, as you can see it's easier to read/scroll etc. and keeps your formatting.
You simply format it like so: [ code ] your code here [ /code ]
(I added spaces at the brackets for visual purposes, you wouldn't have those spaces when actually doing this)
Re: Change attribute textstyle within block
thanks ted! I forgot how to use the CODE tags :O