ShynnSup
(Shynn Sup)
February 1, 2019, 1:12pm
1
Hi everyone,
I am currently looking for a way to reset block transformations, it would come in real handy.
I found this thread by some scripts uploaded but the link seems broken.
Reset (or change) block instances transformations (scale, rotation) ’
Thanks!
On the same thread you can find a link to rhinotools
:
You can find what you’re looking for there:
"""
@name: ResetBlockScale
@description: Resets the scale of a block, keeping the rotation around the insertion point.
@author: Ejnar Brendsdal
@version: 1.3
@attribution: Inspired by the ResetBlock script by Dale Fugier. Thank you.
@link: https://github.com/ejnaren/rhinotools
@notes: Works with Rhino 5.
@license:
The MIT License (MIT)
Copyright (c) 2016 Ejnar Brendsdal
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
This file has been truncated. show original
ShynnSup
(Shynn Sup)
February 1, 2019, 2:14pm
3
Hi! Thank you, but I am afraid the script isn’t doing what I need, I think this one only resets scale…
I runs okay, but I can see the block has not been reset by looking at the gumball. Then I check the Base Point of the Block, and indeed it is still located differently from a newly inserted block.
If you want to reset everything, you can simply use Transform.TryGetInverse() :
import rhinoscriptsyntax as rs
import scriptcontext as sc
def RunCommand( is_interactive ):
if sc.escape_test(False):
print "script cancelled" #do something
print "Resetting..."
objectIds = rs.GetObjects("Pick some blocks", 4096, preselect=True)
if not objectIds:
print "No objects"
return False
rs.EnableRedraw(False)
for id in objectIds:
blockXForm = rs.BlockInstanceXform(id)
inverseBlockXForm = blockXForm.TryGetInverse()[1]
rs.TransformObject(id, inverseBlockXForm)
rs.SelectObjects(objectIds)
rs.EnableRedraw(True)
print "...aaand its done."
return 0
RunCommand(True)
ShynnSup.py (680 Bytes)
1 Like
pascal
(Pascal Golay)
February 1, 2019, 3:55pm
6
Wouldn’t just inserting a new instance at W0,0,0 do that?
-Pascal
dale
(Dale Fugier)
February 1, 2019, 3:59pm
7
ShynnSup
(Shynn Sup)
February 1, 2019, 4:28pm
8
Technically but the script can be applied to multiple blocks at once!
And it saves the trouble of looking for the block in the insert window.
pascal
(Pascal Golay)
February 1, 2019, 5:25pm
9
Yes, of course, but the script could be greatly simplified, it seems to me…
import rhinoscriptsyntax as rs
ids = rs.GetObjects(filter=4096, preselect=True)
if ids:
for id in ids:
rs.InsertBlock(rs.BlockInstanceName(id), [0,0,0])
rs.DeleteObject(id)
or, in place:
import rhinoscriptsyntax as rs
ids = rs.GetObjects(filter=4096, preselect=True)
if ids:
for id in ids:
rs.InsertBlock(rs.BlockInstanceName(id), rs.BlockInstanceInsertPoint(id))
rs.DeleteObject(id)
-Pascal
5 Likes