# Resets a block instance by modifying its transformation to be
# translation only. Thus, only position (not rotation or scale)
# are retained.
import rhinoscriptsyntax as rs
def main():
blocks = rs.GetObjects("Select block instances to reset",
filter=rs.filter.instance, preselect=True)
if not blocks:
return
rs.EnableRedraw(False)
for str_block in blocks:
xform = rs.BlockInstanceXform(str_block)
xform_inverse = xform.TryGetInverse()[1]
rs.TransformObject(id, xform_inverse)
rs.EnableRedraw(True)
if __name__ == '__main__':
main()
It seems like rs.Transform() excludes block transforms and rs.BlockInstanceXform() does not have the second argument anymore, that allows to set the matrix of the block. Is there any other way to change the block transformation matrix?
# Resets a block instance by modifying its transformation to be
# translation only. Thus, only position (not rotation or scale)
# is retained.
import Rhino
import scriptcontext as sc
def ResetBlock():
filter = Rhino.DocObjects.ObjectType.InstanceReference
rc, objrefs = Rhino.Input.RhinoGet.GetMultipleObjects('Select block instances to reset', False, filter)
if rc != Rhino.Commands.Result.Success:
return
for objref in objrefs:
irefObj = objref.Object()
if isinstance(irefObj, Rhino.DocObjects.InstanceObject):
idef = irefObj.InstanceDefinition
dir = irefObj.InsertionPoint - Rhino.Geometry.Point3d.Origin
xform = Rhino.Geometry.Transform.Translation(dir)
iref = Rhino.Geometry.InstanceReferenceGeometry(idef.Id, xform)
sc.doc.Objects.Replace(objref, iref, False)
sc.doc.Views.Redraw()
if __name__ == "__main__":
ResetBlock()
@dale Many thanks for the quick reply. Maybe I did not explain correctly what I try to achieve or the script is not working as expected. Please see the below video. To my understanding, the rotation components of the object’s matrix did not change. Also xform holds the identity matrix (please see print of script).