コード例 #1
0
        public BlockDefinition BlockDefinitionToSpeckle(RH.InstanceDefinition definition)
        {
            var geometry = new List <Base>();

            foreach (var obj in definition.GetObjects())
            {
                if (CanConvertToSpeckle(obj))
                {
                    Base converted = ConvertToSpeckle(obj);
                    if (converted != null)
                    {
                        converted["Layer"] = Doc.Layers[obj.Attributes.LayerIndex].FullPath;
                        geometry.Add(converted);
                    }
                }
            }

            var _definition = new BlockDefinition()
            {
                name      = definition.Name,
                basePoint = PointToSpeckle(Point3d.Origin), // rhino by default sets selected block def base pt at world origin
                geometry  = geometry,
                units     = ModelUnits
            };

            return(_definition);
        }
コード例 #2
0
    public static Rhino.Commands.Result InstanceArchiveFileStatus(Rhino.RhinoDoc doc)
    {
        for (int i = 0; i < doc.InstanceDefinitions.Count; i++)
        {
            Rhino.DocObjects.InstanceDefinition iDef = doc.InstanceDefinitions[i];
            Rhino.DocObjects.InstanceDefinitionArchiveFileStatus iDefStatus = iDef.ArchiveFileStatus;

            string status = "Unknown";
            switch (iDefStatus)
            {
            case Rhino.DocObjects.InstanceDefinitionArchiveFileStatus.NotALinkedInstanceDefinition:
                status = "not a linked instance definition.";
                break;

            case Rhino.DocObjects.InstanceDefinitionArchiveFileStatus.LinkedFileNotReadable:
                status = "archive file is not readable.";
                break;

            case Rhino.DocObjects.InstanceDefinitionArchiveFileStatus.LinkedFileNotFound:
                status = "archive file cannot be found.";
                break;

            case Rhino.DocObjects.InstanceDefinitionArchiveFileStatus.LinkedFileIsUpToDate:
                status = "archive file is up-to-date.";
                break;

            case Rhino.DocObjects.InstanceDefinitionArchiveFileStatus.LinkedFileIsNewer:
                status = "archive file is newer.";
                break;

            case Rhino.DocObjects.InstanceDefinitionArchiveFileStatus.LinkedFileIsOlder:
                status = "archive file is older.";
                break;

            case Rhino.DocObjects.InstanceDefinitionArchiveFileStatus.LinkedFileIsDifferent:
                status = "archive file is different.";
                break;
            }

            Rhino.RhinoApp.WriteLine("{0} - {1}", iDef.Name, status);
        }

        return(Rhino.Commands.Result.Success);
    }
コード例 #3
0
    public static Rhino.Commands.Result CreateBlock(Rhino.RhinoDoc doc)
    {
        // Select objects to define block
        var go = new Rhino.Input.Custom.GetObject();

        go.SetCommandPrompt("Select objects to define block");
        go.ReferenceObjectSelect = false;
        go.SubObjectSelect       = false;
        go.GroupSelect           = true;

        // Phantoms, grips, lights, etc., cannot be in blocks.
        const ObjectType forbidden_geometry_filter = Rhino.DocObjects.ObjectType.Light |
                                                     Rhino.DocObjects.ObjectType.Grip | Rhino.DocObjects.ObjectType.Phantom;
        const ObjectType geometry_filter = forbidden_geometry_filter ^ Rhino.DocObjects.ObjectType.AnyObject;

        go.GeometryFilter = geometry_filter;
        go.GetMultiple(1, 0);
        if (go.CommandResult() != Rhino.Commands.Result.Success)
        {
            return(go.CommandResult());
        }

        // Block base point
        Rhino.Geometry.Point3d base_point;
        var rc = Rhino.Input.RhinoGet.GetPoint("Block base point", false, out base_point);

        if (rc != Rhino.Commands.Result.Success)
        {
            return(rc);
        }

        // Block definition name
        string idef_name = "";

        rc = Rhino.Input.RhinoGet.GetString("Block definition name", false, ref idef_name);
        if (rc != Rhino.Commands.Result.Success)
        {
            return(rc);
        }
        // Validate block name
        idef_name = idef_name.Trim();
        if (string.IsNullOrEmpty(idef_name))
        {
            return(Rhino.Commands.Result.Nothing);
        }

        // See if block name already exists
        Rhino.DocObjects.InstanceDefinition existing_idef = doc.InstanceDefinitions.Find(idef_name, true);
        if (existing_idef != null)
        {
            Rhino.RhinoApp.WriteLine("Block definition {0} already exists", idef_name);
            return(Rhino.Commands.Result.Nothing);
        }

        // Gather all of the selected objects
        var geometry   = new System.Collections.Generic.List <Rhino.Geometry.GeometryBase>();
        var attributes = new System.Collections.Generic.List <Rhino.DocObjects.ObjectAttributes>();

        for (int i = 0; i < go.ObjectCount; i++)
        {
            var rhinoObject = go.Object(i).Object();
            if (rhinoObject != null)
            {
                geometry.Add(rhinoObject.Geometry);
                attributes.Add(rhinoObject.Attributes);
            }
        }

        // Gather all of the selected objects
        int idef_index = doc.InstanceDefinitions.Add(idef_name, string.Empty, base_point, geometry, attributes);

        if (idef_index < 0)
        {
            Rhino.RhinoApp.WriteLine("Unable to create block definition", idef_name);
            return(Rhino.Commands.Result.Failure);
        }
        return(Rhino.Commands.Result.Failure);
    }