Creates new nodes in Autodesk Dynamo for Civil 3D for creating points, adding points to a point group, and creating a surface from a point group.
Sample Dynamo script: CoGoPoints.dyn
Sample project: CoGoPoints.dwg
The nodes that are created when you import CoGoPoints.dll are shown in the following illustration.
COGO points are created in the drawing and added to a point group, and a surface is created from the point group.
Dynamo offers two ways to realize a trace mechanism. One is to use the existing method (CommonConstruct) when creating new nodes. The other is to write trace code with a template.
To realize a trace mechanism for new nodes, classes must be derived from Autodesk.AutoCAD.DynamoNodes.ObjectBase or Autodesk.AutoCAD.DynamoNodes.Object. A traced node must have an output of the created class of the node to make the trace valid.
The CommonConstruct function is created in both Autodesk.AutoCAD.DynamoNodes.ObjectBase and Autodesk.AutoCAD.DynamoNodes.Object.
Autodesk.AutoCAD.DynamoNodes.ObjectBase | Autodesk.AutoCAD.DynamoNodes.Object |
---|---|
You can create classes to inherit either Autodesk.AutoCAD.DynamoNodes.ObjectBase or Autodesk.AutoCAD.DynamoNodes.Object. The methods above can be called when you create new nodes according to the inherited relationship. For example, notice the following node PointGroup.CreateFromPoints.
The node creates a point group in Civil 3D from a list of points.
Autodesk.Civil.DatabaseServices.PointGroup defines a point group in Civil 3D derived from Autodesk.AutoCAD.DatabaseServices.Object. A new class called PointGroup derived from Autodesk.AutoCAD.DynamoNodes.Objectbase needs to be created to encapsulate the Civil 3D point group type. The attribute DynamoServices.RegisterForTrace can be added to the class PointGroup to realize a trace mechanism. This is not required because Dynamo supports this by default, but it is a good coding convention.
The CreateFromPoints node can now be defined in PointGroup. Because of the inherent relationship, CommonConstruct in Autodesk.AutoCAD.DynamoNodes.ObjectBase can be called.
The TNode method is the type of the node and required to inherit Autodesk.AutoCAD.DynamoNodes.ObjectBase.
TNode = CogoPoints.PointGroupTObject is the type of the AutoCAD object required to inherit Autodesk.AutoCAD.DatabaseServices.DBObject.
TObject = Autodesk.Civil.DatabaseServices.PointGroupThe objectCreator function creates an object. In this example it is defined as the creation of a new point group.
The objectUpdater function updates an object. In this example it is defined as the update of an existing point group.
The CommonConstruct function tries to find existing objects from the traced handle. When found, it updates with the call objectUpdater with isExisting==true. If updating fails, objectCreator calls to create a new object and then the objectUpdater calls isExisting==false.
The CommonConstruct function tries to update existing objects in the database with the same traced handle value. If that fails, it will create a new object. If your object does not support updates you can return isExisting==false. This means you will creating a new object and delete the old object. CommonConstruct will still try to maintain the same handle value in this case.
The complete sample codes are displayed in PointGroup.cs and the CommonConstruct method in Autodesk.AutoCAD.DynamoNodes.Object is as described above.
You can write trace code with the following template. However, the class for new nodes still needs to inherit Autodesk.AutoCAD.DynamoNodes.Object or Autodesk.AutoCAD.DynamoNodes.Entity.
You can fill in both the create and the update code to realize the trace code in the above template.
DocumentContext ensures that the document lock is obtained for read/write access of the database and when making a transaction to open database objects. Any node that wants to read or write database objects, needs to use the above method.