Quantcast
Channel: All Revit API Forum posts
Viewing all 66917 articles
Browse latest View live

Re: GetNumberOfLightTypes for Revit lights

$
0
0

It does seem to be an issue with Revit, or maybe the family itself. 

 

I had the same problem with 3 out of 3 light fixture families I frequently use.  Here is a  short macro that demonstrates the issue:

 

using Autodesk.Revit.DB.Lighting;

 

public void GetLightTypes()
        {
            UIDocument uidoc = this.ActiveUIDocument;
            Document famDoc = this.ActiveUIDocument.Document;
                        
            // LightFamily API should work only in light fixture family document.
            if (famDoc.OwnerFamily.FamilyCategory.Id.IntegerValue != (int)BuiltInCategory.OST_LightingFixtures)
            {        
            TaskDialog.Show ("Error""Not a Light Fixture Family");
            }     
            else
            {        
                int n = 0;
                 LightFamily lightFamily = LightFamily.GetLightFamily(famDoc);     
                n = lightFamily.GetNumberOfLightTypes();
                TaskDialog.Show("Revit", n.ToString());
                for (int index = 0; index < lightFamily.GetNumberOfLightTypes(); index++)
                    {
                TaskDialog.Show("Index and Name", index.ToString() + "    " + lightFamily.GetLightTypeName(index).ToString ());
                    }
            }

The families i used were all older, and have probably been upgraded from earlier versions of Revit.  That may be the problem. 

 

When I made a new family, and created new types, it worked fine.   

 

Unfortunately, doing an audit on the older family didn't seem to help.  Neither did renaming the missing family type, or even duplicating the type and deleting the original type (one of the other types just goes missing.)

 

As a side note, anytime you turn off the light source for the family (under the family category and parameters), Revit starts giving an error message saying the family is a "non-lighting" family, and fails to run the code.  

 


Array of Boxes (FilledRegion)

$
0
0

Hi All,

First of all thank to   for example here (Create Filledregion)

at the moment it's creating only one filleregion type, so i made minor adjustment to make each type a filledregion

and my problem is they are all in the same location, my question is how can i modify it in a way that it'll create each type as shown below. Maybe an array or boxes but not sure how to do that. any ideas? thanks in advance.

Untitled.png

FilteredElementCollector fillRegionTypes = new FilteredElementCollector(doc).OfClass(typeof(FilledRegionType));
                List<FilledRegion> x = new List<FilledRegion>();
                foreach (FilledRegionType frt in fillRegionTypes)
                {
                    List<CurveLoop> profileloops = new List<CurveLoop>();

                    XYZ[] points = new XYZ[5];
                    points[0] = new XYZ(0.0, 0.0, 0.0);
                    points[1] = new XYZ(10.0, 0.0, 0.0);
                    points[2] = new XYZ(10.0, 10.0, 0.0);
                    points[3] = new XYZ(0.0, 10.0, 0.0);
                    points[4] = new XYZ(0.0, 0.0, 0.0);


                    CurveLoop profileloop = new CurveLoop();

                    for (int i = 0; i < 4; i++)
                    {
                        Line line = Line.CreateBound(points[i],
                          points[i + 1]);

                        profileloop.Append(line);
                    }
                    profileloops.Add(profileloop);
                    ElementId activeViewId = doc.ActiveView.Id;

                    FilledRegion filledRegion = FilledRegion.Create(doc, frt.Id, activeViewId, profileloops);

Question? Updated RVT to NWC Export? (Automated)

$
0
0

Does anyone know if there is a way to use a Dynamo script and apply to all RVTs in a folder, to export them all as Navisworks NWC’s? (see attached visual for more information)

 

My question is specifically focused on step 2 of this process I am trying to automate, and how Dynamo could help me achieve this?

 

My first thought was to use Dynamo to achieve this, but if anyone knows of a better way to resolve this process I am certainly open to hearing it.

Slide1.JPG

Re: Array of Boxes (FilledRegion)

$
0
0

Maybe just define your points 0-4 before the For-Each loop.

 

Then after you have made the first region, add something like this for each point zero through 4;

 

point[0].Y = point[0].Y - 10;

point[1].Y= point[1].Y - 10;

.....

Re: Creating Holes inside Filled Regions

$
0
0

I have managed to figure this out, though with some interesting notes:

 

It seems that Revit automatically detects if the boundaries passed into a filled region are representing holes or not. For example, if a closed loop of curves is found within another closed loop of curves, Revit will automatically render it as a hole. However, boundaries that are touching or intersecting each other will prevent the filled region from being created and will cause Revit to throw an error. This is something to note because though the clipper library supports such an arbitrary case, Revit does not. 

 

What I was doing before was returning only 1 path of closed loops (a contour according to the clipper library terminology), which was incorrect. Instead I iterated through all of the paths returned from the clipper object that does the Boolean functions and was able to collect all of the boundaries that I needed to render more correct shadows.

Re: Creating Holes inside Filled Regions

$
0
0

Thank you very much for discovering and describing the solution.

 

Can you provide a minimal sample code snippet illustrating the creation of a filled region with a hole in it?

 

Re: Creating Holes inside Filled Regions

$
0
0

Hi Jeremy,

 

Here is the minimum code snippet for creating a Filled Region with holes in it. I put the name for the draft view and region type as Level 1 Shadows and Shadow Proposed as it was already available in my document, but you can change it to whatever is convenient for you.

 

var doc = ActiveUIDocument.Document;
//Getting the view where we want the filled region to be drawn var draftView = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Views).First(n=>n.Name=="Level 1 Shadows");
//Getting the region type for the filled region var regionType = new FilteredElementCollector(doc).OfClass(typeof(FilledRegionType)).First(f=>f.Name=="Shadow Proposed"); //Boundaries of the filled region List<CurveLoop> profileLoops = new List<CurveLoop>();

//Coordinates of the outer loop XYZ[] points = new XYZ[5]; points[0] = new XYZ(0.0,0.0,0.0); points[1] = new XYZ(100.0,0.0,0.0); points[2] = new XYZ(100.0,100.0,0.0); points[3] = new XYZ(0.0,100.0,0.0); points[4] = new XYZ(0.0,0.0,0.0);
//Connecting the points of the outer loop CurveLoop outerLoop = new CurveLoop(); for (int i = 0; i < 4; i++)
{ Line line = Line.CreateBound(points[i], points[i+1]); outerLoop.Append(line); }
//Adding outer loop to the boundaries of the filled region profileLoops.Add(outerLoop);

//Coordinates of the inner loop XYZ[] points2 = new XYZ[5]; points2[0] = new XYZ(25.0,25.0,0.0); points2[1] = new XYZ(50.0,25.0,0.0); points2[2] = new XYZ(50.0,50.0,0.0); points2[3] = new XYZ(25.0,50.0,0.0); points2[4] = new XYZ(25.0,25.0,0.0);
//Connecting the points of the inner loop CurveLoop innerLoop = new CurveLoop(); for (int i = 0; i < 4; i++) { Line line = Line.CreateBound(points2[i], points2[i+1]); innerLoop.Append(line);
}
//Adding the inner loop to the filled region profileLoops.Add(innerLoop);
//Creating the filled region Transaction tr = new Transaction(doc,"Create Filled Region"); tr.Start(); var region = FilledRegion.Create(doc,regionType.Id,draftView.Id,profileLoops); tr.Commit();

 

 

 

Re: Array of Boxes (FilledRegion)

$
0
0

Hi   Thank you for your suggestion sorry im quite new to this could you show me please where to add that code?

 

Thank you.

 

               List<CurveLoop> profileloops = new List<CurveLoop>();

                XYZ[] points = new XYZ[5];
                points[0] = new XYZ(0.0, 0.0, 0.0);
                points[1] = new XYZ(2, 0.0, 0.0);
                points[2] = new XYZ(2, 2, 0.0);
                points[3] = new XYZ(0.0, 2, 0.0);
                points[4] = new XYZ(0.0, 0.0, 0.0);

                foreach (XYZ point in points)
                {

                    point[0].Y = point[0].Y - 10;
                    point[1].Y = point[1].Y - 10;


                    foreach (FilledRegionType filledRegion in filledregions)
                    {

                        CurveLoop profileloop = new CurveLoop();

                        for (int i = 0; i < 4; i++)
                        {
                            Line line = Line.CreateBound(point[i],
                              point[i + 1]);

                            profileloop.Append(line);
                        }
                        profileloops.Add(profileloop);

                        ElementId activeViewId = doc.ActiveView.Id;
                        FilledRegion nfilledRegion = FilledRegion.Create(doc, regionType.Id, activeViewId, profileloops);
                    }
                }
            }

