Restore Exploded Cogo Points with Civil 3D Dynamo
Some questions trigger to take a deep dive into the subject. For example, a recent question from someone who had received a drawing from a third party. The drawing initially contained Cogo Points, but somehow these were exploded into basic objects like a symbol and a text, which was supposed to represent an Existing Ground elevation. The objects themselves no longer had an elevation property. The question is: how (apart from requesting the original drawing) can you restore the symbols and elevation texts back into Cogo Points? Or, because the original objects are gone and unrecoverable, how to create new Cogo Points with the original location properties?
BIM/CIM, intelligence, company confidentiality
The fact that objects were exploded in a drawing does not always have to be intentional, but sometimes it is. In the past, I experienced that certain companies exploded everything because they did not want the next party to be able to use intelligent objects they had spent a lot of time on 'for free'. For example, useful dynamic blocks or a Corridor model with complex Assemblies, you wouldn't want someone else to take advantage of that, would you?
In the construction world, sharing a BIM model is already more common, in the civil world- not so yet. A BIM model in Civil 3D, which is also called a CIM, is often the result of much effort and often based on own Assemblies, Styles, Templates and knowledge. Sometimes the creation of a CIM is done for one's own convenience, for example for calculating volumes or creating stake-out drawings, and not on behalf of the client for, e.g. class detection. Then it feels a bit awkward to start giving away such a model for free.
A CIM model contains intelligence, and that is often considered the blacksmith's secret, a kind of trade secret that must be protected. By exploding the model, you ensure that someone else has to put in as much effort as you did yourself, which feels more fair. But you better make sure you do the making of such a model on commission and get paid for it. Then the model belongs to the client, and they can decide where it goes. That way everyone benefits from it.
But it may also be that the person who sent you such a drawing only got it that way too. Or it was delivered out of ignorance by a draftsman who himself always works with AutoCAD and doesn't know about the Civil 3D objects in the drawing. Perhaps assuming he is doing a good deed by breaking up that silly Proxy object into recognizable objects for you. Anyway, you're stuck with it. How do you get those objects back as Cogo Points? Well, with Dynamo of course!
Collecting data with Dynamo
You first start by analyzing the objects you do have. Do you have a symbol with a single text close to it? Or did the symbol also explode into single lines? Is the text an MText or a Text object?
Fortunately, there is plenty of variation in the objects. In this case, the symbols are Blocks and quite easy to filter with Dynamo. They are on a separate Layer, so you can filter by Layer, but also by object type. If they were separate entities, then you could still filter by the Circle objects. The Text objects are also on separate Layers, but otherwise you could filter by the object's color, and even whether a text contains a point, to filter the texts by that characteristic.
With Dynamo, you easily filter texts and symbols. In this example, the texts are on the 'Elevations' Layer and the symbols are on the 'Symbols' Layer.
It is possible to use the out-of-the box nodes, but for your convenience it is advised to add the packages 'Civil3DToolkit', 'Camber', and 'Arkance Systems Node Library', adding thousands of new helpful nodes to your Civil 3D Dynamo environment.
As shown in the drawing above, some texts have been moved for readability reasons. The texts were not at the insertion point of the symbol anyway. If you want to place Cogo Points at the insertion point of the symbol, you will need only the symbols, but since there is no elevation attached to the Block, you will have to find the nearest text object and extract the elevation from the text value. Now it is useful to determine the insertion point of both symbols and texts and then calculate the shortest distance, to find a list of symbols and associated texts.
To get the text positions, you need a node from the Arkance Systems Node Library. The symbol positions are extracted from the Coordinate System property. Then you can compare each text position to the entire set of symbol positions.
You can duplicate as many lists from the symbols as there are texts, to compare each text to the full list of symbols. I haven't tested it, but after working this out, it occurred to me that you could also do a direct comparison with a Cross Product Lacing. Then, you wouldn't have to duplicate the symbol list. But as is often the case, with Dynamo you can easily go in three or four different directions to achieve the same result.
The result in this case is lists of distances, as many lists as there are texts. Each list of distances belongs to one text. From that list of distances, you have to filter out the shortest distance. But since in the end you don't need the distance, but the symbol associated with that distance, you first find the shortest distance, then the index where it is in the list, and with that index you finally look up the symbol.
You now have the location of the nearest symbol to each text. You don't have a guarantee that this was actually supposed to be the case, because the texts sometimes shifted, and in such a way that they might have moved closer to another symbol. You will have to build in some checks. For example, draw a construction line in AutoCAD between text and found symbol.
Often it seems correct, but in some cases it isn’t.
Another option is to change the color of the used symbols, leaving some symbols that are not colored. If there are not too many, you can still manually move the texts near the symbols, so they are closer, or afterwards adjust the generated Cogo Points that did not go well. Because you are looking for the nearest symbol to each text, the position of the generated Cogo Points might be incorrect, but the elevation will be correct. At least it is visually to be checked and the Cogo Points are easily moved to the correct symbol's position. If you were looking for the nearest text to each symbol, the position of the generated Cogo Points would be correct, but the elevation might not, which is not easily checked and fixed.
If there are many anomalies, you may have to find another approach.
Finally, with the numerical value of the elevation and the X and Y of the symbol, you have a location to place new Cogo Points on. Now your drawing contains the missing Cogo Points, with the correct elevation. Of course, first you do check that visually, or in another way, right?