Community
Civil 3D Customization
Welcome to Autodesk’s AutoCAD Civil 3D Forums. Share your knowledge, ask questions, and explore popular AutoCAD Civil 3D Customization topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Create civil 3d general note label from .net

8 REPLIES 8
SOLVED
Reply
Message 1 of 9
wang890
1079 Views, 8 Replies

Create civil 3d general note label from .net

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.

Stantec
Dell Precision 5530, Prism M320PU, C3D 14/17/19
8 REPLIES 8
Message 2 of 9
Jeff_M
in reply to: wang890

Look in the help for NoteLabel 🙂 This class has the Create() method with 2 overloads
Jeff_M, also a frequent Swamper
EESignature
Message 3 of 9
wang890
in reply to: Jeff_M

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
Stantec
Dell Precision 5530, Prism M320PU, C3D 14/17/19
Message 4 of 9
Jeff_M
in reply to: wang890

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?

Jeff_M, also a frequent Swamper
EESignature
Message 5 of 9
wang890
in reply to: Jeff_M

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.

Stantec
Dell Precision 5530, Prism M320PU, C3D 14/17/19
Message 6 of 9
Jeff_M
in reply to: wang890

Bob, send me a project I can test. jeffm AT quuxsoft DOT com
Jeff_M, also a frequent Swamper
EESignature
Message 7 of 9
Jeff_M
in reply to: wang890

Bob, I went ahead and created a form to show the styles and a button to add a label based on the selected style. It works just fine. So seeing your project would likely help in tracking down why it fails for you.
Jeff_M, also a frequent Swamper
EESignature
Message 8 of 9
Jeff_M
in reply to: Jeff_M

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);
        }
    }
Jeff_M, also a frequent Swamper
EESignature
Message 9 of 9
ramd401
in reply to: Jeff_M

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

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Rail Community


 

Autodesk Design & Make Report