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: 

New Instance of a General Note

14 REPLIES 14
SOLVED
Reply
Message 1 of 15
Edoc13
623 Views, 14 Replies

New Instance of a General Note

Using VB.net I would like to insert General Note objects into the drawing.

 

Could someone please provide a snippet of creating an instance of said object?

 

TIA

14 REPLIES 14
Message 2 of 15
Jeff_M
in reply to: Edoc13

I don't use VB, but I'll take a stab at it...

Dim noteId As ObjectId = NoteLabel.Create(ptLocation, styleId, markerId)

 Where ptLocation is a valid 3dPoint, styleId is the ObjectId of the NoteLabelStyle to use, and markerId is the ObjectId of the MarkerStyle to use.

Or:

Dim noteId As ObjectId = NoteLabel.Create(db, ptLocation)

 Where db is the Database to add the label to and ptLocation is a valide 3dPoint. This will use the default styles set in the AddGeneralNoteLabel command settings.

Jeff_M, also a frequent Swamper
EESignature
Message 3 of 15
Partha.Sarkar
in reply to: Edoc13

This might be useful to you as well :

 

http://docs.autodesk.com/CIV3D/2013/ENU/API_Reference_Guide/html/dee72505-64e5-ac9c-4b73-932667eac51...

 

Thanks,

 



Partha Sarkar
Developer Technical Services
Autodesk Developer Network

Message 4 of 15
Edoc13
in reply to: Edoc13

Thanks!

 

NoteLable! I had the word General stuck in my head and couldn’t find it.

 

So the following code works great:

Dim pt3D As Point3d = New Point3d(5, 10, 0)

Dim NoteId As ObjectId = Autodesk.Civil.DatabaseServices.NoteLabel.Create(m_Database, pt3D)

 

But as soon as I use a CogoPoint X and Y, it works BUT when you try to drag the NoteLabel AutoCAD crashes. Is it me?

Dim pointId As ObjectId = Nothing

pointId = CogoPoints.GetPointByPointNumber(1)

Dim cogoPoint As CogoPoint = TryCast(pointId.GetObject(OpenMode.ForRead), CogoPoint)

Dim pt3D As Point3d = New Point3d(cogoPoint.Easting, cogoPoint.Northing, 0)

Dim NoteId As ObjectId = Autodesk.Civil.DatabaseServices.NoteLabel.Create(m_Database, pt3D)

Message 5 of 15
Jeff_M
in reply to: Edoc13

Are you committing your Transaction? As I mentioned, I don't use VB, but the following test in C# works fine for me.

using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Runtime;
using Autodesk.Civil.ApplicationServices;
using Autodesk.Civil.DatabaseServices;
using AcDb = Autodesk.AutoCAD.DatabaseServices;

        [CommandMethod("Notetest")]
        public void noyetest()
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;
            AcDb.Database db = doc.Database;
            Editor ed = doc.Editor;
            PromptEntityOptions eOpts = new PromptEntityOptions("Select CogoPoint:");
            eOpts.SetRejectMessage("...not a Cogo Point, try again!");
            eOpts.AddAllowedClass(typeof(CogoPoint), true);
            PromptEntityResult eRes = ed.GetEntity(eOpts);
            while (eRes.Status == PromptStatus.OK)
            {
                using (AcDb.Transaction tr = db.TransactionManager.StartTransaction())
                {
                    CogoPoint pt = (CogoPoint)eRes.ObjectId.GetObject(AcDb.OpenMode.ForRead);
                    AcDb.ObjectId noteId = NoteLabel.Create(db, new Autodesk.AutoCAD.Geometry.Point3d(pt.Easting, pt.Northing, 0));
                    tr.Commit();
                }
                eRes = ed.GetEntity(eOpts);
            }
        }

 

Jeff_M, also a frequent Swamper
EESignature
Message 6 of 15
Edoc13
in reply to: Edoc13

