Beispiel #1
0
            /// <summary>
            /// Returns an array of all group names.
            /// </summary>
            /// <param name="ignoreDeletedGroups">Ignore any groups that were deleted.</param>
            /// <returns>An array if group names if succesful, null if there are no groups.</returns>
            /// <since>5.0</since>
            public string[] GroupNames(bool ignoreDeletedGroups)
            {
                int count = Count;

                if (count < 1)
                {
                    return(null);
                }
                Rhino.Collections.RhinoList <string> names = new Rhino.Collections.RhinoList <string>(count);
                for (int i = 0; i < count; i++)
                {
                    if (ignoreDeletedGroups && IsDeleted(i))
                    {
                        continue;
                    }
                    string name = GroupName(i);
                    if (!string.IsNullOrEmpty(name))
                    {
                        names.Add(name);
                    }
                }
                if (names.Count < 1)
                {
                    return(null);
                }
                return(names.ToArray());
            }
Beispiel #2
0
 public BakeGeometry GetBKGT(Rhino.Geometry.Point3d[] m)
 {
     return(new BakeGeometry((d, a, o) =>
     {
         Rhino.DocObjects.ObjectAttributes a2 = a.Duplicate();
         a2.LayerIndex = 3;
         Rhino.Collections.RhinoList <Guid> id = d.Objects.AddPoints(m, a2);
         o.AddRange(id);
     }));
 }
        public DocObjects.ObjRef[] Objects()
        {
            int count = ObjectCount;

            if (count < 1)
            {
                return(null);
            }
            Rhino.Collections.RhinoList <DocObjects.ObjRef> objrefs = new Rhino.Collections.RhinoList <Rhino.DocObjects.ObjRef>(count);
            for (int i = 0; i < count; i++)
            {
                DocObjects.ObjRef objref = Object(i);
                objrefs.Add(objref);
            }
            return(objrefs.ToArray());
        }
Beispiel #4
0
 /// <summary>
 /// Adds a list of objects to an existing group.
 /// </summary>
 /// <param name="groupIndex">The group index value.</param>
 /// <param name="objectIds">An array, a list or any enumerable set of IDs to objects.</param>
 /// <returns>true if at least an operation was successful.</returns>
 /// <since>5.0</since>
 public bool AddToGroup(int groupIndex, System.Collections.Generic.IEnumerable <Guid> objectIds)
 {
     if (null == objectIds)
     {
         return(false);
     }
     Rhino.Collections.RhinoList <Guid> ids = new Rhino.Collections.RhinoList <Guid>();
     foreach (Guid id in objectIds)
     {
         ids.Add(id);
     }
     if (ids.Count < 1)
     {
         return(false);
     }
     return(UnsafeNativeMethods.CRhinoGroupTable_AddToGroup(m_doc.RuntimeSerialNumber, groupIndex, ids.Count, ids.m_items));
 }
Beispiel #5
0
 /// <summary>
 /// Adds a new group to the group table with a set of objects.
 /// </summary>
 /// <param name="groupName">Name of new group.</param>
 /// <param name="objectIds">An array, a list or any enumerable set of object IDs.</param>
 /// <returns>
 /// &gt;=0 index of new group.
 /// <para>-1 group not added because a group with that name already exists.</para>
 /// </returns>
 /// <remarks>
 /// In some cases, calling Add() can cause the group indices to become invalid.
 /// </remarks>
 /// <since>5.0</since>
 public int Add(string groupName, System.Collections.Generic.IEnumerable <Guid> objectIds)
 {
     if (null == objectIds)
     {
         return(Add(groupName));
     }
     Rhino.Collections.RhinoList <Guid> ids = new Rhino.Collections.RhinoList <Guid>();
     foreach (Guid id in objectIds)
     {
         ids.Add(id);
     }
     if (ids.Count < 1)
     {
         return(Add(groupName));
     }
     return(UnsafeNativeMethods.CRhinoGroupTable_Add(m_doc.RuntimeSerialNumber, groupName, ids.Count, ids.m_items));
 }
