Site Tools


Differences

This shows you the differences between two versions of the page.

Link to this comparison view

developer:rhinocommonsamples:blockinsertionpoint [2015/09/14] (current)
Line 1: Line 1:
 +===== Sample: Obtain insertion point of block =====
 +
 +===== C# =====
 +<code c#>
 +public static Rhino.Commands.Result BlockInsertionPoint(Rhino.RhinoDoc doc)
 +{
 +  Rhino.Commands.Result rc = Rhino.Commands.Result.Success;​
 +  Rhino.DocObjects.ObjRef objref;
 +  rc = Rhino.Input.RhinoGet.GetOneObject("​Select instance",​ true, Rhino.DocObjects.ObjectType.InstanceReference,​ out objref);
 +  if (rc != Rhino.Commands.Result.Success)
 +    return rc;
 +  Rhino.DocObjects.InstanceObject instance = objref.Object() as Rhino.DocObjects.InstanceObject;​
 +  if (instance != null)
 +  {
 +    Rhino.Geometry.Point3d pt = instance.InsertionPoint;​
 +    doc.Objects.AddPoint(pt);​
 +    doc.Views.Redraw();​
 +  }
 +  return Rhino.Commands.Result.Success;​
 +}
 +</​code>​
 +===== VB.NET =====
 +<code vb>
 +Public Shared Function BlockInsertionPoint(ByVal doc As Rhino.RhinoDoc) As Rhino.Commands.Result
 +  Dim rc As Rhino.Commands.Result = Rhino.Commands.Result.Success
 +  Dim objref As Rhino.DocObjects.ObjRef = Nothing
 +  rc = Rhino.Input.RhinoGet.GetOneObject("​Select instance",​ True, Rhino.DocObjects.ObjectType.InstanceReference,​ objref)
 +  If rc <> Rhino.Commands.Result.Success Then
 +    Return rc
 +  End If
 +  Dim instance As Rhino.DocObjects.InstanceObject = TryCast(objref.[Object](),​ Rhino.DocObjects.InstanceObject)
 +  If instance IsNot Nothing Then
 +    Dim pt As Rhino.Geometry.Point3d = instance.InsertionPoint
 +    doc.Objects.AddPoint(pt)
 +    doc.Views.Redraw()
 +  End If
 +  Return Rhino.Commands.Result.Success
 +End Function
 +</​code>​
 +===== Python =====
 +<code python>
 +import Rhino
 +import scriptcontext
 +
 +def BlockInsertionPoint():​
 +    rc, objref = Rhino.Input.RhinoGet.GetOneObject("​Select instance",​ True, Rhino.DocObjects.ObjectType.InstanceReference)
 +    if rc!=Rhino.Commands.Result.Success:​ return rc;
 +    instance = objref.Object()
 +    if instance:
 +        pt = instance.InsertionPoint
 +        scriptcontext.doc.Objects.AddPoint(pt)
 +        scriptcontext.doc.Views.Redraw()
 +        return Rhino.Commands.Result.Success
 +    return Rhino.Commands.Result.Failure
 +
 +if __name__=="​__main__":​
 +    BlockInsertionPoint()
 +</​code>​
 +
 +{{tag>​Developer rhinocommon}}
  
developer/rhinocommonsamples/blockinsertionpoint.txt ยท Last modified: 2015/09/14 (external edit)