Hi,
Thanks for your quick reply,
Good to know that i didnt make all that code for nothing!
my addin is pretty big, but below i've pasted the code for the main class,
I mananged to get it installed on my dev pc now, and with visual studio debugger i can at least see that it loads the dll and steps into the Initialize function
but any idea why my command methods are not available?
Just saw your second post: jup that developer guide is what scared me too.... but at least it loads, so maybe there is some hocus pocus setting somewhere that makes my commands invisible?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Runtime;
using Tagit;
using Application = Autodesk.AutoCAD.ApplicationServices.Application;
[assembly: CommandClass(typeof(Program))]
[assembly: ExtensionApplication(typeof(Program))]
namespace Tagit
{
class Program : IExtensionApplication
{
public static TagitMainAutocad TagitMain;
private static Document Doc;
[CommandMethod("TTBalloon")]
public static void PlaceBalloon()
{
if (TagitMain == null)
{
if (!ActivateDocument(true))
return;
}
TagitMain.ShowPosForm();
}
[CommandMethod("TTBOM")]
public static void ShowBOMForm()
{
if (TagitMain == null)
{
if(!ActivateDocument(true))
return;
}
TagitMain.ShowForm();
}
[CommandMethod("TTADD")]
public static void CreateItem()
{
if (TagitMain == null)
{
if (!ActivateDocument(true))
return;
}
TagitMain.CurrentBOM.BOMTable.CreateItem(TagitMain);
}
[CommandMethod("TTCLEANUP")]
public static void Cleanup()
{
if (TagitMain == null)
{
if (!ActivateDocument(true))
return;
}
TagitMain.CurrentBOM.Cleanup();
}
[CommandMethod("GetRevision")]
public static void ReadRevision()
{
Doc.Editor.WriteMessage("Revision: " + TagitMain.CurrentBOM.Revision.DisplayValue + "\n\n");
}
[CommandMethod("SetRevision")]
public static void WriteRevision()
{
var res = Doc.Editor.GetString("Enter revision");
TagitMain.CurrentBOM.Revision = new Revision(res.StringResult);
}
[CommandMethod("ReadBalloons")]
public static void ReadBalloons()
{
using (var tr = new QueryTransaction(TagitMain.Database))
{
foreach (DBObject obj in tr.Find(e => e is MLeader))
{
var xdata = obj.GetXDataForApplication(TagitMainAutocad.ApplicationName);
if (xdata == null)
{
TagitMain.Editor.WriteMessage("No XDATA \n\n");
continue;
}
var array = xdata.AsArray();
TagitMain.Editor.WriteMessage("MLeader: " + array[0].Value.ToString() + ", " + array[1].Value.ToString() + ", " + array[2].Value.ToString() + "\n\n");
}
}
}
[CommandMethod("ReadItems")]
public static void ReadBOMItems()
{
foreach (var block in TagitMain.CurrentBOM.BOMTable.GetTableItems())
{
using (var trans = new QueryTransaction(TagitMain.Database))
{
string items = "";
foreach (var item in trans.GetBlockAttributes(block))
{
items += item.Key + ": " + item.Value + ", ";
}
items += "\n\n";
TagitMain.Editor.WriteMessage(items);
}
}
}
[CommandMethod("ReadXData")]
public static void ReadXData()
{
using (var trans = new QueryTransaction(TagitMain.Database))
{
foreach (
BlockReference block in
trans.Find(e => e is BlockReference && e.Name == BOMTable.TableItemBlockName))
{
var x = block.GetXDataForApplication(TagitMainAutocad.ApplicationName);
TagitMain.Editor.WriteMessage("Xdata: " + x.ToString());
}
}
}
public void Initialize()
{
Application.DocumentManager.DocumentActivated += DocumentManagerOnDocumentActivated;
Application.DocumentManager.DocumentToBeDeactivated += DocumentManagerOnDocumentToBeDeactivated;
ActivateDocument();
}
private void DocumentManagerOnDocumentToBeDeactivated(object sender, DocumentCollectionEventArgs e)
{
if (TagitMain != null)
{
using (e.Document.LockDocument())
{
ActivateDocument();
}
}
TagitMain = null;
}
public static bool ActivateDocument(bool showMessage = false)
{
var errors = TagitMainAutocad.IsValidDocument(Application.DocumentManager.MdiActiveDocument);
if (errors.Count > 0)
{
if (showMessage)
{
var message = "This document is not compatible with Tagit. Missing following elements: \n";
foreach (var error in errors)
{
message += "- " + error + "\n";
}
MessageBox.Show(message, "Tagit: Incompatible document.");
}
return false;
}
TagitMain = new TagitMainAutocad();
Doc = Application.DocumentManager.MdiActiveDocument;
TagitMain.Initialize(Doc);
return true;
}
private void DocumentManagerOnDocumentActivated(object sender, DocumentCollectionEventArgs e)
{
using (e.Document.LockDocument())
{
ActivateDocument();
}
}
public void Terminate()
{
Application.DocumentManager.DocumentActivated -= DocumentManagerOnDocumentActivated;
Application.DocumentManager.DocumentToBeDeactivated -= DocumentManagerOnDocumentToBeDeactivated;
}
}
}