Visual LISP, AutoLISP and General Customization

Reply
Distinguished Contributor
bhull1985
Posts: 388
Registered: ‎07-17-2013
Message 1 of 24 (334 Views)
Accepted Solution

Get user string, check to see if any layers in drawing match user-input

334 Views, 23 Replies
09-05-2013 05:55 AM

Hello everyone, I am attempting to tackle a new project.

I'm writing a small routine to enable layer toggles based off of a few characters inputted by a user, such as:

 

Laymod "IFC" thaw

 

would be the user execution command, and within that I want this program to search for any matches within the list of returned layers in the drawing to what's in the double-quotes, in the example above, it would return any or all layers that have the string "IFC" within them.

 

I've been able to construct the layer list, and have set vars for the layers to be an argument of the subfunction required to toggle the layers.

 

What I need some assistance with is the string matching portion of this routine, that would search the table of layers and return any matches to the user input....if anyone would assist me in this i would be grateful.

 

Thanks and cheeeeeeers!

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Please use code tags and credit where credit is due. Accept as solution, if solved. Let's keep it trim people!
*Expert Elite*
Lee_Mac
Posts: 1,038
Registered: ‎12-29-2009
Message 2 of 24 (329 Views)

Re: Get user string, check to see if any layers in drawing match user-input

09-05-2013 06:18 AM in reply to: bhull1985

bhull1985 wrote:

What I need some assistance with is the string matching portion of this routine, that would search the table of layers and return any matches to the user input

 


 

Look into the tblsearch function.

Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)
Expert Elite
With Mathematics there is the possibility of perfect rigour, so why settle for less?
Distinguished Contributor
bhull1985
Posts: 388
Registered: ‎07-17-2013
Message 3 of 24 (323 Views)

Re: Get user string, check to see if any layers in drawing match user-input

09-05-2013 06:30 AM in reply to: Lee_Mac

Thanks Lee, I will look into it!

I was wondering on an unrelated note if you had received the email I sent to you yesterday?

Just simply inquiring as to if you've written a specific program or not because I was not able to locate it on your website....yet I would think you've done something similar, so was just hoping to find out.

 

Anyhow, thanks for the hint with this one, i'll study up!

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Please use code tags and credit where credit is due. Accept as solution, if solved. Let's keep it trim people!
*Expert Elite*
Kent1Cooper
Posts: 4,955
Registered: ‎09-13-2004
Message 4 of 24 (310 Views)

Re: Get user string, check to see if any layers in drawing match user-input

09-05-2013 08:34 AM in reply to: bhull1985

bhull1985 wrote:

....

I'm writing a small routine to enable layer toggles based off of a few characters inputted by a user, such as:

 

Laymod "IFC" thaw

 

would be the user execution command, and within that I want this program to search for any matches within the list of returned layers in the drawing to what's in the double-quotes, in the example above, it would return any or all layers that have the string "IFC" within them.

....


If you really mean toggle [that is, switch from one state of a possible pair, whichever it is, to the opposite], it's more complicated, but your sample User input suggests maybe you mean to switch to a specified state, regardless of which of the possible pair of states they start in.  If that User input means you want to thaw all Layers containing "IFC" in their names, rather than toggle their freeze/thaw state, you don't need to make a list, but can do something as simple as this:

 

(defun laymod (substr option)

  (command "_.layer" option (strcat "*" substr "*") "")

)

 

Usage:

 

In your example:

(laymod "IFC" "Thaw")

or even just

(laymod "IFC" "T")

 

Note that the option argument needs to be in double-quotes, in addition the Layer-name substring as in your example.  And as a function with arguments, the whole thing needs to be in parentheses, but:

 

If you want it as a Command, with User inputs in answer to prompts rather than as arguments to a function:

 

(defun C:LAYMOD (/ substr option)

  (setq

    substr (getstring "\nPortion of Layer name(s) to apply option to: ")

    option (getstring "\nLayer option to apply to them: ")

  ); setq

  (command "_.layer" option (strcat "*" substr "*") "")

); defun

 

And then, in answer to the prompts, the User wouldn't include the double-quotes around the substring or option.

 

You could also use (initget) and (getkword) to force the User to supply a valid Layer option [the above will have trouble if they type something wrong].

Kent Cooper
*Expert Elite*
Kent1Cooper
Posts: 4,955
Registered: ‎09-13-2004
Message 5 of 24 (305 Views)

Re: Get user string, check to see if any layers in drawing match user-input

09-05-2013 08:46 AM in reply to: Lee_Mac

bhull1985 wrote:
....it would return any or all layers that have the string "IFC" within them.
Lee_Mac wrote:
....
Look into the tblsearch function

