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

Condition Lisp

2 REPLIES 2
Reply
Message 1 of 3
1bdchristian
281 Views, 2 Replies

Condition Lisp

Could someone tell why this is not working, I cannot figure why it does not change the layer description as I want.

 

 

(cond ( (= (tblobjname "LAYER" "Dim1") "Dim1")           

            (vla-put-description (vlax-ename->vla-object (tblobjname "LAYER" "Dim1")) "Dimensions")         

          )

)

 

thank you in advance, Byron

2 REPLIES 2
Message 2 of 3
hmsilva
in reply to: 1bdchristian

Byron;
perhaps something like

 

(cond ((/=(tblobjname "LAYER" "Dim1") nil)          
            (vla-put-description (vlax-ename->vla-object (tblobjname "LAYER" "Dim1")) "Dimensions")
)
)

 Henrique

EESignature

Message 3 of 3
Kent1Cooper
in reply to: 1bdchristian


@1bdchristian wrote:

Could someone tell why this is not working, I cannot figure why it does not change the layer description as I want.

 

(cond ( (= (tblobjname "LAYER" "Dim1") "Dim1")           

            (vla-put-description (vlax-ename->vla-object (tblobjname "LAYER" "Dim1")) "Dimensions")         

....


It doesn't work because the (tblobjname) function returns not a Layer name but an entity name.  If you want to do it by way of that function, you need to extract the Layer name from that, this way:

(cond ( (= (cdr (assoc 2 (entget (tblobjname "LAYER" "Dim1")))) "Dim1")

  (vla-put-... blah-blah-blah ....)

....

 

But for any Layer at all, if it exists in the drawing, that test will be True -- it's asking: "does the Layer with this name have this for a name?"  [It certainly doesn't have any other name....]  In effect, you're only checking whether the Layer is there, and there are far easier ways to do that:

 

(if (tblsearch "layer" "Dim1")

  (vla-put-Description... blah-blah-blah ....)

); end if

 

[That's similar to hmsilva's suggestion, but it's not necessary to check whether something is not equal to nil as he does.  An (if) test doesn't require a T return explicitly to be satisfied, as his (/=) function would get, but will be satisfied by anything that is not nil.  If the Layer exists, (tblobjname) without the (/=) "wrapper" function will return something different from what (tblsearch) returns, but neither will be nil, so either will satisfy the (if) function's test, so the function name (tblobjname) could be substuted for my (tblsearch).]

 

But I'm going to go out on a limb here and suggest an even simpler way to do this.  I don't have a new-enough version of AutoCAD to have adding a Description to a Layer as an option in the Layer command, but can do Descriptions only in the Arch.Desktop Layer Manager dialog box [or possibly via (vla-put...) -- I haven't tried].  But if that is an option within that command in later versions, you should be able to do the whole thing with no more than this:

 

(command "_.layer" "_description" "Dimensions" "Dim1" "")

 

If that option exists and works as others do [give it option name, then value, then Layer(s) to apply it to], that command line would assign that description to that Layer if it's there, and you don't even need to check whether or not the Layer exists!  If it doesn't, a message will go by [if you have command echoing on] that it didn't find any matching Layer name(s), and it will just return to the Layer sub-prompt, and the "" will finish the command.

 

If that option exists but doesn't work quite as others do, you should be able to re-arrange the answers to the prompts to get what you need.

Kent Cooper, AIA

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

Post to forums  

Autodesk Design & Make Report

”Boost