assafius Posted September 15, 2012 Posted September 15, 2012 Hi, If I have a set of entities, can I lisp something to group them together (to a single group) ? Thanks. Quote
Lee Mac Posted September 15, 2012 Posted September 15, 2012 Are you referring to creating an AutoCAD Group, or perhaps a Selection Set? Quote
Tharwat Posted September 15, 2012 Posted September 15, 2012 (defun c:grp (/ ss name) (if (and (setq ss (ssget "_:L")) (not (eq (setq name (getstring "\n Enter a group name :")) "") ) (snvalid name) ) (vl-cmdf "_.-group" "" name "" ss "") ) (princ) ) Quote
assafius Posted September 15, 2012 Author Posted September 15, 2012 Ok thanks, But can your code be changed so that it groups a list of entities, which are not selected by the user (i.e. an already defined list of entities) ? Quote
Tharwat Posted September 15, 2012 Posted September 15, 2012 Ok thanks, But can your code be changed so that it groups a list of entities, which are not selected by the user (i.e. an already defined list of entities) ? If you mean a subfunction , here it goes and just add the list of your selection set like this . e.g. (grp <selectionSetOfEntities>) (defun grp (lst / name) (if (and (not (eq (setq name (getstring "\n Enter a group name :")) "") ) (snvalid name) ) (vl-cmdf "_.-group" "" name "" lst "") ) (princ) ) Quote
assafius Posted September 15, 2012 Author Posted September 15, 2012 Great, thanks. One last question please: I've added a new selection-set item, but I can't seem to add a new item to it. I've tried something like: (vlax-invoke my_set 'AddItems (vlax-ename->vla-object some_entity)) Quote
Tharwat Posted September 15, 2012 Posted September 15, 2012 I've added a new selection-set item, but I can't seem to add a new item to it. Just use the function ssadd to add to your current selection set . e.g. to add the variable s to the current selection set . (setq s (ssget)) (ssadd s <selectionSet>) Quote
Lee Mac Posted September 16, 2012 Posted September 16, 2012 One last question please:I've added a new selection-set item, but I can't seem to add a new item to it. I've tried something like: (vlax-invoke my_set 'AddItems (vlax-ename->vla-object some_entity)) Your code is failing because the additems method requires an array of VLA-Objects, (or list of VLA-Objects since you are using the vlax-invoke function). Consider the following example: ([color=BLUE]defun[/color] c:test ( [color=BLUE]/[/color] ent lst obj sel sln ssc ) ([color=BLUE]setq[/color] sln [color=MAROON]"MySelectionSet"[/color]) [color=GREEN];; Selection Set Name[/color] [color=GREEN];; Retrieve a list of objects to be added to the set[/color] ([color=BLUE]while[/color] ([color=BLUE]progn[/color] ([color=BLUE]setvar[/color] 'errno 0) ([color=BLUE]setq[/color] ent ([color=BLUE]car[/color] ([color=BLUE]entsel[/color] [color=MAROON]"\nSelect Object to include in Selection Set <Done>: "[/color]))) ([color=BLUE]cond[/color] ( ([color=BLUE]=[/color] 7 ([color=BLUE]getvar[/color] 'errno)) ([color=BLUE]princ[/color] [color=MAROON]"\nMissed, try again."[/color]) ) ( ([color=BLUE]=[/color] 'ename ([color=BLUE]type[/color] ent)) ([color=BLUE]if[/color] ([color=BLUE]member[/color] ([color=BLUE]setq[/color] obj ([color=BLUE]vlax-ename->vla-object[/color] ent)) lst) ([color=BLUE]princ[/color] [color=MAROON]"\nObject already selected."[/color]) ([color=BLUE]setq[/color] lst ([color=BLUE]cons[/color] obj lst)) ) ) ) ) ) [color=GREEN];; If the user has made a selection[/color] ([color=BLUE]if[/color] lst ([color=BLUE]progn[/color] [color=GREEN];; Check that a set of the same name doesn't already exist[/color] ([color=BLUE]if[/color] ([color=BLUE]vl-catch-all-error-p[/color] ([color=BLUE]setq[/color] sel ([color=BLUE]vl-catch-all-apply[/color] '[color=BLUE]vla-item[/color] ([color=BLUE]list[/color] ([color=BLUE]setq[/color] ssc ([color=BLUE]vla-get-selectionsets[/color] ([color=BLUE]vla-get-activedocument[/color] ([color=BLUE]vlax-get-acad-object[/color])) ) ) sln ) ) ) ) [color=GREEN];; If not, create it[/color] ([color=BLUE]setq[/color] sel ([color=BLUE]vla-add[/color] ssc sln)) [color=GREEN];; Else clear the existing set[/color] ([color=BLUE]vla-clear[/color] sel) ) [color=GREEN];; Add the selected objects to the set[/color] ([color=BLUE]vla-additems[/color] sel ([color=BLUE]vlax-make-variant[/color] ([color=BLUE]vlax-safearray-fill[/color] ([color=BLUE]vlax-make-safearray[/color] [color=BLUE]vlax-vbobject[/color] ([color=BLUE]cons[/color] 0 ([color=BLUE]1-[/color] ([color=BLUE]length[/color] lst)))) lst ) ) ) [color=GREEN];; The above could alternatively be replaced with:[/color] [color=GREEN];; (vlax-invoke sel 'additems lst)[/color] [color=GREEN];; Highlight the objects in the set[/color] ([color=BLUE]vla-highlight[/color] sel [color=BLUE]:vlax-true[/color]) [color=GREEN];; Delete the set[/color] ([color=BLUE]vla-delete[/color] sel) ) ) [color=GREEN];; Suppress the return of the last evaluated expression[/color] ([color=BLUE]princ[/color]) ) [color=GREEN];; Load Visual LISP Extensions[/color] ([color=BLUE]vl-load-com[/color]) [color=GREEN];; Suppress the return of (vl-load-com)[/color] ([color=BLUE]princ[/color]) Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.