Beispiel #6
0
 /// <summary>
 /// Initializes a new <see cref="SimpleArrayDouble"/> instance, with items.
 /// </summary>
 public SimpleArrayDouble(System.Collections.Generic.IEnumerable<double> items)
 {
   Rhino.Collections.RhinoList<double> list = new Rhino.Collections.RhinoList<double>(items);
   UnsafeNativeMethods.ON_DoubleArray_Append(m_ptr, list.Count, list.m_items);
 }
 public DocObjects.ObjRef[] Objects()
 {
   int count = ObjectCount;
   if (count < 1)
     return null;
   Rhino.Collections.RhinoList<DocObjects.ObjRef> objrefs = new Rhino.Collections.RhinoList<Rhino.DocObjects.ObjRef>(count);
   for(int i=0; i<count; i++)
   {
     DocObjects.ObjRef objref = Object(i);
     objrefs.Add(objref);
   }
   return objrefs.ToArray();
 }
    /// <summary>
    /// Draws a collection of arrow objects. An arrow consists of a Shaft and an Arrow head at the end of the shaft. 
    /// </summary>
    /// <param name="lines">Arrow shafts.</param>
    /// <param name="color">Color of arrows.</param>
    public void DrawArrows(System.Collections.Generic.IEnumerable<Line> lines, System.Drawing.Color color)
    {
      if (lines == null) { return; }

      int argb = color.ToArgb();

      // Cast Line array
      Line[] line_array = lines as Line[];
      if (line_array != null)
      {
        UnsafeNativeMethods.CRhinoDisplayPipeline_DrawArrows(m_ptr, line_array.Length, line_array, argb);
        return;
      }

      // Cast RhinoList<Line>
      Rhino.Collections.RhinoList<Line> line_list = lines as Rhino.Collections.RhinoList<Line>;
      if (line_list != null)
      {
        UnsafeNativeMethods.CRhinoDisplayPipeline_DrawArrows(m_ptr, line_list.Count, line_list.m_items, argb);
        return;
      }

      // Iterate over the enumeration
      Rhino.Collections.RhinoList<Line> line_copy = new Rhino.Collections.RhinoList<Line>();
      line_copy.AddRange(lines);
      if (line_copy.Count > 0)
      {
        UnsafeNativeMethods.CRhinoDisplayPipeline_DrawArrows(m_ptr, line_copy.Count, line_copy.m_items, argb);
      }
    }
 /// <summary>
 /// Intersects a mesh with an (infinite) plane.
 /// </summary>
 /// <param name="mesh">Mesh to intersect.</param>
 /// <param name="plane">Plane to intersect with.</param>
 /// <returns>An array of polylines describing the intersection loops or null (Nothing in Visual Basic) if no intersections could be found.</returns>
 public static Polyline[] MeshPlane(Mesh mesh, Plane plane)
 {
   Rhino.Collections.RhinoList<Plane> planes = new Rhino.Collections.RhinoList<Plane>(1, plane);
   return MeshPlane(mesh, planes);
 }
Beispiel #10
0
 public string[] GroupNames( bool ignoreDeletedGroups )
 {
   int count = Count;
   if (count < 1)
     return null;
   Rhino.Collections.RhinoList<string> names = new Rhino.Collections.RhinoList<string>(count);
   for (int i = 0; i < count; i++)
   {
     if (ignoreDeletedGroups && IsDeleted(i))
       continue;
     string name = GroupName(i);
     if (!string.IsNullOrEmpty(name))
       names.Add(name);
   }
   if (names.Count < 1)
     return null;
   return names.ToArray();
 }
