Get Block Name using RhinoCommons in Python

import Rhino 

go = Rhino.Input.Custom.GetObject()
go.SetCommandPrompt("Select objects")
go.GetMultiple(1,1)

go.Objects().InstanceDefinitionPart()

I am trying to get the name of one or more block instance. But this is as far as i can go. Something is definitely missing there.
Can someone point me to the right direction?

I know we can do it in rhinoscriptsyntax like this:

import rhinoscriptsyntax as rs

objs = rs.GetObjects(preselect = True)
for obj in objs:
    print rs.BlockInstanceName(obj)

bump for tag change

Hi Wiley
try this

import Rhino 

go = Rhino.Input.Custom.GetObject()
go.SetCommandPrompt("Select objects")
go.GetMultiple(1,1)

objs =  go.Objects()
if(objs):
    for obj in objs:
        print obj.Object().InstanceDefinition.Name

Hi Naruto,
Thanks for the answer.

I am still learning Rhinocommons.

How to test if it is a block?

In Rhinoscriptsyntax we can do sth like this:
rs.IsBlock()

Hi Wiley
You can learn rhinocommon by looking at the code of rhinoscriptsyntax.
like this.
1ļ¼šdebug code


2ļ¼šRun the code态Step intoļ¼ˆF11ļ¼‰

3ļ¼šYou can see the IsBlock() function.

1 Like

Thanks Naruto.
Thatā€™s a great way to learn RhinoCommon!

really appreciate it!

If you donā€™t mind me asking againā€¦

about the naming convention:
sometimes the in-built python functions start with two underscore __
such as below
__InstanceObjectFromId(object_id, False)

How are they differentiated with the normal ones?

Hi @Wiley,

The underscore prefix is meant as a hint to another programmer that a variable or method starting with a single underscore is intended for internal use. Python does not have strong distinctions between ā€œprivateā€ and ā€œpublicā€ variables, like other languages, so this convention is often used by programmers.

ā€“ Dale

2 Likes

Thanks!
So the underscore is actually the private equivalent in C#. got it!