Can you remove clusters with Object Model? (not using "Application"")

Discussions concerning programming of SOFTIMAGE©
Post Reply
wesserbro
Posts: 177
Joined: 27 Oct 2012, 18:05

Can you remove clusters with Object Model? (not using "Application"")

Post by wesserbro » 07 Apr 2019, 17:16

All i can find is something like this, but its pretty slow and im guessing its not 'object model' way, right? =((

Code: Select all

for item in Application.Selection:
    sampleClusters = item.ActivePrimitive.Geometry.Clusters
    for cluster in sampleClusters:
        Application.DeleteObj(cluster)

User avatar
rray
Moderator
Posts: 1775
Joined: 26 Sep 2009, 15:51
Location: Bonn, Germany
Contact:

Re: Can you remove clusters with Object Model? (not using "Application"")

Post by rray » 07 Apr 2019, 18:49

I think that's the only way, as deleting a cluster is a bit of a refactoring operation
softimage resources section updated Jan 5th 2024

wesserbro
Posts: 177
Joined: 27 Oct 2012, 18:05

Re: Can you remove clusters with Object Model? (not using "Application"")

Post by wesserbro » 08 Apr 2019, 14:37

So can we state that, as a general rule, you cant create or remove entities with object model methods, only read and change values?

User avatar
rray
Moderator
Posts: 1775
Joined: 26 Sep 2009, 15:51
Location: Bonn, Germany
Contact:

Re: Can you remove clusters with Object Model? (not using "Application"")

Post by rray » 08 Apr 2019, 16:08

There's a number of add and remove methods in the Model class https://download.autodesk.com/global/do ... Model.html

Also a RemoveCluster Function: https://download.autodesk.com/global/do ... uster.html

but nothing simple like "ActivePrimitive.Clusters.Remove(thisCluster)". Maybe it has to do with the cleanup that is required, so removing only the list item could have unwanted side effects.
softimage resources section updated Jan 5th 2024

User avatar
Daniel Brassard
Posts: 878
Joined: 18 Mar 2010, 23:38
Location: St. Thomas, Ontario
Contact:

Re: Can you remove clusters with Object Model? (not using "Application"")

Post by Daniel Brassard » 08 Apr 2019, 18:44

If I am not mistaken Clusters are a XSICollection and can be manipulated via XSICollection Methods. You access the XSICollection via the geometry as follows:

Geometry.Clusters

You can then add or remove item from the collection as such

Geometry.Clusters.Item(Item)
Geometry.Clusters.Add (item)
Geometry.Clusters.AddItems(Items)
Geometry.Clusters.Remove(item)
Geometry.Clusters.RemoveItems(Items)
Geometry.Clusters.RemoveAll()

http://docs.autodesk.com/SI/2015/ENU/So ... sters.html
$ifndef "Softimage"
set "Softimage" "true"
$endif

luceric
Posts: 1251
Joined: 22 Jun 2009, 00:08

Re: Can you remove clusters with Object Model? (not using "Application"")

Post by luceric » 09 Apr 2019, 03:00

It's just style, whatever you do is going to call the same code anyway that the deleteobj command runs. you can speed things up by turning off undo, that's all

User avatar
rray
Moderator
Posts: 1775
Joined: 26 Sep 2009, 15:51
Location: Bonn, Germany
Contact:

Re: Can you remove clusters with Object Model? (not using "Application"")

Post by rray » 09 Apr 2019, 14:09

if you delete multiple clusters deleting all of them in one call is probably a bit faster too
softimage resources section updated Jan 5th 2024

User avatar
myara
Posts: 403
Joined: 28 Sep 2011, 10:33

Re: Can you remove clusters with Object Model? (not using "Application"")

Post by myara » 10 Apr 2019, 06:20

And you can turn off the log too.

Every time a command is run, it will log the result. This slow things up quite a lot when you are iterating a lot of objects.
You can disable it like this:

Code: Select all

xsi = Application

# Log Off
prefs = xsi.Preferences
prefs.SetPreferenceValue( "scripting.cmdlog", 0 )
The log preference will return to it's original when the script has done so there is no need to put it back to it's default value.

But you can see the most improvement by deleting all at once like rray said.
And even if you have log ON, it will log only once.

You can do it by gathering the clusters according to your needs into a collection, and then delete the collection with one DeleteObj.

Code: Select all

from win32com.client import Dispatch as disp

DeleteClusters = disp( "XSI.Collection" )
for item in xsi.Selection:
    sampleClusters = item.ActivePrimitive.Geometry.Clusters
    for cl in sampleClusters:
        #Add your coniditions here
        DeleteClusters.Add(cl)
xsi.DeleteObj(DeleteClusters)
Or, if it is a more simple task, you can just filter what you want and delete it.

Code: Select all

for item in xsi.Selection:
    sampleClusters = item.ActivePrimitive.Geometry.Clusters.Filter('sample')
    xsi.DeleteObj(sampleClusters)
M.Yara
Character Modeler | Softimage Generalist (sort of)

wesserbro
Posts: 177
Joined: 27 Oct 2012, 18:05

Re: Can you remove clusters with Object Model? (not using "Application"")

Post by wesserbro » 10 Apr 2019, 14:36

Thanks everyone for the answers!
yes, gathering a collection and deleting all at once is definitely the fastest way and so obvious, but i just got fixated on this words from docs ("The object model is implemented using a COM (ActiveX) layer which basically negotiates directly with the core engine of Softimage. ") so it didnt cross my mind :)
i also got frustrated this code didn't work Geometry.Clusters.RemoveAll(). but apparently clusters are represented with their special ClusterCollection, which doesn't have that method

User avatar
myara
Posts: 403
Joined: 28 Sep 2011, 10:33

Re: Can you remove clusters with Object Model? (not using "Application"")

Post by myara » 10 Apr 2019, 16:24

The remove methods are for removing items from a Collection, it doesn’t delete the items.
M.Yara
Character Modeler | Softimage Generalist (sort of)

Post Reply

Who is online

Users browsing this forum: No registered users and 19 guests