Cluster renaming (but magically not renaming) VBS problem

Discussions concerning programming of SOFTIMAGE©
Post Reply
SpookyMunky
Posts: 102
Joined: 14 Jun 2012, 02:30

Cluster renaming (but magically not renaming) VBS problem

Post by SpookyMunky » 25 Mar 2013, 21:06

Hello all, I was playing around testing new version of my script collection toolbar thingy looking for any bugs I might have missed and came across one that is rather strange. In two of my scripts I have coded in a few checks to see if you want to rename a cluster to CL ( if there are existing clusters but none of them called CL ).. it works fine apart from the odd strange situation where the cluster was created after some specific modelling was done, in which case the cluster gets renamed... but it doesn't.. lol, it's very bizarre, I made a quick vid since I knew I would be hopeless at describing this..

http://www.youtube.com/watch?v=kANzww9XXQY

Is this a known issue ?, or could it just be something that is happening for me alone ? .. the renaming lines themselves are simple...

Code: Select all

SetValue oCol(i) & ".Name" , "CL"

SetValue oSelecto & ".polymsh.cls.edge.clslist.Edge.Name", "CL"
The first is used when the script is run with a cluster selected, the second is if the object is selected and an edge cluster called edge exists, for me it happens with either... I have tried a few things to get it to work, but with my limited knowledge I'm a bit stuck.. one thing I did notice when I was playing around with logmessage and different ways of doing things I saw a cluster being called Edge_INTERNAL or something similar, not sure what that is about ?.. xsi crashed shortly after and I'm not sure what I had done to see that.. was new to me atleast.

http://pastebin.com/qW18e8wi and http://pastebin.com/vx7ZdbfT are the scripts that it is happening with..

If someone is able to replicate my results I recommend deleting the object pretty soon after you have noticed the cluster has been renamed ( but not actually renamed, lol ) since ( for me at least ) xsi gets unstable and dies if I play around with the objects too much trying to figure out what is going on :P

Any tips / advice / help / suggestions / anything would be greatly appreciated :) .. the re-naming isn't essential to the script, just find it a lot nicer than having to do all the renaming myself , one less step..

The rest of the scripts can be found at http://pastebin.com/u/spookymunky incase anyone wants to play around / help me bug check .. or point out simple ways to do things I have needlessly overcomplicated :P... I thought I was close to finishing up until I noticed this bug.. arr, always something new hehe

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

Re: Cluster renaming (but magically not renaming) VBS problem

Post by myara » 30 Jul 2013, 16:05

I know this is an old thread but, I just had some free time today and reading the forum got here by casualty.

When you use deformers they create internal clusters and the SetValue seems to confuse the cluster you want to rename. I don't know the technical aspect of this.

Try using the Object Method instead, something like this:

Code: Select all

set obj = selection(0)   'Your object
set cl = obj.activeprimitive.geometry.clusters   'Your object clusters
set cledge = cl("Edge")    'Your object's cluster named "Edge"
cledge.name = "A"
M.Yara
Character Modeler | Softimage Generalist (sort of)

SpookyMunky
Posts: 102
Joined: 14 Jun 2012, 02:30

Re: Cluster renaming (but magically not renaming) VBS problem

Post by SpookyMunky » 01 Aug 2013, 13:33

Thank you so much myara ! :)

Glad you had some spare time and stumbled across this thread since I had pretty much gave up on ever figuring it out myself after a while. A hidden cluster getting renamed by accident does explain what was happening for me, can't seem to replicate it using this method though.. rock on :)

Took me a bit of head scratching to get it working with a selected cluster as well but this seems to work..

Code: Select all

oSelecto.activeprimitive.geometry.clusters(oCol(i).Name).name = "CL"
oCol(i) being the application selection (if it's a cluster) and oSelecto being it's .Parent3DObject

.. hope thats an ok way to do it ? :)

I will hopefully have a mini update to my toolbar with this bug finally gone soon, has been annoying me alot hehe. Thanks again!

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

Re: Cluster renaming (but magically not renaming) VBS problem

Post by myara » 01 Aug 2013, 14:15

SpookyMunky wrote:

Code: Select all

oSelecto.activeprimitive.geometry.clusters(oCol(i).Name).name = "CL"
oCol(i) being the application selection (if it's a cluster) and oSelecto being it's .Parent3DObject

.. hope thats an ok way to do it ? :)
Yes, that's the Object Method.
Instead of using commands to change the objects properties and parameters, you just change them directly. This is the best way to script, it's process is faster, doesn't log, and you have more control.
M.Yara
Character Modeler | Softimage Generalist (sort of)

SpookyMunky
Posts: 102
Joined: 14 Jun 2012, 02:30

