Re: SDK: Preserve selection
On 2/28/2013 9:11 PM, Christian Gotzinger wrote: preselection = [s for s in Application.Selection] # This list now includes all objects you had selected (the objects, not just their names!) # When you're done with the script, this brings back the original selection: Application.Selection.Clear() for obj in preselection: Application.Selection.Add(obj) Thanks Christian - yes, this works for simple objects and for entire branches. What Mihail and I are concerned, however, is how this code would work when the user has done a polygon, vertex, etc. selection - note that in the 'processing' part of this code (after we save the original object list and before we attempt the restore), we mess around with existing scene polymeshes (via the C++ CMeshBuilder API). The user might even have selected items within the meshes we're modifying as part of this processing.
Re: SDK: Preserve selection
P.S.: It also respects branch selections.
Re: SDK: Preserve selection
Hi Mihail, Using the GetAsString and SetAsString is bad whenever you add, reparent or delete objects - it tends to break because the selection is stored according to the object names. Here's how I usually do it (not sure if there is a better way), Python: preselection = [s for s in Application.Selection] # This list now includes all objects you had selected (the objects, not just their names!) # When you're done with the script, this brings back the original selection: Application.Selection.Clear() for obj in preselection: Application.Selection.Add(obj)
Re: SDK: Preserve selection
GetAsText, in scripting at least, does return the "B:" prefix. But SetAsText ignores it. OTOH, SelectObj takes it. si = Application sel = si.Selection Application.SelectObj("XSI_Man", "BRANCH", "") tmp = sel.GetAsText() print tmp # B:XSI_Man sel.Clear() si.SelectObj(s) print sel.GetAsText() # B:XSI_Man On 28/02/2013 1:49 PM, Alan Fregtman wrote: For every item in the Selection object, there's .BranchFlag property which will return 1 if it was branch selected, or 0 if not. Perhaps build your own GetAsString equivalent where you prefix "B:" before any FullName that is branch-selected? On Thu, Feb 28, 2013 at 12:06 PM, Mihail Djurev mailto:mihail.dju...@chaosgroup.com>> wrote: Hello, list! I have a command that clears the selection as a side effect. I want to memorize the selection before calling it, so I can restore it later. I tried to keep the string from the GetAsString() method and then restore it via SetAsString(), but that didn't seem to work for branch select. Right now I'm using the GetArray() method and later on I'm adding all the CRefs to the selection. This seems to keep the selection for all cases that I've tried, but there's an annoying side effect. Every time I have polygons selected, the selection filter is changed. Any thoughts? Thanks Mihail
Re: SDK: Preserve selection
For every item in the Selection object, there's .BranchFlag property which will return 1 if it was branch selected, or 0 if not. Perhaps build your own GetAsString equivalent where you prefix "B:" before any FullName that is branch-selected? On Thu, Feb 28, 2013 at 12:06 PM, Mihail Djurev < mihail.dju...@chaosgroup.com> wrote: > Hello, list! > > I have a command that clears the selection as a side effect. I want to > memorize the selection before calling it, so I can restore it later. > > I tried to keep the string from the GetAsString() method and then restore > it via SetAsString(), but that didn't seem to work for branch select. > > Right now I'm using the GetArray() method and later on I'm adding all the > CRefs to the selection. This seems to keep the selection for all cases that > I've tried, but there's an annoying side effect. Every time I have polygons > selected, the selection filter is changed. > > Any thoughts? > > Thanks > Mihail >
SDK: Preserve selection
Hello, list! I have a command that clears the selection as a side effect. I want to memorize the selection before calling it, so I can restore it later. I tried to keep the string from the GetAsString() method and then restore it via SetAsString(), but that didn't seem to work for branch select. Right now I'm using the GetArray() method and later on I'm adding all the CRefs to the selection. This seems to keep the selection for all cases that I've tried, but there's an annoying side effect. Every time I have polygons selected, the selection filter is changed. Any thoughts? Thanks Mihail