Placing a custom mass family instance in a model using Revit API - c#

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

Related

How to set level of newly placed FamilyInstance?

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

Changing the layer mask of a pointer in MRTK v2.1

I need to change the layer mask during runtime in order to select different objects depending on the context.
From my understanding this should be done in the InputSystemProfile by editing the Pointers property:
CoreServices.InputSystem.InputSystemProfile.PointerProfile.PointingRaycastLayerMasks
But the field is read-only, and I can't find another way to edit it, other than manually in the editor.
Btw I'm using an editable profile for the input system.
In HTK this was achieved by assigning a value to:
GazeManager.Instance.RaycastLayerMasks
Any suggestions?
For the returned field PointingRaycastLayerMasks, it is an instance of reference type LayerMask[]. Therefore, although you cannot change the value of the reference itself, it is possible to change the data that belongs to that referenced object.
So, you can change Layer Mask with the following code:
//Uncheck [PostProcessing],[Spatial Awareness]
CoreServices.InputSystem.InputSystemProfile.PointerProfile.PointingRaycastLayerMasks[0].value = 19;
If you have questions about how to use LayerMasks in Unity, please see here: How do I use layermasks?
you could change the pointers layer mask by overriding it
All the pointers can by found here: CoreServices.InputSystem.DetectedInputSources
and in each one you can do:
ptr.PrioritizedLayerMasksOverride
Hope this helps

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?

Extending the sealed Pushpin class to include more fields

I am developing a windows store app that allows a User to place points on a map and load them from a server. I have this working fine but I need to include more properties than the standard Pushpin class allows (rating / description / user).
Because Pushpin is sealed, I cannot add these fields and use my own object in place of Pushpin. I tried over the past couple of hours to compose my own PointOfInterest class with a Pushpin object inside it however, this approach fails in a number of areas (When I place a point on a map, I want to retrieve more details than just name / tag and have no way of getting a reference back to the original object.)
If anybody has an idea of where to go from here I would like to hear from you !
If you need access to the private members of a sealed class then you are out of luck.
Best you can do is proxy (which you already seem to be doing by including it as a member). Also called faking it :)

TiledLib for XNA throws ArgumentException on loading

Essentially, what I'm trying to do is to load/draw a map from a Tiled map using Nick Gravelyn's TiledLib. The map is saved in Tiled's XML format. However, when I try loading the map with the line
TiledLib.Map map = Content.Load<TiledLib.Map>("Maps/Map1");
it throws an ArgumentException. The whole thing renders like this in Tiled itself:
The map's XML source looks like this (not posted directly onto StackOverflow for obvious size reasons).
It worked at first (with a pretty simple map using only one tileset) but when I edited it to include a bit more stuff then it suddenly started doing this. Could it be related to my usage of tile objects?
EDIT: I have been able to work out that using tile objects was not the culprit; this map structure still creates the same error.
you get an exception because you didn't name the objects in the map, this will cause ArgumentException in TiledLib. So, to solve this issue you need to go back to Tiled program, (re)edit this map, and select every object in the map and give it a name (not property but name) then export the map again and (re)import it into the game content. This should fix the problem.
BTW: I recommend using regular layer for collide check not object layer.
Like this: Make small png file with a transparent red rectangle tile in it in the same map tile dimensions, add new layer to the map, name it CollideLayer, and in this CollideLayer put that red rectangle tile where you want to be a collide, and then in the game code you can check to see if the CollideLayer cell is empty or not. I find this is simpler.
I',m guessing, but looking at your XML structure in the section, there are a lot of repeats of
<tile gid="0"/>
in the data element. There is no documentation or schema definition on the structure of this file on the official site, and the content pipeline source is not available. Also, the demo of TileLib comes with that section as
<data encoding="base64" compression="gzip">
H4sIAAAAAAAAC2NmYGBgpjKmFkA2jxCNrg+bHD7z0PWSYx428wmZjW4+qf7Fxyc3PnDFJS3jdzCbx4QFg8QZScTUzmcgDACR4mfdwAMAAA==
I'm not sure if you have an option to include encryption or not. But, the "gid" (global id ??) attribute cannot be the same for every tile defined if that is what it is. If I was writing this engine, I would have some way to readily identify each basic defined tile. Like a primary key on a data table. Which has to be unique. That would be the "gid" attribute for me.
Since the exception does not give any information (which is stupid - who deploys public libraries like that??), the argument exception is either that your "gid" attribute value is already defined, or that you're missing the encryption attributes which it expects in the pipeline importer or processor.

Categories

Resources