View Full Version : Add Selected, one command instead of 5 or so
Mr Cory
2007-03-05, 05:23 AM
Hay all,
In ADT their are commands for adding walls, doors, windows, window/door assembles etc. i was wondering if it was possible to group these commands together so if you had a wall selected you could run this one command and add a wall. Instead of having 1 command for each type of object. Sorry if i didnt explain it very well.
DoorWinAssemblyAddSelected
DoorAddSelected
WallAddSelected
WindowAddSelected
Cheers for any ideas!
Mr Cory
2007-03-06, 02:59 AM
E.g. is selected object type door > yes, then dooraddselected, no, is selected object window > yes windowaddselected, no, etc etc
Is that possible?
E.g. is selected object type door > yes, then dooraddselected, no, is selected object window > yes windowaddselected, no, etc etc
Is that possible?
Being that you are looking for an object type other than what comes with vanilla AutoCAD, you will need to interrogate the object that is selected. I do not have access to ADT, therefore I do not know what type of objects to look for. Once you know the specific object type, you can use the type in a conditional statement to execute the desired command.
Mr Cory
2007-03-06, 03:54 AM
Do you have an example of a conditional statement? The object types are
Door
Wall
Door/Window Assembly
Window
Or is that not what you are meaning?
If you want the code to decide which to use, the code must equate the type to a known value. I have no way to do find that information out, at the moment, without ADT.
Maybe someone else can help determine the object types needed. Can you post a drawing that contains the objects you are wanting to work with?
Mr Cory
2007-03-06, 04:19 AM
How do you determine that?
aaronic_abacus
2007-03-06, 04:22 AM
(entget(car(entsel)))
;or even
(nentget(car(entsel)))
;then compair DXF group codes.
Mr Cory
2007-03-06, 04:24 AM
Woa lol this is what i got when i selected a wall
Select object: ((-1 . <Entity name: 7ef2fb58>) (0 . "AEC_WALL") (330 . <Entity
name: 7ef33cf8>) (5 . "20B") (100 . "AcDbEntity") (67 . 0) (410 . "Model") (8 .
"A-Wall") (100 . "AecDbEntity") (102 . "{AEC_SUBOBJECT") (300 .
"AecImpWallLinear") (100 . "AecImpObj") (3 . "") (100 . "AecImpEnt") (171 . 0)
(100 . "AecImpGeo") (10 297.294 421.41 0.0) (15 1.0 0.0 0.0) (16 0.0 1.0 0.0)
(210 0.0 0.0 1.0) (360 . <Entity name: 0>) (100 . "AecImpWall") (102 .
"{AEC_NULLOBJECT}") (102 . "{AEC_NULLOBJECT}") (40 . 2438.4) (73 . 3) (42 .
152.4) (341 . <Entity name: 7ef2faf8>) (74 . 2) (43 . 0.0) (102 .
"{AEC_WALL_MODIFIERS") (100 . "AecImpObj") (3 . "") (100 . "AecImpArray") (90 .
0) (102 . "AEC_WALL_MODIFIERS}") (102 . "{AEC_WALLSTYLE_OVERRIDES") (100 .
"AecImpObj") (3 . "") (100 . "AecImpArray") (90 . 0) (102 .
"AEC_WALLSTYLE_OVERRIDES}") (102 . "{AEC_WALL_INTERFERENCE") (100 .
"AecImpObj") (3 . "") (100 . "AecImpArray") (90 . 0) (102 .
"AEC_WALL_INTERFERENCE}") (343 . <Entity name: 7ef2faf0>) (102 .
"{AEC_WALL_MERGERS") (100 . "AecImpObj") (3 . "") (100 . "AecImpArray") (90 .
0) (102 . "AEC_WALL_MERGERS}") (102 . "{AEC_WALL_CUSTOM_GEOMETRY") (100 .
"AecImpObj") (3 . "") (100 . "AecImpArray") (90 . 0) (102 .
"AEC_WALL_CUSTOM_GEOMETRY}") (100 . "AecImpWallLinear") (102 . "{ACGECURVE3D")
(280 . 3) (10 297.294 421.41 0.0) (10 10477.0 0.0 0.0) (102 . "ACGECURVE3D}")
(210 0.0 0.0 1.0) (102 . "AEC_SUBOBJECT}") (102 . "{AEC_SUBOBJECT") (300 .
"AecImpArray") (100 . "AecImpObj") (3 . "") (100 . "AecImpArray") (90 . 1) (102
. "{AEC_SUBOBJECT") (300 . "AecOverrideCanBoundSpaces") (100 . "AecImpObj") (3
. "") (100 . "AecOverride") (100 . "AecOverrideCanBoundSpaces") (102 .
"AEC_SUBOBJECT}") (102 . "AEC_SUBOBJECT}") (100 . "AecDbGeo") (100 .
"AecDbWall"))
So is what im after "AEC_WALL"?
aaronic_abacus
2007-03-06, 04:27 AM
(0 . "AEC_WALL")
for one above is the entity type.
oops you got that one.
Mr Cory
2007-03-06, 04:31 AM
So it might be
If object is (0 . "AEC_WALL") then command dooraddselected
Is that the sort of thing im after? (sorry i havnt a clue of how to write it)
aaronic_abacus
2007-03-06, 04:38 AM
Look into ENTMOD and ENTUPD.
You could draw a wall, then modify the entity list(given by entget) with SUBST, ENTMOD, and ENTUPD.
Mr Cory
2007-03-06, 04:43 AM
Im sorry im lost a lol :?
You can also inspect the drawing database through the Visual Lisp IDE (VLIDE). This can be found from the View menu -> Browse Drawing Database -> Browse All Entities
With that I was able to determine the AEC objects found in your posted drawing above.
AEC_WALL
AEC_WINDOW_ASSEMBLY
AEC_WINDOW
AEC_DOOR
AEC_CURTAIN_WALL_LAYOUT
AEC_RAILING
AEC_STAIR
The above items where listed as the object type, group code 0. The below code will display the object type of the selected object. If you miss the object during selection, an error will occur. You can just copy and paste the code to the command prompt, again.
(setq ObjectType (cdr (assoc 0 (entget (car (entsel "\nSelect object: "))))))
Once you determine the object type, you can check that object type through a series of conditional statements.
(cond ((= "AEC_DOOR" ObjectType)
(command "dooraddselected")
)
((= "AEC_WINDOW" ObjectType)
(command "WindowAddSelected")
)
((= "AEC_WINDOW_ASSEMBLY" ObjectType)
(command "DoorWinAssemblyAddSelected")
)
((= "AEC_WALL" ObjectType)
(command "WallAddSelected")
)
(T)
)
We can then combine this statement with the previous statement to create a routine.
(defun c:AddSelected (/ ObjectType)
(setq ObjectType
(cdr (assoc 0 (entget (car (entsel "\nSelect object: "))))
)
)
(cond ((= "AEC_DOOR" ObjectType)
(command "dooraddselected")
)
((= "AEC_WINDOW" ObjectType)
(command "WindowAddSelected")
)
((= "AEC_WINDOW_ASSEMBLY" ObjectType)
(command "DoorWinAssemblyAddSelected")
)
((= "AEC_WALL" ObjectType)
(command "WallAddSelected")
)
(T)
)
)
I'm not certain any of the commands listed above will work. You will have to test it out and let us know.
Mr Cory
2007-03-06, 04:57 AM
MINT! it asks to select the object, then to select a wall (For example) then it adds it. I was wondering if there was any way to make it use the LAST object selected. It works for when i input "L" @ the command line.
Other than that it works perfect!
MINT! it asks to select the object, then to select a wall (For example) then it adds it. I was wondering if there was any way to make it use the LAST object selected. It works for when i input "L" @ the command line.
Other than that it works perfect!
Try this. Naturally, I have not tested it. ;) Let me know of any errors
(defun c:AddSelected (/ ObjectType SelectObject)
(setq SelectObject (ssget "I"))
(if (not SelectObject)
(setq SelectObject (ssget ":S"))
)
(setq ObjectType (cdr (assoc 0 (ssname SelectObject 0))))
(cond ((= "AEC_DOOR" ObjectType)
(command "dooraddselected")
)
((= "AEC_WINDOW" ObjectType)
(command "WindowAddSelected")
)
((= "AEC_WINDOW_ASSEMBLY" ObjectType)
(command "DoorWinAssemblyAddSelected")
)
((= "AEC_WALL" ObjectType)
(command "WallAddSelected")
)
)
)
Mr Cory
2007-03-06, 05:12 AM
Nop :(
bad argument type: listp <Entity name: 7381eb58>
Nop :(
bad argument type: listp <Entity name: 7381eb58>
:Oops:
Replace this line
(setq ObjectType (cdr (assoc 0 (ssname SelectObject 0))))
with this one
(setq ObjectType (cdr (assoc 0 (entget (ssname SelectObject 0)))))
Mr Cory
2007-03-06, 05:18 AM
Legend!! thats exactly what im after! thank you sooo much
Legend!! thats exactly what im after! thank you sooo much
Imagine that. I got one right. ;) You can change the command you want to use at the command prompt by changing the highlighted section below.
(defun c:AddSelected (/ ObjectType SelectObject)
Mr Cory
2007-03-06, 05:32 AM
Ha bet its not the first or the last lol. Sweet Cheers and if i want to add other objects i just carry on with the same format but making it apply to the new objects? eg mass element i would add...
((= "AEC_MASS ELEM" ObjectType)
(command "masselementAddSelected")
Ha bet its not the first or the last lol. Sweet Cheers and if i want to add other objects i just carry on with the same format but making it apply to the new objects? eg mass element i would add...
((= "AEC_MASS ELEM" ObjectType)
(command "masselementAddSelected")
Pretty much. Follow along with the rest of the conditional testing and you should be fine. Place your check before the (T) statement and your code will work.
Pretty soon, you'll be helping out around here with this stuff. ;)
Mr Cory
2007-03-06, 05:40 AM
Ha! That will be the day! I must of done something wrong because now it doesnt work @ all lol
There isnt a (T) in the lisp :?
Mr Cory
2007-03-06, 05:46 AM
Maybe that day might come sooner if i read things correctly lol i had a space instead of an _ duh! After i done (entget(car(entsel))) it looked like it was part of the number below, well thats my excuse and im sticking to it! lol
Ha! That will be the day! I must of done something wrong because now it doesnt work @ all lol
There isnt a (T) in the lisp :?
There should have been a (T). It's no biggie. Try this.
(defun c:AddSelected (/ ObjectType SelectObject)
(setq SelectObject (ssget "I"))
(if (not SelectObject)
(setq SelectObject (ssget ":S"))
)
(setq ObjectType (cdr (assoc 0 (entget (ssname SelectObject 0)))))
(cond ((= "AEC_DOOR" ObjectType)
(command "dooraddselected")
)
((= "AEC_WINDOW" ObjectType)
(command "WindowAddSelected")
)
((= "AEC_WINDOW_ASSEMBLY" ObjectType)
(command "DoorWinAssemblyAddSelected")
)
((= "AEC_WALL" ObjectType)
(command "WallAddSelected")
)
((= "AEC_MASS_ELEM" ObjectType) ; I added an underscore. You need to verify the correct spelling and capitalization for this to work.
(command "masselementAddSelected")
)
(T)
)
Anything else and you will need to play around with it, or wait for someone else to pop in. It's getting a tad late on this side of the world. I'll be back on in my morning. Good luck.
Mr Cory
2007-03-06, 05:55 AM
Thanks for all your help Opie, very much appreciated!
It seems to work without the (t) strange... yea i clicked to that after i had redone (entget(car(entsel))) sigh :roll:
Thanks again!!
kennet.sjoberg
2007-03-06, 09:19 AM
. . .It seems to work without the (t) strange...
Yes, it will work without the T
The cond statement execute the first true statement that occur,
but if there is no statement that is true, the last line (T nil) is executed, like an “else” statement
So if the last line in the cond statement is (T (princ “no match”)) you know what’s going on.
: ) Happy Computing !
kennet
Mr Cory
2007-03-06, 08:38 PM
Is that why i get "nil" appearring? Weird works fine lol
Is that why i get "nil" appearring? Weird works fine lol
You could add (princ) before the last closing ) to not have that show.
Mr Cory
2007-03-07, 01:35 AM
Yeah? Sweet might give that a try cheers!
Mr Cory
2007-09-30, 11:12 PM
Its me again, i've been using the above code for quite a few different situations but i have hit the wall. What i need to do is exclude a single object type. Is this possible?
(defun c:tr (/ ObjectType SelectObject)
(setq SelectObject (ssget "I"))
(if (not SelectObject)
(setq SelectObject (ssget ":S"))
)
(setq ObjectType (cdr (assoc 0 (entget (ssname SelectObject 0)))))
(cond ((= "aec_roofslab" ObjectType)
(command "roofslabtrim")
)
((= "all excluding aec_roofslab" ObjectType)
(command "trim")
)
)
(princ))
I'm assuming the aec_roofslab object type is correct. Also, the "\" may need to be the "/". I can't remember at this time.
(cond
(
(= "aec_roofslab" ObjectType)
(command "roofslabtrim")
)
(
(\= "aec_roofslab" ObjectType)
(command "trim")
)
)
Mr Cory
2007-10-01, 04:57 AM
Hey Opie
It needed a "/" for some reason its just firing the normal trim command, why would it be doing that?
Hey Opie
It needed a "/" for some reason its just firing the normal trim command, why would it be doing that?
Because that is the one you are calling. If you needed a specific trim command, you would need to replace "trim" with the appropriate command.
jwanstaett
2007-10-01, 05:24 PM
Because that is the one you are calling. If you needed a specific trim command, you would need to replace "trim" with the appropriate command.
RoofSlabTrim is the command to use
RoofSlabTrim is the command to use
It could be a string case issue. What is the value of the ObjectType variable?
Mr Cory
2007-10-01, 10:18 PM
I thought it was aec_roofslab...
Command: (entget(car(entsel)))
Select object: ((-1 . <Entity name: 787fadc8>) (0 . "AEC_ROOFSLAB") (330 .
<Entity name: 681decf8>) (5 . "9D989") (100 . "AcDbEntity") (67 . 0) (410 .
"Model") (8 . "L3-Roof") (100 . "AecDbEntity") (102 . "{AEC_SUBOBJECT") (300 .
"AecImpSlab") (100 . "AecImpObj") (3 . "") (100 . "AecImpEnt") (171 . 0) (100 .
"AecImpGeo") (10 35449.0 -34616.6 2950.0) (15 1.5264e-015 -1.0 0.0) (16
0.984808 1.50321e-015 0.173648) (210 -0.173648 -2.69134e-016 0.984808) (360 .
<Entity name: 0>) (100 . "AecImpSlab") (102 . "{AEC_SUBOBJECT") (300 .
"AecGeSlabFace") (100 . "AecImpObj") (3 . "") (100 . "AecGeSlabFace") (102 .
"{AEC_SUBOBJECT") (300 . "AecGeProfile") (100 . "AecImpObj") (3 . "") (100 .
"AecGeProfile") (102 . "{AECGERINGS") (100 . "AecImpObj") (3 . "") (100 .
"AecImpArray") (90 . 1) (102 . "{AEC_SUBOBJECT") (300 . "AecGeSlabLoop") (100 .
"AecImpObj") (3 . "") (100 . "AecGeCompCurve2d") (102 . "{AECGESEGMENTS") (100
:shock: it continues....
Mr Cory
2007-10-01, 10:20 PM
Heres the code as it stands...
(defun c:tr (/ ObjectType SelectObject)
(setq SelectObject (ssget "I"))
(if (not SelectObject)
(setq SelectObject (ssget ":S"))
)
(setq ObjectType (cdr (assoc 0 (entget (ssname SelectObject 0)))))
(cond ((= "aec_roofslab" ObjectType)
(command "roofslabtrim")
)
((/= "aec_roofslab" ObjectType)
(command "trim" SelectObject "")
)
)
(princ))
Mr Cory
2007-10-01, 10:39 PM
No, its still calling the acad trim command. I dont see why it would be :?
It could be due to case sensitivity.
Try the following two code snippets and see what you can discover.
(setq ObjectType "AEC_ROOFSLAB")
(if (= ObjectType "aec_roofslab")
(princ "\nThis is a true statement")
(princ "\nThis is not a true statement")
)
(setq ObjectType "AEC_ROOFSLAB")
(if (= ObjectType "AEC_ROOFSLAB")
(princ "\nThis is a true statement")
(princ "\nThis is not a true statement")
)
You may want to look into the strcase function.
Mr Cory
2007-10-01, 11:38 PM
I tryed both but they both came up with true even when i had a pline selected :?
(i copied the code into a lisp file, selected the object then dragged the lisp into adt, is that correct?)
I tryed both but they both came up with true even when i had a pline selected :?
(i copied the code into a lisp file, selected the object then dragged the lisp into adt, is that correct?)
Neither of the two snippets does anything with objects. They both set a variable "ObjectType" to an uppercase string. They then check to see if the variable matches a given string. The first snippet checks it against an uppercase string, the second with a lowercase string. The second one should have returned "This is not a true statement".
Mr Cory
2007-10-02, 12:00 AM
O :Oops: Sorry.
The first one returns NOT TRUE
The second returns TRUE
Mr Cory
2007-10-02, 12:04 AM
So it did need to be upper case! i changed my code and it works now :) cheers Opie! i didnt think lisps were case sensitive :?
So it did need to be upper case! i changed my code and it works now :) cheers Opie! i didnt think lisps were case sensitive :?
You are welcome. And, yes, AutoLisp is case sensitive. You need to make sure you are using the right comparisons.
Mr Cory
2007-10-02, 04:21 AM
Gez you learn something everyday :) turns out it wasnt going to work the way i needed it to unless there was someway when you call the lisp that unless the roof slab object is already selected it would just use the normal trim. If thats too much work dont worry about it
Mr Cory
2007-10-02, 04:26 AM
Acturally no dont worry about it too much trouble. Thanks again for all your help Opie! :mrgreen:
RobertB
2007-10-02, 05:54 PM
You are welcome. And, yes, AutoLisp is case sensitive. You need to make sure you are using the right comparisons.I think that needs to be clarified a bit.
Visual LISP is not case-sensitive when it comes to functions and statements. For example, both (setq a 123) and (SETQ A 123) will result in the same thing, the symbol A being set to to the value 123.
However, just as with most programming languages, you must be very careful when comparing data. Especially with strings. For instance, (wcmatch) and (=) are case-sensitive, since "abc" does not equal "ABC" when dealing with strings.
I think that needs to be clarified a bit.
Visual LISP is not case-sensitive when it comes to functions and statements. For example, both (setq a 123) and (SETQ A 123) will result in the same thing, the symbol A being set to to the value 123.
However, just as with most programming languages, you must be very careful when comparing data. Especially with strings. For instance, (wcmatch) and (=) are case-sensitive, since "abc" does not equal "ABC" when dealing with strings.
It looks like you clarified it a bit. ;) Thanks.
Mr Cory
2007-10-02, 09:34 PM
That makes sense, i thought that might be the case but wasnt too sure. Cheers for your time, its very much appreciated! :)
T.Willey
2007-10-02, 09:38 PM
That makes sense, i thought that might be the case but wasnt too sure. Cheers for your time, its very much appreciated! :)
You're welcome. Seems you might be on your way to better understand lisp. Congratulations. :)
Mr Cory
2007-10-02, 09:39 PM
I have come leaps and bounds since i first started messing with them, but still have a very long way to go
T.Willey
2007-10-02, 09:51 PM
I have come leaps and bounds since i first started messing with them, but still have a very long way to go
Just keep at, and it will come I'm sure. As long as you enjoy it, it will be easy to learn.
Mr Cory
2007-10-02, 09:58 PM
Just keep at, and it will come I'm sure. As long as you enjoy it, it will be easy to learn.
Yeah, im kinda hooked at the moment, just need to find some to read the instructions ;)
vBulletin® v3.6.7, Copyright ©2000-2009, Jelsoft Enterprises Ltd.