2 weeks ago i figured out how to add general segment label to a feature line.
is the general note label exposed?
i found this one
Autodesk.Civil.DatabaseServices.Label
ideally i want t o drag the label to an xyz location and looks in this object it has this:
Label.DraggedOffset As Autodesk.AutoCAD.Geometry.Vector3d
so is this one the general note label?
thank you.
Solved! Go to Solution.
Solved by Jeff_M. Go to Solution.
hi Jeff
i spent a long time testing and it just doesn't insert the general note object. not sure why.
Imports System Imports System.Math Imports Autodesk.AutoCAD Imports Autodesk.AutoCAD.Interop Imports Autodesk.AutoCAD.ApplicationServices Imports Autodesk.AECC.Interop.Land Imports Autodesk.AECC.Interop.Roadway Imports Autodesk.AEC.Interop.UIBase Imports Autodesk.AECC.Interop.UiRoadway Imports Autodesk.AutoCAD.Interop.Common Imports Autodesk.AECC.Interop.UiLand Imports Autodesk.AutoCAD.EditorInput Imports Autodesk.AutoCAD.DatabaseServices Imports Autodesk.AutoCAD.Runtime Imports oAcadApp1 = Autodesk.AutoCAD.ApplicationServices.Application Imports System.IO Imports Autodesk.AutoCAD.Geometry Imports Autodesk.Civil.DatabaseServices Imports Autodesk.Civil.ApplicationServices Imports Autodesk.Civil.DatabaseServices.Styles Public Class frmConvert_Multileader_to_General_Note_Label Private Sub frmConvert_Multileader_to_General_Note_Label_Load(sender As Object, e As EventArgs) Handles MyBase.Load Dim db As Database = HostApplicationServices.WorkingDatabase Using tr As Transaction = db.TransactionManager.StartTransaction() 'Dim GeneralSegmentLbl As generallinklabel = DirectCast(tr.GetObject(pres.ObjectId, OpenMode.ForWrite), AlignmentCurveLabel) Dim curDoc As CivilDocument = CivilApplication.ActiveDocument Dim lStyles As LabelStyleCollection = curDoc.Styles.LabelStyles.GeneralNoteLabelStyles For Each stId As ObjectId In lStyles Dim generalCurveLblStyl As LabelStyle = TryCast(tr.GetObject(stId, OpenMode.ForRead), LabelStyle) cmbNoteStyle.Items.Add(generalCurveLblStyl.Name) Next End Using cmbNoteStyle.Text = cmbNoteStyle.Items(0) End Sub Private Sub btnSelect_Click(sender As Object, e As EventArgs) Handles btnSelect.Click Dim db As Database = HostApplicationServices.WorkingDatabase Using tr As Transaction = db.TransactionManager.StartTransaction Dim ID As New ObjectId Dim curDoc As CivilDocument = CivilApplication.ActiveDocument Dim lStyles As LabelStyleCollection = curDoc.Styles.LabelStyles.GeneralNoteLabelStyles Dim mkStyles As MarkerStyleCollection = curDoc.Styles.MarkerStyles Dim stId As ObjectId For Each stId In lStyles Dim lstyle As LabelStyle = TryCast(tr.GetObject(stId, OpenMode.ForRead), LabelStyle) If lstyle.Name = cmbNoteStyle.Text Then Exit For End If Next Dim noteID As ObjectId = NoteLabel.Create(db, New Point3d(0, 0, 0)) tr.Commit() End Using End Sub End Class
Bob, do you get any errors? I don't see anything inherintly wrong with your code (other than it being VB 🙂 ). This simple tests below both worked for me.
[CommandMethod("AddMyNoteLabel")] public void addmynotelabel() { var noteId = NoteLabel.Create(HostApplicationServices.WorkingDatabase, new Point3d(10,10,0)); } [CommandMethod("AddMyNoteLabel")] public void addmynotelabel() { var civdoc = CivilApplication.ActiveDocument; var styleId = civdoc.Styles.LabelStyles.GeneralNoteLabelStyles[0]; var noteId = NoteLabel.Create(Point3d.Origin, styleId, ObjectId.Null); }
Have you stepped throughthe code to see where it's failing?
your code works by itself but when i put it in the windows form and a button to run the code it still won't insert the general note. i need a form so user can control the style in the beginning.
so weird.
Here is what I used, hopefully it helps you:
//in my Command class [CommandMethod("AddMyNoteLabel")] public void addmynotelabel() { var civdoc = CivilApplication.ActiveDocument; List<StyleData> styledata = new List<StyleData>(); using (Transaction tr = HostApplicationServices.WorkingDatabase.TransactionManager.StartTransaction()) { foreach (ObjectId id in civdoc.Styles.LabelStyles.GeneralNoteLabelStyles) { var styl = (LabelStyle)id.GetObject(OpenMode.ForRead); StyleData sd = new StyleData(); sd.Name = styl.Name; sd.OiD = id; styledata.Add(sd); getChildren(styl, " ", ref styledata); } tr.Commit(); } NoteLabelForm form = new NoteLabelForm(styledata); Application.ShowModalDialog(form); } private void getChildren(LabelStyle styl, string padding, ref List<StyleData>styledata) { for (int i = 0; i < styl.ChildrenCount; i++) { var childstyl = (LabelStyle)styl[i].GetObject(OpenMode.ForRead); StyleData sd = new StyleData(); sd.Name = padding + childstyl.Name; sd.OiD = styl[i]; styledata.Add(sd); getChildren(childstyl, padding + " ", ref styledata); } } } public class StyleData { public string Name { get; set; } public ObjectId OiD { get; set; } } //and then in my form class which has 1 Listbox and 1 button: public partial class NoteLabelForm : Form { public NoteLabelForm(List<StyleData> styledata) { InitializeComponent(); listBox1.DataSource = styledata; listBox1.DisplayMember = "Name"; listBox1.ValueMember = "OiD"; } private void button1_Click(object sender, EventArgs e) { NoteLabel.Create(Point3d.Origin, (ObjectId)listBox1.SelectedValue, ObjectId.Null); } }
Hi, iam trying to create a macro in AutoCAD Civil 3D using vba that asks me to select a general segment label (Feature is LWPOLYLINE) and after selects he shown me the informations of
Side (Eg L1)
Start Easting
Start Northing
Segment Length
Azimuth
End Easting
End Northing
Waiting feedback
Regards