Beispiel #11
0
 /// <summary>
 /// Adds a list of objects to an existing group.
 /// </summary>
 /// <param name="groupIndex">The group index value.</param>
 /// <param name="objectIds">An array, a list or any enumerable set of IDs to objects.</param>
 /// <returns>true if at least an operation was successful.</returns>
 public bool AddToGroup(int groupIndex, System.Collections.Generic.IEnumerable<Guid> objectIds)
 {
   if (null == objectIds)
     return false;
   Rhino.Collections.RhinoList<Guid> ids = new Rhino.Collections.RhinoList<Guid>();
   foreach (Guid id in objectIds)
   {
     ids.Add(id);
   }
   if (ids.Count < 1)
     return false;
   return UnsafeNativeMethods.CRhinoGroupTable_AddToGroup(m_doc.m_docId, groupIndex, ids.Count, ids.m_items);
 }
Beispiel #12
0
 /// <summary>
 /// Adds a new group to the group table with a set of objects.
 /// </summary>
 /// <param name="groupName">Name of new group.</param>
 /// <param name="objectIds">An array, a list or any enumerable set of object IDs.</param>
 /// <returns>
 /// &gt;=0 index of new group. 
 /// <para>-1 group not added because a group with that name already exists.</para>
 /// </returns>
 /// <remarks>
 /// In some cases, calling Add() can cause the group indices to become invalid.
 /// </remarks>
 public int Add(string groupName, System.Collections.Generic.IEnumerable<Guid> objectIds)
 {
   if( null==objectIds )
     return Add(groupName);
   Rhino.Collections.RhinoList<Guid> ids = new Rhino.Collections.RhinoList<Guid>();
   foreach( Guid id in objectIds)
   {
     ids.Add(id);
   }
   if( ids.Count<1 )
     return Add(groupName);
   return UnsafeNativeMethods.CRhinoGroupTable_Add(m_doc.m_docId, groupName, ids.Count, ids.m_items);
 }
        // This is the method that actually does the work.
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            // Some variables
            string output = "";                        // The file output
            string status = "Starting component...\n"; // The debug output

            // Several arrays where the data is stored
            List <Material>     materials     = new List <Material>();
            List <CrossSection> crossSections = new List <CrossSection>();
            List <Node>         nodes         = new List <Node>();
            List <Beam>         beams         = new List <Beam>();
            List <Load>         loads         = new List <Load>();


            // We need to reset some variables because the objects are not freed until Grasshopper is unloaded
            Parser.id_count = 1;

            bool   iSofistik      = false;
            string sofistikPath   = "";
            bool   iTeddy         = false;
            bool   AccessDatabase = false;

            DA.GetData(1, ref beamSplit);
            DA.GetData(3, ref iSofistik);
            DA.GetData(4, ref iTeddy);
            DA.GetData(5, ref AccessDatabase);
            if (!Directory.Exists(@"C:/Program Files/SOFiSTiK/2018/SOFiSTiK 2018"))
            {
                DA.GetData(6, ref sofistikPath);
            }

            if (AccessDatabase)
            {
                AccessSofistik.AccessSofData.Main();
            }

            try {
                // Load the data from Karamba

                // Retrieve and clone the input model
                GH_Model in_gh_model = null;
                if (!DA.GetData <GH_Model>(0, ref in_gh_model))
                {
                    return;
                }
                Model model = in_gh_model.Value;
                model = (Karamba.Models.Model)model.Clone();  // If the model is not cloned a modification to this variable will imply modification of the input model, thus modifying behavior in other components.
                if (model == null)
                {
                    status += "ERROR: The input model is null.";
                    output  = "Nothing to convert";
                }
                else
                {
                    string path = null;
                    if (!DA.GetData <string>(2, ref path))
                    {
                        path = "";
                    }
                    if (path == "")
                    {
                        status  += "No file path specified. Will not save data to a .dat file.\n";
                        filePath = path;
                    }


                    // Retrieve and store the data
                    // Materials
                    for (int i = 0; i < model.materials.Count; i++)
                    {
                        materials.Add(new Material(model.materials[i], i + 1));
                    }

                    status += materials.Count + " materials loaded...\n";

                    // Cross sections
                    for (int i = 0; i < model.crosecs.Count; i++)
                    {
                        crossSections.Add(new CrossSection(model.crosecs[i], i + 1));
                    }

                    //Add beam ID's to crossections/materials/loads
                    foreach (Karamba.Elements.ModelBeam beam in model.elems)
                    {
                        foreach (CrossSection crosec in crossSections)
                        {
                            if (beam.crosec.name == crosec.name)
                            {
                                crosec.ids.Add(beam.ind.ToString());
                            }
                        }

                        foreach (Material material in materials)
                        {
                            if (beam.crosec.material.name == material.name)
                            {
                                material.ids.Add(beam.ind.ToString());
                            }
                        }
                    }


                    // Nodes
                    foreach (Karamba.Nodes.Node node in model.nodes)
                    {
                        nodes.Add(new Node(node));
                    }
                    status += nodes.Count + " nodes loaded...\n";

                    // Supports
                    foreach (Karamba.Supports.Support support in model.supports)
                    {
                        nodes[support.node_ind].addConstraint(support);
                    }
                    status += "Support constraints added to " + model.supports.Count + " nodes.\n";

                    // Beams
                    foreach (Karamba.Elements.ModelElement beam in model.elems)
                    {
                        Beam curBeam = new Beam(beam);
                        // Adding the start and end nodes
                        curBeam.start = nodes[curBeam.ids[0]];
                        curBeam.end   = nodes[curBeam.ids[1]];
                        beams.Add(curBeam);
                    }

                    status += beams.Count + " beams loaded...\n";

                    // Loads
                    foreach (KeyValuePair <int, Karamba.Loads.GravityLoad> load in model.gravities)
                    {
                        loads.Add(new Load(load));
                    }
                    status += model.gravities.Count + " gravity loads added.\n";
                    foreach (Karamba.Loads.PointLoad load in model.ploads)
                    {
                        Load current = new Load(load);
                        current.node = nodes[load.node_ind];
                        loads.Add(current);
                    }
                    status += model.ploads.Count + " point loads added.\n";

                    foreach (Karamba.Loads.ElementLoad load in model.eloads)
                    {
                        // Create a load variable base on the load type
                        Load current = new Load();
                        Karamba.Loads.UniformlyDistLoad line = load as Karamba.Loads.UniformlyDistLoad;
                        //Karamba.Loads.PreTensionLoad pret = load as Karamba.Loads.PreTensionLoad;
                        Karamba.Loads.TemperatureLoad temp = load as Karamba.Loads.TemperatureLoad;


                        //else if (pret != null) {
                        //    current = new Load(pret);
                        //}

                        //If there is not target element, apply the load to the whole structure


                        if (load.beamIds[0] == "")
                        {
                            current.beam_id = "";
                            loads.Add(current);
                        }
                        else
                        {
                            // We search the element
                            foreach (string beamid in load.beamIds)
                            {
                                if (line != null)
                                {
                                    current = new Load(line);
                                }
                                // Very important to check Temperature BEFORE Pretension becaus Temperature derivates from Pretension
                                else if (temp != null)
                                {
                                    current = new Load(temp);
                                }
                                current.beam.user_id = beamid;
                                current.beam_id      = (beamid);
                                loads.Add(current);
                            }
                        }
                    }

                    // ID matching
                    // Karamba and Sofistik use different ID systems
                    // Karamba's materials and cross sections are pointing to an element ID
                    // Sofistik's elements need a cross section ID which needs a material ID

                    foreach (Material material in materials)
                    {
                        // If the IDs list is empty, it means that we want to apply the material to the whole structure (whichi is the default behavior: the default material is set by the constructors of all elements)
                        bool test = false;
                        foreach (string id in material.ids)
                        {
                            if (id != "")
                            {
                                test = true;
                            }
                        }
                        if (test)
                        {
                            foreach (CrossSection crosec in crossSections)
                            {
                                if (material.ids.Contains((crosec.id).ToString()))
                                {
                                    crosec.material = material;
                                }
                            }
                        }
                    }
                    status += "Matching with material IDs...\n";

                    foreach (CrossSection crosec in crossSections)
                    {
                        // If the IDs list is empty, it means that we want to apply the cross section to the whole structure (which is the default behavior: the default cross section is set by the constructors of all elements)
                        bool test = false;
                        foreach (string id in crosec.ids)
                        {
                            if (id != "")
                            {
                                test = true;
                            }
                        }
                        if (test)
                        {
                            foreach (Beam beam in beams)
                            {
                                if (crosec.ids.Contains((beam.id - 1).ToString()))
                                {
                                    beam.sec = crosec;
                                }
                            }
                        }
                    }
                    status += "Matching with cross section IDs...\n";

                    // Write the data into a .dat file format
                    Parser parser = new Parser(materials, crossSections, nodes, beams, loads);
                    output = parser.file;

                    if (path != "")
                    {
                        status += "Saving file to " + path + "\n";

                        System.IO.File.WriteAllText(@path, output);
                        status += "File saved!\n";
                    }



                    if (iSofistik == true && Directory.Exists(@"C:/Program Files/SOFiSTiK/2018/SOFiSTiK 2018") && path != "")
                    {
                        string targetPath = Path.GetFullPath(path);
                        System.Diagnostics.Process          process   = new System.Diagnostics.Process();
                        System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
                        startInfo.FileName  = "cmd.exe";
                        startInfo.Arguments = "/k cd C:/Program Files/SOFiSTiK/2018/SOFiSTiK 2018/ & sps -B " + targetPath;
                        process.StartInfo   = startInfo;
                        process.Start();
                    }
                    else if (Directory.Exists(@"C:/Program Files/SOFiSTiK/2018/SOFiSTiK 2018") == false)
                    {
                        string targetPath = Path.GetFullPath(path);
                        string sofPath    = Path.GetFullPath(sofistikPath);
                        System.Diagnostics.Process          process   = new System.Diagnostics.Process();
                        System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
                        startInfo.FileName  = "cmd.exe";
                        startInfo.Arguments = "/k cd " + sofPath + " & sps -B " + targetPath;
                        process.StartInfo   = startInfo;
                        process.Start();
                    }

                    if (iTeddy)
                    {
                        string targetPath = Path.GetFullPath(path);
                        System.Diagnostics.Process          process   = new System.Diagnostics.Process();
                        System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
                        startInfo.FileName  = "cmd.exe";
                        startInfo.Arguments = "/c" + targetPath;
                        process.StartInfo   = startInfo;
                        process.Start();
                    }
                }
            }
            catch (Exception e) {
                status += "\nERROR!\n" + e.ToString() + "\n" + e.Data;
            }

            Rhino.Collections.RhinoList <string> oBeamForces = new Rhino.Collections.RhinoList <string>();

            foreach (string force in AccessSofistik.AccessSofData.SofBeamForces)
            {
                oBeamForces.Add(force.ToString());
            }

            // Return data
            DA.SetData(0, output);
            DA.SetData(1, status);
            DA.SetDataList(2, AccessSofistik.AccessSofData.SofBeamForces);
        }
Beispiel #14
0
 /// <summary>
 /// Initializes a new <see cref="SimpleArrayDouble"/> instance, with items.
 /// </summary>
 public SimpleArrayDouble(System.Collections.Generic.IEnumerable <double> items)
 {
     Rhino.Collections.RhinoList <double> list = new Rhino.Collections.RhinoList <double>(items);
     UnsafeNativeMethods.ON_DoubleArray_Append(m_ptr, list.Count, list.m_items);
 }