Okay my test drawing somehow became corrupt.

Drags perfectly in a new drawing.

Thanks for the help.

Message 7 of 15
Jeff_M
in reply to: Edoc13

Glad I could help. BTW, I tested one version where I just passed the CogoPoint.Location as the 3dpoint and it worked as well.

 

If you find a response which answers your question, please be sure to accept the actual post which helped you as the solution. This will help future searchers quickly find answers to their own questions. Thanks!

Jeff_M, also a frequent Swamper
EESignature
Message 8 of 15
Edoc13
in reply to: Edoc13

I'm a noob who is still learning.

The drawing wasn’t corrupt.

The following code I found is my problem:

Dim oNoteLabel As Autodesk.Civil.DatabaseServices.Label = DirectCast(m_trans.GetObject(NoteId, OpenMode.ForWrite, True), Autodesk.Civil.DatabaseServices.Label)
oNoteLabel.SetTextComponentOverride(oNoteLabel.GetTextComponentIds(0), "New Text")

 

Message 9 of 15
Jeff_M
in reply to: Edoc13

Are you saying you found the problem and fixed it? Or you still have a problem and it's in that bit of code? At first glance it appears that code should work. You may try setting a variable to the ObjectId of the TextComponent, then passing that variable as the argument in the SetTextComponentOverride. This works for me (based on the same code previously posted):

 

            while (eRes.Status == PromptStatus.OK)
            {
                using (AcDb.Transaction tr = db.TransactionManager.StartTransaction())
                {
                    CogoPoint pt = (CogoPoint)eRes.ObjectId.GetObject(AcDb.OpenMode.ForRead);
                    AcDb.ObjectId noteId = NoteLabel.Create(db, new Autodesk.AutoCAD.Geometry.Point3d(pt.Easting, pt.Northing, 0));
                    NoteLabel lbl = (NoteLabel)noteId.GetObject(AcDb.OpenMode.ForWrite);
                    AcDb.ObjectId txtcomponentId = lbl.GetTextComponentIds()[0];
                    lbl.SetTextComponentOverride(txtcomponentId, "MyTest");
                    tr.Commit();
                }
                eRes = ed.GetEntity(eOpts);
            }

 

 

Jeff_M, also a frequent Swamper
EESignature
Message 10 of 15
Edoc13
in reply to: Edoc13

Not sure what's going on. It works but using AutoCAD if you try to drag the lable AutoCAD crashes.

    <CommandMethod("TESTING123")> _
    Public Sub TESTING123()
        Dim m_doc As CivilDocument = Nothing
        Dim m_Database As Database = Nothing
        Dim m_Editor As Editor = Nothing
        Dim docCol As Autodesk.AutoCAD.ApplicationServices.DocumentCollection = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager
        m_Database = docCol.MdiActiveDocument.Database
        m_Editor = docCol.MdiActiveDocument.Editor
        m_doc = Autodesk.Civil.ApplicationServices.CivilApplication.ActiveDocument()

        Dim CogoPoints As CogoPointCollection = m_doc.CogoPoints
        Using doclock As DocumentLock = docCol.MdiActiveDocument.LockDocument()
            Using m_trans As Transaction = m_Database.TransactionManager.StartTransaction()
                Dim pointId As ObjectId = CogoPoints.GetPointByPointNumber(1)
                Dim cogoPoint As CogoPoint = TryCast(pointId.GetObject(OpenMode.ForRead), CogoPoint)
                Dim pt3D As Autodesk.AutoCAD.Geometry.Point3d = New Point3d(cogoPoint.Easting, cogoPoint.Northing, 0)
                Dim NoteId As ObjectId = Autodesk.Civil.DatabaseServices.NoteLabel.Create(m_Database, pt3D)

                Dim lbl As NoteLabel = CType(NoteId.GetObject(OpenMode.ForWrite), NoteLabel)
                Dim txtcomponentId As ObjectId = lbl.GetTextComponentIds(0)
                lbl.SetTextComponentOverride(txtcomponentId, "MyTest")

                m_trans.Commit()
            End Using
        End Using
    End Sub

 

