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

Conditional Attribute value editor

6 REPLIES 6
SOLVED
Reply
Message 1 of 7
Anonymous
867 Views, 6 Replies

Conditional Attribute value editor

I'm trying to develop a lisp routine that can do the following (Conceptually it's a conditional attribute edit program):

 

Search for a specific block(s) "MyBlock" and Attribute tag "Tag1" to find a given value "MyValue".

 

IF that value is found in the given block and attribute, then edit the attribute "Tag2" in "MyBlock" to a static value "MyNewValue".

 

I'm getting hung up on syntac and ACAD keeps returning with Error: too few arguments. 

 

Any help is appreciated!

Tags (4)
6 REPLIES 6
Message 2 of 7
pbejse
in reply to: Anonymous


@Anonymous wrote:

I'm trying to develop a lisp routine that can do the following (Conceptually it's a conditional attribute edit program):

 


A hint / guide / advise is what you're looking for YES?

  • (ssget ) use a filter for entity type [ 0 ] , block name [ 2 ] , attribute flag [ 66 ]
  • (entnext) to get attribute tag names [ 2 ] and value  [ 1 ]
  • (if .. ) or (cond..) Test for existence of both tags and value
  • (entmod (subst ...))(entupd ...) if evaluates to T then assign new value

HTH

 

 

 

Message 3 of 7
Sea-Haven
in reply to: Anonymous

Following on from the Pbejse suggestions here is a VL example can use as a start for your solution.

 

(foreach att (vlax-invoke (vlax-ename->vla-object (ssname SS x)) 'getattributes)
        (if (and (= tag (strcase (vla-get-tagstring att)))
        (= (vla-get-textstring att) teststring)
        )
(vla-put-textstring att newstring)
)
)

 

Message 4 of 7
Moshe-A
in reply to: Anonymous

@Anonymous,

 

in case you were asking what "Error: too few arguments" means?

 

here is an example: (foo a b c)

where a,b,c are arguments to function (foo)

if you call (foo) with less then 3 arguments or no arguments at all, you get that error.

 

here is a tip for debug: there is a nice helper function called (trace)

 

usage:

(trace foo)

(the argument may be a list of functions name to be traced)

 

when your program stuck with an error go back to VLIDE top menu window\trace the trace window is opened.

you will see there the call to your trace function plus the arguments that were sent and the result of the function.

if the error comes from this function, then you will get no result.

 

oh one last more 😀

to disable a traced function use (untrace foo)

 

enjoy

Moshe

 

Message 5 of 7
john.uhden
in reply to: Moshe-A

@Moshe-A  wrote,

"(the argument may be a list of functions name to be traced)"

I didn't know there was a THE function. 😁

John F. Uhden

Message 6 of 7
john.uhden
in reply to: Sea-Haven

That's my style, but your indentation is rather sloppy. 😏

BTW, how do you do parenthesis matching in NotePad++?

John F. Uhden

Message 7 of 7
Moshe-A
in reply to: john.uhden

@john.uhden ,

 

actually it's not a list. you call (trace) with arguments ... 

 

(trace [function ...])

 

 

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