Rhinoceros 7 closed-cell foams 记录

证书失效问题解决方式:关闭科学上网工具

GH在运行voronoi3D电池组后插入C#脚本如下:

using System;
using System.Collections;
using System.Collections.Generic;

using Rhino;
using Rhino.Geometry;

using Grasshopper;
using Grasshopper.Kernel;
using Grasshopper.Kernel.Data;
using Grasshopper.Kernel.Types;

using System.IO;
using System.Linq;
using System.Data;
using System.Drawing;
using System.Reflection;
using System.Windows.Forms;
using System.Xml;
using System.Xml.Linq;
using System.Runtime.InteropServices;

using Rhino.DocObjects;
using Rhino.Collections;
using GH_IO;
using GH_IO.Serialization;

/// <summary>
/// This class will be instantiated on demand by the Script component.
/// </summary>
public class Script_Instance : GH_ScriptInstance
{
#region Utility functions
  /// <summary>Print a String to the [Out] Parameter of the Script component.</summary>
  /// <param name="text">String to print.</param>
  private void Print(string text) { /* Implementation hidden. */ }
  /// <summary>Print a formatted String to the [Out] Parameter of the Script component.</summary>
  /// <param name="format">String format.</param>
  /// <param name="args">Formatting parameters.</param>
  private void Print(string format, params object[] args) { /* Implementation hidden. */ }
  /// <summary>Print useful information about an object instance to the [Out] Parameter of the Script component. </summary>
  /// <param name="obj">Object instance to parse.</param>
  private void Reflect(object obj) { /* Implementation hidden. */ }
  /// <summary>Print the signatures of all the overloads of a specific method to the [Out] Parameter of the Script component. </summary>
  /// <param name="obj">Object instance to parse.</param>
  private void Reflect(object obj, string method_name) { /* Implementation hidden. */ }
#endregion

#region Members
  /// <summary>Gets the current Rhino document.</summary>
  private readonly RhinoDoc RhinoDocument;
  /// <summary>Gets the Grasshopper document that owns this script.</summary>
  private readonly GH_Document GrasshopperDocument;
  /// <summary>Gets the Grasshopper script component that owns this script.</summary>
  private readonly IGH_Component Component;
  /// <summary>
  /// Gets the current iteration count. The first call to RunScript() is associated with Iteration==0.
  /// Any subsequent call within the same solution will increment the Iteration count.
  /// </summary>
  private readonly int Iteration;
#endregion

  /// <summary>
  /// This procedure contains the user code. Input parameters are provided as regular arguments,
  /// Output parameters as ref arguments. You don't have to assign output parameters,
  /// they will have a default value.
  /// </summary>
  private void RunScript(bool enable, Box box, double inflateRelToD, List<Brep> brepList, double D, bool flipInBrep, bool reportVolumes, bool trimMerge, bool trimPlaneFlip, double move, double moveTrimPlane, bool flip, ref object Elapsed, ref object startBox, ref object invardsInflatedBox, ref object hollowBrepList, ref object messageOfTheDay, ref object Merge, ref object MergeSplit)
  {
    // by The Lord of Darkness for no reason (blame Vodka [lot's] I guess)

    messageOfTheDay = "Ducatium Amamus Dum Spiramus";

    if(!enable) return;

    startBox = box.ToBrep().GetWireframe(0);

    brepList = brepList.Where(x => x != null).ToList();
    if(!brepList.Any()) {Print("You are rather optimistic"); return;}
    double tol = RhinoDoc.ActiveDoc.ModelAbsoluteTolerance;

    System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
    sw.Start();

    box.Inflate(-(inflateRelToD + D));
    Brep whole = box.ToBrep();
    whole.Flip(); 
    invardsInflatedBox = whole.GetWireframe(0); //>>out

    List<Brep> hollowBreps = new List<Brep>();

    for(int i = 0; i < brepList.Count;i++){
      Brep brep = brepList[i];
      Point3d p = AreaMassProperties.Compute(brep).Centroid;
      Transform scale = Transform.Scale(p, D);
      Brep inBrep = brep.DuplicateBrep();
      inBrep.Transform(scale);

      Print(" ");//----------------------------------------------------------------------- Abysus abysum Invocat
      Print("Merge [hollow] report (good luck) at: {0}", i);
      if(flipInBrep)inBrep.Flip();

      Brep merge = Brep.MergeBreps(new Brep[2]{brep,inBrep}, tol);
      if(merge.IsManifold){
        Print("Manifold brep (lucky you)");
        string log;
        if(merge.IsValidWithLog(out log))
        {
          Print("Valid brep (ditto)");
          if(reportVolumes){
            double hollowVolume = Math.Round(VolumeMassProperties.Compute(merge).Volume, 2);
            double wholeVolume = Math.Round(VolumeMassProperties.Compute(brep).Volume, 2);
            Print("Hollow vs whole volume: {0}-{1}", hollowVolume, wholeVolume);
          }

          BoundingBox hollowBox = merge.GetBoundingBox(true);
          if(box.Contains(hollowBox, true)){Print("Inside at: {0}", i); hollowBreps.Add(merge);}
          else{
            try{
              Brep[] hollow = Brep.CreateBooleanDifference(merge, whole, tol);
              hollowBreps.Add(hollow[0]);
            }
            catch{Print("Oops moment at index: {0}", i);}
          }
        }
        else{
          Print("Non valid brep due: {0}", log);
        }
      }
      else{
        Print("Non manifold brep (get CATIA)");
      }
    }

    hollowBrepList = hollowBreps;//>>out

    sw.Stop();
    Elapsed = (string.Format("Elapsed: {0}ms", sw.Elapsed.TotalMilliseconds));
  }