Unfortunately, (tblsearch) doesn't like wildcards, but needs a fully spelled-out individual [in this case] Layer name.  It can't find more than one Layer, nor even a single Layer if only one matches, given only a portion of the Layer name(s).

Kent Cooper
Distinguished Contributor
bhull1985
Posts: 388
Registered: ‎07-17-2013
Message 6 of 24 (304 Views)

Re: Get user string, check to see if any layers in drawing match user-input

09-05-2013 08:46 AM in reply to: Kent1Cooper

Great, thanks again Kent.

I'll attempt my routine using these instead, and see how it works.

Much appreciated!

 

And ah, alright. I wasn't intent on using wcmatch, just thought that it may be the best option for a user to type a few characters and have it match those few characters with any layers containing those characters from a list of layers obtained earlier in the routine.

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Please use code tags and credit where credit is due. Accept as solution, if solved. Let's keep it trim people!
*Expert Elite*
Kent1Cooper
Posts: 4,955
Registered: ‎09-13-2004
Message 7 of 24 (296 Views)

Re: Get user string, check to see if any layers in drawing match user-input

09-05-2013 08:56 AM in reply to: bhull1985

bhull1985 wrote:

Great, thanks again Kent.

I'll attempt my routine using these instead, and see how it works.

Much appreciated!

 

And ah, alright. I wasn't intent on using wcmatch, just thought that it may be the best option for a user to type a few characters and have it match those few characters with any layers containing those characters from a list of layers obtained earlier in the routine.


You're welcome.  The Layer command itself will perform the (wcmatch)-like operation on the Layer collection, without the need for you to make a list of them, in the place where it's asking for Layer name(s), where [unlike (tblsearch)] it can work with (wcmatch)-style wildcards.

Kent Cooper
Distinguished Contributor
bhull1985
Posts: 388
Registered: ‎07-17-2013
Message 8 of 24 (292 Views)

Re: Get user string, check to see if any layers in drawing match user-input

09-05-2013 09:45 AM in reply to: Kent1Cooper

Okay, and with the quickprop hover over item information boxes in autocad that show the layer of the item being hovered, that will work great. Thanks for the zillionth time :smileyhappy:

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Please use code tags and credit where credit is due. Accept as solution, if solved. Let's keep it trim people!
Distinguished Contributor
bhull1985
Posts: 388
Registered: ‎07-17-2013
Message 9 of 24 (261 Views)

Re: Get user string, check to see if any layers in drawing match user-input

09-06-2013 06:52 AM in reply to: Kent1Cooper

Alright I'm getting a strange error message,

one that I haven't seen before.

Perhaps someone else has??

And could tell me why...

 

I'm having a bit of difficulty in establishing the variables in a manner that will have the program display a list of the layers in the drawing (table "layer") within the code to do that, calling a sub.

That's step 1, then I want the users to be able to simply issue on their command line the following:

 

Laymod "Layername-From-list-or-portion-of-layername-from-list" State

 

where Laymod is the command to invoke the routine, the quoted information is the layer to be modified , accepting full or partial layer name from the given list, and then state is the layers property to be modified.

I've got the subroutines all in it and am just having a hard time in establishing a way to inform the user to only enter those 3 words as their terms, and having it set the vars correctly based from that

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Please use code tags and credit where credit is due. Accept as solution, if solved. Let's keep it trim people!
*Expert Elite*
Kent1Cooper
Posts: 4,955
Registered: ‎09-13-2004
Message 10 of 24 (252 Views)

Re: Get user string, check to see if any layers in drawing match user-input

09-06-2013 08:06 AM in reply to: bhull1985

bhull1985 wrote:

Alright I'm getting a strange error message,

one that I haven't seen before.

....

then I want the users to be able to simply issue on their command line the following:

 

Laymod "Layername-From-list-or-portion-of-layername-from-list" State

....


Posting the error message would help.

 

A command defined by way of

  (defun C:Something ...

cannot contain arguments [entries before the backslash in the parentheses following the command name].

 

If you want it as a command the User can type in as a command name, remove those [it looks like the first is not used except inside sub-routines anyway, and the second is also in the localized variables list after the parentheses, which I imagine would be a conflict].

 

If you want it as a function with arguments, then remove the C:, and it has to be used with those three terms in parentheses, and the last one would also need to be in double-quotes [see my first Reply on this thread].

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
Welcome to the new Autodesk Community!
If this is your first visit, click here to get started and make the most of the Community. Let us know what you think of the new experience in the Community Feedback Forum.

Need installation help?

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

Ask the Community