Storing data in a drawing AutoCad C# - c#

In one dwg file I will have several drawings. Each as a separate whole. I want to make an overlay to describe the bars and draw them from the drawing. The numbering is done automatically. The most important thing is that every drawing starts from scratch, from position 1 (everything within the same file).
How to store all bar data?
The values ​​must be kept constant. When you open the file again, you must have access to continue the drawing.
I know there is XData but I do not know how to apply it in this situation. Assigning variables to an object somehow does not seem to me here. Are there no more storage options in the latest versions such as in a dictionary or a list?
Can you create an external database and store all the information you need? If so, in what way?
Stored data are not just single values ​​for whole collections. One bar will contain different information such as number, length, diameter and bars in the drawing can be very much.
Additional question:
A bar consists of a description, a dimension, and a line or polyline. Would it be better to place this set in a new class with MText MLeader and Polyline objects or as a block with elements and attributes?
Everything that can be found here in the forums or blogs is a few years old and I hope that we already have some interesting methods for the given problem. Thank you in advance for your help.

Where you store the data depends on who needs to have access to it. Users don't have direct access to Xdata or ExtensionDictionary. You could use blocks with attributes to store the data since you know what the properties are. Attributes are user-accessible and are basically a key-value store for each block. MLeaders is another way but it isn't much of a data model. It really depends on who uses the data and how.
Everything that can be found here in the forums or blogs is a few years old
That doesn't matter, AutoCAD hasn't changed a whole lot over the years, the only obsolete information is where new features have changed things or the pre-2013 API where things were in different places, there isn't much that's different from 10 years ago.
See the AutoCAD Tag wiki for more dev resources.

Related

What's the fastest way to validate if a GeoJson Polygon contains a certain section, using .net

