How to find the first obj after insert by RunScript


#1

Hello all,

I insert a Block and I want give him some Usertext infos.

But I can´t get the first RhinoObject.

public static void mycommand(string script)
    {
        RhinoApp.WriteLine(script);
        RhinoApp.RunScript(script, true);
    }

This worked well but ,

public static Rhino.DocObjects.RhinoObject first_obj(RhinoDoc doc)
{
Rhino.DocObjects.RhinoObject first;
first = doc.Objects.First();

        return first;
    }

but this find one Block only if I run the script two times.

so I think after run scrip I need somethink so this first_obj can work well ???


#2

You have to add 2 things to your “script” I think. Add at the end:

 _selnone _sellast 

with this your new created item will be selected. After this you can get the selected item with:

Dim go = New Rhino.Input.Custom.GetObject
go.EnablePreSelect(True, False)
go.EnablePostSelect(False)
Dim res As Rhino.Input.GetResult = go.Get()
If (res = Rhino.Input.GetResult.Object) Then
Dim objRef As Rhino.DocObjects.ObjRef = go.Object(0)
Dim obj As Rhino.DocObjects.RhinoObject = objRef.Object()
End If

The user will not be able to select more objects or another one.

(Sorry I only know how vb.net works but it is almost the same. Think you will be able to translate it :))


#3

Thanks jordy,

but _selLast give you not the Last it give you all you create in the plug-in.

If I insert a point by

my_id = doc.Objects.AddPoint§;

I can find this point as the first object.
so I think Insert the block by the scrip metode is not the best.
so I have to find a way read a file and insert by
my_id = doc.Objects.AddInstanceObject(index, xform);

but I don´t know how to read a 3dm-file and find the index

Thanks Robert


#4

to create a block see:

So that means block information is used in:

doc.InstanceDefinitions

and can search by name with:

doc.InstanceDefinitions.Find("blockname", False)

If you want to test this use:

Dim MyBlock As DocObjects.InstanceDefinition
MyBlock = doc.InstanceDefinitions.Find("blabla", False)
MsgBox(MyBlock.Description.ToString)

Give your block a name like “blabla” use a description and let it return to you :wink: