Ejemplo n.º 1
0
        private static LevelBlockDetails GenerateOrUpdateBlock(Editor ed, Database db, GenerateArgs args)
        {
            if (IsNewBlock(ed))
            {
                var endPoint = ed.PromptForPosition(Resources.Command_Prompt_SelectEndPoint);
                if (!endPoint.HasValue)
                {
                    return(LevelBlockDetails.CreateEmpty());
                }

                var levelArgs = CreateNewBlockLevelBlockArgs(args, endPoint.Value);

                return(LevelBlockHelper.NewLevelBlockAtPoint(db, levelArgs));
            }

            var trans    = db.TransactionManager.TopTransaction;
            var existing = LevelBlockHelper.GetPromptedBlockDetails(Resources.Command_Prompt_SelectExistingLevelBlock, ed, trans);

            if (!existing.IsValid)
            {
                return(LevelBlockDetails.CreateEmpty());
            }

            if (args.HasLevel)
            {
                return(LevelBlockHelper.UpdateExistingLevelBlock(existing.BlockReference, args.BlockLevel));
            }

            var endLevel = CalculateLevel(args.StartPoint, existing.Point3d, args.StartLevel, args.Gradient);

            return(LevelBlockHelper.UpdateExistingLevelBlock(existing.BlockReference, endLevel));
        }
Ejemplo n.º 2
0
        public static void GeneratePolyline3dFromLevels()
        {
            HousingExtensionApplication.Current.Logger.LogCommand(typeof(PolylineCommands), nameof(GeneratePolyline3dFromLevels));

            var doc = Application.DocumentManager.MdiActiveDocument;
            var ed  = doc.Editor;
            var db  = doc.Database;

            using var trans = db.TransactionManager.StartTransaction();

            var initial = LevelBlockHelper.GetPromptedBlockDetails(Resources.Command_Prompt_SelectInitialBlock, ed, trans);

            if (!initial.IsValid)
            {
                return;
            }

            var points = new List <Point3d> {
                initial.Point3d
            };
            var nextLevel = true;

            var options = new PromptEntityOptions(Resources.Command_Prompt_SelectNextBlock);

            options.SetRejectMessage(Resources.Command_Prompt_RejectBlockReference);
            options.AddAllowedClass(typeof(BlockReference), true);
            options.AppendKeywordsToMessage = true;

            foreach (var keyword in PolylineOptions)
            {
                options.Keywords.Add(keyword);
            }

            PromptEntityResult result = null;

            while (nextLevel)
            {
                nextLevel = false;
                result    = ed.GetEntity(options);

                if (result.Status == PromptStatus.OK)
                {
                    var details = new LevelBlockDetails(LevelBlockHelper.GetBlockReference(result.ObjectId, trans));
                    if (!details.IsValid)
                    {
                        HousingExtensionApplication.Current.Logger.Entry(Resources.Message_Invalid_Level_Block_Selected, Severity.Warning);
                        return;
                    }

                    if (points.Any(p => p.Y.Equals(details.Point3d.Y) && p.X.Equals(details.Point3d.X) && p.Z.Equals(details.Point3d.Z)))
                    {
                        HousingExtensionApplication.Current.Logger.Entry(Resources.Message_Block_Already_Selected, Severity.Information);
                    }
                    else
                    {
                        points.Add(details.Point3d);
                    }

                    nextLevel = true;
                }
            }

            var close = false;

            if (result.Status == PromptStatus.Keyword)
            {
                close = result.StringResult == PolylineOptions[0];
            }

            CreatePolyline3dFromPoints(db, points, close);

            trans.Commit();
        }