Author Topic: DevTV: Introductory recordings on Autodesk APIs  (Read 18203 times)

0 Members and 1 Guest are viewing this topic.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: DevTV: Introductory recordings on Autodesk APIs
« Reply #15 on: November 14, 2007, 11:55:55 PM »
Yes, It can be done ..
just a bit tricky when dealing with new concepts ..

and I don't have the time at the moment.

the real waste is that EVERYONE who wants to play with C# has to translate the code,
and that may proove a little difficult for newb's ...

Michael's use of the "P" word covers it nicely
Quote
.. professionally written C# (sample)....




kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Nathan Taylor

  • Guest
Re: DevTV: Introductory recordings on Autodesk APIs
« Reply #16 on: November 15, 2007, 01:23:17 AM »
Lucky I ignored eveyones advice on C#.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: DevTV: Introductory recordings on Autodesk APIs
« Reply #17 on: November 15, 2007, 05:24:49 AM »
Anyone .. ?
I've wittled them down from 74 to 8 to 3

Some of the fixups may be less than perfect .. I'm a little brain dead :-)

Quote
Error   4   'fullEntPath' is a 'variable' but is used like a 'method'
Quote
 ... fixed


added:
and the 2 solutions ZIP FILES REMOVED :-
« Last Edit: November 15, 2007, 09:48:51 AM by Kerry Brown »
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: DevTV: Introductory recordings on Autodesk APIs
« Reply #18 on: November 15, 2007, 05:50:33 AM »
Any VB'rs know why these warnings would be suppressed ... ( I bite my tongue)

Quote
Warning   9   '42016' is not a valid warning number   DevTvIntro
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8690
  • AKA Daniel
Re: DevTV: Introductory recordings on Autodesk APIs
« Reply #19 on: November 15, 2007, 09:10:41 AM »
Kerry, please look at this one.. don't have much time to play as I have family visiting this week

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: DevTV: Introductory recordings on Autodesk APIs
« Reply #20 on: November 15, 2007, 09:28:26 AM »
Thanks Dan .. That seems to do the trick .... I couldn't see the trees for the forest !

Haven't tested all .. but it compiles, netloads and runs 'helloworld' :-)

I'm off to bed !

ta man !
« Last Edit: November 15, 2007, 09:36:41 AM by Kerry Brown »
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Glenn R

  • Guest
Re: DevTV: Introductory recordings on Autodesk APIs
« Reply #21 on: November 15, 2007, 08:20:06 PM »
I'm sorry I missed this Kerry. I didn't realise you were posting questions about the source code.
Are you still having trouble? If so, let me know and when I get back from breakfast (I'm in Singapore at the moment) I'll have a go at rewriting it for you and anybody else.

Cheers,
Glenn.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: DevTV: Introductory recordings on Autodesk APIs
« Reply #22 on: November 15, 2007, 08:32:49 PM »
Hi Glenn,
sorry I missed the send -off !

The code Dan posted compiles, netloads and runs the simple stuff.
however,
After the Palette and addDBEvents Commands are run the TreeView is not visible on the pallete and subsequent drawing additions crash Acad.

I'm running in 3 directions at once , so if you have a moment between drinks and pestering hosties ...
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Glenn R

  • Guest
Re: DevTV: Introductory recordings on Autodesk APIs
« Reply #23 on: November 15, 2007, 08:44:25 PM »
I'm running in 3 directions at once

Neat trick ;)

I'll see what I can do...the view is quite exceptional...<wanders off>

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: DevTV: Introductory recordings on Autodesk APIs
« Reply #24 on: November 15, 2007, 08:47:35 PM »
I'm running in 3 directions at once

Kerry's a triathlete?
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: DevTV: Introductory recordings on Autodesk APIs
« Reply #25 on: November 15, 2007, 08:58:08 PM »
>>  triathlete

 :lmao:
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8690
  • AKA Daniel
Re: DevTV: Introductory recordings on Autodesk APIs
« Reply #26 on: November 15, 2007, 09:43:46 PM »
Try this one, it seems the controls didn’t get translated correctly

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: DevTV: Introductory recordings on Autodesk APIs
« Reply #27 on: November 15, 2007, 10:47:42 PM »

