Hi there,
is there a way to extract an item from a block instance (blockreference) without exploding it?
I did not find any possiblity in Rhino.Input so far.
Maybe I simply did nto see it.
Otherwise I would have to explode a copy of the instance and then pick it, right?
Or is there an easier way?
Thanks,
T.
dale
(Dale Fugier)
July 22, 2021, 3:47pm
2
Hi @tobias.stoltmann ,
Just hold the Shift key down when selecting:
import Rhino
import scriptcontext as sc
filter = Rhino.DocObjects.ObjectType.Surface | \
Rhino.DocObjects.ObjectType.PolysrfFilter
go = Rhino.Input.Custom.GetObject()
go.SetCommandPrompt("Select surfaces and polysurfaces")
go.GeometryFilter = filter
go.GetMultiple(1, 0)
if go.CommandResult() == Rhino.Commands.Result.Success:
print('{0} object(s) selected'.format(go.ObjectCount))
– Dale
1 Like
As always: works like a charm,@dale .
Is there any chance to get the instance reference the surface belongs to by any chance?
@dale , I do not even have to hold the Shift key to do so.
dale
(Dale Fugier)
July 23, 2021, 3:22pm
5
Hi @tobias.stoltmann ,
Try this:
import Rhino
import scriptcontext as sc
go = Rhino.Input.Custom.GetObject()
go.SetCommandPrompt("Select surfaces and polysurfaces")
go.GeometryFilter = Rhino.DocObjects.ObjectType.Surface
go.GetMultiple(1, 0)
if go.CommandResult() == Rhino.Commands.Result.Success:
for objref in go.Objects():
obj = objref.Object()
if obj:
print('Id = {0}, Type = {1}'.format(obj.Id, obj.ObjectType))
srf = objref.Surface()
if srf:
print(' Degree "U" = {0}, "V" = {1}'.format(srf.Degree(0), srf.Degree(1)))
– Dale
@dale , thanks. Without testing (I will be able later), I guess I was a bit to inprecise. What I would need is the block definition or block instance this item is contained in to be able to replace it to it after modifying it.
dale
(Dale Fugier)
July 23, 2021, 5:42pm
7
Hi @tobias.stoltmann ,
This is the instance object:
obj = objref.Object()
And this will get you the instance definition:
if isinstance(obj, Rhino.DocObjects.InstanceObject):
idef = obj.InstanceDefinition
if idef:
print('Block name = {0}'.format(idef.Name))
– Dale
dale:
import Rhino
import scriptcontext as sc
go = Rhino.Input.Custom.GetObject()
go.SetCommandPrompt("Select surfaces and polysurfaces")
go.GeometryFilter = Rhino.DocObjects.ObjectType.Surface
go.GetMultiple(1, 0)
if go.CommandResult() == Rhino.Commands.Result.Success:
for objref in go.Objects():
obj = objref.Object()
if obj:
print('Id = {0}, Type = {1}'.format(obj.Id, obj.ObjectType))
srf = objref.Surface()
if srf:
print(' Degree "U" = {0}, "V" = {1}'.format(srf.Degree(0), srf.Degree(1)))
I have to admit I was always stuggling with the ObjRefs so far, but now I got the idea.
THANKS!
@dale , I do not intend to carry this too far, but there is one last question.
This only works for “simple” block references, right?
If I am dealing with nested blocks, this will not work. As far as I tested it now, it always refers to the “superior” block.