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

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?

Related

Get selected items in solution with native interfaces

I am trying to get all selected items in a solution and this with native code. With native code I am referring to code which does not use the DTE.
I checked the documentation and tried to find a suitable solution, however I din't come very far. What I found was the IVsUiHierarchy which contains the ExecCommand method which contains the following.
Commands that act on a specific item within the hierarchy. (If ItemID equals VSITEMID_SELECTION, the command is applied to the selected item or items.)
So I suspect the method they are talking about, is the before mentioned ExecCommand one. For one I am not quite sure how I will get to the IVsHierarchy object from a IVsHierarchy or similar, on the other hand I am not really sure on how to use the ExecCommand method properly. Additionally I am not even quite certain, if this is even the 'right way' of approaching this.
Note: I am searching for a solution which does not contain the following code in this answer.
You can use IVsMonitorSelection.GetCurrentSelection, to identify all the selected items in the solution explorer.
The above will return you an IVsMultItemSelect interface which you can use to invoke IVsMultiItemSelect.GetSelectedItems to retrieve an array of VSITEMSELECTION values.
There are a few extensibilty samples, that utilize GetSelectedItems, you can use as a reference.
Sincerely,
Ed Dore

Is it possible to save an oxyplot into a list?

I'm trying to save some oxyplots into a list where I can then later generate a pdf or png file for printing to a printer. Is this something that is possible?
I have two classes; one is a plotUsercontrol and the other being a Baseplot.
Also, I did not implement the oxyplots feature of the app so I'm not fully aware of the differences between PlotModel and PlotView.
In my snippet PlotUserControl. I have the following function which I created to grab all the plots from the BasePlot. I declared it as void because I was not sure what type to declare the Data type for the list and function as.
public void getPlots()
{
foreach(var plot in plots)
{
Console.WriteLine(" ");
Console.WriteLine(plot.getImage());
}
}
Bellow is just a fucntion from my baseplot that gets the PlotModel. Also I wasn't sure whether to return the plotModel or the plotView.
public PlotModel getImage()
{
return this.plotModel;
}
I hope this make sense. New to c#.
Do you want to safe your images or the plots into a list? If you want to save plots into a list, that's already done (plots).
However if you want to save images into a list that's a bit different but very easy. I suggest you take a look at List<T>. I can supply you with method that will do all the work but it is so easy that i think you can manage to set up the list on your own.
Here is a quick rundown tho: List<T> will create a list which allows you to save objects of the datatype T inside of it. T is a so-called generic type which means you can hand it every data type that can be instantiated.
Hint: T would be PlotModel in your example.
If you need any more help, feel free to contact me but I think you can manage creating said list on your own.
This is the link to the Microsoft Docs of List<T>, but imo they are not the best docs for beginners. Just look for some tutorials on Google.
Another tip tho, rename your functions. In C# first letters of words in method names are uppercase (e.g: GetPlots(), GetImage()). This is just a common naming style although you can stick to lowercase.

Easiest way to plot a node structure which re-groups its nodes?

The kind of structure I am talking about is shown in the picture below.
By now my DB contains each item with giver_id (the previous item) | receiver_id (the next item). When I retrieve these items in-memory, I would like to show them in a meaningful way to the user.
I have researched and this seems to be called a "vertex/edge graph". The only option I've found is QuickGraph, and I don't seem to be able to implement it in my WindowsForm application (which is my other constraint).
Anybody knows about any other options to solve this problem?
Note: my solution does not need to be perfect, it will be used internally as a helper to configure the node chain in the DB.

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.

Programatic way to do linear referencing in ArcGIS

I am working on a custom ArcGIS Desktop tool project and I would like to implement an automated linear referencing feature in it. To make a long story short, I would like to display problematic segments along a route and show the severity by using a color code (say green, yellow, red, etc.). I know this is a pretty common scenario and have come to understand that the "right way" of accomplishing this task is to create a linear event table which will allow me to assign different codes to certain route segments. Some of my colleagues know how to do it manually but I can't seem to find any way to replicate this programaticaly.
The current tool is written in C# and already performs all the needed calculations to determine the problematic areas. The problem mainly is that I don't know where to start since I don't know a lot about ArcObjects. Any code sample or suggestion is welcome (C# is preferred but C++, VB and others will surely help me anyway).
EDIT :
I'm trying to use the MakeRouteEventLayer tool but can't seem to get the different pre-conditions met. The routes are hosted on an SDE server. So far, I am establishing a connection this way :
ESRI.ArcGIS.esriSystem.IPropertySet pConnectionProperties = new ESRI.ArcGIS.esriSystem.PropertySet();
ESRI.ArcGIS.Geodatabase.IWorkspaceFactory pWorkspaceFactory;
ESRI.ArcGIS.Geodatabase.IWorkspace pWorkspace;
ESRI.ArcGIS.Location.ILocatorManager pLocatorManager;
ESRI.ArcGIS.Location.IDatabaseLocatorWorkspace pDatabaseLocatorWorkspace;
pConnectionProperties.SetProperty("server", "xxxx");
pConnectionProperties.SetProperty("instance", "yyyy");
pConnectionProperties.SetProperty("database", "zzzz");
pConnectionProperties.SetProperty("AUTHENTICATION_MODE", "OSA");
pConnectionProperties.SetProperty("version", "dbo.DEFAULT");
pWorkspaceFactory = new ESRI.ArcGIS.DataSourcesGDB.SdeWorkspaceFactory();
pWorkspace = pWorkspaceFactory.Open(pConnectionProperties, 0);
pLocatorManager = new ESRI.ArcGIS.Location.LocatorManager();
pDatabaseLocatorWorkspace = (ESRI.ArcGIS.Location.IDatabaseLocatorWorkspace)pLocatorManager.GetLocatorWorkspace(pWorkspace);
Now I am stuck trying to prepare everything for MakeRouteEventLayer's constructor. I can't seem to find how i'm supposed to get the Feature Layer to pass as the Input Route Features. Also, I don't understand how to create an event table properly. I can't seem to find any exemple relating to what I am trying to accomplish aside from this one which I don't understand since it isn't documented/commented and the datatypes are not mentionned.
I'm not entirely certain what it is you want to do. If you want to get Linear Referencing values or manipulate them directly in a feature class that already has linear referencing defined, that's pretty straight forward.
IFeatureClass fc = ....;
IFeature feature = fc.GetFeature(...);
IMSegmentation3 seg = (IMSegmentation3)feature;
... blah ...
If you need to create a Feature class with linear referencing, you should start witht he "Geoprocessing" tools in the ArcToolbox. If the out-of-the-box tools can do most of what you need, this will minimize your coding.
I would strongly recommend trying to figure what you need to do with ArcMap if at all possible... then backing out the ArcObjects.
Linear Referencing API
Linear Referencing Toolbox
Understanding Linear Referencing

Categories

Resources