Author Topic: ( C3D ) Quick-change General Note and Line/Curve Label Layers  (Read 3706 times)

0 Members and 1 Guest are viewing this topic.

sinc

  • Guest
Here's a little routine that allows the user to quickly and easily change the General Note and Line/Curve Label layer.  Assign it to a keyboard shortcut (CTRL + a key) in the CUI, and it's a lot more convenient than digging in the Toolspace to change these settings.

As always, a DLL compiled for Civil-3D 2007 (which should also work with 2008, although we have not tested it) can be found on our website, along with complete source code.

Access to these items does not seem to be documented in the Civil-3D API documentation.  I discovered them by using code-completion in the C# IDE.

Code: [Select]
/*
 * Created by Richard Sincovec
 * User: Sinc
 * Date: 3/16/2007
 * Time: 6:32 PM
 *
 */

using System;
using System.Collections;
using System.Drawing;
using System.Windows.Forms;
using Autodesk.AutoCAD.ApplicationServices;
using AcadApplication = Autodesk.AutoCAD.ApplicationServices.Application;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AECC.Interop.Land;
using AutocadUtilities;
using Civil3DUtilities;

namespace Sincpac.Layer
{
/// <summary>
/// Description of LabelLayers.
/// </summary>
public partial class LabelLayers
{
public LabelLayers()
{
//
// The InitializeComponent() call is required for Windows Forms designer support.
//
InitializeComponent();
this.b_OK.Click += new System.EventHandler(this.ok_Click);
}

[CommandMethod("LABLAY")]
public void LabelLayersCommand()
{
C3DUtil c3dUtil = new C3DUtil();
Database db = AcadApplication.DocumentManager.MdiActiveDocument.Database;
using (Transaction tr = db.TransactionManager.StartTransaction()) {
ArrayList layerNames = CadUtil.GetThawedLayerNames(db, tr);
AeccSettingsObjectLayers settings = c3dUtil.AeccDb.Settings.DrawingSettings.ObjectLayerSettings;
int idxGeneral=0, idxLineCurve=0, i=0;
foreach (string s in layerNames) {
cb_GeneralNote.Items.Add(s);
if (s.Equals(settings.GeneralNoteLabelLayer.Layer))
idxGeneral=i;
cb_LineCurve.Items.Add(s);
if (s.Equals(settings.GeneralSegmentLabelLayer.Layer))
idxLineCurve=i;
++i;
}
cb_GeneralNote.SelectedIndex = idxGeneral;
cb_LineCurve.SelectedIndex = idxLineCurve;
AcadApplication.ShowModalDialog(this);
if (this.DialogResult == DialogResult.OK) {
settings.GeneralNoteLabelLayer.Layer = (string)cb_GeneralNote.SelectedItem;
settings.GeneralSegmentLabelLayer.Layer = (string)cb_LineCurve.SelectedItem;
tr.Commit();
}
else tr.Abort();
}
}

private void ok_Click(object sender, System.EventArgs e)
{
this.Close();
}
}
}

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Re: ( C3D ) Quick-change General Note and Line/Curve Label Layers
« Reply #1 on: March 17, 2007, 12:37:27 PM »
Access to these items does not seem to be documented in the Civil-3D API documentation.  I discovered them by using code-completion in the C# IDE.
Wow, you are on a roll, Sinc. :-) Looks like you are starting to like this C# & C3D programming.

But, it also looks like you need to spend some time in the civilauto help file.....The AeccSettingsObjectLayers Object is covered pretty well (as well as the current docs do, anyway).

Keep up the steady flow of quite useful routines, though. :-) Besides helping to make life easier in C3D, it's helping me to understand the C# side of coding, too. Thanks!

sinc

  • Guest
Re: ( C3D ) Quick-change General Note and Line/Curve Label Layers
« Reply #2 on: March 17, 2007, 12:59:23 PM »
But, it also looks like you need to spend some time in the civilauto help file.....The AeccSettingsObjectLayers Object is covered pretty well (as well as the current docs do, anyway).


Ah, I see it now.  I actually have spent an awful lot of time in that help file, mainly because it is so bad that everything is a puzzle that must be "figured out"...    :wink:

This is one of the many things that is missing from the overall graphic of the Object Model.  If you look at the graphic containing the class hierarchy, it gets down to the "Settings" object off of the "Document" and "Database" classes, but then it ends without showing any of the Settings content.  And the "Settings" item is one of the many broken links, so clicking on it yields an error.  It's easy to find it once you know its there, and it's possible to find it if you just start reading through all the class descriptions, but it's very difficult to find otherwise.

I'm now discovering the roundabout way that it's necessary to use this document, and now that I'm getting the hang of it, I'm finding more things hidden in it.  It is incredibly difficult to use, though.  Autodesk seriously needs to create a Civil-3D SDK with complete documentation that can be loaded into the IDE, like the ObjectARX one.  One that has some EXAMPLES, and tells you things like the Item() methods are implemented using the array syntax in C#...

Or is it just unreasonable to expect a good API for a product that is barely-functional for the daily tasks of its average users...?   :-D

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Re: ( C3D ) Quick-change General Note and Line/Curve Label Layers
« Reply #3 on: March 17, 2007, 01:21:25 PM »
Heh, I know you've spent a lot of time perusing the "help" file....that was supposed to be a quick Saturday morning attempt at a funny.....

I couldn't agree more about needing better documentation and samples. I've sent a number of emails to the documentation team about the broken links, but they remain in the new docs.

I just tested this in 2008 and it fails. I think that the Autocad specific portions are fine, but the C3D Interops have changed so they do not......here's a pic when trying to run. I'll see what I can do with the code in 2008 later today.

