Is there a copy or move property for a group of objects?

Is there a copy or move property for a group of objects?

greneebb
Participant Participant
322 Views
2 Replies
Message 1 of 3

Is there a copy or move property for a group of objects?

greneebb
Participant
Participant

I have a group of objects and can use the color property to color all the objects at once.  Similarly, I would like to copy and move all the objects at once, but I am unsuccessful. Can this be confirmed? I can copy and move the objects individually, but that defeats the purpose of grouping.

 

Any advice or assistance would be welcomed. Below is the code that works fine for coloring all the objects at once.


Public Sub AddAGroup()


Dim GroupObject As AcadGroup
Dim ObjectsForGroup() As AcadEntity
Dim CircleObject As AcadCircle

Dim Center(0 To 2) As Double
Dim Radius As Double
Dim Count As Integer

Center(0) = 1: Center(1) = 1: Center(2) = 0
Radius = 1.5
Set CircleObject = ThisDrawing.ModelSpace.AddCircle(Center, Radius)

ReDim ObjectsForGroup(0 To ThisDrawing.ModelSpace.Count - 1) As AcadEntity

For Count = 0 To ThisDrawing.ModelSpace.Count - 1
   Set ObjectsForGroup(Count) = ThisDrawing.ModelSpace.Item(Count)
Next

Set GroupObject = ThisDrawing.Groups.Add("MyGroup")
 GroupObject.AppendItems ObjectsForGroup
GroupObject(0).Color = acGreen
GroupObject.Highlight True
ThisDrawing.Regen acActiveViewport
   
   
End Sub

 

0 Likes
323 Views
2 Replies
Replies (2)
Message 2 of 3

norman.yuan
Mentor
Mentor

<QUOTE>

... and can use the color property to color all the objects at once...

</QUOTE>

 

The quoted claim, I believe, was backed up by this line of code of yours:

GroupObject(0).Color = acGreen

 

Well, it is wrong. This line of code ONLY sets the color of THE FIRST ENTITY in the group to green, other entities' color will remain unchanged.

 

So, as to your question: you need to copy/move one by one in a For Each/For loop, going through the Group or SelectionSet, with AcadEntity.Copy()/Move() method.

Norman Yuan

Drive CAD With Code

EESignature

0 Likes
Message 3 of 3

greneebb
Participant
Participant

Thanks for your response and keen eye to detect that line of code you referenced. 

 

However, that code was not what I wanted to post. This is the code here that I wanted to post.  Note that in this code there is a circle and a line. Then note the code line: GroupObject.color = acGreen. This code changes both the circle and the line into color Green without looping through the group explicitly with the for loop. So I want to know if this can be done for the copy or move commands as well

Public Sub AddAGroup()


Dim GroupObject As AcadGroup
Dim ObjectsForGroup() As AcadEntity
Dim CircleObject As AcadCircle


    Dim LineObj As AcadLine
    Dim StartPoint(0 To 2) As Double
    Dim EndPoint(0 To 2) As Double
    
    ' Define the start and end points for the line
    StartPoint(0) = 0: StartPoint(1) = 0: StartPoint(2) = 0
    EndPoint(0) = 1: EndPoint(1) = 6: EndPoint(2) = 0
    
    ' Create the line in model space
    Set LineObj = ThisDrawing.ModelSpace.AddLine(StartPoint, EndPoint)

Dim Center(0 To 2) As Double
Dim Radius As Double
Dim Count As Integer

Center(0) = 1: Center(1) = 1: Center(2) = 0
Radius = 1.5
Set CircleObject = ThisDrawing.ModelSpace.AddCircle(Center, Radius)

ReDim ObjectsForGroup(0 To ThisDrawing.ModelSpace.Count - 1) As AcadEntity


For Count = 0 To ThisDrawing.ModelSpace.Count - 1
   Set ObjectsForGroup(Count) = ThisDrawing.ModelSpace.Item(Count)
Next

Set GroupObject = ThisDrawing.Groups.Add("MyGroup")
 GroupObject.AppendItems ObjectsForGroup
GroupObject.Color = acGreen
GroupObject.Highlight True
ThisDrawing.Regen acActiveViewport
   
   
End Sub

 

0 Likes