Re: Returning Fabrication ITM Item Properties

$
0
0

Dear Jes,

 

Thank you for your query.

 

Welcome to the Revit API!

 

I assume you have gone through the getting started material and are clear about the basic Revit architecture, installation and all that stuff?

 

https://thebuildingcoder.typepad.com/blog/about-the-author.html#2

 

Great!

 

Whenever you are faced with any Revit API task, it is almost always useful to check the manual solution and situation first and then analyse your model using RevitLookup to determine how to address it programmatically.

 

http://thebuildingcoder.typepad.com/blog/2017/01/virtues-of-reproduction-research-mep-settings-ontology.html#3

 

In this case, your screen capture displays certain properties on a specific element.

 

Normally, all those properties can also be accessed programmatically from that same element.

 

Please install RevitLookup, if you have not already done so:

 

https://github.com/jeremytammik/RevitLookup

 

Select the element of interest and look at its parameters.

 

That will show you the appropriate path to access them programmatically as well.

 

I hope this helps.

 

Best regards,

 

Jeremy

 

Re: Editing Calculated Value Formula

$
0
0

Dear Dan,

 

Thank you for your query.

 

As you say, the FieldType property is a get and set property, so it can apparently be modified.

 

However, as far as I understand your query, you are interested in setting the formula value itself, not the field type, so that will not help.

 

