#Region "Associative Network - Parametrics" #Region "Geometric Constraints" Public Sub SetCoincidentConstraint(ByVal curve1 As Curve, ByVal curve2 As Curve, ByVal curveEnd1 As CurvePoint, ByVal curveEnd2 As CurvePoint, ByVal trans As Transaction) Using trans2 As Transaction = trans.TransactionManager.StartTransaction 'work with sub transactions in order to allow 1 undo that undoes it all. Dim SubEntEdgePath1 As FullSubentityPath 'logical path to the edge (one edge object pretty simple) Dim SubEntEdgePath2 As FullSubentityPath Dim subEntPointPath1 As FullSubentityPath 'logical path to the user selected point (usually start, end, or mid) Dim subEntPointPath2 As FullSubentityPath 'create a logical path from the object to its sub entities CreateSubEntityPath(curve1, curveEnd1, SubEntEdgePath1, subEntPointPath1, trans2) CreateSubEntityPath(curve2, curveEnd2, SubEntEdgePath2, subEntPointPath2, trans2) 'get the constraint group that exists on the same plane as our points (in this case just wcs + elevation, but if you get more advanced, this may need to be modified big time) Dim consGrpId As ObjectId = GetConstraintGroup(True, trans2) 'use the logical paths to create a constraint between 2 selected points(CurvePoint) of the 2 supplied edges(curves) Dim consGeomEdge1 As ConstrainedGeometry = Nothing Dim consGeomEdge2 As ConstrainedGeometry = Nothing Using constGrp As Assoc2dConstraintGroup = DirectCast(trans2.GetObject(consGrpId, OpenMode.ForWrite, False), Assoc2dConstraintGroup) Try consGeomEdge1 = AddConstrainedGeometry(constGrp, SubEntEdgePath1) Catch ex As Exception 'aready there move on End Try Try consGeomEdge2 = AddConstrainedGeometry(constGrp, SubEntEdgePath2) Catch ex As Exception 'aready there move on End Try Dim paths As FullSubentityPath() = New FullSubentityPath(1) {subEntPointPath1, subEntPointPath2} Dim newConstraint As GeometricalConstraint = constGrp.AddGeometricalConstraint(GeometricalConstraint.ConstraintType.Coincident, paths) End Using trans2.Commit() End Using End Sub Public Sub SetFixedConstraint(ByVal curve As Curve, ByVal curvePnt As CurvePoint, ByRef trans As Transaction) Using trans2 As Transaction = trans.TransactionManager.StartTransaction Dim SubEntEdgePath As FullSubentityPath 'logical path to the edge (one edge object pretty simple) Dim subEntPointPath As FullSubentityPath 'logical path to the user selected point (usually start, end, or mid) CreateSubEntityPath(curve, curvePnt, SubEntEdgePath, subEntPointPath, trans2) 'get the constraint group that exists on the same plane as our points (in this case just wcs + elevation, but if you get more advanced, this may need to be modified big time) Dim consGrpId As ObjectId = GetConstraintGroup(True, trans2) Using constGrp As Assoc2dConstraintGroup = DirectCast(trans2.GetObject(consGrpId, OpenMode.ForWrite, False), Assoc2dConstraintGroup) 'Pass in geometry to constrain (the line edge) Try Dim consGeom As ConstrainedGeometry = AddConstrainedGeometry(constGrp, SubEntEdgePath) Catch ex As Exception 'aready there move on End Try 'Now create the constraint, a Fixed constraint applied to the line's startpoint. Dim paths As FullSubentityPath() = New FullSubentityPath(0) {subEntPointPath} Dim newConstraint As GeometricalConstraint = constGrp.AddGeometricalConstraint(GeometricalConstraint.ConstraintType.Fix, paths) End Using trans2.Commit() End Using End Sub Public Sub SetHorizontalAlignConstraint(ByVal curve As Curve, ByVal trans As Transaction) Using trans2 As Transaction = trans.TransactionManager.StartTransaction() Dim subEntPathEdge As FullSubentityPath Dim subEntPath1 As FullSubentityPath Dim subEntPath2 As FullSubentityPath 'To query the subentities of the line, we create and use a protocol extension (PE) provided by the associativity API Dim subentityIdPE As AssocPersSubentityIdPE = GetProtocalExtension(curve) 'Now we have the PE, we query the subentities Dim edgeSubentityIds As SubentityId() = Nothing 'First we retrieve a list of all edges (a line has one edge) edgeSubentityIds = subentityIdPE.GetAllSubentities(curve, SubentityType.Edge) Dim startSID As SubentityId = SubentityId.Null, endSID As SubentityId = SubentityId.Null Dim other As SubentityId() = Nothing 'Now we retrieve the vertices associated with that edge. subentityIdPE.GetEdgeVertexSubentities(curve, edgeSubentityIds(0), startSID, endSID, other) 'The PE returns a SubEntId. We want a Full SubentityPath subEntPathEdge = New FullSubentityPath(New ObjectId(0) {curve.ObjectId}, edgeSubentityIds(0)) subEntPath1 = New FullSubentityPath(New ObjectId(0) {curve.ObjectId}, startSID) subEntPath2 = New FullSubentityPath(New ObjectId(0) {curve.ObjectId}, endSID) Dim consGrpId As ObjectId = GetConstraintGroup(True, trans2) Dim consGeom As ConstrainedGeometry = Nothing Using constGrp As Assoc2dConstraintGroup = DirectCast(trans2.GetObject(consGrpId, OpenMode.ForWrite, False), Assoc2dConstraintGroup) 'Pass in geometry to constrain (the line edge) Try consGeom = AddConstrainedGeometry(constGrp, subEntPathEdge) Catch ex As Exception 'aready there move on End Try 'Now create the constraint (using the start and end vertices of the line) Dim paths As FullSubentityPath() = New FullSubentityPath(1) {subEntPath1, subEntPath2} Dim newConstraint As GeometricalConstraint = constGrp.AddGeometricalConstraint(GeometricalConstraint.ConstraintType.Horizontal, paths) End Using trans2.Commit() End Using End Sub Public Sub SetHorizontalConstraint(ByVal curve As Curve, ByVal trans As Transaction) Using trans2 As Transaction = trans.TransactionManager.StartTransaction() Dim SubEntEdgePath As FullSubentityPath 'logical path to the edge (one edge object pretty simple) CreateSubEntityPath(curve, SubEntEdgePath, trans2) 'Our constrained geometry will be the edge of the line Dim consGrpId As ObjectId = GetConstraintGroup(True, trans2) Dim consGeom As ConstrainedGeometry = Nothing Using constGrp As Assoc2dConstraintGroup = DirectCast(trans2.GetObject(consGrpId, OpenMode.ForWrite, False), Assoc2dConstraintGroup) 'Add the constrained geometry to which the geometrical constraint will be applied Try consGeom = AddConstrainedGeometry(constGrp, SubEntEdgePath) Catch ex As Exception 'aready there move on End Try Dim paths As FullSubentityPath() = New FullSubentityPath(0) {SubEntEdgePath} 'Now add the geometrical constraint Dim newConstraint As GeometricalConstraint = Nothing newConstraint = constGrp.AddGeometricalConstraint(GeometricalConstraint.ConstraintType.Horizontal, paths) Dim constraintArray As New List(Of GeometricalConstraint)() constraintArray.Add(newConstraint) End Using trans2.Commit() End Using End Sub Public Sub SetRadialConstraint(ByVal Roundedcurve As Curve, ByVal varID As ObjectId, ByVal trans As Transaction) Dim db As Database = Roundedcurve.Database Using trans2 As Transaction = trans.TransactionManager.StartTransaction() Dim SubEntEdgePath As FullSubentityPath 'logical path to the edge (one edge object pretty simple) CreateSubEntityPath(Roundedcurve, SubEntEdgePath, trans2) 'Our constrained geometry will be the edge of the line Dim consGrpId As ObjectId = GetConstraintGroup(True, trans2) Dim consGeom As ConstrainedGeometry = Nothing Using constGrp As Assoc2dConstraintGroup = DirectCast(trans2.GetObject(consGrpId, OpenMode.ForWrite, False), Assoc2dConstraintGroup) 'Add the constrained geometry to which the geometrical constraint will be applied Try consGeom = AddConstrainedGeometry(constGrp, SubEntEdgePath) Catch ex As Exception 'aready there move on End Try Dim paths As FullSubentityPath() = New FullSubentityPath(0) {SubEntEdgePath} 'Now add the geometrical constraint Dim newConstraint As GeometricalConstraint = Nothing Dim valDepId As ObjectId Using valDep As New AssocValueDependency() valDepId = db.AddDBObject(valDep) Dim compoundId As New CompoundObjectId(varID, db) valDep.AttachToObject(compoundId) End Using newConstraint = constGrp.AddRadiusDiameterConstraint(consGeom, RadiusDiameterConstraint.RadDiaConstrType.CircleRadius, valDepId, Nothing) Dim constraintArray As New List(Of GeometricalConstraint)() constraintArray.Add(newConstraint) End Using trans2.Commit() End Using End Sub Public Sub SetHorizontalPoints(ByVal point1 As DBPoint, ByVal point2 As DBPoint, ByVal trans As Transaction) Using trans2 As Transaction = trans.TransactionManager.StartTransaction() 'Our constrained geometry will be the vertex of each POINT Dim subentPath1 As FullSubentityPath = CreateSubEntityPath(point1, SubentityType.Vertex) Dim subentPath2 As FullSubentityPath = CreateSubEntityPath(point2, SubentityType.Vertex) Dim consGrpId As ObjectId = GetConstraintGroup(True, trans2) Dim consGeom As ConstrainedGeometry = Nothing Using constGrp As Assoc2dConstraintGroup = DirectCast(trans2.GetObject(consGrpId, OpenMode.ForWrite, False), Assoc2dConstraintGroup) 'Add the geometrical constraint to be applied to the constrained geometry Try consGeom = AddConstrainedGeometry(constGrp, subentPath1) Catch ex As Exception 'aready there move on End Try Try consGeom = AddConstrainedGeometry(constGrp, subentPath2) Catch ex As Exception 'aready there move on End Try Dim paths As FullSubentityPath() = New FullSubentityPath(1) {subentPath1, subentPath2} 'Now add geometrical constraints Dim newConstraint As GeometricalConstraint = constGrp.AddGeometricalConstraint(GeometricalConstraint.ConstraintType.Horizontal, paths) End Using trans2.Commit() End Using End Sub Public Sub SetVertical(ByVal curve As Curve, ByVal trans As Transaction) Using trans2 As Transaction = trans.TransactionManager.StartTransaction() ' We've put the protocol extension code into a helper function Dim subEntPath As FullSubentityPath = CreateSubEntityPath(curve, SubentityType.Edge) Dim consGrpId As ObjectId = GetConstraintGroup(True, trans2) Dim consGeom As ConstrainedGeometry = Nothing Using constGrp As Assoc2dConstraintGroup = DirectCast(trans2.GetObject(consGrpId, OpenMode.ForWrite, False), Assoc2dConstraintGroup) Try consGeom = AddConstrainedGeometry(constGrp, subEntPath) Catch ex As Exception 'aready there move on End Try Dim paths As FullSubentityPath() = New FullSubentityPath(0) {subEntPath} Dim newConstraint As GeometricalConstraint = constGrp.AddGeometricalConstraint(GeometricalConstraint.ConstraintType.Vertical, paths) End Using trans2.Commit() End Using End Sub Public Sub SetVerticalAlign(ByVal curve As Curve, ByVal trans As Transaction) Using trans2 As Transaction = trans.TransactionManager.StartTransaction() Dim subEntEdgePath As FullSubentityPath Dim subentPath1 As FullSubentityPath Dim subentPath2 As FullSubentityPath Dim subentityIdPE As AssocPersSubentityIdPE = GetProtocalExtension(curve) Dim edgeSubentityIds As SubentityId() = Nothing edgeSubentityIds = subentityIdPE.GetAllSubentities(curve, SubentityType.Edge) Dim startSID As SubentityId = SubentityId.Null, endSID As SubentityId = SubentityId.Null Dim other As SubentityId() = Nothing subentityIdPE.GetEdgeVertexSubentities(curve, edgeSubentityIds(0), startSID, endSID, other) subEntEdgePath = New FullSubentityPath(New ObjectId(0) {curve.ObjectId}, edgeSubentityIds(0)) subentPath1 = New FullSubentityPath(New ObjectId(0) {curve.ObjectId}, startSID) subentPath2 = New FullSubentityPath(New ObjectId(0) {curve.ObjectId}, endSID) Dim consGrpId As ObjectId = GetConstraintGroup(True, trans2) Dim consGeom As ConstrainedGeometry = Nothing Using constGrp As Assoc2dConstraintGroup = DirectCast(trans2.GetObject(consGrpId, OpenMode.ForWrite, False), Assoc2dConstraintGroup) Try consGeom = AddConstrainedGeometry(constGrp, subEntEdgePath) Catch ex As Exception 'aready there move on End Try Dim paths As FullSubentityPath() = New FullSubentityPath(1) {subentPath1, subentPath2} Dim newConstraint As GeometricalConstraint = constGrp.AddGeometricalConstraint(GeometricalConstraint.ConstraintType.Vertical, paths) End Using trans2.Commit() End Using End Sub Public Sub SetColinear(ByVal curve1 As Curve, ByVal curve2 As Curve, ByVal trans As Transaction) Using trans2 As Transaction = trans.TransactionManager.StartTransaction Dim SubEntEdgePath1 As FullSubentityPath 'logical path to the edge (one edge object pretty simple) Dim SubEntEdgePath2 As FullSubentityPath 'create a logical path from the object to its sub entities CreateSubEntityPath(curve1, SubEntEdgePath1, trans2) CreateSubEntityPath(curve2, SubEntEdgePath2, trans2) Dim consGrpId As ObjectId = GetConstraintGroup(True, trans2) Dim consGeom1 As ConstrainedGeometry = Nothing Dim consGeom2 As ConstrainedGeometry = Nothing Using constGrp As Assoc2dConstraintGroup = DirectCast(trans2.GetObject(consGrpId, OpenMode.ForWrite, False), Assoc2dConstraintGroup) Try consGeom1 = AddConstrainedGeometry(constGrp, SubEntEdgePath1) Catch ex As Exception 'aready there move on End Try Try consGeom2 = AddConstrainedGeometry(constGrp, SubEntEdgePath2) Catch ex As Exception 'aready there move on End Try Dim paths As FullSubentityPath() = New FullSubentityPath(1) {SubEntEdgePath1, SubEntEdgePath2} Dim newConstraint As GeometricalConstraint = constGrp.AddGeometricalConstraint(GeometricalConstraint.ConstraintType.Collinear, paths) End Using trans2.Commit() End Using End Sub Public Sub SetEqualLength(ByVal curve1 As Curve, ByVal curve2 As Curve, ByVal trans As Transaction) Using trans2 As Transaction = trans.TransactionManager.StartTransaction() Dim SubEntEdgePath1 As FullSubentityPath 'logical path to the edge (one edge object pretty simple) Dim SubEntEdgePath2 As FullSubentityPath 'create a logical path from the object to its sub entities CreateSubEntityPath(curve1, SubEntEdgePath1, trans2) CreateSubEntityPath(curve2, SubEntEdgePath2, trans2) Dim consGrpId As ObjectId = GetConstraintGroup(True, trans2) Dim consGeom1 As ConstrainedGeometry = Nothing Dim consGeom2 As ConstrainedGeometry = Nothing Using constGrp As Assoc2dConstraintGroup = DirectCast(trans2.GetObject(consGrpId, OpenMode.ForWrite, False), Assoc2dConstraintGroup) consGeom1 = AddConstrainedGeometry(constGrp, SubEntEdgePath1) consGeom2 = AddConstrainedGeometry(constGrp, SubEntEdgePath2) Dim paths As FullSubentityPath() = New FullSubentityPath(1) {SubEntEdgePath1, SubEntEdgePath2} Dim newConstraint As GeometricalConstraint = constGrp.AddGeometricalConstraint(GeometricalConstraint.ConstraintType.EqualLength, paths) End Using trans2.Commit() End Using End Sub Public Sub SetConcentric(ByVal curve1 As Curve, ByVal curve2 As Curve, ByVal trans As Transaction) Using trans2 As Transaction = trans.TransactionManager.StartTransaction() Dim SubEntEdgePath1 As FullSubentityPath 'logical path to the edge (one edge object pretty simple) Dim SubEntEdgePath2 As FullSubentityPath 'create a logical path from the object to its sub entities CreateSubEntityPath(curve1, SubEntEdgePath1, trans2) CreateSubEntityPath(curve2, SubEntEdgePath2, trans2) Dim consGrpId As ObjectId = GetConstraintGroup(True, trans2) Dim consGeom1 As ConstrainedGeometry = Nothing Dim consGeom2 As ConstrainedGeometry = Nothing Using constGrp As Assoc2dConstraintGroup = DirectCast(trans2.GetObject(consGrpId, OpenMode.ForWrite, False), Assoc2dConstraintGroup) Try consGeom1 = AddConstrainedGeometry(constGrp, SubEntEdgePath1) Catch ex As Exception 'aready there move on End Try Try consGeom2 = AddConstrainedGeometry(constGrp, SubEntEdgePath2) Catch ex As Exception 'aready there move on End Try Dim paths As FullSubentityPath() = New FullSubentityPath(1) {SubEntEdgePath1, SubEntEdgePath2} Dim newConstraint As GeometricalConstraint = constGrp.AddGeometricalConstraint(GeometricalConstraint.ConstraintType.Concentric, paths) End Using trans2.Commit() End Using End Sub Public Sub SetEqualRadius(ByVal curve1 As Circle, ByVal curve2 As Circle, ByVal trans As Transaction) Using trans2 As Transaction = trans.TransactionManager.StartTransaction() Dim SubEntEdgePath1 As FullSubentityPath 'logical path to the edge (one edge object pretty simple) Dim SubEntEdgePath2 As FullSubentityPath 'create a logical path from the object to its sub entities CreateSubEntityPath(curve1, SubEntEdgePath1, trans2) CreateSubEntityPath(curve2, SubEntEdgePath2, trans2) Dim consGrpId As ObjectId = GetConstraintGroup(True, trans2) Dim consGeom1 As ConstrainedGeometry = Nothing Dim consGeom2 As ConstrainedGeometry = Nothing Using constGrp As Assoc2dConstraintGroup = DirectCast(trans2.GetObject(consGrpId, OpenMode.ForWrite, False), Assoc2dConstraintGroup) Try consGeom1 = AddConstrainedGeometry(constGrp, SubEntEdgePath1) Catch ex As Exception 'aready there move on End Try Try consGeom2 = AddConstrainedGeometry(constGrp, SubEntEdgePath2) Catch ex As Exception 'aready there move on End Try Dim paths As FullSubentityPath() = New FullSubentityPath(1) {SubEntEdgePath1, SubEntEdgePath2} Dim newConstraint As GeometricalConstraint = constGrp.AddGeometricalConstraint(GeometricalConstraint.ConstraintType.EqualRadius, paths) End Using trans2.Commit() End Using End Sub Public Sub SetParallel(ByVal curve1 As Curve, ByVal curve2 As Curve, ByVal trans As Transaction) Using trans2 As Transaction = trans.TransactionManager.StartTransaction() Dim SubEntEdgePath1 As FullSubentityPath 'logical path to the edge (one edge object pretty simple) Dim SubEntEdgePath2 As FullSubentityPath 'create a logical path from the object to its sub entities CreateSubEntityPath(curve1, SubEntEdgePath1, trans2) CreateSubEntityPath(curve2, SubEntEdgePath2, trans2) Dim consGrpId As ObjectId = GetConstraintGroup(True, trans2) Dim consGeom1 As ConstrainedGeometry = Nothing Dim consGeom2 As ConstrainedGeometry = Nothing Using constGrp As Assoc2dConstraintGroup = DirectCast(trans2.GetObject(consGrpId, OpenMode.ForWrite, False), Assoc2dConstraintGroup) Try consGeom1 = AddConstrainedGeometry(constGrp, SubEntEdgePath1) Catch ex As Exception 'aready there move on End Try Try consGeom2 = AddConstrainedGeometry(constGrp, SubEntEdgePath2) Catch ex As Exception 'aready there move on End Try Dim paths As FullSubentityPath() = New FullSubentityPath(1) {SubEntEdgePath1, SubEntEdgePath2} Dim newConstraint As GeometricalConstraint = constGrp.AddGeometricalConstraint(GeometricalConstraint.ConstraintType.Parallel, paths) End Using trans2.Commit() End Using End Sub Public Sub SetPerpendicular(ByVal curve1 As Curve, ByVal curve2 As Curve, ByVal trans As Transaction) Using trans2 As Transaction = trans.TransactionManager.StartTransaction() Dim SubEntEdgePath1 As FullSubentityPath 'logical path to the edge (one edge object pretty simple) Dim SubEntEdgePath2 As FullSubentityPath 'create a logical path from the object to its sub entities CreateSubEntityPath(curve1, SubEntEdgePath1, trans2) CreateSubEntityPath(curve2, SubEntEdgePath2, trans2) Dim consGrpId As ObjectId = GetConstraintGroup(True, trans2) Dim consGeom1 As ConstrainedGeometry = Nothing Dim consGeom2 As ConstrainedGeometry = Nothing Using constGrp As Assoc2dConstraintGroup = DirectCast(trans2.GetObject(consGrpId, OpenMode.ForWrite, False), Assoc2dConstraintGroup) Try consGeom1 = AddConstrainedGeometry(constGrp, SubEntEdgePath1) Catch ex As Exception 'aready there move on End Try Try consGeom2 = AddConstrainedGeometry(constGrp, SubEntEdgePath2) Catch ex As Exception 'aready there move on End Try Dim paths As FullSubentityPath() = New FullSubentityPath(1) {SubEntEdgePath1, SubEntEdgePath2} Dim newConstraint As GeometricalConstraint = constGrp.AddGeometricalConstraint(GeometricalConstraint.ConstraintType.Perpendicular, paths) End Using trans2.Commit() End Using End Sub Public Sub SetSmooth(ByVal spline1 As Spline, ByVal spline2 As Spline, ByVal trans As Transaction) Using trans2 As Transaction = trans.TransactionManager.StartTransaction() If spline1.HasFitData Then spline1.PurgeFitData() End If If spline2.HasFitData Then spline2.PurgeFitData() End If Dim subEntEdgePath1 As FullSubentityPath Dim subEntEdgePath2 As FullSubentityPath Using entity As Entity = DirectCast(trans2.GetObject(spline1.ObjectId, OpenMode.ForRead, False), Entity) If entity Is Nothing Then System.Windows.MessageBox.Show("cannot get entity1") Return End If Dim subentityIdPE As AssocPersSubentityIdPE = GetProtocalExtension(entity) Dim edgeSubentityIds As SubentityId() = Nothing edgeSubentityIds = subentityIdPE.GetAllSubentities(entity, SubentityType.Edge) Dim startSID As SubentityId = SubentityId.Null, endSID As SubentityId = SubentityId.Null Dim other As SubentityId() = Nothing subentityIdPE.GetEdgeVertexSubentities(entity, edgeSubentityIds(0), startSID, endSID, other) subEntEdgePath1 = New FullSubentityPath(New ObjectId(0) {spline1.ObjectId}, edgeSubentityIds(0)) End Using Using entity As Entity = DirectCast(trans2.GetObject(spline2.ObjectId, OpenMode.ForRead, False), Entity) If entity Is Nothing Then System.Windows.MessageBox.Show("cannot get entity2") Return End If Dim subentityIdPE As AssocPersSubentityIdPE = GetProtocalExtension(entity) Dim edgeSubentityIds As SubentityId() = Nothing edgeSubentityIds = subentityIdPE.GetAllSubentities(entity, SubentityType.Edge) Dim startSID As SubentityId = SubentityId.Null, endSID As SubentityId = SubentityId.Null Dim other As SubentityId() = Nothing subentityIdPE.GetEdgeVertexSubentities(entity, edgeSubentityIds(0), startSID, endSID, other) subEntEdgePath2 = New FullSubentityPath(New ObjectId(0) {spline2.ObjectId}, edgeSubentityIds(0)) End Using Dim consGrpId As ObjectId = GetConstraintGroup(True, trans2) Dim consGeom1 As ConstrainedCurve = Nothing Dim consGeom2 As ConstrainedCurve = Nothing Using constGrp As Assoc2dConstraintGroup = DirectCast(trans2.GetObject(consGrpId, OpenMode.ForWrite, False), Assoc2dConstraintGroup) Dim cg As ConstrainedGeometry = Nothing Try cg = AddConstrainedGeometry(constGrp, subEntEdgePath1) Catch ex As Exception 'aready there move on End Try consGeom1 = DirectCast(cg, ConstrainedCurve) cg = Nothing Try cg = AddConstrainedGeometry(constGrp, subEntEdgePath2) Catch ex As Exception 'aready there move on End Try consGeom2 = DirectCast(cg, ConstrainedCurve) ' Splines are a little different. We have to constrain using 'Implicit Points'. ' Query geometry we just constrained for Constrained Implicit Points. First point is the start point. Dim consPts1 As ConstrainedImplicitPoint() = consGeom1.ConstrainedImplicitPoints Dim consPts2 As ConstrainedImplicitPoint() = consGeom2.ConstrainedImplicitPoints constGrp.AddGeometricalConstraint(GeometricalConstraint.ConstraintType.Smooth, New ConstrainedGeometry() {consPts1(0), consPts2(0)}) End Using trans2.Commit() End Using End Sub Public Sub SetSymmetry(ByVal circle1 As Circle, ByVal circle2 As Circle, ByVal line As Line, ByVal trans As Transaction) Using trans2 As Transaction = trans.TransactionManager.StartTransaction() Dim subEntEdgePath1 As FullSubentityPath Dim subEntEdgePath2 As FullSubentityPath Dim subEntEdgePath3 As FullSubentityPath CreateSubEntityPath(circle1, subEntEdgePath1, trans2) CreateSubEntityPath(circle2, subEntEdgePath2, trans2) CreateSubEntityPath(line, subEntEdgePath3, trans2) Dim consGrpId As ObjectId = GetConstraintGroup(True, trans2) Dim consGeom1 As ConstrainedGeometry = Nothing Dim consGeom2 As ConstrainedGeometry = Nothing Dim consGeom3 As ConstrainedGeometry = Nothing Using constGrp As Assoc2dConstraintGroup = DirectCast(trans2.GetObject(consGrpId, OpenMode.ForWrite, False), Assoc2dConstraintGroup) Try consGeom1 = AddConstrainedGeometry(constGrp, subEntEdgePath1) Catch ex As Exception 'aready there move on End Try Try consGeom2 = AddConstrainedGeometry(constGrp, subEntEdgePath2) Catch ex As Exception 'aready there move on End Try Try consGeom3 = AddConstrainedGeometry(constGrp, subEntEdgePath3) Catch ex As Exception 'aready there move on End Try Dim paths As FullSubentityPath() = New FullSubentityPath(2) {subEntEdgePath1, subEntEdgePath2, subEntEdgePath3} Dim newConstraint As GeometricalConstraint = constGrp.AddGeometricalConstraint(GeometricalConstraint.ConstraintType.Symmetric, paths) End Using trans2.Commit() End Using End Sub Public Sub SetTangent(ByVal roundedCurve As Curve, ByVal curve2 As Curve, ByVal trans As Transaction) Using trans2 As Transaction = trans.TransactionManager.StartTransaction() Dim subEntEdgePath1 As FullSubentityPath Dim subEntEdgePath2 As FullSubentityPath CreateSubEntityPath(roundedCurve, subEntEdgePath1, trans) CreateSubEntityPath(curve2, subEntEdgePath2, trans) Dim consGrpId As ObjectId = GetConstraintGroup(True, trans2) Dim consGeom1 As ConstrainedGeometry = Nothing Dim consGeom2 As ConstrainedGeometry = Nothing Using constGrp As Assoc2dConstraintGroup = DirectCast(trans2.GetObject(consGrpId, OpenMode.ForWrite, False), Assoc2dConstraintGroup) Try consGeom1 = AddConstrainedGeometry(constGrp, subEntEdgePath1) Catch ex As Exception 'aready there move on End Try Try consGeom2 = AddConstrainedGeometry(constGrp, subEntEdgePath2) Catch ex As Exception 'aready there move on End Try Dim paths As FullSubentityPath() = New FullSubentityPath(1) {subEntEdgePath1, subEntEdgePath2} Dim newConstraint As GeometricalConstraint = constGrp.AddGeometricalConstraint(GeometricalConstraint.ConstraintType.Tangent, paths) End Using trans2.Commit() End Using End Sub Public Sub SetNormal(ByVal roundedCurve As Curve, ByVal curve2 As Curve, ByVal trans As Transaction) Using trans2 As Transaction = trans.TransactionManager.StartTransaction() Dim subEntEdgePath1 As FullSubentityPath Dim subEntEdgePath2 As FullSubentityPath CreateSubEntityPath(roundedCurve, subEntEdgePath1, trans) CreateSubEntityPath(curve2, subEntEdgePath2, trans) Dim consGrpId As ObjectId = GetConstraintGroup(True, trans2) Dim consGeom1 As ConstrainedGeometry = Nothing Dim consGeom2 As ConstrainedGeometry = Nothing Using constGrp As Assoc2dConstraintGroup = DirectCast(trans2.GetObject(consGrpId, OpenMode.ForWrite, False), Assoc2dConstraintGroup) Try consGeom1 = AddConstrainedGeometry(constGrp, subEntEdgePath1) Catch ex As Exception 'aready there move on End Try Try consGeom2 = AddConstrainedGeometry(constGrp, subEntEdgePath2) Catch ex As Exception 'aready there move on End Try Dim paths As FullSubentityPath() = New FullSubentityPath(1) {subEntEdgePath1, subEntEdgePath2} Dim newConstraint As GeometricalConstraint = constGrp.AddGeometricalConstraint(GeometricalConstraint.ConstraintType.Normal, paths) End Using trans2.Commit() End Using End Sub #End Region #Region "Dimensional Contraints" Public Sub SetVerticalDistanceWithParameter(ByVal curve1 As Curve, ByVal curvePnt1 As CurvePoint, ByVal curve2 As Curve, ByVal curvePnt2 As CurvePoint, ByVal varID As ObjectId, ByVal trans As Transaction) Using trans2 As Transaction = trans.TransactionManager.StartTransaction Dim db As Database = curve1.Database Dim SubEntEdgePath1 As FullSubentityPath 'logical path to the edge (one edge object pretty simple) Dim SubEntEdgePath2 As FullSubentityPath Dim subEntPointPath1 As FullSubentityPath 'logical path to the user selected point (usually start, end, or mid) Dim subEntPointPath2 As FullSubentityPath Dim valDepId As ObjectId Using valDep As New AssocValueDependency() valDepId = db.AddDBObject(valDep) Dim compoundId As New CompoundObjectId(varID, db) valDep.AttachToObject(compoundId) End Using 'get the constraint group that exists on the same plane as our points (in this case just wcs + elevation, but if you get more advanced, this may need to be modified big time) Dim consGrpId As ObjectId = GetConstraintGroup(True, trans2) 'set a vertical only dimension to midpoint of curve 1 to midpoint of curve 2 CreateSubEntityPath(curve1, curvePnt1, SubEntEdgePath1, subEntPointPath1, trans2) CreateSubEntityPath(curve1, curvePnt2, SubEntEdgePath2, subEntPointPath2, trans2) Dim consGeom1 As ConstrainedGeometry = Nothing Dim consGeom2 As ConstrainedGeometry = Nothing Using constGrp As Assoc2dConstraintGroup = DirectCast(trans2.GetObject(consGrpId, OpenMode.ForWrite, False), Assoc2dConstraintGroup) consGeom1 = AddConstrainedGeometry(constGrp, subEntPointPath1) consGeom2 = AddConstrainedGeometry(constGrp, subEntPointPath2) constGrp.AddDistanceConstraint(consGeom1, consGeom2, DistanceConstraint.DistanceDirectionType.FixedDirection, valDepId, Nothing, New Vector3d(0, 1, 0), Nothing) End Using trans2.Commit() End Using End Sub Public Sub SetHorizontalDistanceWithParameter(ByVal curve1 As Curve, ByVal curvePnt1 As CurvePoint, ByVal curve2 As Curve, ByVal curvePnt2 As CurvePoint, ByVal varID As ObjectId, ByVal trans As Transaction) Using trans2 As Transaction = trans.TransactionManager.StartTransaction Dim db As Database = curve1.Database Dim SubEntEdgePath1 As FullSubentityPath 'logical path to the edge (one edge object pretty simple) Dim SubEntEdgePath2 As FullSubentityPath Dim subEntPointPath1 As FullSubentityPath 'logical path to the user selected point (usually start, end, or mid) Dim subEntPointPath2 As FullSubentityPath Dim valDepId As ObjectId Using valDep As New AssocValueDependency() valDepId = db.AddDBObject(valDep) Dim compoundId As New CompoundObjectId(varID, db) valDep.AttachToObject(compoundId) End Using 'get the constraint group that exists on the same plane as our points (in this case just wcs + elevation, but if you get more advanced, this may need to be modified big time) Dim consGrpId As ObjectId = GetConstraintGroup(True, trans2) 'set a vertical only dimension to midpoint of curve 1 to midpoint of curve 2 CreateSubEntityPath(curve1, curvePnt1, SubEntEdgePath1, subEntPointPath1, trans2) CreateSubEntityPath(curve1, curvePnt2, SubEntEdgePath2, subEntPointPath2, trans2) Dim consGeom1 As ConstrainedGeometry = Nothing Dim consGeom2 As ConstrainedGeometry = Nothing Using constGrp As Assoc2dConstraintGroup = DirectCast(trans2.GetObject(consGrpId, OpenMode.ForWrite, False), Assoc2dConstraintGroup) consGeom1 = AddConstrainedGeometry(constGrp, subEntPointPath1) consGeom2 = AddConstrainedGeometry(constGrp, subEntPointPath2) constGrp.AddDistanceConstraint(consGeom1, consGeom2, DistanceConstraint.DistanceDirectionType.FixedDirection, valDepId, Nothing, New Vector3d(1, 0, 0), Nothing) End Using trans2.Commit() End Using End Sub Public Sub SetAlignedDistanceWithParameter(ByVal curve1 As Curve, ByVal curvePnt1 As CurvePoint, ByVal curve2 As Curve, ByVal curvePnt2 As CurvePoint, ByVal varID As ObjectId, ByVal trans As Transaction) Using trans2 As Transaction = trans.TransactionManager.StartTransaction Dim db As Database = curve1.Database Dim SubEntEdgePath1 As FullSubentityPath 'logical path to the edge (one edge object pretty simple) Dim SubEntEdgePath2 As FullSubentityPath Dim subEntPointPath1 As FullSubentityPath 'logical path to the user selected point (usually start, end, or mid) Dim subEntPointPath2 As FullSubentityPath Dim valDepId As ObjectId Using valDep As New AssocValueDependency() valDepId = db.AddDBObject(valDep) Dim compoundId As New CompoundObjectId(varID, db) valDep.AttachToObject(compoundId) End Using 'get the constraint group that exists on the same plane as our points (in this case just wcs + elevation, but if you get more advanced, this may need to be modified big time) Dim consGrpId As ObjectId = GetConstraintGroup(True, trans2) 'set a vertical only dimension to midpoint of curve 1 to midpoint of curve 2 CreateSubEntityPath(curve1, curvePnt1, SubEntEdgePath1, subEntPointPath1, trans2) CreateSubEntityPath(curve2, curvePnt2, SubEntEdgePath2, subEntPointPath2, trans2) Dim consGeom1 As ConstrainedGeometry = Nothing Dim consGeom2 As ConstrainedGeometry = Nothing Using constGrp As Assoc2dConstraintGroup = DirectCast(trans2.GetObject(consGrpId, OpenMode.ForWrite, False), Assoc2dConstraintGroup) consGeom1 = AddConstrainedGeometry(constGrp, subEntPointPath1) consGeom2 = AddConstrainedGeometry(constGrp, subEntPointPath2) constGrp.AddDistanceConstraint(consGeom1, consGeom2, DistanceConstraint.DistanceDirectionType.NotDirected, valDepId, Nothing, New Vector3d(1, 0, 0), Nothing) End Using trans2.Commit() End Using End Sub Public Function CreateRadiusDimensionalConstraint(ByVal roundedCurve As Curve, ByVal varID As ObjectId, ByVal btrID As ObjectId, ByVal trans As Transaction) As ObjectId Dim dimRadiusID As ObjectId = Nothing Using trans2 As Transaction = trans.TransactionManager.StartTransaction Dim db As Database = roundedCurve.Database Dim dimRadius As New RadialDimension ' Create dim dependency (the relationship between the AssocAction and an Entity) Dim dimDepId As ObjectId = ObjectId.Null Dim dimDepBodyId As ObjectId = ObjectId.Null Dim center As Point3d Dim radius As Double Dim chordPoint As New Point3d If TypeOf roundedCurve Is Arc Then Dim arc As Arc = roundedCurve radius = arc.Radius center = arc.Center chordPoint = arc.StartPoint ElseIf TypeOf roundedCurve Is Circle Then Dim circle As Circle = roundedCurve radius = circle.Radius center = circle.Center chordPoint = New Point3d(center.X + radius, center.Y, center.Z) End If dimRadius = New RadialDimension(center, chordPoint, 1, "", db.DimStyleTableId) dimRadius.DynamicDimension = True Dim btr As BlockTableRecord = trans2.GetObject(btrID, OpenMode.ForWrite) btr.AppendEntity(dimRadius) trans2.AddNewlyCreatedDBObject(dimRadius, True) Dim valDepId As ObjectId Using valDep As New AssocValueDependency() valDepId = db.AddDBObject(valDep) Dim compoundId As New CompoundObjectId(varID, db) valDep.AttachToObject(compoundId) End Using AssocDimDependencyBody.CreateAndPostToDatabase(dimRadius.ObjectId, dimDepId, dimDepBodyId) ' IF adding constraint fails, we want to keep our dimension. We reset to the old value later Dim bPreviousValue As Boolean = AssocDimDependencyBodyBase.SetEraseDimensionIfDependencyIsErased(False) ' Add dimensional constraint to the circle Dim consGrpId As ObjectId = GetConstraintGroup(True, trans2) Dim consGeom As ConstrainedGeometry = Nothing Using constGrp As Assoc2dConstraintGroup = DirectCast(trans2.GetObject(consGrpId, OpenMode.ForWrite, False), Assoc2dConstraintGroup) ' Get FullSubentityPath of circle edge. Dim subEntEdgePath As FullSubentityPath CreateSubEntityPath(roundedCurve, subEntEdgePath, trans2) ' Constrain circle edge Try consGeom = AddConstrainedGeometry(constGrp, subEntEdgePath) Catch ex As Exception 'aready there move on End Try ' Add constraint to constraint group constGrp.AddRadiusDiameterConstraint(consGeom, RadiusDiameterConstraint.RadDiaConstrType.CircleRadius, valDepId, dimDepId) ' Reset SetEraseDimensionIfDependencyIsErased back to old value AssocDimDependencyBodyBase.SetEraseDimensionIfDependencyIsErased(bPreviousValue) Dim dimDepBody As AssocDimDependencyBody = trans2.GetObject(dimDepBodyId, OpenMode.ForWrite) Dim valDep As AssocValueDependency = trans2.GetObject(valDepId, OpenMode.ForWrite) Debug.Print(dimDepBody.Variable.ToString) End Using trans2.Commit() End Using Return dimRadiusID End Function Public Sub SetRadiusToDimension(ByVal roundedCurve As Curve, ByVal dimRadius As RadialDimension, ByVal varName As String, ByVal varExpression As String, ByVal trans As Transaction) Using trans2 As Transaction = trans.TransactionManager.StartTransaction() Dim varId As ObjectId, valDepId As ObjectId Dim db As Database = roundedCurve.Database 'create user parameter varId = AddOrModifyVariable(varName, varExpression, trans2) ' Create value dependency (the relationship between the AssocAction and a scalar value - the variable value) Using valDep As New AssocValueDependency() valDepId = db.AddDBObject(valDep) Dim compoundId As New CompoundObjectId(varId, db) valDep.AttachToObject(compoundId) End Using ' Create dim dependency (the relationship between the AssocAction and an Entity) Dim dimDepId As ObjectId = ObjectId.Null Dim dimDepBodyId As ObjectId = ObjectId.Null AssocDimDependencyBody.CreateAndPostToDatabase(dimRadius.ObjectId, dimDepId, dimDepBodyId) ' IF adding constraint fails, we want to keep our dimension. We reset to the old value later Dim bPreviousValue As Boolean = AssocDimDependencyBodyBase.SetEraseDimensionIfDependencyIsErased(False) ' Add dimensional constraint to the circle Dim consGrpId As ObjectId = GetConstraintGroup(True, trans2) Dim consGeom As ConstrainedGeometry = Nothing Using constGrp As Assoc2dConstraintGroup = DirectCast(trans2.GetObject(consGrpId, OpenMode.ForWrite, False), Assoc2dConstraintGroup) ' Get FullSubentityPath of circle edge. Dim subEntEdgePath As FullSubentityPath CreateSubEntityPath(roundedCurve, subEntEdgePath, trans2) ' Constrain circle edge Try consGeom = AddConstrainedGeometry(constGrp, subEntEdgePath) Catch ex As Exception 'aready there move on End Try ' Add constraint to constraint group constGrp.AddRadiusDiameterConstraint(consGeom, RadiusDiameterConstraint.RadDiaConstrType.CircleRadius, valDepId, dimDepId) ' Reset SetEraseDimensionIfDependencyIsErased back to old value AssocDimDependencyBodyBase.SetEraseDimensionIfDependencyIsErased(bPreviousValue) Dim dimDepBody As AssocDimDependencyBody = trans.GetObject(dimDepBodyId, OpenMode.ForWrite) Debug.Print(dimDepBody.Variable.ToString) End Using trans2.Commit() End Using End Sub Public Sub SetRadiusWithoutDimension(ByVal roundedCurve As Curve, ByVal varName As String, ByVal varExpression As String, ByVal trans As Transaction) Using trans2 As Transaction = trans.TransactionManager.StartTransaction() Dim db As Database = roundedCurve.Database ' Get FullSubentityPath of circle edge. Dim subentPath As FullSubentityPath = CreateSubEntityPath(roundedCurve, SubentityType.Edge) Dim varId As ObjectId, valDepId As ObjectId 'create user parameter varId = AddOrModifyVariable(varName, varExpression, trans2) ' Create value dependency (the relationship between the AssocAction and a scalar value - the variable value) Using valDep As New AssocValueDependency() valDepId = db.AddDBObject(valDep) Dim compoundId As New CompoundObjectId(varId, db) valDep.AttachToObject(compoundId) End Using ' Add dimensional constraint to the circle Dim consGrpId As ObjectId = GetConstraintGroup(True, trans2) Dim consGeom As ConstrainedGeometry = Nothing Using constGrp As Assoc2dConstraintGroup = DirectCast(trans2.GetObject(consGrpId, OpenMode.ForWrite, False), Assoc2dConstraintGroup) ' Constrain circle edge Try consGeom = AddConstrainedGeometry(constGrp, subentPath) Catch ex As Exception 'aready there move on End Try ' Add constraint to constraint group constGrp.AddRadiusDiameterConstraint(consGeom, RadiusDiameterConstraint.RadDiaConstrType.CircleRadius, valDepId, ObjectId.Null) End Using trans2.Commit() End Using End Sub Public Sub SetDiameterToDimension(ByVal roundedCurve As Curve, ByVal dimDiameter As DiametricDimension, ByVal varName As String, ByVal varExpression As String, ByVal trans As Transaction) Dim db As Database = roundedCurve.Database Using trans2 As Transaction = trans.TransactionManager.StartTransaction() Dim subentPath As FullSubentityPath = CreateSubEntityPath(roundedCurve, SubentityType.Edge) Dim idConstrGroup As ObjectId = ObjectId.Null ' Create value dependency Dim varId As ObjectId, valDepId As ObjectId ' Create variable varId = AddOrModifyVariable(varName, varExpression, trans2) Using valDep As New AssocValueDependency() valDepId = db.AddDBObject(valDep) Dim compoundId As New CompoundObjectId(varId, db) valDep.AttachToObject(compoundId) End Using ' Create dim dependency (the relationship between the AssocAction and an Entity) Dim dimDepId As ObjectId = ObjectId.Null Dim dimDepBodyId As ObjectId = ObjectId.Null AssocDimDependencyBody.CreateAndPostToDatabase(dimDiameter.ObjectId, dimDepId, dimDepBodyId) Dim bPreviousValue As Boolean = AssocDimDependencyBodyBase.SetEraseDimensionIfDependencyIsErased(False) ' Add dimensional constraint to the entity Dim consGrpId As ObjectId = GetConstraintGroup(True, trans2) Dim consGeom As ConstrainedGeometry = Nothing Using constGrp As Assoc2dConstraintGroup = DirectCast(trans2.GetObject(consGrpId, OpenMode.ForWrite, False), Assoc2dConstraintGroup) Try consGeom = AddConstrainedGeometry(constGrp, subentPath) Catch ex As Exception 'aready there move on End Try constGrp.AddRadiusDiameterConstraint(consGeom, RadiusDiameterConstraint.RadDiaConstrType.CircleRadius, valDepId, dimDepId) AssocDimDependencyBodyBase.SetEraseDimensionIfDependencyIsErased(bPreviousValue) End Using trans2.Commit() End Using End Sub Public Sub SetAngularToDimension(ByVal line1 As Curve, ByVal line2 As Curve, ByVal dimAngular As LineAngularDimension2, ByVal varName As String, ByVal varExpression As String, ByVal trans As Transaction) Dim db As Database = line1.Database Using trans2 As Transaction = trans.TransactionManager.StartTransaction() Dim subEntEdgePath1 As FullSubentityPath = CreateSubEntityPath(line1, SubentityType.Edge) Dim subEntEdgePath2 As FullSubentityPath = CreateSubEntityPath(line2, SubentityType.Edge) Dim idConstrGroup As ObjectId = ObjectId.Null Dim varId As ObjectId, valDepId As ObjectId 'create variable 'Angle', dependent on 'A' and 'B' varId = AddOrModifyVariable(varName, varExpression, trans2) 'create value dependency (required to associatevariable with dimensional constraint) Using valDep As New AssocValueDependency() valDepId = db.AddDBObject(valDep) trans2.AddNewlyCreatedDBObject(valDep, True) Dim compoundId As New CompoundObjectId(varId, db) valDep.AttachToObject(compoundId) End Using 'create dim dependency Dim dimDepId As ObjectId = ObjectId.Null Dim dimDepBodyId As ObjectId = ObjectId.Null AssocDimDependencyBody.CreateAndPostToDatabase(dimAngular.ObjectId, dimDepId, dimDepBodyId) Dim bPreviousValue As Boolean = AssocDimDependencyBodyBase.SetEraseDimensionIfDependencyIsErased(False) 'add dimconstraint to the entities Dim consGrpId As ObjectId = GetConstraintGroup(True, trans2) Dim consGeom1 As ConstrainedGeometry = Nothing Dim consGeom2 As ConstrainedGeometry = Nothing Using constGrp As Assoc2dConstraintGroup = DirectCast(trans2.GetObject(consGrpId, OpenMode.ForWrite, False), Assoc2dConstraintGroup) Try consGeom1 = AddConstrainedGeometry(constGrp, subEntEdgePath1) Catch ex As Exception 'aready there move on End Try Try consGeom2 = AddConstrainedGeometry(constGrp, subEntEdgePath2) Catch ex As Exception 'aready there move on End Try constGrp.AddAngularConstraint(DirectCast(consGeom1, ConstrainedLine), DirectCast(consGeom2, ConstrainedLine), AngularConstraint.AngularSectorType.ParallelClockwise, valDepId, dimDepId) AssocDimDependencyBodyBase.SetEraseDimensionIfDependencyIsErased(bPreviousValue) End Using trans2.Commit() End Using End Sub Public Sub SetAngularWithoutDimension(ByVal arc1 As Arc, ByVal varName As String, ByVal varExpression As String, ByVal trans As Transaction) Dim db As Database = arc1.Database Using trans2 As Transaction = trans.TransactionManager.StartTransaction() ' Create Arc entity Dim subEntEdgePath As FullSubentityPath = CreateSubEntityPath(arc1, SubentityType.Edge) Dim varId As ObjectId, valDepId As ObjectId 'create variable 'Angle' varId = AddOrModifyVariable(varName, varExpression, trans2) 'create value dependency (required to associate variable with dimensional constraint) Using valDep As New AssocValueDependency() valDepId = db.AddDBObject(valDep) trans2.AddNewlyCreatedDBObject(valDep, True) Dim compoundId As New CompoundObjectId(varId, db) valDep.AttachToObject(compoundId) End Using 'add dimconstraint to the entities Dim consGrpId As ObjectId = GetConstraintGroup(True, trans2) Dim consGeom1 As ConstrainedCurve = Nothing Dim startPt As ConstrainedPoint = Nothing Dim endPt As ConstrainedPoint = Nothing Dim centerPt As ConstrainedPoint = Nothing Using constGrp As Assoc2dConstraintGroup = DirectCast(trans2.GetObject(consGrpId, OpenMode.ForWrite, False), Assoc2dConstraintGroup) Dim cg As ConstrainedGeometry = Nothing Try cg = AddConstrainedGeometry(constGrp, subEntEdgePath) Catch ex As Exception 'aready there move on End Try consGeom1 = DirectCast(cg, ConstrainedCurve) Dim consPts As ConstrainedImplicitPoint() = consGeom1.ConstrainedImplicitPoints For Each pt As ConstrainedImplicitPoint In consPts If pt.PointType = ConstrainedImplicitPoint.ImplicitPointType.StartImplicit Then startPt = pt End If If pt.PointType = ConstrainedImplicitPoint.ImplicitPointType.EndImplicit Then endPt = pt End If If pt.PointType = ConstrainedImplicitPoint.ImplicitPointType.CenterImplicit Then centerPt = pt End If Next constGrp.Add3PointAngularConstraint(centerPt, startPt, endPt, AngularConstraint.AngularSectorType.ParallelClockwise, valDepId, ObjectId.Null) End Using trans2.Commit() End Using End Sub Public Sub Set2PointDistanceToDimension(ByVal point1 As DBPoint, ByVal point2 As DBPoint, ByVal dimAligned As AlignedDimension, ByVal varName As String, ByVal varExpression As String, ByVal trans As Transaction) Using trans2 As Transaction = trans.TransactionManager.StartTransaction() Dim db As Database = point1.Database Dim subEntPointPath1 As FullSubentityPath = CreateSubEntityPath(point1, SubentityType.Vertex) Dim subEntPointPath2 As FullSubentityPath = CreateSubEntityPath(point2, SubentityType.Vertex) Dim idConstrGroup As ObjectId = ObjectId.Null 'create value dependency Dim varId As ObjectId Dim valDepId As ObjectId varId = AddOrModifyVariable(varName, varExpression, trans2) Using valDep As New AssocValueDependency() valDepId = db.AddDBObject(valDep) Dim compoundId As New CompoundObjectId(varId, db) valDep.AttachToObject(compoundId) End Using 'create dim dependency Dim dimDepId As ObjectId = ObjectId.Null Dim dimDepBodyId As ObjectId = ObjectId.Null AssocDimDependencyBody.CreateAndPostToDatabase(dimAligned.ObjectId, dimDepId, dimDepBodyId) Dim bPreviousValue As Boolean = AssocDimDependencyBodyBase.SetEraseDimensionIfDependencyIsErased(False) 'add dimconstraint to the entities Dim consGrpId As ObjectId = GetConstraintGroup(True, trans2) Dim consGeom1 As ConstrainedGeometry = Nothing Dim consGeom2 As ConstrainedGeometry = Nothing Using constGrp As Assoc2dConstraintGroup = DirectCast(trans2.GetObject(consGrpId, OpenMode.ForWrite, False), Assoc2dConstraintGroup) Try consGeom1 = AddConstrainedGeometry(constGrp, subEntPointPath1) Catch ex As Exception 'aready there move on End Try Try consGeom2 = AddConstrainedGeometry(constGrp, subEntPointPath2) Catch ex As Exception 'aready there move on End Try constGrp.AddDistanceConstraint(consGeom1, consGeom2, DistanceConstraint.DistanceDirectionType.NotDirected, valDepId, dimDepId, New Vector3d(1, 0, 0), _ Nothing) AssocDimDependencyBodyBase.SetEraseDimensionIfDependencyIsErased(bPreviousValue) End Using trans2.Commit() End Using End Sub Public Sub SetAlignedDimCommand(ByVal line1 As Curve, ByVal dimAligned As AlignedDimension, ByVal varName As String, ByVal varExpression As String, ByVal trans As Transaction) Dim db As Database = line1.Database Using trans2 As Transaction = trans.TransactionManager.StartTransaction() Dim idConstrGroup As ObjectId = ObjectId.Null 'To query the subentities of the line, we create and use a protocol extension (PE) provided by the associativity API Dim subentityIdPE As AssocPersSubentityIdPE = GetProtocalExtension(line1) 'Now we have the PE, we query the subentities Dim edgeSubentityIds As SubentityId() = Nothing 'First we retrieve a list of all edges (a line has one edge) edgeSubentityIds = subentityIdPE.GetAllSubentities(line1, SubentityType.Edge) Dim startSID As SubentityId = SubentityId.Null, endSID As SubentityId = SubentityId.Null Dim other As SubentityId() = Nothing 'Now we retrieve the vertices associated with that edge. subentityIdPE.GetEdgeVertexSubentities(line1, edgeSubentityIds(0), startSID, endSID, other) 'The PE returns a SubEntId. We want a Full SubentityPath Dim subentPathEdge As New FullSubentityPath(New ObjectId(0) {line1.ObjectId}, edgeSubentityIds(0)) Dim subentPath1 As New FullSubentityPath(New ObjectId(0) {line1.ObjectId}, startSID) Dim subentPath2 As New FullSubentityPath(New ObjectId(0) {line1.ObjectId}, endSID) 'create value dependency Dim varId As ObjectId, valDepId As ObjectId varId = AddOrModifyVariable(varName, varExpression, trans2) Using valDep As New AssocValueDependency() valDepId = db.AddDBObject(valDep) Dim compoundId As New CompoundObjectId(varId, db) valDep.AttachToObject(compoundId) End Using 'create dim dependency Dim dimDepId As ObjectId = ObjectId.Null Dim dimDepBodyId As ObjectId = ObjectId.Null AssocDimDependencyBody.CreateAndPostToDatabase(dimAligned.ObjectId, dimDepId, dimDepBodyId) Dim bPreviousValue As Boolean = AssocDimDependencyBodyBase.SetEraseDimensionIfDependencyIsErased(False) Dim consGrpId As ObjectId = GetConstraintGroup(True, trans2) Dim consGeom0 As ConstrainedGeometry = Nothing Dim consLine As ConstrainedLine = Nothing Using constGrp As Assoc2dConstraintGroup = DirectCast(trans2.GetObject(consGrpId, OpenMode.ForWrite, False), Assoc2dConstraintGroup) Try consGeom0 = AddConstrainedGeometry(constGrp, subentPathEdge) Catch ex As Exception 'aready there move on End Try 'Sometimes you have to access implicit constrained geometry. 'In this case, we're constraining the lines by its endpoints, so we have to query the constrained line edge for its ConstrainedImplicitPoints. 'If we try to pass the line's end point subentity directly via a call to AddConstrainedGeometry, we'll get an error. consLine = DirectCast(consGeom0, ConstrainedLine) Dim consPts As ConstrainedImplicitPoint() = consLine.ConstrainedImplicitPoints Dim consStartPt As ConstrainedGeometry = Nothing Dim consEndPt As ConstrainedGeometry = Nothing 'We don't know which is start or end point, so we test. (And we could have a midpoint in there too). For Each pt As ConstrainedImplicitPoint In consPts If pt.PointType = ConstrainedImplicitPoint.ImplicitPointType.StartImplicit Then consStartPt = pt End If If pt.PointType = ConstrainedImplicitPoint.ImplicitPointType.EndImplicit Then consEndPt = pt End If Next 'If something went wrong ... If (consStartPt Is Nothing) OrElse (consEndPt Is Nothing) Then Exit Sub End If 'Now we add our constraint constGrp.AddDistanceConstraint(consStartPt, consEndPt, DistanceConstraint.DistanceDirectionType.NotDirected, valDepId, dimDepId, New Vector3d(1, 0, 0), _ Nothing) AssocDimDependencyBodyBase.SetEraseDimensionIfDependencyIsErased(bPreviousValue) End Using trans2.Commit() End Using End Sub Public Sub SetNestedAlignedDistanceWithParameter(ByRef SubEnt1NestedIDs As List(Of ObjectId), ByVal curve1 As Curve, ByVal curvePnt1 As CurvePoint, ByVal curve2 As Curve, ByVal curvePnt2 As CurvePoint, ByVal varID As ObjectId, ByVal trans As Transaction) Using trans2 As Transaction = trans.TransactionManager.StartTransaction Dim db As Database = curve1.Database Dim SubEntEdgePath1 As FullSubentityPath Dim SubEntEdgePath2 As FullSubentityPath Dim subEntPointPath1 As FullSubentityPath 'logical path to the user selected point (usually start, end, or mid) Dim subEntPointPath2 As FullSubentityPath Dim valDepId As ObjectId Using valDep As New AssocValueDependency() valDepId = db.AddDBObject(valDep) Dim compoundId As New CompoundObjectId(varID, db) valDep.AttachToObject(compoundId) End Using 'get the constraint group that exists on the same plane as our points (in this case just wcs + elevation, but if you get more advanced, this may need to be modified big time) Dim consGrpId As ObjectId = GetConstraintGroup(True, trans2) 'set a vertical only dimension to midpoint of curve 1 to midpoint of curve 2 CreateSubEntityPath(curve1, curvePnt1, SubEntEdgePath1, SubEnt1NestedIDs, subEntPointPath1, trans2) CreateSubEntityPath(curve2, curvePnt2, SubEntEdgePath2, subEntPointPath2, trans2) Dim consGeom1 As ConstrainedGeometry = Nothing Dim consGeom2 As ConstrainedGeometry = Nothing Using constGrp As Assoc2dConstraintGroup = DirectCast(trans2.GetObject(consGrpId, OpenMode.ForWrite, False), Assoc2dConstraintGroup) consGeom1 = AddConstrainedGeometry(constGrp, subEntPointPath1) consGeom2 = AddConstrainedGeometry(constGrp, subEntPointPath2) constGrp.AddDistanceConstraint(consGeom1, consGeom2, DistanceConstraint.DistanceDirectionType.NotDirected, valDepId, Nothing, New Vector3d(1, 0, 0), Nothing) End Using trans2.Commit() End Using End Sub #End Region #Region "Common Methods" Public Function GetAssociativeNetwork(ByVal strDictionary As String) As AssocNetwork Dim doc As Document = AAppServ.Application.DocumentManager.MdiActiveDocument Dim db As Database = doc.Database Dim asn As AssocNetwork = Nothing Using trans As Transaction = db.TransactionManager.StartTransaction Dim oid As ObjectId = AssocNetwork.GetInstanceFromDatabase(db, True, strDictionary) If oid <> Nothing Then asn = trans.GetObject(oid, OpenMode.ForRead) End If End Using Return asn End Function Public Enum CurvePoint As Integer StartPoint = 1 EndPoint = 2 MidPoint = 3 End Enum ''' ''' Get Edge path, and 1 selected point path ''' ''' ''' ''' ''' ''' ''' Private Sub CreateSubEntityPath(ByVal curve As Curve, ByVal curvePnt As CurvePoint, ByRef SubEntEdgePath As FullSubentityPath, ByRef subEntPointPath As FullSubentityPath, ByVal trans As Transaction) Using entity As Entity = DirectCast(trans.GetObject(curve.ObjectId, OpenMode.ForRead, False), Entity) If entity Is Nothing Then System.Windows.MessageBox.Show("Cannot Get entity") Exit Sub End If 'get the added language controls to work with sub entities (Protocal Extension) Dim subentityIdPE As AssocPersSubentityIdPE = GetProtocalExtension(entity) Dim edgeSubentityIds As SubentityId() = Nothing 'break the first curve down into its sub entities edgeSubentityIds = subentityIdPE.GetAllSubentities(entity, SubentityType.Edge) 'select the sub entities usable points, start, end, mid, others... Dim startSID As SubentityId = SubentityId.Null Dim endSID As SubentityId = SubentityId.Null Dim otherSIDs As SubentityId() = Nothing subentityIdPE.GetEdgeVertexSubentities(entity, edgeSubentityIds(0), startSID, endSID, otherSIDs) 'create a logical path from the entity to the desired point SubEntEdgePath = New FullSubentityPath(New ObjectId(0) {curve.ObjectId}, edgeSubentityIds(0)) Dim sid As SubentityId Select Case curvePnt Case CurvePoint.StartPoint sid = startSID Case CurvePoint.EndPoint sid = endSID Case CurvePoint.MidPoint sid = otherSIDs(0) End Select subEntPointPath = New FullSubentityPath(New ObjectId(0) {curve.ObjectId}, sid) End Using End Sub Private Sub CreateSubEntityPath(ByVal curve As Curve, ByVal curvePnt As CurvePoint, ByRef SubEntEdgePath As FullSubentityPath, ByVal nestedIDs As List(Of ObjectId), ByRef subEntPointPath As FullSubentityPath, ByVal trans As Transaction) Using entity As Entity = DirectCast(trans.GetObject(curve.ObjectId, OpenMode.ForRead, False), Entity) If entity Is Nothing Then System.Windows.MessageBox.Show("Cannot Get entity") Exit Sub End If 'get the added language controls to work with sub entities (Protocal Extension) Dim subentityIdPE As AssocPersSubentityIdPE = GetProtocalExtension(entity) Dim edgeSubentityIds As SubentityId() = Nothing 'break the first curve down into its sub entities edgeSubentityIds = subentityIdPE.GetAllSubentities(entity, SubentityType.Edge) 'select the sub entities usable points, start, end, mid, others... Dim startSID As SubentityId = SubentityId.Null Dim endSID As SubentityId = SubentityId.Null Dim otherSIDs As SubentityId() = Nothing subentityIdPE.GetEdgeVertexSubentities(entity, edgeSubentityIds(0), startSID, endSID, otherSIDs) 'create a logical path from the entity to the desired point SubEntEdgePath = New FullSubentityPath(nestedIDs.ToArray(), edgeSubentityIds(0)) Dim sid As SubentityId Select Case curvePnt Case CurvePoint.StartPoint sid = startSID Case CurvePoint.EndPoint sid = endSID Case CurvePoint.MidPoint sid = otherSIDs(0) End Select subEntPointPath = New FullSubentityPath(nestedIDs.ToArray(), sid) End Using End Sub ''' ''' Get Edge path only ''' ''' ''' ''' ''' Private Sub CreateSubEntityPath(ByVal curve As Curve, ByRef SubEntEdgePath As FullSubentityPath, ByVal trans As Transaction) Using entity As Entity = DirectCast(trans.GetObject(curve.ObjectId, OpenMode.ForRead, False), Entity) If entity Is Nothing Then System.Windows.MessageBox.Show("Cannot Get entity") Exit Sub End If 'get the added language controls to work with sub entities (Protocal Extension) Dim subentityIdPE As AssocPersSubentityIdPE = GetProtocalExtension(entity) Dim edgeSubentityIds As SubentityId() = Nothing 'break the first curve down into its sub entities edgeSubentityIds = subentityIdPE.GetAllSubentities(entity, SubentityType.Edge) 'create a logical path from the entity to the desired point SubEntEdgePath = New FullSubentityPath(New ObjectId(0) {curve.ObjectId}, edgeSubentityIds(0)) End Using End Sub ''' ''' Get variable path based on Subentity Type ''' ''' ''' ''' ''' Private Function CreateSubEntityPath(ByVal entity As Entity, ByVal subentityType As SubentityType) As FullSubentityPath If entity Is Nothing Then System.Windows.MessageBox.Show("cannot get entity") Return New FullSubentityPath() End If Dim subentityIdPE As AssocPersSubentityIdPE = GetProtocalExtension(entity) Dim edgeSubentityIds As SubentityId() = Nothing edgeSubentityIds = subentityIdPE.GetAllSubentities(entity, subentityType) Return New FullSubentityPath(New ObjectId(0) {entity.ObjectId}, edgeSubentityIds(0)) End Function Public Function GetProtocalExtension(ByVal ent As Entity) As AssocPersSubentityIdPE Dim subentityIdPE As AssocPersSubentityIdPE Dim peCls As RXClass = AssocPersSubentityIdPE.GetClass(GetType(AssocPersSubentityIdPE)) Dim pSubentityIdPE As IntPtr = ent.QueryX(peCls) If pSubentityIdPE = IntPtr.Zero Then System.Windows.MessageBox.Show("cannot get pSubentityIdPE1") Return Nothing End If subentityIdPE = TryCast(AssocPersSubentityIdPE.Create(pSubentityIdPE, False), AssocPersSubentityIdPE) If subentityIdPE Is Nothing Then System.Windows.MessageBox.Show("cannot get subentityIdPE1") Return Nothing End If Return subentityIdPE End Function Private Function GetConstraintGroup(ByVal createIfDoesNotExist As Boolean, ByVal trans As Transaction) As ObjectId ' Calculate the current plane on which new entities are added by the editor ' (A combination of UCS and ELEVATION sysvar). Dim ed As Autodesk.AutoCAD.EditorInput.Editor = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor Dim ucsMatrix As Matrix3d = ed.CurrentUserCoordinateSystem Dim origin As Point3d = ucsMatrix.CoordinateSystem3d.Origin Dim xAxis As Vector3d = ucsMatrix.CoordinateSystem3d.Xaxis Dim yAxis As Vector3d = ucsMatrix.CoordinateSystem3d.Yaxis Dim zAxis As Vector3d = ucsMatrix.CoordinateSystem3d.Zaxis origin = origin + CDbl(AAppServ.Application.GetSystemVariable("ELEVATION")) * zAxis Dim currentPlane As New Plane(origin, xAxis, yAxis) ' get the constraint group from block table record Dim idConstrGroup As ObjectId = ObjectId.Null Dim db As Database = AAppServ.Application.DocumentManager.MdiActiveDocument.Database Dim networkId As ObjectId = AssocNetwork.GetInstanceFromObject(SymbolUtilityServices.GetBlockModelSpaceId(db), createIfDoesNotExist, True, "") If networkId.IsNull Then System.Windows.MessageBox.Show("Network id is null") Return idConstrGroup End If ' Try to find the constraint group in the associative network Using trans2 As Transaction = trans.TransactionManager.StartTransaction() Using network As AssocNetwork = DirectCast(trans2.GetObject(networkId, OpenMode.ForRead, False), AssocNetwork) If network Is Nothing Then Return idConstrGroup End If ' Iterate all actions in network to find Assoc2dConstraintGroups Dim actionsInNetwork As ObjectIdCollection = network.GetActions For nCount As Integer = 0 To actionsInNetwork.Count - 1 Dim idAction As ObjectId = actionsInNetwork(nCount) If idAction = ObjectId.Null Then Continue For End If ' Is this action a type of Assoc2dConstraintGroup? If idAction.ObjectClass.IsDerivedFrom(RXObject.GetClass(GetType(Autodesk.AutoCAD.DatabaseServices.Assoc2dConstraintGroup))) Then Using action As AssocAction = DirectCast(trans2.GetObject(idAction, OpenMode.ForRead, False), AssocAction) If action Is Nothing Then Continue For End If Dim constGrp As Assoc2dConstraintGroup = DirectCast(action, Assoc2dConstraintGroup) ' Is this the Assoc2dConstraintGroup for our plane of interest? If constGrp.GetWorkPlane.IsCoplanarTo(currentPlane) Then ' If it is then we've found an existing constraint group we can use. Return idAction End If End Using End If Next End Using ' If we get to here, a suitable contraint group doesn't exist, create a new one if that's what calling fn wanted. If idConstrGroup.IsNull AndAlso createIfDoesNotExist Then Using network As AssocNetwork = DirectCast(trans2.GetObject(networkId, OpenMode.ForWrite, False), AssocNetwork) ' Create construction plane Dim constraintPlane As New Plane(currentPlane) ' If model extent is far far away from origin then we need to shift ' construction plane origin within the model extent. ' (Use Pextmin, PExtmax in paper space) Dim extmin As Point3d = db.Extmin Dim extmax As Point3d = db.Extmax If extmin.GetAsVector().Length > 100000000.0 Then Dim originL As Point3d = extmin + (extmax - extmin) / 2.0 Dim result As PointOnSurface = currentPlane.GetClosestPointTo(originL) constraintPlane.[Set](result.GetPoint(), currentPlane.Normal) End If ' Create the new constraint group and add it to the associative network. Using constGrp As New Assoc2dConstraintGroup(constraintPlane) idConstrGroup = db.AddDBObject(constGrp) End Using network.AddAction(idConstrGroup, True) End Using End If trans2.Commit() End Using Return idConstrGroup End Function ''' ''' Place into ModelspaceBTR ''' ''' ''' ''' ''' ''' Public Function AddOrModifyVariable(ByVal varName As String, ByVal varExpression As String, ByVal trans As Transaction) As ObjectId Dim doc As Document = AAppServ.Application.DocumentManager.MdiActiveDocument Dim db As Database = doc.Database Dim sourceObjectID As ObjectId = SymbolUtilityServices.GetBlockModelSpaceId(db) Dim varid As ObjectId = AddOrModifyVariable(varExpression, varExpression, sourceObjectID, trans) Return varid End Function ''' ''' Place into any BTR ''' ''' ''' ''' ''' ''' ''' Public Function AddOrModifyVariable(ByVal varName As String, ByVal varExpression As String, ByVal sourceObjectID As ObjectId, ByVal trans As Transaction) As ObjectId Dim db As Database = sourceObjectID.Database Dim varId As ObjectId = ObjectId.Null Using trans2 As Transaction = trans.TransactionManager.StartTransaction() ' Open the AssocNetwork Dim networkId As ObjectId = AssocNetwork.GetInstanceFromObject(sourceObjectID, True, True, "") Dim network As AssocNetwork = DirectCast(trans2.GetObject(networkId, OpenMode.ForWrite), AssocNetwork) Dim var As AssocVariable = Nothing ' Iterate through all actions in the network Dim actionIds As ObjectIdCollection = network.GetActions For Each actionId As ObjectId In network.GetActions ' Is this action an AssocVariable? If actionId.ObjectClass.IsDerivedFrom(RXObject.GetClass(GetType(Autodesk.AutoCAD.DatabaseServices.AssocVariable))) Then ' If so, we check if it has the name we're looking for. var = DirectCast(trans2.GetObject(actionId, OpenMode.ForWrite), AssocVariable) If var IsNot Nothing Then ' If name matches, then we exit loop and set its expression If var.Name = varName Then Exit For Else var = Nothing End If End If End If Next ' If variable with correct name wasn't found, we create it. If var Is Nothing Then var = New AssocVariable() varId = network.Database.AddDBObject(var) network.AddAction(varId, True) trans2.AddNewlyCreatedDBObject(var, True) var.SetName(varName, True) End If ' Finally we set its expression to the new value. Dim errMsg As String = "" Try var.SetExpression(varExpression, "", True, True, errMsg, False) Dim rb As New ResultBuffer() errMsg = var.EvaluateExpression(rb) var.Value = rb Catch ex As Exception var.SetExpression(varExpression, "", False, False, errMsg, False) End Try trans2.Commit() End Using Return varId End Function Public Function AddConstrainedGeometry(ByVal constGrp As Assoc2dConstraintGroup, ByVal SubEntPath As FullSubentityPath) As ConstrainedGeometry Dim consGeom As ConstrainedGeometry = Nothing 'check constrGroup for existing path Dim cgIndex As Integer = constGrp.ConstrainedGeometries.Length If cgIndex > 0 Then For index As Integer = 0 To cgIndex - 1 Dim cg As ConstrainedGeometry = constGrp.ConstrainedGeometries(index) Dim fspIndex As Integer = cg.FullSubentityPaths.Length If fspIndex > 0 Then For jIndex As Integer = 0 To fspIndex - 1 Dim fsp As FullSubentityPath = cg.FullSubentityPaths(jIndex) If fsp = SubEntPath Then Return cg End If Next End If Next End If consGeom = constGrp.AddConstrainedGeometry(SubEntPath) Return consGeom End Function