lubracali Posted April 1, 2011 Posted April 1, 2011 I start from a situation like this I have to create a loop for each iteration allows me to select segments of a group(in the picture I have 5 groups, marked in red), so I have 5 "boxes/containers"(in this case, can be any number) that list each segment of the corresponding group. I tried to use Dim objSset(J) As AcadSelectionSet Dim J as integer or Dim objSset(J) As Collection Dim J as integer but I always got the error "Constant expression required". What can I use to run something like this? Private Sub cmdGruppi_Click() Dim j As Integer Dim objSset(j) As AcadSelectionSet answer = vbYes j = 1 Do Name = j Set objSset(j) = ThisDrawing.SelectionSets.Add(Name) MsgBox "Choose all the segments in a group", vbOKOnly, "Group" Me.Hide objSset(j).SelectOnScreen answer = MsgBox("Another group?", vbYesNo, "New group") If answer = vbYes Then MsgBox "yes", vbOKOnly, "yes" ElseIf answer = vbNo Then MsgBox "no", vbOKOnly, "no" End If j = j + 1 Loop Until answer = vbNo End Sub Is there any container for objects that can be used? Quote
Hickoz_bro Posted May 18, 2011 Posted May 18, 2011 I've just had a quick look at your post so I might have missed something, but what about adding each group of lines to an AutoCAD Group? Dim oSSetGroup As AcadGroup Set oSSetGroup = ThisDrawing.Groups.Add("SG") 'SG = group name as string oSSetGroup.name = "GroupName" Dim AddItem(0) As AcadEntity Set AddItem(0) = SSet(X1) 'SSet(X1) are items from your selection set oSSetGroup.AppendItems AddItem 'AddItem is the name of the AcadEntity in previous step Then you can just call your group using the group name... e.g. (command "copy" GroupName "") Quote
SEANT Posted May 18, 2011 Posted May 18, 2011 (edited) An error will be thrown unless either the array size is set explicitly: Dim objSset(4) As AcadSelectionSet Or set up as a Dynamic array: Dim objSset() As AcadSelectionSet If a dynamic array is used (and it looks like that is the direction you are headed) then it would have to be “ReDim”ed as needed. See this link for the procedure. http://msdn.microsoft.com/en-us/library/aa140074(v=office.10).aspx Edited May 18, 2011 by SEANT Quote
Hickoz_bro Posted May 18, 2011 Posted May 18, 2011 SEANT - In the code discussed in the other thread (here) I ended up using "ReDim Array (variable) as XXXXX" and it worked fine. I didn't need to Dim it as a dynamic array to start with... Is this OK practice? Quote
SEANT Posted May 18, 2011 Posted May 18, 2011 Variables are the usual method for working with dynamic arrays. It is just that the variable has to be assigned an integer value prior to Dim”ming” or Redim”ing”. Looking back on the OP, the first two code snippets posted didn’t assign a value type until after the array was declared. The routine in the code tags, though, did declare; Dim j As Integer. That may actually work okay due to the fact that Integer value types are automatically initialized to 0. The massage given at the error("Constant expression required") leads me to believe that dimming the array without a constant (or empty braces for a dynamic array) was the cause. 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.