You say you can retrieve the Calculated Value as a ScheduleField. Interestingly, the remarks on that class say:

 

The SchedulableField class represents a non-calculated field...

 

Anyway, regardless of all that, I cannot imagine that you can edit whatever is displayed by the calculated field, since, as its name implies, the value is calculated.

 

I hope this helps.

 

Best regards,

 

Jeremy

 

Re: Question? Updated RVT to NWC Export? (Automated)

$
0
0

Yes, you can automate exporting the Revit RVT to Navisworks.

 

The Revit API provides the Doucment.Export overload taking a NavisworksExportOptions argument for this purpose:

 

https://www.revitapidocs.com/2017/1b9538a9-a76b-0a40-2aed-e02f6974a43a.htm

 

In a Revit add-in, you can use the OS functionality to access all RVT files in the folder, open, export and close each in turn.

 

This functionality can also be made available in a Dynamo node.

 

Best regards,

 

Jeremy

 

Re: Creating Holes inside Filled Regions

$
0
0

Dear Mohsen,

 

Thank you very much!

 

Looks perfect, and will hopefully be useful for others encountering this issue.

 

Best regards,

 

Jeremy

 

Non-API | Show .rfa Preview Pane Icon

$
0
0

Hello,

 

My question does not directly pertain to the Revit API, but (apparently) has to do with Revit developers, and hence this question seems better suited to the API forum than to the Architecture/Structure/MEP forums. Please let me know where I should rather post it and I will be happy to.

 

In the meanwhile, t would be great if someone could advice me on the following:

