当前位置: 首页>>代码示例>>C#>>正文


C# Geometry.Scale方法代码示例

本文整理汇总了C#中Geometry.Scale方法的典型用法代码示例。如果您正苦于以下问题:C# Geometry.Scale方法的具体用法?C# Geometry.Scale怎么用?C# Geometry.Scale使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Geometry的用法示例。


在下文中一共展示了Geometry.Scale方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: _buildInstanceLibraryFromFilePath

        /// <summary>
        /// this is a test method that creates an instance library from geometry to transforms - each piece of geometry is hashed to use as
        /// a key using some geometrical properties - like the length as in this test.
        /// </summary>
        /// <param name="filepath"></param>
        /// <returns></returns>
        public static Dictionary<string, Tuple<Geometry, int>> _buildInstanceLibraryFromFilePath(string filepath, int lengthTol, Geometry baseGeo)
        {
            //create a new library, both a return object, and the real lib
            var returnlibrary = new Dictionary<string, Tuple<Geometry, int>>();
            var doc = RevitServices.Persistence.DocumentManager.Instance.CurrentDBDocument;
            var lib = DirectShapeLibrary.GetDirectShapeLibrary(doc);
            lib.Reset();

            ElementId categoryId = new ElementId(BuiltInCategory.OST_GenericModel);

            using (StreamReader r = new StreamReader(filepath))
            {
                //we are going to chunk our CSV file as well, so we will not load the entire csv into memory at once...

                while (!r.EndOfStream)
                {

                    var line = r.ReadLine();
                    var cells = line.Split(',');
                    var startPoint = Autodesk.DesignScript.Geometry.Point.ByCoordinates(double.Parse(cells[0]), double.Parse(cells[1]), double.Parse(cells[2]));
                    var endPoint = Autodesk.DesignScript.Geometry.Point.ByCoordinates(double.Parse(cells[3]), double.Parse(cells[4]), double.Parse(cells[5]));

                    //create a line from start to end
                    var geoline = Autodesk.DesignScript.Geometry.Line.ByStartPointEndPoint(startPoint, endPoint);
                    var key = Math.Round(geoline.Length, lengthTol).ToString();
                    var dubkey = Math.Round(geoline.Length, lengthTol);

                    //if the library doesnt have this key then generate some new geometry
                    if (!returnlibrary.ContainsKey(key))
                    {
                        var scaledcube = baseGeo.Scale(1.0, Math.Max(dubkey, 0.01), 1.0);

                        returnlibrary.Add(key, Tuple.Create(scaledcube, 0));
                    }

                    //now store the new count in the retur dict
                    var oldval = returnlibrary[key];
                    returnlibrary[key] = Tuple.Create(oldval.Item1, oldval.Item2 + 1);

                    geoline.Dispose();

                }

            }

            return returnlibrary;
        }
开发者ID:mjkkirschner,项目名称:GeometryTranslationExperiments,代码行数:53,代码来源:DirectShapeInstance.cs

