regroup a group you have ungrouped in AutoLisp

regroup a group you have ungrouped in AutoLisp

Anonymous
Not applicable
3,684 Views
27 Replies
Message 1 of 28

regroup a group you have ungrouped in AutoLisp

Anonymous
Not applicable

I hope you enjoyed the title

 

Hello, I'm new to my job and I'm asked to rotate an object inside a group, without rotating it as a whole.

The only way I'm seeing is to ungroup it, rotate the said object and regroup the objects once more.

The problem is, I don't know how to identify every member of the group before ungrouping, so i could make a list to regroup later.

 

I hope you understood my problem and any parallel thinking is welcome, since this is my third day using AutoLisp

0 Likes
Accepted solutions (2)
3,685 Views
27 Replies
Replies (27)
Message 2 of 28

ronjonp
Mentor
Mentor
Accepted solution

No need to ungroup the items. Set the variable PICKSTYLE to 2, rotate your object(s) then set it back to what you had it before.

Message 3 of 28

CodeDing
Advisor
Advisor

@ronjonp ,

 

That would have saved me some heartache Smiley LOL

 

@Anonymous ,

 

My take before rperez's info haha:

(defun c:RGO ( / e eCopy grps gName)
;Rotate Group Object
;get object
(setq e (car (entsel "\nSelect object in Group to rotate: ")))
;create copy of item for command call
(setq eCopy (entmakex (cdr (entget e))))
(command-s "_.ROTATE" eCopy "")
;replace original ent with our copy
(if (and (setq grps (GetGroupNames))
	 (setq gName (GroupNameOfEntity e grps)))
  (progn
    (command "-GROUP" "a" gName eCopy "")
    (command "-GROUP" "r" gName e "")
    (if (entget ecopy) (entdel e))
    (prompt "\nRGO Complete..")
  );progn
;else
  (prompt "\nSomething went wrong!")
);if
(princ)
);defun

(defun GetGroupNames ( / ret dict)
;returns list of pairs (("group1name" . Group1Ename) ("group2name" . Group2Ename) ...)
(setq ret '())
(setq dict (entget (cdr (assoc -1 (dictsearch (namedobjdict) "ACAD_GROUP")))))
(foreach x dict
  (if (= 3 (car x)) (setq ret (cons (cons (cdr x) (cdr (cadr (member x dict)))) ret)))
);foreach
(if (> (length ret) 0) ret nil)
);defun

(defun GroupNameOfEntity (e pairList / )
;searches all groups for original entity, returns group name that it exists in
(setq ret nil)
(foreach x pairList
  (setq tmp (entget (cdr x)))
  (if (member (cons 340 e) tmp) (setq ret (car x)))
);foreach
ret
);defun

Best,

~DD

Message 4 of 28

ronjonp
Mentor
Mentor
Accepted solution

Hahaha 🙂 quick test and also using CNTRL and select will modify the objects independent of the group.

2019-07-03_11-34-38.gif

Message 5 of 28

Anonymous
Not applicable

Thank you very much, it was just what I needed and simple.

 

Thank you too, @CodeDing, I didn't run the code but for what @ronjonp showed, it would have worked too 🙂

0 Likes
Message 6 of 28

ВeekeeCZ
Consultant
Consultant

There is an icon right on the Ribbon that switch the 'pickstyle this way.

 

image.png

0 Likes
Message 7 of 28

cadffm
Consultant
Consultant

The main place for pickstyle/group selection mode is at 'Selection' Tab of Options dialog, command OPTIONS.

CTRL+R is also a toggle für group-selectionmode, same as the button, but independent of current ribbon tab.

Sebastian

0 Likes
Message 8 of 28

martin_leiter
Advocate
Advocate

Hello rperez,
I have another question about this useful Lisp.
With the object selection in this Lisp one can select only one object.
How can I select multiple objects in the same group?

can you show me this?
Thank you!

Greetings Martin

0 Likes
Message 9 of 28

ronjonp
Mentor
Mentor

@martin_leiter wrote:

Hello rperez,
I have another question about this useful Lisp.
With the object selection in this Lisp one can select only one object.
How can I select multiple objects in the same group?

can you show me this?
Thank you!

Greetings Martin


All you have to do is hold down the CTRL key before making your selection then modify as needed. No code necessary.

2019-07-10_7-54-14.gif

0 Likes
Message 10 of 28

martin_leiter
Advocate
Advocate

Hello,
Thank you for your answer.
Unfortunately, I can not raise a window. I can only choose 1 object with their code. The CTRL key does not help here.
Or am I doing something wrong?
greetings Martin

0 Likes
Message 11 of 28

ВeekeeCZ
Consultant
Consultant

@ronjonp wrote:


All you have to do is hold down the CTRL key before making your selection...

 


 

Do you have some magic ctrl key? Because with my regular one it is not working like that.

The only thing that works to me with ctrl is polyline sub-selection.

0 Likes
Message 12 of 28

ronjonp
Mentor
Mentor

@ВeekeeCZ wrote:

@ronjonp wrote:


All you have to do is hold down the CTRL key before making your selection...

 


 

Do you have some magic ctrl key? Because with my regular one it is not working like that.

The only thing that works to me with ctrl is polyline sub-selection.


Not sure if it's magical but it works 🙂 I have AutoCAD '19 & '20 and it works in both? Could be a combination of another variable set that makes it work. I'll have to investigate.

0 Likes
Message 13 of 28

ronjonp
Mentor
Mentor

 @ВeekeeCZ what is pickadd set to on your system? If it's 0 then the sub selection will not work. 

0 Likes
Message 14 of 28

martin_leiter
Advocate
Advocate

Hello,
For me Pickadd is on 2
greetings Martin

0 Likes
Message 15 of 28

ВeekeeCZ
Consultant
Consultant

Yep, pickadd is 2. (acad 2020)

Tried all values, no relation to the issue.

0 Likes
Message 16 of 28

ronjonp
Mentor
Mentor

@ВeekeeCZ wrote:

Yep, pickadd is 2. (acad 2020)

Tried all values, no relation to the issue.


You're right .. I was picking the objects individually and not a crossing selection.

0 Likes
Message 17 of 28

ВeekeeCZ
Consultant
Consultant

@ronjonp wrote:

@ВeekeeCZ wrote:

Yep, pickadd is 2. (acad 2020)

Tried all values, no relation to the issue.


You're right .. I was picking the objects individually and not a crossing selection.


No, no... can't select them either way.

What type of entities are on your gif, are they polylines? That could work. But not if they are lines or anything else

0 Likes
Message 18 of 28

martin_leiter
Advocate
Advocate

Hello,
Mine are rectangles
greetings Martin

0 Likes
Message 19 of 28

ronjonp
Mentor
Mentor

@martin_leiter wrote:

Hello,
For me Pickadd is on 2
greetings Martin


If you set PICKSTYLE to 0 as mentioned in my first post then make your edits and set the variable back then code still is not necessary :).

 

0 Likes
Message 20 of 28

ronjonp
Mentor
Mentor

@ВeekeeCZ wrote:

@ronjonp wrote:

@ВeekeeCZ wrote:

Yep, pickadd is 2. (acad 2020)

Tried all values, no relation to the issue.


You're right .. I was picking the objects individually and not a crossing selection.


No, no... can't select them either way.

What type of entities are on your gif, are they polylines? That could work. But not if they are lines or anything else


Yup .. that's the issue. I had all polylines in the group. Other items do not work. That seems a bit half baked ;/

0 Likes