I would like to be able to view the preview image of my Revit families when in Windows explorer. It seems unnecessary to have to open the Revit application and go to the Insert family icon to see a sizable image preview (Details pane shows a tiny icon which isn't descriptive) of families. Sometimes when sorting through libraries or choosing families it is done from outside the Revit application and descriptive icons would be great.

I tried to find the solution on the Windows forums and thought maybe it could be done with a regedit, but it was stated that this needs to be changed from the developers side?

 

Please see the link below for more information:

https://answers.microsoft.com/en-us/windows/forum/windows_10-other_settings/how-to-change-size-of-details-pane-image-preview/70fb516b-0a10-4829-b708-d317e3d86ffb?messageId=e52c895b-65ca-4482-8c9c-0680495aac43

 

Any assistance would be most appreciated.


If this isn't quite easily fixed, I can post it to Ideas forum.

 

Thank you!

Re: Method or logic to dynamically generate Collectors in a loop to get Model Gr

$
0
0

Sure this is possible.

 

However, would it not be much easier and clearer to retrieve all elements having a level property in one single filtered element collector, and then sorting them by levels afterwards?

 

Re: Revit || Unity Reflect || ForgeToolkit


How to get Identity Data of a sheet?

$
0
0

Снимок.PNGI can obtain the parameter name "BI_Раздел проекта" by using FilteredElementCollector(doc).OfClass(ViewSheet), calling GetOrderedParameters() on each sheet, and accessing it via parameter.Definition.Name.  But how do I get its value?

Re: Method or logic to dynamically generate Collectors in a loop to get Model Gr

$
0
0

Thanks a lot for diving into this! I've modified the code by trying LogicalAndFilter. I'm new to C# so don't know how to check the dictionary members which I passes as a list. Can you tell me what part needs to be changed?

 

using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
namespace Lab2ModelGroups
{
    [Transaction(TransactionMode.Manual)]

    public class Class1 : IExternalCommand
    {

        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            Document activeDoc = commandData.Application.ActiveUIDocument.Document;
            String level_names = "";
            String demo = "";
            List<String> level_name = new List<String> { };
            List<ElementId> level_idlist = new List<ElementId> { };
            Dictionary<ElementId, List<String>> dict = new Dictionary<ElementId, List<String>>();
            List<String> mg_name = new List<String> { };
            FilteredElementCollector collector_levels1 = new FilteredElementCollector(activeDoc);
            ElementClassFilter filter_level = new ElementClassFilter(typeof(Level));
            collector_levels1.WherePasses(filter_level);
            foreach (Element l in collector_levels1)
            {
                level_names += l.Name + "," + l.Id;
                level_name.Add(l.Name);
                level_idlist.Add(l.Id);
            }

            // FilteredElementCollector collector = new FilteredElementCollector(activeDoc).OfClass(typeof(View));
            for (int i1 = 0; i1 < level_idlist.Count; i1++)
            {
                ElementLevelFilter elemlevelfilter = new ElementLevelFilter(level_idlist[i1]);
                ElementCategoryFilter mgCategoryfilter = new ElementCategoryFilter(BuiltInCategory.OST_IOSModelGroups);
                LogicalAndFilter mgFilter = new LogicalAndFilter(elemlevelfilter, mgCategoryfilter);
                FilteredElementCollector collector = new FilteredElementCollector(activeDoc);
                IList<Element> mg = collector.WherePasses(mgFilter).ToElements();
                foreach (Element e in mg)
                {
                    //mg_name.Add(e.Name);
                    //demo += e.Name + "\n";
                    if (dict.ContainsKey(level_idlist[i1]))
                    {
                        dict[level_idlist[i1]].Add(e.Name);
                    }
                    else
                    {
                        dict[level_idlist[i1]] = new List<string> { e.Name };
                    }
                }


            } 
            
           // TaskDialog.Show("Hi", demo);
            return Result.Succeeded;
        }
    }
}

Re: How to get Identity Data of a sheet?

Re: Matching floor sub elements

$
0
0

Yes I did!

After many failures, the "find nearest" with reference intersector worked.

I've used it in a couple of projects, it's not perfect, but it works :)

I'll attach the bit of code that made it work: 

 

 #region draw referenced points on new floor
                            using (Transaction t01 = new Transaction(doc, "tu"))
                            {
                                try
                                {
                                    t01.Start();


                                    foreach (XYZ p in points)
                                    {
                                        XYZ p_end = new XYZ(p.X, p.Y, (p.Z + 1000));
                                        XYZ direction = new XYZ(0, 0, -1);
                                        FilteredElementCollector collector = new FilteredElementCollector(doc);
                                        Func<View3D, bool> isNotTemplate = v3 => !(v3.IsTemplate);
                                        View3D vy = collector.OfClass(typeof(View3D)).Cast<View3D>().First<View3D>(isNotTemplate);

                                        //försök två

                                        ReferenceIntersector refin2 = new ReferenceIntersector(golv.Id, FindReferenceTarget.All, vy);
                                        ReferenceWithContext refcon2 = refin2.FindNearest(p_end, direction);
                                        Reference ref2 = refcon2.GetReference();
                                        XYZ insec = ref2.GlobalPoint;
                                        points2.Add(insec);

                                    }
                                    t01.Commit();

                                }
                                catch (Exception ex)
                                {

                                }
                            }

                            #endregion

 

How can I launch my plugin from the surface edit mode?

$
0
0

Hi everyone.
Does anyone know if I can launch some add-in while in edit surface mode?
Ideally, if I can subscribe to an event of transition to the surface editing mode, and then launch your plugin
I will be glad to any ideas.

Viewing all 66917 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>