Selecting specific objects with a script

Selecting specific objects with a script

Anonymous
Not applicable
3,942 Views
6 Replies
Message 1 of 7

Selecting specific objects with a script

Anonymous
Not applicable

Hello!

 

I'm working on a 3D project where I want to generate a simple model of a house, like this:

House ModelHouse Model

I did this mainly with a quick sweep and a couple of extrusions. So far, with only a script, I can get as far as the first face and the sweep path:

Capture.PNG

But to go further I have to invoke the sweep command, then select the surface and then the path. I don't know if I can do this with a script. Here are my questions:

 

(A) Can I select these objects within a command (like sweep) with a script? 

(B) If not, is there a way to automate actions like this? Eventually I wanna randomly-generate different house layouts.

(C) If I can do this with a script, will I inevitably keep running into script limitations in case I want more complicated layouts, like 2-story houses?

 

If scripts aren't as limited as they seem then I'd do the random-generating business with a program that would spit out a unique script per randomized house. But maybe there's a simpler way, so...

 

(D) Am I missing a big obvious method of doing this?

 

Any suggestions and insights are much appreciated. Thank you!

 

0 Likes
3,943 Views
6 Replies
Replies (6)
Message 2 of 7

serag.hassouna
Advocate
Advocate

Within the script itself, instead of typing the command itself, you can use an Autolisp expression like this

(command "._Sweep" (car (entsel)) "" (car (entsel)) "" "")

the part (car (entsel)) is responsible for selection, and the empty strings "" represent hitting ENTER.

 

_______

As for automation IMO, Autolisp is more flexible & compact than scripts.

0 Likes
Message 3 of 7

roland.r71
Collaborator
Collaborator

For clarity:

By "script" you do mean the AutoCAD "definition" of the word, meaning its actually a batch process using a *.scr file ? (its nothing more then a list of commands & arguments as you would type at the commandline) -or- are you actually refering to a LISP (a *.lsp file) ?

 

If .scr: Any reason for doing this with a script (& not LISP)?

 

I'm asking since you can do a whole lot more with LISP as one ever can with a mere script. (but not everybody is aware of the difference/meaning in relation to ACAD and use "script" where they realy mean LISP)

If there is a reason and the reason is "LT", you might as well stop. Even the simple solution above isn't going to work in that case, as LISP is not supported by LT. (THE reason it's called "LighT")

If you do have full ACAD & you are using just a batch process "script" file, you should realy check out (& learn) LISP.

0 Likes
Message 4 of 7

Anonymous
Not applicable

Sorry for not being super clear, I meant a plain-old script file with .scr. I guess I wanted to know if it was possible to do it this way so that I wouldn't have to learn a whole bunch of LISP syntax, but it seems like that might be the way to go. Though I've seen that LISP isn't the only way to automate stuff in AutoCAD. So my questions are:

 

1. For randomly-generating these simple house models, would you guys recommend LISP or VBA or something else?

2. What are your favorite resources for learning whatever language you'd recommend?

 

Thanks in advance!

0 Likes
Message 5 of 7

Anonymous
Not applicable

@serag.hassouna I've been looking into AutoLISP now and I realize that (car(entsel)) still makes me select the entities I want by hand. I want to complete the operation without any input after I call the function. Is this possible?

Thanks again!

0 Likes
Message 6 of 7

roland.r71
Collaborator
Collaborator

@Anonymous wrote:

@serag.hassouna I've been looking into AutoLISP now and I realize that (car(entsel)) still makes me select the entities I want by hand. I want to complete the operation without any input after I call the function. Is this possible?

Thanks again!


In theory, yes.

As you can use lisp code inside scripts, you can do a lot (more then you think).

...but, it does depend on how exactly you do things.

For example, 'it' will need to know which entities to use. (a manual selection (entsel) is easiest)

For automation it needs to know what to use as surface & what to use as path, which could potentially be problematic.

 

I would need to see the script, to be able to determine what you should do.

 

As for preference; I think it's a matter of taste. Use whatever feels best for you.

I've been using lisp for roughly 14 years (with a 7 year gap inbetween) and it suits me well (although i'm no expert). I realy don't have time to learn VBA too. (but i'm not saying one is better as the other)

 

My favorite resource, is actually right here. Thanks to this forum & all the other resources autodesk provides I've been able to do whatever I want.

 

When looking for info on commands I just use Google, (search for: autolisp <command> & 9/10 times the top link will get you to the right page within the Knowledge Network) - This actually works better as using the search on the network itself.

 

When I need info on how to do things (or if its possible) I just search the forum & 99/100 times I find what I need without even starting a thread.

Message 7 of 7

serag.hassouna
Advocate
Advocate

Simple enough, refer to the functions that are used with selection sets ({ssget, ssname, sslength} at least).
_________
First of all, Check out the "AutoLISP Developer's Guide" to know about syntax, data types, objects processing & modification (in general).
The "AutoLISP Reference Guide" contains the functions that are supported by AutoLISP, but be notified that there are other functions that are related to the Visual Lisp extension, these functions are documented through the knowledge center website (vla, vlax, vlr functions).
This is also a good reference

AutoCAD 2016 Help: Functions Reference (AutoLISP)

Also, look for these 2 files {acadauto.chm, acadaag.chm} within your AutoCAD's installation path, the 1st one documents AutoCAD's object model, and the 2nd one documents how to deal with VBA.
The 1st document is really a great documentation, it contains examples with AutoLISP/Visual LISP code & VBA code for almost every method.
___________
I've also included 2 files that may aid you to get some hands-on work, & the last 3rd file is a reference to AutoLISP's functions, but it doesn't contain any other extensions/additions after AutoCAD 2013, hopefully, you can find them in the above-mentioned URL, or if not, simply search for them and in most cases you'll find them in the 1st results.