Re: Cluster renaming (but magically not renaming) VBS problem

Post by SpookyMunky » 03 Aug 2013, 17:39

This does seem like a nicer way of doing things.. trying to go through my scripts and make them more "object method" now, as well as cleaning out some sillyness :)

I'm finding I have to keep using dictionary.getobject for some things now that I'm not sure I should have to.. e.g....

Code: Select all

Set oSphere = ActiveSceneRoot.AddGeometry( "Sphere", "MeshSurface", "moo" )

set oSlice = ApplyTopoOp ( "SlicePolygons", oSphere, siUnspecified, siPersistentOperation )
set oSlice = Dictionary.GetObject ( oSlice )
oSlice.planeref.Value = 1
oSlice.sliceaction.Value = 3

set oDupe = Duplicate (oSphere, , 2, 1, 1, 0, 0, 1, 0, 1, , , , , , , , , , , 0)
set oDupe = Dictionary.GetObject ( oDupe )
oDupe.Kinematics.Local.Parameters("PosX").value = 5
oDupe.PosY.Value = 1
Just a silly example, is it normal to have to do this though ?. I don't mind really, it has just left me scratching my head a few times thinking something should work where it wasn't :)

User avatar
csaez
Posts: 253
Joined: 09 Jul 2012, 15:31
Skype: csaezmargotta
Location: Sydney, Australia
Contact:

Re: Cluster renaming (but magically not renaming) VBS problem

Post by csaez » 04 Aug 2013, 20:18

Just get the first element of the collection :)
Returns an XSICollection that contains a list of the created operators.
http://download.autodesk.com/global/doc ... opoOp.html

SpookyMunky
Posts: 102
Joined: 14 Jun 2012, 02:30

Re: Cluster renaming (but magically not renaming) VBS problem

Post by SpookyMunky » 08 Aug 2013, 15:33

Thanks csaez :), silly me.. didn't realise I was still creating collections when applying ops to only one object, makes sense now B-)

SpookyMunky
Posts: 102
Joined: 14 Jun 2012, 02:30

Re: Cluster renaming (but magically not renaming) VBS problem

Post by SpookyMunky » 14 Aug 2013, 00:42

Sorry to ask yet another silly question, I have already got all the info I could ever want from this thread :D, just hmm.. in my bid to convert my stuff to object model (and making some more scripts to keep me amused) I'm a bit unsure how to match an object's center to another object.... e.g. how to replace :

Code: Select all

'Store oDupe's SRT to use for matching up oMerge's Center
oDupeScaleX = oSelecto.Kinematics.Global.Parameters("SclX").Value
oDupeScaleY = oSelecto.Kinematics.Global.Parameters("SclY").Value
oDupeScaleZ = oSelecto.Kinematics.Global.Parameters("SclZ").Value
			
oDupeRotX = oSelecto.Kinematics.Global.Parameters("RotX").Value
oDupeRotY = oSelecto.Kinematics.Global.Parameters("RotY").Value
oDupeRotZ = oSelecto.Kinematics.Global.Parameters("RotZ").Value
			
oDupePosX = oSelecto.Kinematics.Global.Parameters("PosX").Value
oDupePosY = oSelecto.Kinematics.Global.Parameters("PosY").Value
oDupePosZ = oSelecto.Kinematics.Global.Parameters("PosZ").Value	
			
			
'Match oMerge's Center to oDupe's SRT
Translate oMerge, oDupePosX, oDupePosY, oDupePosZ, siAbsolute, siGlobal, siCtr, siXYZ, , , , , , , , , , 0
Rotate oMerge, oDupeRotX, oDupeRotY, oDupeRotZ, siAbsolute, siGlobal, siCtr, siXYZ, , , , , , , , 0
Scale oMerge, oDupeScaleX, oDupeScaleY, oDupeScaleZ, siAbsolute, siGlobal, siCtr, siXYZ, , , , , , , , 0
with something more like...

Code: Select all

'Match oMerge's Center to oDupe's SRT
oMerge.Kinematics.Local.Parameters("PSclX").Value = oSelecto.Kinematics.Global.Parameters("SclX").Value
oMerge.Kinematics.Local.Parameters("PSclY").Value = oSelecto.Kinematics.Global.Parameters("SclY").Value
oMerge.Kinematics.Local.Parameters("PSclZ").Value = oSelecto.Kinematics.Global.Parameters("SclZ").Value

oMerge.Kinematics.Local.Parameters("PRotX").Value = oSelecto.Kinematics.Global.Parameters("RotX").Value
oMerge.Kinematics.Local.Parameters("PRotY").Value = oSelecto.Kinematics.Global.Parameters("RotY").Value
oMerge.Kinematics.Local.Parameters("PRotZ").Value = oSelecto.Kinematics.Global.Parameters("RotZ").Value

