Visual LISP, AutoLISP and General Customization

Reply
Distinguished Contributor
1bdchristian
Posts: 159
Registered: ‎07-28-2006
Message 1 of 3 (137 Views)

Condition Lisp

137 Views, 2 Replies
02-14-2013 07:06 AM

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

*Expert Elite*
hmsilva
Posts: 2,701
Registered: ‎12-17-2004
Message 2 of 3 (129 Views)

Re: Condition Lisp

02-14-2013 07:39 AM 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

*Expert Elite*
Kent1Cooper
Posts: 5,294
Registered: ‎09-13-2004
Message 3 of 3 (106 Views)

Re: Condition Lisp

02-14-2013 11:28 AM 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

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community