How to set level of newly placed FamilyInstance? - c#

I'm placing a new face-based family instance into my Revit model with the help of the NewFamilyInstance Method (Face, XYZ, XYZ, FamilySymbol) method described here. This works fine, except the instance does not have its level set to that of the host (it's set to -1 when accessed through the API and just left blank in the UI).
I tried setting the level like such
placedInstance.LevelId = hostWall.LevelId
and following this approach also tried
placedInstance.get_Parameter(BuiltInParameter.FAMILY_LEVEL_PARAM).Set(hostWall.LevelId);
but both throw an error saying the parameter is readonly.
Any help would be appreciated!

On some elements, the element level can only be set during the creation of the element. For that, I would assume that you need to use a different overload of the NewFamilyInstance method. Please refer to this explanation by The Building Coder and a few recent discussions of related topics in the Revit API discussion forum:
Change level of existing element
LevelId is null
Change level on line based family

Related

Could not access element by ID

I am facing with problem when I tried to access Android element by ID in C#, I also tried with Appium-desktop version and seems not accessible for example:
I tried with and without package name and there is an exception every time which says could not find element. Also from Appium desktop selector.
AndroidElement selectPlant = driver.FindElementById("com.heidelbergcement.aom.stage.dev:id/loginForm-plantSelection")
You're misunderstanding something.
FindElementById refers to the unique identifier of the element which in most cases is the RuntimeId of the UI element.
What you should use is findElementByAccessibilityId, which refers to AutomationId of the UI element as shown in the inspect tool.
Total credit to this.

Placing a custom mass family instance in a model using Revit API

I created a custom Mass family, which is a simple cylinder. I'm trying to place it on a specific point on a specific level using the NewFamilyInstance method.
This is the code I'm using to place the instance:
doc.Create.NewFamilyInstance(new XYZ(0, 0, 0), symbol,
ele.Document.GetElement(ele.LevelId),
Autodesk.Revit.DB.Structure.StructuralType.UnknownFraming);
The problem is that the instance is placed always at level 1, no matter what the input level.
I noticed that the input level appears on the instance's Host constraints. Please refer to the image below:
Would highly appreciate it if anyone points out my mistake.
Cheers!
The code seems to be correct for me, check the source of the ele.LevelId.
If you don't find anything to be corrected you can try to change the level after the creation of the family instance:
//Start Transaction
FamilyInstance famInst; //--> your code
famInst.get_Parameter(BuiltInParameter.FAMILY_LEVEL_PARAM).Set(/*Level Id*/);
I used this method to place the Family Instance and it solved the issue:
Create.NewFamilyInstance(interiorFaceRef, location, refDir, symbol)
https://www.revitapidocs.com/2020/be4b822c-829a-7e7b-8c03-a3a324bfb75b.htm

Sitecore Custom Rules

I have a custom rule in Sitecore:
where person's status is [condition,Tree,root=/sitecore/content/Home/PersonStates, specified state]
I want to replace the hard coded path with one that points to any folder that has it's template id matching the one I specified. This is because the author will create these values (of a specific template in the root folder).
I have tried this and it does not work:
where person's status is [condition,Tree,root=query:/sitecore/content/Common/Categories/*[##templateid='{3B0461BF-9ABC-4AF1-B937-C8D225FC2313}'], specified state]
Furthermore, I need to restrict some of these values based on properties that these items would have.
Eg: The author adds 5 states. I need only those states which have the active flag set to true.
How would I do this?
Out of the box the Tree Macro does not support this, the solution is to create a custom Macro that allows a query to be executed. In order to do this you will have to implement IRuleMacro and implement your logic. Make sure to URL encode your query. Also note that the macro does not have any context when called, so you will have to implement this yourself. An example of this can be found here

How to access element cut areas/filled regions through Revit API

I'm trying to figure out how to access the filled regions created when an object is cut in plan or section. My aim is to write a tool that duplicates these regions in order to quickly create dual hatches in a view.
I'm unsure at the moment whether these regions are associated with the family instance itself, or the view, or the work plane, etc.I've poured through Revit Lookup but can't locate it.
There is some information here about creating new filled regions through
FilledRegion.Create(...)
But I'm more interested in accessing the ones already created in a view.
Any suggestions would be much appreciated.
The code snippet below would return Elements of all the FilledRegions of the current Document (doc) in a specified View (v). I hope that gets you going in the right direction.
FilteredElementCollector collector = FilteredElementCollector(doc,v.Id).OfClass(typeof(FilledRegion));
Sorry, I misunderstood what you were looking for.
You can get the CutPatternId of a Material, which would return the pattern you see when an element is cut. I don't have a code snippet for you, but, what you'd want is:
User selects the Element
API gets all the Materials of that Element
API returns all the CutPatternIds of those Materials
(FillPatternElement)
API returns all the FilledRegionType(s) with
the same FillPatternId (creating them is necessary)
API generates the FilledRegion using the correct FilledRegionType.
Item 5 is the trickiest part because I'm not sure how you could determine the boundary it's supposed to draw. #jeremy-tammik is super smart, and he's the author of the blog you referenced. Maybe he could fill in the gap on this part. Maybe there is something you could return from an "Intersect" method?

Definition.Entity property is null

Whenever I create a ReloadableObjectRegistry with path to directory containing compiled modules, Definitions in the tree have Entity property set to null. The reason why I need to access this property is to be able to read the syntax of a definition.
I suspect, the Entity property only gets set after parsing a MIB... Is this a correct assumption? How else can I find out definition's syntax? The Type property is always 'Unknown'.
Sample code:
private ReloadableObjectRegistry Objects;
Objects = new ReloadableObjectRegistry(#"some_path");
P.S. By the looks of it, parsed module (.module) does not have any information about MIB Types in it.
The open source edition SharpSnmpLib.Mib was designed that way, where most of the classes are just placeholders.
If you do need to learn the syntax, you have to use SharpSnmpPro.Mib at http://sharpsnmp.com.
A sample project has been published on GitHub to demonstrate usage of the new APIs.

Categories

Resources