Work Plane Grid Spacing

Work Plane Grid Spacing

sofia_feist
Enthusiast Enthusiast
2,059 Views
10 Replies
Message 1 of 11

Work Plane Grid Spacing

sofia_feist
Enthusiast
Enthusiast

Hello,

 

Is there a way to access and modify the Work Plane Grid spacing through the Revit API like you can do in Revit's interface? I haven't been able to find anything but maybe I'm missing something? Any feedback would be appreciated. 

 

Thanks,

Sofia

 

Screeshot.png

Accepted solutions (2)
2,060 Views
10 Replies
Replies (10)
Message 2 of 11

naveen.kumar.t
Autodesk Support
Autodesk Support
Accepted solution

Hi @sofia_feist ,

try using the below code

Element workPlane;
workPlane.get_Parameter(BuiltInParameter.SKETCH_GRID_SPACING_PARAM).Set("value");

 


Naveen Kumar T
Developer Technical Services
Autodesk Developer Network

Message 3 of 11

TripleM-Dev.net
Advisor
Advisor
Accepted solution

Hi,

 

Use Revit lookup to inspect the element.

Results: the element doesn't have a direct API class, but can be filtered by it's category, and a builtin parameter has the spacing.

 

Builtin category: OST_IOSSketchGrid

Builtin parameter: SKETCH_GRID_SPACING_PARAM

 

Retrieving the element could be the challange, maybe use ShowActiveWorkPlane ? and retieve all elements in view with the above builtin category..

 

- Michel

 

Message 4 of 11

RitaRolAguiar
Contributor
Contributor

Thank you @TripleM-Dev.net and @naveen.kumar.t.

Me and @sofia_feist implemented a solution that follows your advice.

Here is a possible solution but that still has some flaws:

We were able to successfully retrieve all BuiltInCategory Elements of OST.IOSketchGrid. For the project in case, there were 6 elements retrieved which consisted mostly of levels in the projects. One of these elements is in fact the Active Work Plane Grid. The only problem we have is retrieving just this one element logically.

We ended up setting the grid spacing value for all (in the case of this project 6) elements and this way we are sure that the Work Plane Grid has the spacing we want. This is not an ideal solution but it does the job.

We tried checking all properties of the retrieved elements but there seems to be nothing that could help in selecting the one element that is the current Work Plane Grid by distinguishing it from the other retrived elements.

If anyone has any other suggestion on how to retrieve the Work Plane Grid logically please let us know.

ElementCategoryFilter filter = new ElementCategoryFilter(BuiltInCategory.OST_IOSSketchGrid);


     using (Transaction trans = new Transaction(doc, "Move Module"))
       {
           trans.Start();

           FilteredElementCollector collector = new FilteredElementCollector(doc);
           IEnumerable<Element> sketchGrids = collector.WherePasses(filter)
              .WhereElementIsNotElementType()
              .Where(e => e.get_Parameter(BuiltInParameter.SKETCH_GRID_SPACING_PARAM).HasValue)
              .Where(e => e.get_Parameter(BuiltInParameter.SKETCH_GRID_SPACING_PARAM).SetValueString("500"));
              trans.Commit();
       }

 e

Message 5 of 11

Anonymous
Not applicable
I'd like to add that we are also looking into changing other aspects of the Work Plane Grid. For example, resizing and moving the Work Plane Grid, but it seems to not be possible. Only the properties Category, Design Option, Family Name, Type Name, and Work Plane Grid Spacing are available in the Revit API. :S
Message 6 of 11

TripleM-Dev.net
Advisor
Advisor

Hi,

 

You can move the grid by dragging the workspace grid, so I thinks MoveElement Method would work on this also.

 

Also seems the Workspace grid has geometry, from it a single face can be obtained from which a origin, edge size etc can be obtained so you can work out the move vector for MoveElement method.

 

The total size of the displayed grid doesn't seem to be exposed.

The trick would be to see if you can determine the position of the gridlines themself to align....

 

- Michel

Message 7 of 11

rita.aguiar
Advocate
Advocate

@TripleM-Dev.net Thank you for your suggestion

I applyed a new condition to the filteredelementcollector to find which SketchGrid elements have geometry. By doing so I was able to retrieve exacly one item, which is the Active WorkPlane Grid! This element is the only SketchGrid that has geometry (I confirmed the ID of the Element to be sure it is indeed the Active WorkPlane Grid).

When applying get_Geometry method, the other elements return null, except the Active WorkPlane Grid, which returns an ElementGeometry that is Empty: Enumeration yields no results.

Because the ElementGeometry of the Active WorkPlane Grid is empty I can't transform the Active WorkPlane Grid as I wish to.

Not sure why this is happening, any thoughts?

 

ElementCategoryFilter filter = new ElementCategoryFilter(BuiltInCategory.OST_IOSSketchGrid);
            Options options = new Options();

FilteredElementCollector collector = new FilteredElementCollector(doc);
            IEnumerable<Element> sketchGrids = collector.WherePasses(filter)
                .WhereElementIsNotElementType()
                .Where(e => e.get_Geometry(options) != null)
                .Where(e => e.get_Parameter(BuiltInParameter.SKETCH_GRID_SPACING_PARAM).HasValue);

