Civil 3D 2014, Pre SP2
Does this method work for surface references? I can get it to work for all of the other types of reference text objects, but the Surface throws an error "The reference object is not match with the text component.". All of the objects utilize the same code block and I've made sure the objectId of the reference object does belong to a surface.
This error also occurs in 2015.
Could you please provide a sample project and test drawing so that we can reproduce this issue?
Here is a link to a code sample: http://blog.civil3dreminders.com/2014/09/set-reference-text.html
Attached is a sample file to test the code. Run the command, select the surface, select the label, and then find the easter egg in the code! If the developer's are lucky then the easter egg won't show up.
Has anyone resolved this issue? I'm coming across the same issue.
Here's a sample in VB.net
Dim labAtt As String = "RefAlign" Dim LabelObj As C3DData.Label = DirectCast(TransMgr.GetObject(LabelID, OpenMode.ForWrite, True), C3DData.Label) Dim MyComponents As ObjectIdCollection = LabelObj.GetTextComponentIds() Dim ComponentID As ObjectId = Nothing For x As Int16 = 0 To MyComponents.Count - 1 Dim GenericObj As Object = MyComponents(x).GetObject(OpenMode.ForRead) Dim CompType As String = GenericObj.GetType().Name If CompType = "LabelStyleReferenceTextComponent" Then Dim tmpTxtComp As C3DData.Styles.LabelStyleReferenceTextComponent = MyComponents(x).GetObject(OpenMode.ForRead) If tmpTxtComp.Name = labAtt Then ComponentID = tmpTxtComp.ObjectId End If End If Next If ComponentID <> Nothing Then 'Validate that Label type and Target object type are same type If ValidateTarget(ComponentID, TargetID) Then
' This works for everything except Surface components LabelObj.SetReferenceTextTarget(ComponentID, TargetID) End If End If
API work appears to have been put at the bottom of the to do bucket. Most, if not all, of the Civil 3D API people got moved over to Infraworks. I haven't tested it recently, but I doubt it's been resolved.
Maybe it has something to do with the Label component's ReferenceTextObjectType not being equal to the target objects GetType().Name?
They are the same for "Alignment", "CogoPoint", and "Parcel".
But with surface references, the ReferenceTextObjectType is only "Surface" which doesn't correlate to a Civil3D object type.
There is only "TinSurface", "GridSurface", "VolumeSurface". The internal method SetReferenceTextTarget probably compares these and throws the error...
System.ArgumentException: The reference object is not match with the text component.
Just speculating... in case someone from Autodesk actually reads this.