Conditional Attribute value editor

Conditional Attribute value editor

Anonymous
Not applicable
1,111 Views
6 Replies
Message 1 of 7

Conditional Attribute value editor

Anonymous
Not applicable

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!

0 Likes
Accepted solutions (1)
1,112 Views
6 Replies
Replies (6)
Message 2 of 7

pbejse
Mentor
Mentor

@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
Mentor
Mentor
Accepted solution

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

@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
Mentor
Mentor

@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
Mentor
Mentor

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

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

John F. Uhden

0 Likes
Message 7 of 7

Moshe-A
Mentor
Mentor

@john.uhden ,

 

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

 

(trace [function ...])

 

 

0 Likes