  // <Custom additional code> 

  // </Custom additional code> 
}

这段脚本定义了一个名为Script_Instance的类,该类继承自GH_ScriptInstance类。类中包含了一些常用的函数和变量,包括Print()Reflect()RhinoDocumentGrasshopperDocumentComponentIteration等。

主函数是RunScript()函数,该函数包含多个参数,其中enable参数是一个布尔值,表示是否启用脚本。box是一个Rhino.Geometry.Box类型的参数,代表一个立方体。inflateRelToD是一个双精度浮点型的参数,用于调整box的大小。brepList是一个Rhino.Geometry.Brep类型的列表,表示Brep对象列表。D是一个双精度浮点型的参数,表示比例因子。flipInBrepreportVolumes都是布尔型的参数,代表是否翻转Brep和是否报告体积。其他参数的含义在注释中有详细的解释。

主函数的主要逻辑是:

  1. box向内部膨胀。
  2. box转换为Brep对象,并将其翻转。
  3. brepList中的每个Brep对象按照一定比例缩放,并与原Brep对象进行合并。
  4. 判断合并后的Brep对象是否是流形的,并报告体积等信息。
  5. 将合并后的Brep对象添加到hollowBreps列表中。
  6. hollowBreps中的Brep对象进行一些操作,如旋转、移动等,并输出结果。

输入参数包括:

  • enable:一个布尔值,如果为真,则启用脚本。
  • box:一个 Box 对象,表示一个立方体。
  • inflateRelToD:一个浮点数,表示膨胀盒子大小相对于 D 的比例。
  • brepList:一个 Brep 对象列表,表示要处理的多边形集合。
  • D:一个浮点数,表示比例缩放因子。
  • flipInBrep:一个布尔值,表示是否翻转多边形。
  • reportVolumes:一个布尔值,表示是否报告中空和整体几何体的体积。
  • trimMerge:一个布尔值,表示是否修剪和合并中空的几何体。
  • trimPlaneFlip:一个布尔值,表示是否翻转修剪平面。
  • move:一个浮点数,表示沿法线移动修剪平面的距离。
  • moveTrimPlane:一个浮点数,表示平移修剪平面的距离。
  • flip:一个布尔值,表示是否翻转几何体。

输出参数包括:

  • Elapsed:一个对象,记录脚本运行的时间。
  • startBox:一个对象,表示初始立方体的线框。
  • invardsInflatedBox:一个对象,表示盒子向内膨胀的结果的线框。
  • hollowBrepList:一个 Brep 对象列表,表示中空的几何体集合。
  • messageOfTheDay:一个字符串,表示今天的消息。
  • Merge:一个对象,表示修剪和合并的结果。
  • MergeSplit:一个对象,表示修剪和分裂的结果。

脚本的实现基于这些参数对多边形进行一系列的操作,包括缩放、膨胀、修剪、合并等等。最终输出的结果是闭孔泡沫结构,以及一些修剪和合并的结果。

安装插件:lunch box/karamba 3D/Galapagos/Human/Weaverbird/bifocals

运算器哪一步的模型有需要就在哪一步的电池组右键bake后在rhino界面转存stp文件

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值