'###########################################################################
#####
'NAME: Add Null To Point v2.0
'AUTHOR: Olivier Ozoux <[email protected]>
'LAST MODIFIED: 2001-05-22
'
'v2.0 is a complete rewrite using the Object Model where possible
'
'INSTALL
'
'1. Copy the SPDL file:
' {5CD342AD-2FB1-4646-9D14-3E82C805177D}.spdl
' to the spdl directory of XSI (for example):
' C:\Softimage\XSI_1.5\Application\spdl
'
'2. Copy the Preset file:
' AddNullToPointDialog.Preset
' to the Preset Property directory of XSI (for example):
' D:\Softimage\XSI_1.5\DSPresets\Properties
'
'3. Restart XSI
'
'4. Run the Script or Create a Command/Button on a toolbar
'
'
'This tool will create a single Null for each point of the selected
object(s).
'(you can also select a point cluster, or tag points). Then based on the
dialog
'choice, it will either Constrain the Null to the Point using Object to
Cluster
'constraint, or Deform the point to the Null with a Cluster Center operator.
'
'-Olivier Ozoux
'###########################################################################
####
Option Explicit
AddNullToPointProc
'---------'---------'---------'---------'---------'---------'---------'-----
----
sub AddNullToPointProc()
'---------'---------'---------'---------'---------'---------'---------'-----
----
Dim oSel, Name, Parent, Mode, oDialog
'Create the dialog
set oDialog = CreateUIDialog
On Error Resume Next
InspectObj oDialog,,,4
if Err.Number = 0 then
On Error Goto 0
'Read the dialog values
Mode = oDialog.parameters("CnsType").value
Name = oDialog.parameters("NullName").value
Parent = oDialog.parameters("ParentObj").value
'loop over the selection
for each oSel in selection
addNullToPoint oSel, Mode,Name,Parent
next
end if
'Cleanup
DeleteObj oDialog
end sub
'---------'---------'---------'---------'---------'---------'---------'-----
----
function CreateUIDialog()
'---------'---------'---------'---------'---------'---------'---------'-----
----
Dim oRoot, oDialog, oParam
set oRoot = ActiveProject.ActiveScene.Root
On Error Resume Next
'Try to load the edited dialog first
set oDialog =
oRoot.AddProperty("AddNullToPointDialog",,"AddNullToPoint")
if Err.Number <> 0 then
'Build a custom dialog
set oDialog =
oRoot.AddProperty("Custom_Parameter_List",,"AddNullToPoint")
set oParam = oDialog.AddParameter("CnsType", siInt4,,4,,
"Constrain Type", , 0, 0, 1)
set oParam = oDialog.AddParameter("NullName",
siString,,4,,"Null Names",,"<name>_Null")
set oParam = oDialog.AddParameter("ParentObj",
siBool,,4,,"Parent Nulls ",,TRUE)
end if
oDialog.parameters("NullName").Value = "<obj>_pnt"
'Return the Dialog Object
set CreateUIDialog = oDialog
end function
'---------'---------'---------'---------'---------'---------'---------'-----
----
sub addNullToPoint(oSel, Mode, Name, Parent)
'---------'---------'---------'---------'---------'---------'---------'-----
----
Dim oRoot, oGeom, oPoints, oCls, oNull
Dim aTmp(), i, aIndex, tmp, pntName
'There are 3 cases we support
'1 oSel is a Geometry object (poly,srf,curve)
'2 oSel is a tagged selection
'3 oSel is a point Cluster
set oRoot = ActiveProject.ActiveScene.root
'First Case
if oSel.type = "polymsh"_
Or oSel.type = "surfmsh"_
Or oSel.type = "crvlist" then
set oGeom = oSel.ActivePrimitive.Geometry
set oPoints = oGeom.Points
'Create a 1:1 index array
redim aTmp(oPoints.count -1)
for i=0 to oPoints.count -1
aTmp(i) = i
next
aIndex = aTmp
'Second Case
elseif oSel.type = "pntSubComponent" then
'this is a tag selection.
aIndex = oSel.subelements
'Workaround to get the object from the selection
tmp = split(oSel, ".")
if ubound(tmp) = 2 then
'under a model
oSel = tmp(0) & "." & tmp(1)
else
'under the scene_root
oSel = tmp(0)
end if
set oSel = getvalue(oSel)
if oSel.type = "polymsh"_
Or oSel.type = "polymsh"_
Or oSel.type = "surfmsh"_
Or oSel.type = "crvlist" then
set oGeom = oSel.ActivePrimitive.Geometry
set oPoints = oGeom.Points
else
logmessage "Not a valid Geometry!"
exit sub
end if
'Third Case
elseif oSel.type = "pnt" then
'It's a Point Cluster
aIndex = oSel.Elements.Array
set oGeom = oSel.Parent
'workaround to get the object from the cluster
tmp = split(oSel, ".")
if ubound(tmp) = 4 then
'under a model
oSel = tmp(0) & "." & tmp(1)
else
'under the scene_root
oSel = tmp(0)
end if
set oSel = getvalue(oSel)
set oPoints = oGeom.Points
else
logmessage "Not a Geometry!"
exit sub
end if
'Mangle a name together, replacing <obj> with the real name of the
object.
pntName = Replace(Name, "<obj>", oSel.name)
'Start going thru the points in the index
for i=0 to uBound(aIndex)
'Create a Cluster with that point
set oCls = oGeom.addCluster( "pnt", "pnt" & aIndex(i),
array(aIndex(i)) )
'Create a Null
set oNull = oSel.AddNull( pntName & aIndex(i) )
Select Case Mode
Case 0 'Null to Point
'Constrain the Null to the Cluster
oNull.Kinematics.AddConstraint
"ObjectToCluster", oCls, False
Case 1 'Point to Null
'Move the Null in position
oNull.kinematics.local.parameters("posx").value =
oPoints(aIndex(i)).position.x
oNull.kinematics.local.parameters("posy").value =
oPoints(aIndex(i)).position.y
oNull.kinematics.local.parameters("posz").value =
oPoints(aIndex(i)).position.z
'Create ClusterCenter
ApplyOperator "ClusterCenter", oCls & ";" &
oNull , 0
End Select
'Cut The Null iff needed
if Parent = False then
CutObj oNull
end if
next
end sub
-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Gerbrand Nel
Sent: Thursday, July 19, 2012 1:50 PM
To: xsi group
Subject: OO_addnullstopoint script
Ok this might give away my age, but I remember a time when the "add nulls to
points" script gave you a choice between constrain to nulls, and constrain
points to nulls.
In 2013 it only constrains to the nulls.
Anyone know where I can find a script to create nulls on selected points,
constrained to those points?
I saw some Ice stuff to do this on rray.de, but I miss the old way.
Thanks guys
G