quick Test ... seems to hold together Dan.

I'll have a look tonight. Thanks heaps!



kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: DevTV: Introductory recordings on Autodesk APIs
« Reply #28 on: November 15, 2007, 10:59:03 PM »

I've just had one of 'those' thoughts ...

I wonder if doing the translation from VB to C# with Lutz Roeder's Reflector would be more efficient and accurate than using SharpDevelop ??

[addToListOfThingsToTest]
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

LE

  • Guest
Re: DevTV: Introductory recordings on Autodesk APIs
« Reply #29 on: November 15, 2007, 11:55:34 PM »
Do not know what of the demos you guys are using.... I download the first one on the list and opened on visual studio 2005, removed the debug to a2008, did the compile and open it using lutz reflector and getting something like:

Code: [Select]
[CommandMethod("addAnEnt")]
public void AddAnEnt()
{
    Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
    PromptKeywordOptions getWhichEntityOptions = new PromptKeywordOptions("Which entity do you want to create? [Circle/Block] : ", "Circle Block");
    PromptResult getWhichEntityResult = ed.GetKeywords(getWhichEntityOptions);
    if (getWhichEntityResult.Status == PromptStatus.OK)
    {
        switch (getWhichEntityResult.StringResult)
        {
            case "Circle":
            {
                PromptPointOptions getPointOptions = new PromptPointOptions("Pick Center Point : ");
                PromptPointResult getPointResult = ed.GetPoint(getPointOptions);
                if (getPointResult.Status == PromptStatus.OK)
                {
                    PromptDistanceOptions getRadiusOptions = new PromptDistanceOptions("Pick Radius : ");
                    getRadiusOptions.BasePoint = getPointResult.Value;
                    getRadiusOptions.UseBasePoint = true;
                    PromptDoubleResult getRadiusResult = ed.GetDistance(getRadiusOptions);
                    if (getRadiusResult.Status == PromptStatus.OK)
                    {
                        Database dwg = ed.Document.Database;
                        Transaction trans = dwg.TransactionManager.StartTransaction();
                        try
                        {
                            Circle circle = new Circle(getPointResult.Value, Vector3d.ZAxis, getRadiusResult.Value);
                            ((BlockTableRecord) trans.GetObject(dwg.CurrentSpaceId, OpenMode.ForWrite)).AppendEntity(circle);
                            trans.AddNewlyCreatedDBObject(circle, true);
                            trans.Commit();
                        }
                        catch (Exception exception1)
                        {
                            ProjectData.SetProjectError(exception1);
                            Exception ex = exception1;
                            ed.WriteMessage("problem due to " + ex.Message);
                            ProjectData.ClearProjectError();
                        }
                        finally
                        {
                            trans.Dispose();
                        }
                    }
                }
                break;
            }
            case "Block":
            {
                PromptStringOptions blockNameOptions = new PromptStringOptions("Enter name of the Block to create : ");
                blockNameOptions.AllowSpaces = false;
                PromptResult blockNameResult = ed.GetString(blockNameOptions);
                if (blockNameResult.Status == PromptStatus.OK)
                {
                    Database dwg = ed.Document.Database;
                    Transaction trans = dwg.TransactionManager.StartTransaction();
                    try
                    {
                        BlockTableRecord newBlockDef = new BlockTableRecord();
                        newBlockDef.Name = blockNameResult.StringResult;
                        BlockTable blockTable = (BlockTable) trans.GetObject(dwg.BlockTableId, OpenMode.ForRead);
                        if (!blockTable.Has(blockNameResult.StringResult))
                        {
                            blockTable.UpgradeOpen();
                            blockTable.Add(newBlockDef);
                            trans.AddNewlyCreatedDBObject(newBlockDef, true);
                        }
                        Point3d VB$t_struct$S0 = new Point3d(0.0, 0.0, 0.0);
                        Circle circle1 = new Circle(VB$t_struct$S0, Vector3d.ZAxis, 10.0);
                        VB$t_struct$S0 = new Point3d(20.0, 10.0, 0.0);
                        Circle circle2 = new Circle(VB$t_struct$S0, Vector3d.ZAxis, 10.0);
                        VB$t_struct$S0 = new Point3d(40.0, 20.0, 0.0);
                        Circle circle3 = new Circle(VB$t_struct$S0, Vector3d.ZAxis, 10.0);
                        VB$t_struct$S0 = new Point3d(60.0, 30.0, 0.0);
                        Circle circle4 = new Circle(VB$t_struct$S0, Vector3d.ZAxis, 10.0);
                        VB$t_struct$S0 = new Point3d(80.0, 40.0, 0.0);
                        Circle circle5 = new Circle(VB$t_struct$S0, Vector3d.ZAxis, 10.0);
                        newBlockDef.AppendEntity(circle1);
                        newBlockDef.AppendEntity(circle2);
                        newBlockDef.AppendEntity(circle3);
                        newBlockDef.AppendEntity(circle4);
                        newBlockDef.AppendEntity(circle5);
                        trans.AddNewlyCreatedDBObject(circle1, true);
                        trans.AddNewlyCreatedDBObject(circle2, true);
                        trans.AddNewlyCreatedDBObject(circle3, true);
                        trans.AddNewlyCreatedDBObject(circle4, true);
                        trans.AddNewlyCreatedDBObject(circle5, true);
                        PromptPointOptions blockRefPointOptions = new PromptPointOptions("Pick insertion point of Block : ");
                        PromptPointResult blockRefPointResult = ed.GetPoint(blockRefPointOptions);
                        if (blockRefPointResult.Status != PromptStatus.OK)
                        {
                            trans.Dispose();
                        }
                        else
                        {
                            BlockReference blockRef = new BlockReference(blockRefPointResult.Value, newBlockDef.ObjectId);
                            ((BlockTableRecord) trans.GetObject(dwg.CurrentSpaceId, OpenMode.ForWrite)).AppendEntity(blockRef);
                            trans.AddNewlyCreatedDBObject(blockRef, true);
                            trans.Commit();
                        }
                    }
                    catch (Exception exception2)
                    {
                        ProjectData.SetProjectError(exception2);
                        Exception ex = exception2;
                        ed.WriteMessage("a problem occured because " + ex.Message);
                        ProjectData.ClearProjectError();
                    }
                    finally
                    {
                        trans.Dispose();
                    }
                }
                break;
            }
        }
    }
}