示例2: CreateRevolve

        /*
        public static Autodesk.Revit.DB.GeometryObject CreateRevolve(Autodesk.DesignScript.Geometry.Line axis, Autodesk.DesignScript.Geometry.Curve crv)
        {
            var arr = new ReferenceArray();
            arr.Append(crv.ToRevitType().Reference);
            var formarry = DocumentManager.Instance.CurrentUIApplication..NewRevolveForms(true,arr, axis.ToRevitType().Reference, 0, 360);
            return formarry.get_Item(0).get_Geometry(new Options());
        }
        */
        /// <summary>
        /// a node to create instances from types identifie by hashing properties of each geometrical type, this one uses diameter
        /// </summary>
        /// <param name="filepath">the file path to import a csv from, this csv should contain point pairs on each row, and also any other data to define the type... </param>
        /// <param name="lengthTol"></param>
        /// <param name="diameterTol"></param>
        /// <param name="baseGeo"></param>
        /// <returns></returns>
        public static Dictionary<string, Tuple<GeometryObject, int>> CreateNodeInstancesFromHashedTypes(string filepath, int diameterTol, Geometry baseGeo)
        {
            //create a new library, both a return object, and the real lib
            var returnlibrary = new Dictionary<string, Tuple<GeometryObject, int>>();
            var doc = RevitServices.Persistence.DocumentManager.Instance.CurrentDBDocument;
            var lib = DirectShapeLibrary.GetDirectShapeLibrary(doc);
            lib.Reset();

            ElementId categoryId = new ElementId(BuiltInCategory.OST_GenericModel);

            TransactionManager.Instance.EnsureInTransaction(DocumentManager.Instance.CurrentDBDocument);
            //set the sharedFilePath
            var sharedParameterFile = Path.Combine(Path.GetTempPath(), "directShapeTempFile");
            System.IO.FileStream fileStream = System.IO.File.Create(sharedParameterFile);
            fileStream.Close();

            DocumentManager.Instance.CurrentDBDocument.Application.SharedParametersFilename = sharedParameterFile;

            //create a parameter for diameter which we will put on the DS element... and write to
            DefinitionFile file = DocumentManager.Instance.CurrentDBDocument.Application.OpenSharedParameterFile();
            // if our group is not there, create it
            DefinitionGroup group = file.Groups.get_Item("directShapeParameters");
            if (group == null) group = file.Groups.Create("directShapeParameters");

            // add our parameter to the group
            Definition def =
             group.Definitions.Create(new ExternalDefinitionCreationOptions("diameter",ParameterType.Length));

            // now if we want it in the project, we need to bind it to categories
            CategorySet cats = DocumentManager.Instance.CurrentDBDocument.Application.Create.NewCategorySet();
            cats.Insert(doc.Settings.Categories.get_Item(BuiltInCategory.OST_GenericModel));

            // create a binding - instance or type:
            InstanceBinding bind = DocumentManager.Instance.CurrentDBDocument.Application.Create.NewInstanceBinding(cats);
            doc.ParameterBindings.Insert(def, bind, BuiltInParameterGroup.PG_LENGTH);
            TransactionManager.Instance.TransactionTaskDone();

            using (StreamReader r = new StreamReader(filepath))
            {
                //we are going to chunk our CSV file as well, so we will not load the entire csv into memory at once...

                while (!r.EndOfStream)
                {

                    var line = r.ReadLine();
                    var cells = line.Split(',');
                    var center = Autodesk.DesignScript.Geometry.Point.ByCoordinates(double.Parse(cells[0]), double.Parse(cells[1]), double.Parse(cells[2]));
                    var diameter = double.Parse(cells[3]);

                    var key = Math.Round(diameter, diameterTol).ToString();
                    var dubkey = Math.Round(diameter, diameterTol);

                    //if the library doesnt have this key then generate some new geometry
                    if (!returnlibrary.ContainsKey(key))
                    {
                        var val = Math.Max(dubkey, 0.01);
                        //scale the sphere so that it has the same diameter as the one we want to instance
                        var scaledSphere = baseGeo.Scale(val) as Autodesk.DesignScript.Geometry.Solid;

                        //use a semi-hack to insert a .sat import instance into a directShape...
                        //Replace this when possible

                        var ops = new Options();
                        ops.ComputeReferences = true;

                        TransactionManager.Instance.EnsureInTransaction(DocumentManager.Instance.CurrentDBDocument);
                        var trans = new Autodesk.Revit.DB.SubTransaction(DocumentManager.Instance.CurrentDBDocument);
                        trans.Start();
                        var importElement = Revit.Elements.ImportInstance.ByGeometry(scaledSphere).InternalElement;

                        var elementgeo = importElement.get_Geometry(ops);
                        var enumr = elementgeo.GetEnumerator();
                        enumr.MoveNext();
                        var geo2 = (enumr.Current as GeometryInstance).GetInstanceGeometry();
                        var enumr2 = geo2.GetEnumerator();
                        enumr2.MoveNext();
                        var s1 = enumr2.Current;
                        var revgeo = s1;

                        trans.Commit();

                        lib.AddDefinition(key, revgeo);
                        returnlibrary.Add(key, Tuple.Create(revgeo, 0));
//.........这里部分代码省略.........
开发者ID:mjkkirschner,项目名称:GeometryTranslationExperiments,代码行数:101,代码来源:DirectShapeInstance.cs

示例3: CreateTubeInstancesFromHashedTypes

        /// <summary>
        /// a node to create instances from types identifie by hashing properties of each geometrical type, like length or diameter
        /// </summary>
        /// <param name="filepath">the file path to import a csv from, this csv should contain point pairs on each row, and also any other data to define the type... </param>
        /// <param name="lengthTol"></param>
        /// <param name="diameterTol"></param>
        /// <param name="baseGeo"></param>
        /// <returns></returns>
        public static Dictionary<string, Tuple<GeometryObject, int>> CreateTubeInstancesFromHashedTypes(string filepath,int lengthTol, int diameterTol,Geometry baseGeo)
        {
            //create a new library, both a return object, and the real lib
            var returnlibrary = new Dictionary<string, Tuple<GeometryObject, int>>();
            var doc = RevitServices.Persistence.DocumentManager.Instance.CurrentDBDocument;
            var lib = DirectShapeLibrary.GetDirectShapeLibrary(doc);
            lib.Reset();

            ElementId categoryId = new ElementId(BuiltInCategory.OST_GenericModel);

            using (StreamReader r = new StreamReader(filepath))
            {
                //we are going to chunk our CSV file as well, so we will not load the entire csv into memory at once...

                while (!r.EndOfStream)
                {

                    var line = r.ReadLine();
                    var cells = line.Split(',');
                    var startPoint = Autodesk.DesignScript.Geometry.Point.ByCoordinates(double.Parse(cells[0]), double.Parse(cells[1]), double.Parse(cells[2]));
                    var endPoint = Autodesk.DesignScript.Geometry.Point.ByCoordinates(double.Parse(cells[3]), double.Parse(cells[4]), double.Parse(cells[5]));

                    //create a line from start to end
                    var geoline = Autodesk.DesignScript.Geometry.Line.ByStartPointEndPoint(startPoint, endPoint);
                    var key = Math.Round(geoline.Length, lengthTol).ToString();
                    var dubkey = Math.Round(geoline.Length, lengthTol);

                    //if the library doesnt have this key then generate some new geometry
                    if (!returnlibrary.ContainsKey(key))
                    {
                        //scale the cube so that it, the same length as the line
                        var scaledcube = baseGeo.Scale(1.0, Math.Max(dubkey, 0.01), 1.0) as Autodesk.DesignScript.Geometry.Solid;
                        var revgeo = scaledcube.ToRevitType();
                        lib.AddDefinition(key, revgeo.First());
                        returnlibrary.Add(key, Tuple.Create(revgeo.First(), 0));
                        scaledcube.Dispose();
                    }

                    //in either case add the transform for this line

                    //get a cs in the center of the line
                    var cs = geoline.CoordinateSystemAtParameter(.5);

                    //so now rotate the cube so that it matches the lines rotation...
                    var revtransform = cs.ToTransform();
                    if (!revtransform.IsConformal)
                    {
                        throw new Exception("should have been conformal");
                    }

                    //now store the new count in the retur dict
                    var oldval = returnlibrary[key];
                    returnlibrary[key] = Tuple.Create(oldval.Item1,oldval.Item2+1);

                    //actually instantiate the geometry
                    var inst = Autodesk.Revit.DB.DirectShape.CreateGeometryInstance(doc, key, revtransform);

                    RevitServices.Transactions.TransactionManager.Instance.EnsureInTransaction(doc);
                    var shape = Autodesk.Revit.DB.DirectShape.CreateElement(doc, categoryId, new Guid().ToString(), new Guid().ToString());
                    shape.SetShape(inst);
                    RevitServices.Transactions.TransactionManager.Instance.TransactionTaskDone();

                    cs.Dispose();
                    geoline.Dispose();

                }

            }

            return returnlibrary;
        }
开发者ID:mjkkirschner,项目名称:GeometryTranslationExperiments,代码行数:79,代码来源:DirectShapeInstance.cs


注:本文中的Geometry.Scale方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。