i found that i can do with the following code:
but i think its weird becouse a room object does have the property name. so why is it giving me this exception?
i found that i can do with the following code:
but i think its weird becouse a room object does have the property name. so why is it giving me this exception?
Hi,
in the RevitAPI.chm, there are a few code samples for LightType and its members.
For example on "LightFamily.SetLightDistributionStyle" page.
There you can see how to get LightTypes in the family document:
public void ModifyLightDistributionStyle(Document familyDoc) { // Get the light family from the static method. LightFamily lightFamily = LightFamily.GetLightFamily(familyDoc); // Set the light distribution style to PhotometricWeb lightFamily.SetLightDistributionStyle(LightDistributionStyle.PhotometricWeb); // After light shape style set to PhotometricWeb, each tyoe returns a CircleLightShape instance, for (int index = 0; index < lightFamily.GetNumberOfLightTypes(); index++) { LightType lightData = lightFamily.GetLightType(index); PhotometricWebLightDistribution lightDistribution = lightData.GetLightDistribution() as PhotometricWebLightDistribution; lightDistribution.PhotometricWebFile = @"C:\IES\1x4 2Lamp.ies"; // input a full file path here. lightDistribution.TiltAngle = Math.PI / 6; // use radian value to set lightData.SetLightDistribution(lightDistribution); // set back } }
Once you have a LightType, you can set its properties, for example the initial intensity.
Depending on which BuiltInParameter you want to adress, use
FBX_LIGHT_LIMUNOUS_FLUX
lightData.SetInitialIntensity(new InitialFluxIntensity(lumen));
FBX_LIGHT_LIMUNOUS_INTENSITY
lightData.SetInitialIntensity(new InitialIlluminanceIntensity(1, candela));
FBX_LIGHT_WATTAGE
lightData.SetInitialIntensity(new InitialWattageIntensity(1, watt));
FBX_LIGHT_EFFICACY
lightData.SetInitialIntensity(new InitialLuminousIntensity(lumenPerWatt));
Also, there is a code sample for setting the initial color, on page "LightType.SetInitialColor":
public void SetInitialColorProperty(LightType lightType) { InitialColor initialColor = lightType.GetInitialColor(); if (initialColor is CustomInitialColor) { CustomInitialColor custom = initialColor as CustomInitialColor; double colorTemperature = custom.Temperature; // Set new value for color temperature and set modified initial color to LightType. custom.Temperature = 3450.0; lightType.SetInitialColor(custom); // Create a PresetInitialColor and set it to LightType. PresetInitialColor preset = new PresetInitialColor(ColorPreset.Halogen); lightType.SetInitialColor(preset); } }
And so on.
RevitAPI.chm says "Since: 2013".
Revitalizer
Hello Naveen, thank you for your response.
I had tried to import the SAT files via doc.Import with Sat options and had the same problems. See attached video and code for reference.
As shown in the video, there are still import issues when going through the api but importing the same SAT via the ui works as anticipated..
try:
famDocT = Transaction(famDoc, "FamilyImport") SAT_IOption = SATImportOptions() SAT_IOption.VisibleLayersOnly = True SAT_IOption.Placement = ImportPlacement.Origin SAT_IOption.ColorMode = ImportColorMode.Preserved SAT_IOption.Unit = ImportUnit.Default collector = FilteredElementCollector(famDoc) collector.OfClass(Autodesk.Revit.DB.View) views = [] for view in collector: if not view.IsTemplate: views.append(view) if "ref. level" in view.Title.ToLower(): mainView = view #################################################### #"Start" the transaction famDocT.Start() fam = famDoc.Import(file, SAT_IOption, view) # "End" the transaction famDocT.Commit() famI = famDoc.LoadFamily(doc, FamilyOption()) except Exception as e: pass finally: famDoc.Close(False) if famI: return famI else: messages.append("An Error occured when trying to import: " + file.split("\\")[-1] + ". No geometry could be found to import.") return None
Hi,
your obj is None, so no Name property at all.
You access this invalid property in the except block, so the exception will be forwarded to a higher level.
May it be that the Windows API operations (hide, show, set topmost) interfere with the Revit API selection method?
Revitalizer
I'm using uiDoc.Selection.PickObjects to select multiple objects to operate on.
After the selection I open a wpf-dialog with window.ShowDialog(); and apply some parameters. After clicking Ok I return Result.Secceeded and all is well. Except for a small detail. The objects still looks like they are selected, when they aren't. I have to select and deselect the objects again to make them look like they are not selected.
This feels like a visual bug in Revit (I'm using 2018.2), but has anybody else had this problem or has got any ideas how I can reset the color?
Thanks!
Hi,
just an idea.
In the family document, there may be more than one view of the name "Ref. Level".
What if you get the CeilingPlan instead of the FloorPlan one?
The FilteredElementCollector doesn't sort its result.
If doing the import manually, I bet you always use the correct view, so no chance to reproduce it...
So you just need to check the view.ViewType.
Revitalizer
Hi,
seems that you can go this way:
Get the Connector objects from
yourFabricationPart.ConnectorManager.Connectors
For each Connector object, call its GetFabricationConnectorInfo() method.
The resulting FabricationConnectorInfo object provides some properties.
Looks like "BodyConnectorId" is what you need.
Not tested yet.
Revitalizer
Yes, I have definitely seen that.
I'm not sure how I ever got rid of it. I know I tried setting lots of things to "null" and clearing out all my variables because I was thinking something was hanging around in memory keeping the elements highlighted. I also tried refreshing the document. But I'm not sure any of that helped.
Looking back at my code, one thing I left right at the end was setting the selection set to an empty list of elements, and then disposing of the selection:
ICollection<ElementId> noneselected = new List<ElementId>();
uidoc.Selection.SetElementIds(noneselected);
uidoc.Selection.Dispose();
return Autodesk.Revit.UI.Result.Succeeded;
I'm not sure if that fixed the problem, but it might be worth a try.
When I was finished with my selection object I added uidoc.Selection.Dispose(); as you suggested. This was enough to fix the problem.
Thanks a bunch!
You are absolutely correct. I appreciate the response. While waiting for a reply I stumbled on to the BodyConnectorId property of the FabricationConnectorInfo Class and was able to use the ID and then retrieve the name using the Current FabricationConfiguration.GetFabricationConnectorName(index) method. I am new to the Revit API but slowly finding my way through everything. Again thanks for the response.
That works very well Naveen.
I don't want to hijack this thread, but is there a simple way to add to this to set the Projection Line Color and Pattern?
For the Projection Line Color, it looks like I need to add:
ORGS.SetProjectionLineColor(Color color);
But I don't have enough C# experience to know what to put in the parenthesis. I have a similar issue with the line pattern. I'm not sure how to specify it by name.
Thanks,
Steve
Good idea to check for that, thanks for the suggestion. Unfortunately adding a view.ViewType == ViewType.FloorPlan doesn't fix the issue I'm having (though it certainly makes everything consistent). This also wouldn't have been an issue when using the ShapeImporter/DirectShape.CreateElement method to import the SAT.
In either case it looks like they share the same issue - geometry that can be imported via UI isn't being imported via API. I would chalk it up to geometry being the issue if I couldn't import via UI but it never gave me an issue when I import the sat files via the standard import (as seen in the video).
Hello,
I've been working on a plug-in that needs access to elements (e.g. Gridlines) that are in linked files. I have tried every suggested methods I could find online, but have only found a little success using the CustomExporter to Export a selected 3d view to a custom object. That at least allows me to access an array of all the elements in the documents. However, it seems there are a couple problems with this method.
I'm using c# and Revit 2017 & 2018. Does anyone have any suggestions?
I have tried this before with no luck, but with some more internet searching, and some trial and error, I've managed to answer my own question.
To set the color one can use something like this:
Color black = new Color(0x00, 0x00, 0x00);
Color blue = new Color(0x00, 0x00, 0xFF);
ORGS.SetProjectionLineColor(blue);
or:
ORGS.SetProjectionLineColor(new Color(0x00, 0x00, 0xFF));
Setting the lineweight is pretty easy:
ORGS.SetProjectionLineWeight(5);
Setting the pattern was a little harder since I had to find the line pattern with a filtered element collector. But I found one of Jeremy's examples:
FilteredElementCollector fec = new FilteredElementCollector( doc ).OfClass( typeof( LinePatternElement ) );
LinePatternElement linePatternElem = fec.Cast<LinePatternElement>().First<LinePatternElement>( linePattern => linePattern.Name == "long dash");
ORGS.SetProjectionLinePatternId(linePatternElem.Id);
I also wanted to find a line pattern called Center 1/4", and including the quote was a little more difficult. But following by example I found this would work with 3 quotes on the end:
linePattern.Name == @"Center 1/4"""
I really appreciate your detailed answer. And yes, it solved my problem completely!
(I wonder why I couldn't find anything about the Autodesk.Revit.DB.Lighting namespace while I was googling around...)
Thank you!!
tmishina
Hello
Recently same problem i have also facing. but i could not find any satisfied solution.
But i have one Idea for you and everyone who facing this same type of problems.
Export Revit File Into the CAD
Then Open Exported CAD file into the Autodesk Civil3D Metric
Then only we can export IFC easily without any problem.
But In this process we can't Able to extract attributes along with the IFC
Thanks
Rakesh Jangid
wrote: Hi
I have problem exporting my revit model to IFC.
Its quite large project. 350MB
I have made these size of projects before and still managed to make IFC.
But now i am geting error :
There has been an unrecoverable error during export. Export will now be aborted.
I have Insatlled all the latest uptates , and also IFC exporter 2016 V16.3... nothing works.
Tryed to hide some of the building and then it manage to export.
Could somone try out my revit file to export and find solution for this problem?!
Revit File is to large to have it on attachment!?
Hoping for the best
Kaupo
Dear Paul,
Happy New Year to you!
Sorry, nope, no idea.
Are you aware of these other CAD Terminology Resources for Consistent Translation?
Best regards,
Jeremy
Pleas always search the available resources before asking a question here.
In this case, please search the Revit SDK samples for `RebarShape`.
One of the samples provides is MultiplanarRebar.
This sample is to demo multiplanar rebar creation in API. A user scenario of multiplanar rebar is corbel reinforcement. This sample reinforces sloped corbels.
Cheers,
Jeremy
Thank you,
I finally succeeded with this option
//
FilteredElementCollector FilCol = (new FilteredElementCollector(Doc) + OfClass(typeof(MEPSystemType)));
foreach (MEPSystemType Ele in FilCol) {
TaskDialog.Show("System Type = ", Ele.Name);
}
//
Hi,
It's difficult to tell where the error occurs without knowing how your Door family is created and how the Parameters are organized in your family.
I want to show how i do with an example, maybe this is useful for you (or not).
Assuming you can get access to the sample files on your system, try to open something like the "Technical_school-current.rvt” file.
There is a door family ('M_Single-Flush') with the name '0915 x 2134'.
Looking at the 'Type Parameters', there is a 'Frame Material' parameter.
The value (Door - Frame) is the current Material name.
If i want to change the Material name to 'Glass', something like this will do (FYI it's a macro)
public void changeDoorFrameMaterialType()
{
Document doc = this.ActiveUIDocument.Document;
using (Transaction t = new Transaction(doc, "Change Door Frame"))
{
t.Start();
List<FamilyInstance> doors = new FilteredElementCollector(doc)
.OfClass(typeof(FamilyInstance))
.OfCategory(BuiltInCategory.OST_Doors)
.Cast<FamilyInstance>()
.Where(q => q.Name == "0915 x 2134mm").ToList();
Material mat = new FilteredElementCollector(doc)
.OfClass(typeof(Material))
.Cast<Material>()
.FirstOrDefault(q => q.Name == "Glass") as Material;
foreach (Element door in doors)
{
ElementId elemTypeId = door.GetTypeId();
ElementType elemType = (ElementType)doc.GetElement(elemTypeId);
// BuiltInParameter will create error/
// Object refenrence not set to an instance of an object /error
// elemType.get_Parameter(BuiltInParameter.DOOR_FRAME_MATERIAL).Set(mat.Id);
// try use the LookupParameter
elemType.LookupParameter("Frame Material").Set(mat.Id);
}
t.Commit();
}
}
As you may have noticed there are two 'Frame Material' parameters in the document.
One belongs to an Instance Parameter, and the other one belongs to the Type Parameter.
We are only interested in the Type Parameter so we need to use the ElementType Class and use the LookupParameter instead of the BuiltinParameter for DOOR_FRAME_MATERIAL
Still, i’m not sure if this is similar to your situation.
Anyway, good luck !