[CommandMethod("addData")]
public void addData()
{
    Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
    PromptEntityResult getEntityResult = ed.GetEntity("Pick an entity to add an Extension Dictionary to : ");
    if (getEntityResult.Status == PromptStatus.OK)
    {
        Transaction trans = ed.Document.Database.TransactionManager.StartTransaction();
        try
        {
            Entity ent = (Entity) trans.GetObject(getEntityResult.ObjectId, OpenMode.ForRead);
            if (ent.ExtensionDictionary.IsNull)
            {
                ent.UpgradeOpen();
                ent.CreateExtensionDictionary();
            }
            DBDictionary extensionDict = (DBDictionary) trans.GetObject(ent.ExtensionDictionary, OpenMode.ForRead);
            try
            {
                ObjectId entryId = extensionDict.GetAt("MyData");
                ed.WriteMessage("\nThis entity already has data...");
                Xrecord myXrecord = (Xrecord) trans.GetObject(entryId, OpenMode.ForRead);
                foreach (TypedValue value in myXrecord.Data)
                {
                    ed.WriteMessage("\n" + value.TypeCode.ToString() + " . " + value.Value.ToString());
                }
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                extensionDict.UpgradeOpen();
                Xrecord myXrecord = new Xrecord();
                TypedValue[] VB$t_array$S0 = new TypedValue[5];
                TypedValue VB$t_struct$S1 = new TypedValue(70, 1);
                VB$t_array$S0[0] = VB$t_struct$S1;
                TypedValue VB$t_struct$S2 = new TypedValue(1, "MyStockData");
                VB$t_array$S0[1] = VB$t_struct$S2;
                TypedValue VB$t_struct$S3 = new TypedValue(40, 51.9);
                VB$t_array$S0[2] = VB$t_struct$S3;
                TypedValue VB$t_struct$S4 = new TypedValue(40, 100.0);
                VB$t_array$S0[3] = VB$t_struct$S4;
                TypedValue VB$t_struct$S5 = new TypedValue(40, 320.6);
                VB$t_array$S0[4] = VB$t_struct$S5;
                ResultBuffer data = new ResultBuffer(VB$t_array$S0);
                myXrecord.Data = data;
                extensionDict.SetAt("MyData", myXrecord);
                trans.AddNewlyCreatedDBObject(myXrecord, true);
                if (this.myPalette != null)
                {
                    try
                    {
                        foreach (TreeNode node in this.myPalette.TreeView1.Nodes)
                        {
                            if (Operators.ConditionalCompareObjectEqual(node.Tag, ent.ObjectId.ToString(), false))
                            {
                                TreeNode childNode = node.Nodes.Add("Extension Dictionary");
                                foreach (TypedValue value in myXrecord.Data)
                                {
                                    childNode.Nodes.Add(value.ToString());
                                }
                                goto Label_0302;
                            }
                        }
                    }
                    finally
                    {
                        IEnumerator VB$t_ref$L1;
                        if (VB$t_ref$L1 is IDisposable)
                        {
                            (VB$t_ref$L1 as IDisposable).Dispose();
                        }
                    }
                }
            Label_0302:
                ProjectData.ClearProjectError();
            }
            trans.Commit();
        }
        catch (Exception exception2)
        {
            ProjectData.SetProjectError(exception2);
            Exception ex = exception2;
            ed.WriteMessage("a problem occured because " + ex.Message);
            ProjectData.ClearProjectError();
        }
        finally
        {
            trans.Dispose();
        }
    }
}