//sketchGrids returns exacly one item: the Active WorkPlane Grid:
GeometryElement elemGeometry = activeWorkPlaneGrid.get_Geometry(options);
//elemGeometry: Enumeration yields no results.

 

ElementGeometry Active WorkPlane Grid.JPG

Message 8 of 11

TripleM-Dev.net
Advisor
Advisor

Hi,

 

For the options set the view property to the view where the workplane grid is visible (View Property )

If you use Revit lookup addin, it will only show geometry if a view is used where the worksplane grid is visible!

 

- Michel

Message 9 of 11

rita.aguiar
Advocate
Advocate

@TripleM-Dev.net , that means I must do ShowActiveWorkPlane() before attempting to retrive the Active Work Plane Grid geometry, right?

Indeed I had created a transaction that does just that, before attempting to get the ActiveWorkPlane and its Geometry from the FilteredElementCollection.

Just to be sure, I implemented a method to check whether an element is visible on the active view. (The method I used is this one here: https://stackoverflow.com/questions/44012630/determine-is-a-familyinstance-is-visible-in-a-view)

After being sure that the Active Work Plane Grid is visible in the current view, I checked again the GeometryElement property and it is Empty.

Maybe I am missing something here ;/

 

 

using (Transaction trans = new Transaction(doc, "Show WorkPlane"))
            {
                trans.Start();
                uidoc.Document.ActiveView.ShowActiveWorkPlane();
                trans.Commit();
            }

            //Gets Active Work Plane Grid
            Element activeWorkPlaneGrid = GetActiveWorkPlane(doc);

            using (Transaction trans = new Transaction(doc, "Get Active WorkPlane"))
            {
                trans.Start();
                //Gets Active Work Plane Grid Spacing Parameter
                Parameter param = activeWorkPlaneGrid.get_Parameter(BuiltInParameter.SKETCH_GRID_SPACING_PARAM);
                //Sets Active Work Plane Grid Spacing Value
                param.SetValueString("500");
                trans.Commit();
            }
            bool IsWorkPlaneGridVisible = Extensions.IsElementVisibleInView(uidoc.Document.ActiveView, activeWorkPlaneGrid);

            TaskDialog.Show("Revit", "Is the Work Plane Grid Visible in Current View? " + IsWorkPlaneGridVisible);

            using (Transaction trans = new Transaction(doc, "Get Active WorkPlane Geometry"))
            {
                trans.Start();
                //Gets active Work Plane Grid Geometry
                Options options = new Options();
                GeometryElement elemGeometry = activeWorkPlaneGrid.get_Geometry(options);
                trans.Commit();
            }

 

 

 Is The Work Plane Grid Visible In Current View.JPGEmpty Property.JPG

Message 10 of 11

TripleM-Dev.net
Advisor
Advisor

Hi,

 

You need to set the View of the options for the Get_geometry.

Below a working sample and moves the Grid 50 (internal units) in the X-direction Tested for 3D and floorplans.

 

I hope it helps, see the comments in the code fragment

ps. there's no need for "ElementCategoryFilter", just call OfCategory directly.

 

 

[Transaction(TransactionMode.Manual)]
    public class TestCommand_C11_MoveWorkspaceGrid : IExternalCommand
    {
         
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            UIDocument uidoc = commandData.Application.ActiveUIDocument;
            Autodesk.Revit.DB.Document doc = uidoc.Document;


            Options geooptions = new Options();
            geooptions.View = doc.ActiveView;

            using (Transaction trans = new Transaction(doc, "Show WorkPlane"))
            {
                trans.Start();

                doc.ActiveView.ShowActiveWorkPlane(); // Show else no geometry can be retrieved

                FilteredElementCollector collector = new FilteredElementCollector(doc, doc.ActiveView.Id).WhereElementIsNotElementType().OfCategory(BuiltInCategory.OST_IOSSketchGrid);
                
                //It seems 2 grids are found (in 3D anyway)
                //the Geometry returns a collection, it's just empty.
                IEnumerable<Element> sketchgrids = collector.Where(e => e.get_Geometry(geooptions).Count() > 0); //Warning, assume a collection on Geometry is retuned.

                MessageBox.Show(string.Join(";", sketchgrids.Select(e => e.Id.IntegerValue).ToArray())); //QUick display of IDs

                if (sketchgrids.Count() == 1) //If only 1 with geometry
                {

                    //ToDo: 
                    // inspect geometry itself to determine the amount to move.
                    // Gridlines of the Workplane....can it be retrieved/analyzed?

                    ElementTransformUtils.MoveElement(doc, sketchgrids.First().Id, new XYZ(50, 0, 0));

                    doc.ActiveView.HideActiveWorkPlane(); // only needed if we commit
                    trans.Commit();
                    MessageBox.Show("Moved");
                }


            }
             
                return Result.Succeeded;
        }
    }

 

 

 

Message 11 of 11

sofia_feist
Enthusiast
Enthusiast

Thank you so much @TripleM-Dev.net for your valuable input. Your comments were really helped. There are still a few kinks to fix in the features @rita.aguiar and I wanted to implement but the original question has been answered so I'll close this thread as solved for now.