Hi all,
I am trying to translate this code in Ironpython. I do only need the instance definitions part because I couldnt instantiate a Rhinodoc object for some reason and the instancedefinitions dont have method for adding in Ironpython documentation.
RhinoDoc doc = new RhinoDoc();
// Create a block with a 3D sphere as mnodel representation
var sphere = Brep.CreateFromSphere(new Sphere(Point3d.Origin, 1.0 * unitScale));
doc.InstanceDefinitions.Add("Sphere", string.Empty, Point3d.Origin, new[] { sphere });
I think this is what I was looking for. Thanks !
idef_index = scriptcontext.doc.InstanceDefinitions.Add(idef_name, “”, base_point, geometry, attributes)
I have another problem. for some reason I couldnt input the group of geometries into the python script using
the Rhino.Input.Custom.GetObject() method.
Instead I have tried to use the rhinoscriptsyntax.GetObject()
But now I have this problem that I can input a guid and not a rhino object.
Is there a way to transform the guid into a rhino object ?
and if not why do the Rhino.Input.Custom.GetObject()
not really functioning in Python editor ?.
The most direct way to go from guid to geometry is rs.coercegeometry(). Here is a simplified example to select objects, make a instance definition, and add a block to the doc:
import rhinoscriptsyntax as rs
import scriptcontext as sc
import Rhino as R
# get object guids
guids = rs.GetObjects('select objects')
# get references to object geometries
geometries = []
for guid in guids:
geometries.append(rs.coercegeometry(guid))
# make an instance definition
block_index = sc.doc.InstanceDefinitions.Add('block_name', 'block_description', R.Geometry.Point3d.Origin, geometries)
print('Instance Definition Index: {}'.format(block_index))
# to add the block to the document, we need a transform
transform = R.Geometry.Transform.Translation(20, 20, 0)
# add a block to the document using the instance definition index
block_guid = sc.doc.Objects.AddInstanceObject(block_index, transform)
print('Block guid: {}'.format(block_guid))
As the linked formal example shows, you should probably sanitize what you pass into the instance definition.