[CommandMethod("addDataToNOD")]
public void addDataToNOD()
{
    Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
    Transaction trans = ed.Document.Database.TransactionManager.StartTransaction();
    try
    {
        DBDictionary nod = (DBDictionary) trans.GetObject(ed.Document.Database.NamedObjectsDictionaryId, OpenMode.ForRead);
        try
        {
            ObjectId entryId = nod.GetAt("MyData");
            ed.WriteMessage("\nThis entity already has data...");
            Xrecord myXrecord = (Xrecord) trans.GetObject(entryId, OpenMode.ForRead);
            foreach (TypedValue value in myXrecord.Data)
            {
                ed.WriteMessage("\n" + value.TypeCode.ToString() + " . " + value.Value.ToString());
            }
        }
        catch (Exception exception1)
        {
            ProjectData.SetProjectError(exception1);
            nod.UpgradeOpen();
            Xrecord myXrecord = new Xrecord();
            TypedValue[] VB$t_array$S0 = new TypedValue[5];
            TypedValue VB$t_struct$S0 = new TypedValue(70, 1);
            VB$t_array$S0[0] = VB$t_struct$S0;
            TypedValue VB$t_struct$S1 = new TypedValue(1, "MyCompanyDefaultSettings");
            VB$t_array$S0[1] = VB$t_struct$S1;
            TypedValue VB$t_struct$S2 = new TypedValue(40, 51.9);
            VB$t_array$S0[2] = VB$t_struct$S2;
            TypedValue VB$t_struct$S3 = new TypedValue(40, 100.0);
            VB$t_array$S0[3] = VB$t_struct$S3;
            TypedValue VB$t_struct$S4 = new TypedValue(40, 320.6);
            VB$t_array$S0[4] = VB$t_struct$S4;
            ResultBuffer data = new ResultBuffer(VB$t_array$S0);
            myXrecord.Data = data;
            nod.SetAt("MyData", myXrecord);
            trans.AddNewlyCreatedDBObject(myXrecord, true);
            ProjectData.ClearProjectError();
        }
        trans.Commit();
    }
    catch (Exception exception2)
    {
        ProjectData.SetProjectError(exception2);
        Exception ex = exception2;
        ed.WriteMessage("a problem occurred because " + ex.Message);
        ProjectData.ClearProjectError();
    }
    finally
    {
        trans.Dispose();
    }
}