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: 

My code builds ok but won't load with NETLOAD

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
attilathedunne
483 Views, 3 Replies

My code builds ok but won't load with NETLOAD

Hi, I've just started trying to learn to code for Civil3D and have written a simple command to draw a different coloured circle on a surfec depending on the elevation at that point.

 

My code builds with no errors and I load it into C3D with NETLOAD with no errors but the command doesn't work and doesn't show up in the list of available commands. The last few things I've tried to write have done the same and I've no idea why.

 

Any assistance would be greatly appreciated; I'm pullijng my hair out!

 

Thanks in advance, code is below (not sure if this is the best way to add it) .......

 

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using Autodesk.AutoCAD.Runtime;

using Autodesk.AutoCAD.ApplicationServices;

using Autodesk.AutoCAD.DatabaseServices;

using Autodesk.AutoCAD.Geometry;

using Autodesk.AutoCAD.EditorInput;

using Autodesk.AutoCAD.Colors;

using Autodesk.Civil;

using Autodesk.Civil.Runtime;

using Autodesk.Civil.DatabaseServices;

using Autodesk.Civil.DatabaseServices.Styles;

using Autodesk.Civil.ApplicationServices;

using Autodesk.Civil.Settings;

namespace ElevationColours

{

publicclassCommand : IExtensionApplication

{

#region IExtensionApplication Members

publicvoid Initialize()

{

thrownew System.Exception("The method or operation is not implemented.");

}

publicvoid Terminate()

{

thrownew System.Exception("The method or operation is not implemented.");

}

#endregion

 

 

[CommandMethod("ELEVCOL")]

publicvoid ElevCol()

{

Document acdoc = Application.DocumentManager.MdiActiveDocument;

Database acdb = acdoc.Database;

CivilDocument civdoc = CivilApplication.ActiveDocument;

Editor ed = acdoc.Editor;

PromptPointOptions ppo = newPromptPointOptions("");

PromptPointResult ppr; ;

ppo.Message = ("Pick a point......");

ppr = ed.GetPoint(ppo);

Point3d point = ppr.Value;

double elev;

using (Transaction acTrans = acdoc.TransactionManager.StartTransaction())

{

BlockTable blktbl = acTrans.GetObject(acdb.BlockTableId, OpenMode.ForRead) asBlockTable;

BlockTableRecord blktblrec = acTrans.GetObject(blktbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) asBlockTableRecord;

ObjectIdCollection surfids = civdoc.GetSurfaceIds();

ObjectId surfid = surfids[0];

Autodesk.Civil.DatabaseServices.Surface surf = acTrans.GetObject(surfid, OpenMode.ForRead) as Autodesk.Civil.DatabaseServices.Surface;

elev = surf.FindElevationAtXY(point.X, point.Y);

int color = (int)elev;

Circle circ = newCircle();

circ.SetDatabaseDefaults();

circ.Center = point;

circ.Radius = 10;

circ.ColorIndex = color;

blktblrec.AppendEntity(circ);

acTrans.AddNewlyCreatedDBObject(circ, true);

acTrans.Commit();

}

}

 

}

 

}

 

 

3 REPLIES 3
Message 2 of 4

What version of C3D and .NET are you targeting?

Mike Robertson
FL. Dept. of Transportation
CADD Applications Developer
Message 3 of 4
Jeff_M
in reply to: attilathedunne


@attilathedunne wrote:

....I've no idea why.

 

Any assistance would be greatly appreciated; I'm pullijng my hair out!

 

Thanks in advance, code is below (not sure if this is the best way to add it) .......

 

 

namespace ElevationColours

{

publicclassCommand : IExtensionApplication

{

#region IExtensionApplication Members

publicvoid Initialize()

{

thrownew System.Exception("The method or operation is not implemented."); <<<<<<<<<< You are forcing an exception so it never fully loads, have it do either something or nothing.

}

publicvoid Terminate()

{

thrownew System.Exception("The method or operation is not implemented."); <<<<<<<<<< You are forcing an exception, have it do either something or nothing.

}

#endregion

 

 


 I should add that you don't need to use the IExtensionApplication unless you have code that needs to run in the Initialize process. Most of the sample & free apps I've posted here do not use it. So just this would work for your commands:

///all code prior to here OK
namespace ElevationColours
{
public class CustomCommands 
 
[CommandMethod("ELEVCOL")]
public void ElevCol()

//everything after here should be ok (not checked)

 

Jeff_M, also a frequent Swamper
EESignature
Message 4 of 4

It's C3D and .NET 4.0, sorry should have added that in the first place.

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

Post to forums  

Rail Community


 

Autodesk Design & Make Report