Message 11 of 15
Jeff_M
in reply to: Edoc13

Does it give you any error messages when it crashes? I just copy/pasted your code into one of the sample projects. It runs without issue and I can drag the resulting label all I want.
Jeff_M, also a frequent Swamper
EESignature
Message 12 of 15
Jeff_M
in reply to: Jeff_M

I've learned a few things in this exercise...First, if a TextComponent is a ReferenceText and you set the TextOverride, it doesn't display unless the Reference object is set. Second, the Create(db, text) method does NOT use the default style for the note label...instead, it uses the first style in the styles collection. To use a different style, be sure to either set it to the correct one once it is created, or use the other overload method which accepts the styleid to use.

 

Edoc, I tested your code in both 2013 & 2014. It works just fine in both, no crashing at all. Also tried Debug and Release builds. Do you have all of your references set to NOT CopyLocal?

Jeff_M, also a frequent Swamper
EESignature
Message 13 of 15
Edoc13
in reply to: Edoc13

All references are set to Copy Local False.

I always compile as Debug.

As a noob, you lost me regarding reference text. I’m using “MyTest”.

I ran the same code as before except after the declaration of lbl, I added:

lbl.StyleName = "FIELD"

 

Error is:

Violation Reading 0x0000 Exception at ea58d600h

Followed by the option to save my DWG for RECOVER and to send an Error Report to Autodesk.

Message 14 of 15
Edoc13
in reply to: Edoc13

Okay so I started a new DWG. Created point # 1 and a Gen. Note "FIELD".

And was able to drag with no problem.

In other words, it works great. Thanks for all the help.

Message 15 of 15
Edoc13
in reply to: Edoc13

For anyone else reading this post:

After pulling my hair out (all three of them) the same code would sometimes work and sometimes AutoCAD would crash when trying to drag a label.

I found that if I run AUDIT before and after the sub,AutoCAD does not crash.

    <CommandMethod("TESTING123")> _
    Public Sub TESTING123()
        Dim m_doc As CivilDocument = Nothing
        Dim m_Database As Database = Nothing
        Dim m_Editor As Editor = Nothing
        Dim docCol As Autodesk.AutoCAD.ApplicationServices.DocumentCollection = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager
        m_Database = docCol.MdiActiveDocument.Database
        m_Editor = docCol.MdiActiveDocument.Editor
        m_doc = Autodesk.Civil.ApplicationServices.CivilApplication.ActiveDocument()

        Dim CogoPoints As CogoPointCollection = m_doc.CogoPoints
        Using doclock As DocumentLock = docCol.MdiActiveDocument.LockDocument()
            Using m_trans As Transaction = m_Database.TransactionManager.StartTransaction()
                Dim pointId As ObjectId = CogoPoints.GetPointByPointNumber(1)
                Dim cogoPoint As CogoPoint = TryCast(pointId.GetObject(OpenMode.ForRead), CogoPoint)
                Dim pt3D As Autodesk.AutoCAD.Geometry.Point3d = New Point3d(cogoPoint.Easting, cogoPoint.Northing, 0)
                Dim NoteId As ObjectId = Autodesk.Civil.DatabaseServices.NoteLabel.Create(m_Database, pt3D)

                Dim lbl As NoteLabel = CType(NoteId.GetObject(OpenMode.ForWrite), NoteLabel)
                lbl.StyleName = "FIELD"
                Dim txtcomponentId As ObjectId = lbl.GetTextComponentIds(0)
                Dim s As String = "MyTest"
                lbl.SetTextComponentOverride(txtcomponentId, s)

                m_trans.Commit()
            End Using
        End Using
    End Sub

 

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

Post to forums  

Rail Community


Autodesk Design & Make Report