I have a Polygon (a sequence of 2D-points) loaded (I can parse from GPX, Google polyline and GeoJson) in my C# program. And I have around 1000 of 'segments' that also are GeoJson Linestrings.
Some of these segments are 'far away' off the track, while others could perfectly intersect with the track. My question is what the fastest way (ideally using an existing in memory library) would be to detect which segments are part of the overall track. (The points obviously don't have to match 100%, but can be a few meters off the track)
Consider the situation where I have a recorded GPS-track (of a car for example) and I want to check against a library of streets if that track has been driving through those streets. (ideally in the specified direction, if possible)
So, my main questions:
Is there an out of the box open source library available that has implemented this?
If not, I'm happy to contribute it, but then I'm looking for a good description of such an algorithm.
Further clarification
I have indeed found several options to work out if a point is inside , or on a polygon. (see here).
But the main challenge is to find out if someone has done this before in .net and to understand if there are out of the box possibilities for this.
Any help is appreciated.

Coloring areas of map in unity 2D

I am new to unity, but I know C# very well.
I am working on a game similar to eu4.
When area is conquered, it should change color.
I have no idea how to do it, or what to search in the internet for a solution.
Here is the map:
(The borders separate the areas)
Any help please?
It's very simple, you just have sprites for each "country".
(So, in the dark color.)
Simply turn them on or off as you wish. That's all there is to it.
Another approach is you could learn how to make and use a typical "flood fill algorithm". But that is far beyond the scope of this question and is a general computer science issue. (You might look on, say, gamedev for starter tips on this. Additionally you'll have to become expert at generating textures dynamically in Unity.)
Check EU4 and CK2 map files. It might give you many ideas how to handle grand strategy maps.
You got some work to do to achieve this. But basically, there is a .bmp file in game files which every province is painted with a unique color. Here is an example of small portion which consist Italy:
Once you've done that, you will need some sort of data file (.csv in eu4's case) that includes which color includes which province, which provinces are neighboring, etc... In EU4, color info and adjadency info are in seperate files, but of course you're free to approach however you want.
Once you are done with "Data" part, you will need an algorithm that scans these files and distinguish each province in seperate game objects. Mainly, you must write a method that removes every color in an image except a certain one, instantiate it to the map and repeat process for each province. And you're done.
Edit: You can, of course, do these manually. But automated process is always better especially when you a lot of povinces to sepearate. Also making tweaks in map will be much easier that way, or you'll have a hard time recreating every single sprite for even small changes.
Another advantage is, you can easily add different mapmodes like heightmap, rivermap or such...
As your question doesn't give much in terms of your structure it's hard to give you examples.
The most straightforward for you probably is to separate your map into nodes (your bordered areas) and display them all as unique gameObjects. You can then access things like their Renderer to give them different colour.
We can give much better answers if you give us more information on how your data/graphics are structured.

Identify if an image contains any image (object) from a database

Despite Googling around a fair amount, the only things that surfaced were on neural networks and using existing APIs to find tags about an image, and on webcam tracking.
What I would like to do is create my own data set for some objects (a database containing the images of a product (or a fingerprint of each image), and manufacturer information about the product), and then use some combination of machine learning and object detection to find if a given image contains any product from the data I've collected.
For example, I would like to take a picture of a chair and compare that to some data to find which chair is most likely in the picture from the chairs in my database.
What would be an approach to tackling this problem? I have already considered using OpenCV, and feel that this is a starting point and probably how I'll detect the object, but I've not found how to use this to solve my problem.
I think in the end it doesn't matter what tool you use to tackle your problem. You will probably need some kind of machine learning. It's hard to say which method would result in the best detection, for this I'd recommend to use a tool like weka. It's a collection of multiple machine learning algorithms and lets you easily try out what works best for you.
Before you can start trying out the machine learning you will first need to extract some features out of your dataset. Since you can hardly compare the images pixel by pixel which would result in huge computational effort and does not even necessarily provide the needed results. Try to extract features which make your images unique, like average colour or brightness, maybe try to extract some shapes or sizes out of the image. So in the end you will feed your algorithm just with the features you extracted out of your images and not the images itself.
Which are good features is hard to define, it depends on your special case. Generally it helps to have not just one but multiple features covering completely different aspects of the image. To extract the features you could use openCV, or any other image processing tool you like. Get the features of all images in your dataset and get started with the machine learning.
From what I understood, you want to build a Content Based Image Retrieval system.
There are plenty of methods to do this. What defines the best method to solve your problem has to do with:
the type of objects you want to recognize,
the type of images that will be introduced to search the objects,
the priorities of your system (efficiency, robustness, etc.).
You gave the example of recognizing chairs. In your system which would be the determining factor for selecting the most similar chair? The color of the chair? The shape of the chair? These are typical question that you have to answer before choosing the method.
Either way one of the most used methods to solve such problems is the Bag-of-Words model (also Referred the Bag of Features). I wish I could help more but for that I need that you explain it better which are the final goals of your work / project.

What is the best way to store area data for a text adventure?

I'm developing a "Zork" style text adventure in C#, and it's going to have a fairly large number of different areas with descriptions and environmental modifiers. I don't want to have a database, ideally, unless it really is the best way of doing it.
I need advice on the best way to store/load this data.
It will include:
Area description
Environmental modifiers (windows open/broken, door closed)
Items present by default
I would solve your problem by abandoning C# and writing your program in Inform7. Inform7 is just about the most awesome programming language I have ever seen and it is specifically designed to solve your problem.
The awesome thing about Inform7 is that you write your text adventure in a language that resembles text adventures. For example, here's a fragment of one of the sample adventures' source code:
The iron-barred gate is a door.
"An iron-barred gate leads [gate direction]."
It is north of the Drawbridge and south of the Entrance Hall.
It is closed and openable.
Before entering the castle, try entering the gate instead.
Before going inside in the Drawbridge, try going north instead.
Understand "door" as the gate.
This adds an object to the game - the object is a door, it is called "the iron-barred gate". A door is understood to be between two rooms, in this case, the drawbridge and the entrance hall. If the player tries to "enter the drawbridge" then the game logic will know that this is the same as "go north", and then the door logic will determine whether the door is closed or not. And so on. It makes writing text adventures extremely easy.
Is there some particular reason why you want to use C# instead of a domain-specific language like Inform7? If your goal is to learn how to write C# code or how to build a parser or whatever, then by all means do it yourself. If your goal is to write a text adventure, then I'd use a language designed for that.
Serialize all the data to file. It will ensure the smallest footprint when the user installs the game, without any real disadvantage. A database is great when you have a lot of data, but you are talking about a text adventure in which you will load the entire game contents into memory. A simple file will work for this very nicely.
Note, I'm not talking about xml but binary serialization. Any kind of text serialization will allow users to peek at your data, and either cheat or hack up the game. And you can just as easily swap in/out the serialized data file whether it's text or binary. Remember, your whole 'text' is likely to be just a few hundred kilobytes at most.
There are many interactive fiction engines already. I would take a look at their data formats, that way you can re-use existing content and tools for editing the content.
The most popular engines currently are Glulx http://eblong.com/zarf/glulx/ and Z-Machine http://en.wikipedia.org/wiki/Z-machine
Here is a technical reference for the Glulx format: http://eblong.com/zarf/glulx/technical.txt
I know you didn't want a DB, but have you looked at SQL Server Compact Edition? It might just do what you want.
I'd argue C# offers you precisely the right tools for this. Just encapsulate your structures into classes. Our first OOP project at university was exactly this problem! It is the perfect case study for OOP.
You can then use C#'s many serialization methods to store it persistently (load/save) however you see fit.
How would 'scripting' your adventure as one large text file sound? Then have your application parse this file, build the adventure in classes and run from there?
This would mean you could edit the adventure using a simple text editor. I would imagine that when multiple decisions can be made from a single source it may become tricky visualising the links. However this would also be tricky in a DB without some specialist front-end.
UPDATE:
Or have you considered XML eg...
<area id="DarkRoom1">
<description>Dark Room</description>
<item>Bucket</item>
<item>Spade</item>
</area>
Then use this to populate your classes in memory.
You could store the data in a file system (a zip file or a folder).
Each choice could be stored as a folder, while all descriptions, modifiers and other data could be stored as a text file (xml?). When user makes a decision you go to the appropriate folder and follow the plot.
Example:
Do you want to:
open the door (door)
leave (leave)
If user choses to open the door you go the folder door and reads data from data file in this folder.
Pros:
simple
do not require database
easy to add new adventures
Cons:
problem with rollback decision (getting back to start or to certain point in plot)
Personally, I'd avoid a database in this case, and go with a text-based file format (probably two distinct files, one for the initial state (like terrain and such), which never gets modified, and one for state that is to be modified during the course of the game (the broken windows etc.); or split the entire thing up into one pair of static/dynamic data per area.
A few reasons:
A text file is human-readable; hence, you can create content without a dedicated editor, while with a database approach, you'd either have to enter data through queries, or code a level editor
Assuming a single-player scenario, concurrency is not an issue
Savegames are a matter of copying the modified-state files into a savegame folder, or packing them into a single file
You can easily embed scripts
The data structures you're dealing with are probably simple enough for data integrity not to be a serious issue

how do you create a social graph?

this is a totally unfamiliar area for me. can anyone point me in the right direction on how to create a social graph and the best way to represent it? i'm building a website in C#/asp net and need to create a "friends" feature... is this type of thing usually stored entirely in the DB? if so, how?
Is your primary concern painting a picture of the social network or storing the data?
For storage you might consider a graph database. However, the most mature product in this space is neo4j, which has the name suggests is written in Java. This SO discussion list some alternative approaches for .Net.
edit
You are still not being clear whether you need design advice or code samples. Andrew Siemer wrote a two-part article which outlines the issues and then presents some ASP.net code. I don't think it's by any means a complete solution but it could give you a steer in the right direction.
Your question is rather open-ended. For drawing complex graphs, one of my favorite tools is Graphviz. Graphviz can work with directed or non-directed graphs. It can take the input as a simple text file, and then output the graph in a variety of formats.
So your problem is primarily a data storage issue, and how to store and retrieve edges in your graph. Applying some simple graph terms to your problem:
Node/Vertex: In your case each person will represent a node.
Edge/Link: The relationship between nodes, in this case 'friends', will create an undirected edge between two nodes.
So you will need to maintain a data structure in your DB that allows you to resolve the edge relationships between friends.
Some useful information can probably be found in this question:
challenge-how-to-implement-an-algorithm-for-six-degree-of-separation
Also, something you should consider when deciding how to store your edge list is how many edges you think your site will generate. This will probably effect the storage mechanism you decide on.
Hope those pointers help.

Categories