oMerge.Kinematics.Local.Parameters("PPosX").Value = oSelecto.Kinematics.Global.Parameters("PosX").Value
oMerge.Kinematics.Local.Parameters("PPosY").Value = oSelecto.Kinematics.Global.Parameters("PosY").Value
oMerge.Kinematics.Local.Parameters("PPosZ").Value = oSelecto.Kinematics.Global.Parameters("PosZ").Value
I thought I was onto the center with pivot / PPos etc since hmm.. .something like ..

Code: Select all

set oSelecto = Selection(0)
oSelecto.Kinematics.Local.Parameters("PPosX").Value = 5
will move the objects center... am totally confused to be honest. To me the pivot position I thought would just be for a transform, it works to move the center tho.. I must be being an idiot somewhere hehe.

It makes no difference to the script really, just something that has been bugging me for a week now that I cant seem to find in manual. Apart from this I think I'm a convert to object model way since it makes more sense I guess, was really enjoying learning coding till I came up against that bug with setvalue, kinda killed the joy. Now that I realise it was mostly me being dumb and I'm slowly re-discovering the fun hehe, thanks again :) . For most part its gone fine and with some silly tests (dunno how to time them properly so just counting seconds in my head) my scripts seem to be about twice the speed now :)

Edit: http://pastebin.com/PZs4zzQP is the full script that is mostly working, with the ppos lines commented out at around line 350-360 or so. The code is far from finished, I'v just been concentrating on converting things to object model and fixing bugs, tiny amount of new functionality hehe. The way Iv been checking to see if the center move has been working is just create a sphere, move it away from 0,0,0 and create a model for it, reselect the sphere and run the script... If there's other things I still have that need to be converted I'd love to know :D

User avatar
csaez
Posts: 253
Joined: 09 Jul 2012, 15:31
Skype: csaezmargotta
Location: Sydney, Australia
Contact:

Re: Cluster renaming (but magically not renaming) VBS problem

Post by csaez » 14 Aug 2013, 02:53

Hi there,
Move the center involves move the object (kinematics) and offset the points' positions back (geometry), that's why a center operator is automagically created for you.
You can do it via OM but it's not that easy, you will need some 'matrix maths' to calculate the offset and move the points around will be slower... I would go with the command on this one :)

Cheers!

SpookyMunky
Posts: 102
Joined: 14 Jun 2012, 02:30

Re: Cluster renaming (but magically not renaming) VBS problem

Post by SpookyMunky » 18 Aug 2013, 17:38

thanks again csaez :)

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

Re: Cluster renaming (but magically not renaming) VBS problem

Post by myara » 19 Aug 2013, 09:38

It's better to work with OM but sometimes it gets so complicated that is recommendable to work with commands instead. In this case just use Translate.

When you use Translate, the command will leave a Center Operator, and log the command.

So, freeze the Center if you want it cleaner, and turn off the log if you want a little more speed in an script (for a plugin command it isn't necessary).

Code: Select all

dim prefs : set prefs = Application.Preferences
prefs.SetPreferenceValue "scripting.cmdlog", false
SI will automatically revert the Log Preference to default when the script has finished. You can't turn off the log preference permanently by scripting.

And btw, the "o" in a variable means it's an object (to difference it from a string, or an integer value).

ex:
sCube = "cube"
set oCube = Dictionary.GetObject(sCube)

being sCube just an string value and oCube an object, meaning you can get oCube.posx but not sCube.posx

But, of course you can name your variables the way you want.
M.Yara
Character Modeler | Softimage Generalist (sort of)

SpookyMunky
Posts: 102
Joined: 14 Jun 2012, 02:30

Re: Cluster renaming (but magically not renaming) VBS problem

Post by SpookyMunky » 19 Aug 2013, 16:02

Sadly it took me quite a while before I realised the o part was just for objects, so I guess I have developed a few silly habits :). For things like oDupe I guess I think on that as the full name, as opposed to object Dupe, so for anything related to oDupe to me it seems logical to just add bits on the end even if the variables aren't objects (those names have now been changed to oSelectoScaleX etc now btw hehe, not sure they were still oDupe after I guess I replaced the values.. lazy). In other places there is no excuse :P, I think I just suck at naming anything and default to quickly thinking on a name with o at the start so I will recognise it for later replacing.. then forgetting to :D

Thanks for reminding me though!, I think alot of the strings / integers I use don't have anything at the start, would make a lot of sense to (attempt to) fix that while the code is still fresh in my mind. After a while I guess I feel intimidated to start renaming things :)

Post Reply

Who is online

Users browsing this forum: No registered users and 35 guests