I'm not attaching the pic, as I'm not sure if it's acceptable to post about specifics for 2008 yet. I know that some things can be discussed, but Peter Funk (from Autodesk) hinted at the fact we couldn't talk about other code right now.

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Re: ( C3D ) Quick-change General Note and Line/Curve Label Layers
« Reply #4 on: March 17, 2007, 02:54:31 PM »
Yep, I had to remove all of the AEC/AECC references and re-add the 2008 specific references and it works fine. So unless they change something between now and the final release, you will need different versions for each C3D version.

Unless......is there a way to use Late Binding in C#? (No references used...) I know that in VBA I could write code for LDT that works in LDT3-LDT2007 without changing a thing.

sinc

  • Guest
Re: ( C3D ) Quick-change General Note and Line/Curve Label Layers
« Reply #5 on: March 20, 2007, 08:48:25 AM »
Don't know about the late binding.  I'm still pretty new to this whole C# thing, so I'll have to explore further...   :-)

The initial version of this routine had a bug, that caused the layer list to increase in size every time the command was run.  So I fixed that, and also added a way to change the Drawing Scale from this dialog.  There may be a couple more items to add, too, such as Alignment Label Layer, and then I think this quick-set dialog will contain everything I typically change in the Drawing Settings.  That means I should now rarely need to go into the full Drawing Settings dialog box.  And with it assigned to F4, it pops open much faster and easier than digging in the Prospector.

It also now serves as a somewhat more-complex example of a ComboBox.  It still needs to be fixed to work with metric, which I'll do shortly.  (Actually, it should work fine on a metric drawing, it will just still say "1 inch equals" in the dialog box.  I think that's all I need to fix, so it should be a quick fix, I hope...)

Code: [Select]
/*
 * Created by Richard Sincovec
 * User: Sinc
 * Date: 3/16/2007
 * Time: 6:32 PM
 *
 */

using System;
using System.Collections;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
using Autodesk.AutoCAD.ApplicationServices;
using AcadApplication = Autodesk.AutoCAD.ApplicationServices.Application;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AECC.Interop.Land;
using AutocadUtilities;
using Civil3DUtilities;

namespace Sincpac.Settings
{
/// <summary>
/// Started off as a quick-set for General Note and Line/Curve Label Layers.
/// Now also added Drawing Scale.  Might also add more, such as Alignment Label Layer.
/// </summary>
public partial class LabelLayers
{
private static double[] standardScales = {10,20,30,40,50,60,80,100,
120,150,200,300,400,500,1000,1500,2000,2500,3000,5000};
private List<double> scaleList = null;
public LabelLayers()
{
//
// The InitializeComponent() call is required for Windows Forms designer support.
//
InitializeComponent();
this.b_OK.Click += new System.EventHandler(this.ok_Click);
scaleList = new List<double>(standardScales);
}

[CommandMethod("LABLAY")]
public void LabelLayersCommand()
{
C3DUtil c3dUtil = new C3DUtil();
Database db = AcadApplication.DocumentManager.MdiActiveDocument.Database;
using (Transaction tr = db.TransactionManager.StartTransaction()) {
ArrayList layerNames = CadUtil.GetThawedLayerNames(db, tr);
AeccSettingsDrawing drSettings = c3dUtil.AeccDb.Settings.DrawingSettings;
AeccSettingsObjectLayers olSettings = drSettings.ObjectLayerSettings;
cb_GeneralNote.Items.Clear();
cb_LineCurve.Items.Clear();
cb_DrawingScale.Items.Clear();

int idxGeneral=0, idxLineCurve=0, i=0;
foreach (string layName in layerNames) {
cb_GeneralNote.Items.Add(layName);
if (layName.Equals(olSettings.GeneralNoteLabelLayer.Layer))
idxGeneral=i;
cb_LineCurve.Items.Add(layName);
if (layName.Equals(olSettings.GeneralSegmentLabelLayer.Layer))
idxLineCurve=i;
++i;
}
if (!cb_GeneralNote.Items.Contains(olSettings.GeneralNoteLabelLayer.Layer))
cb_GeneralNote.Items.Insert(0,olSettings.GeneralNoteLabelLayer.Layer);
cb_GeneralNote.SelectedItem = olSettings.GeneralNoteLabelLayer.Layer;
if (!cb_LineCurve.Items.Contains(olSettings.GeneralSegmentLabelLayer.Layer))
cb_LineCurve.Items.Insert(0,olSettings.GeneralSegmentLabelLayer.Layer);
cb_LineCurve.SelectedItem = olSettings.GeneralSegmentLabelLayer.Layer;

double drawingScale = drSettings.UnitZoneSettings.DrawingScale;
if (!scaleList.Contains(drawingScale)) {
scaleList.Add(drawingScale);
scaleList.Sort();
}
foreach (double scale in scaleList) {
cb_DrawingScale.Items.Add(scale.ToString());
}
cb_DrawingScale.SelectedItem = drawingScale.ToString();

AcadApplication.ShowModalDialog(this);
if (this.DialogResult == DialogResult.OK) {
olSettings.GeneralNoteLabelLayer.Layer = (string)cb_GeneralNote.SelectedItem;
olSettings.GeneralSegmentLabelLayer.Layer = (string)cb_LineCurve.SelectedItem;
drawingScale = System.Convert.ToDouble(cb_DrawingScale.Text);
if (drawingScale > 0)
drSettings.UnitZoneSettings.DrawingScale = drawingScale;
tr.Commit();
}
else tr.Abort();
}
}

private void ok_Click(object sender, System.EventArgs e)
{
this.Close();
}
}
}
« Last Edit: March 20, 2007, 08:51:41 AM by sinc »