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: 

programaticaly invoke the command to import survey data

8 REPLIES 8
SOLVED
Reply
Message 1 of 9
mfernandes
711 Views, 8 Replies

programaticaly invoke the command to import survey data

I need to programaticaly invoke the command to import survey data.

 

What would be the vb.net code to bring up and run the Import Survey Data wizard.

I would like to have my program automaticaly delete the point group that is created by the import event.

 

I hope it does not involve  "shell" Smiley Sad command etc etc

 

thanks in advance.

8 REPLIES 8
Message 2 of 9
mfernandes
in reply to: mfernandes

I found a solution to my question.

It can be found at this link

http://docs.autodesk.com/ACD/2010/ENU/AutoCAD%20.NET%20Developer's%20Guide/index.html?url=WS1a919382...

 

essentially

 

Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.Runtime
 
<CommandMethod("SendACommandToAutoCAD")> _
Public Sub SendACommandToAutoCAD()
  Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument

'' runs the import survey data wizard 

 acDoc.SendStringToExecute("_AeccImportSurveyData ", True, False, False)
End Sub

 

 

 

now I just need to get a list of point groups before and after.

Then delete the point group that is recently created.

If anyone has a suggestion, please let me know. It will save me the time.

thanks

 

 

Message 3 of 9
Jeff_M
in reply to: mfernandes

Do you need to be running the command like that? You could monitor the CommandWillStart Event, when that command is started add an eventhandler for the ObjectModified Event, then check the objects that are modified, when you get the PointGroup object, save the ObjectId. Have an Editor_EnteringQuiescentState event handler that can then delete that Object after the command ends.

Jeff_M, also a frequent Swamper
EESignature
Message 4 of 9
mfernandes
in reply to: Jeff_M

Thanks Jeff, I can see why you have reached Expert Elite

 

I knew LISP and VBA inside out a long time ago, and only now have some time to get into dot net.

So this is a little, ok, maybe a lot, over my head. Also it has been a number of years since.

 

I understand what you are saying in concept, but have no idea where to even begin.

my current proccess is simple looking for sample codes and using that to relearn.

 

so any help you can offer is appreciated.

 

step1. CommandWillStart,                  I assume checks if the survey import event is run.

step2. ObjectModified,                        I assumes checks when a new group is created.

step3 Editor_EnteringQuiescentState  I assume is an event that will delete the objectId i.e. point group.

 

do you have sample codes or snippets for these three steps that I can take apart and retool to work for what I am creating.

 

thanks

Message 5 of 9
Jeff_M
in reply to: mfernandes

I'll see what I can drum up. My biggest problem will be trying to explain it properly in VB.NET vs C# (which is what all of my code is in).
Jeff_M, also a frequent Swamper
EESignature
Message 6 of 9
Jeff_M
in reply to: mfernandes

Here is a quick example, in C#, of doing what I described. Besides being C#, this doesn't quite work how you wished, as I don not get a PG created when using the AeccImportSurveyData wizard...not sure what I'm not doing that you are (Idon't use the Survey DB at all, so I'm sure I missed a step somewhere).

 

So I added/commented some of the code so I could test it by manually adding a PointGroup.

 

    public class TestSurvey
    {
        ObjectId pgId;
        Editor ed;
        Database db;

        [CommandMethod("SurveyTest")]
        public void surveytest()
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;
            pgId = ObjectId.Null;
            ed = doc.Editor;
            db = doc.Database;
            doc.CommandWillStart += doc_CommandWillStart;
            //db.ObjectAppended += db_ObjectAppended; //uncomment to test adding a PointGroup manually
            ed.EnteringQuiescentState += ed_EnteringQuiescentState;
        }

        void doc_CommandWillStart(object sender, CommandEventArgs e)
        {
            if(e.GlobalCommandName == "AECCIMPORTSURVEYDATA")
            {
                db.ObjectAppended += db_ObjectAppended; //comment out to test without the command
            }
        }

        void db_ObjectAppended(object sender, ObjectEventArgs e)
        {
            string dxfname = e.DBObject.GetRXClass().DxfName;
            if(dxfname =="AECC_POINT_PG")
            {
                pgId = e.DBObject.ObjectId;
                db.ObjectAppended -= db_ObjectAppended;
            }
        }

        void ed_EnteringQuiescentState(object sender, EventArgs e)
        {
            if(pgId!=ObjectId.Null)
            {
                using (DocumentLock doclock = Application.DocumentManager.MdiActiveDocument.LockDocument())
                {
                    using (Transaction tr = db.TransactionManager.StartOpenCloseTransaction())
                    {
                        CivilApplication.ActiveDocument.PointGroups.Remove(pgId);
                        pgId = ObjectId.Null;
                        tr.Commit();
                    }
                }
            }
        }

    }

 

Jeff_M, also a frequent Swamper
EESignature
Message 7 of 9
mfernandes
in reply to: Jeff_M

thanks Jeff

This is a great start.

 

given that it has been a numbers of years that I have been trying to migrate from VBA to VB.net, it has been on the back of my mind to maybe, I should invest the time to switch to C# instead. There seem to be more samples in C#.

 

Maybe this is the push I need. thanks.

I will go through the code and attempt to dissect it to see how it works. huge, Kudos coming your way.

  

On a side note, utilizing a survey database in C3D offers the advantage of project collaboration.

Survey database do for points, survey figures, breaklines etc, as what shortcuts do for surfaces, alignment etc.

 

In the import wizard, if you toggle the insert points to drawing to yes than by default a point group is created.

Yes, you can delete this point group, but autodesk developers, in the import dialog, should have given us the option to either create the point group or not.

 

 

Message 8 of 9
mfernandes
in reply to: Jeff_M

Hey Jeff......Brilliant Smiley Happycode.

 

thanks for the tip on adding the 

 

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

 

 

I had the using Autodesk.AutoCAD.EditorInput; missing.

The code "works as designed"

 

The issue is if I run the import survey data from either the command line or from the Home tab, create ground data panel the code line

void doc_CommandWillStart(object sender, CommandEventArgs e)

is fired.

 

But if I run the command by right clicking on the survey database, the code does not work.

 

1.png

 

I guess essentially I will have to find what triggers the import dialog box and trap to that.

 

3.png

 

 

All the same thanks very much for you snippet of code it offered a very valuable lesson on trapping to a command event.

Now I just need to find out what command I need to trap to.

 

 

 

If you have any suggestions please let me know.

 

 


 

Message 9 of 9
Jeff_M
in reply to: mfernandes

Yes, I had noticed that selecting the command from the Survey tab doesn't trigger the Command* events. I wasn't sure if you were trying to do so, or not, base don the original quesry. I have been unable to find a suitable alternative to find what has created a PG. Since the PG created by the Survey wizard uses the same name as the Inport Event, I think I'd try to find something that can compare the last import event with any newly created PG's name..but haven't had time to see if there is a way to do so.

Jeff_M, also a frequent Swamper
EESignature

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

Post to forums  

Rail Community


 

Autodesk Design & Make Report