Author Topic: C# & C3D  (Read 13788 times)

0 Members and 1 Guest are viewing this topic.

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
C# & C3D
« on: December 07, 2006, 05:34:53 PM »
OK, so I'm trying to make the plunge from my limited VBA and not so limited Lisp background into the realm of C#.....as directed by the Supreme Beings at Autodesk(East) (aka: the programmers in New Hampshire that create this stuff). So the first thing I want to do is convert my newly created Lisp routine to a C# DLL. First problem I encounter is, how in the heck to I select a FeatureLine? Searching this forum I found the thread that T. Willey started in which Tony T. posted a rather nice solution for selecting specific objects. However, I cannot figure out how I can adapt it to allow the selection of Custom Objects.....I posted this question on the Adesk C3D.customization newsgroup but have had no reponses. I'm hoping that someone here can point me in the right direction......here's the original post I made:

Quote from: Me
I know of a long way to do this, but some code I saw that Tony T. posted for
selecting specific Autocad objects sure works nice......except I can't seem
to grasp how to expand it's use with AECC objects, specifically
FeatureLines.

First, is this even possible.

Second, if it is, How?

Snip of Tony's code which works to select a line:

Code: [Select]
        [CommandMethod("Stake")]
        static public void test()
        {
            ObjectId id = SelectObject("\nSelect FeatureLine: ",
typeof(Line));
        }
        static ObjectId SelectObject(string prompt, System.Type objectClass)
        {
            Editor e = acadApp.DocumentManager.MdiActiveDocument.Editor;
            using (Transaction tr =
e.Document.Database.TransactionManager.StartTransaction())
            {
                while (true)
                {
                    PromptEntityResult res = e.GetEntity(prompt);
                    if (res.Status != PromptStatus.OK)
                        return ObjectId.Null;
                    DBObject ob = tr.GetObject(res.ObjectId,
OpenMode.ForRead);
                    if (objectClass.IsAssignableFrom(ob.GetType()))
                        return res.ObjectId;
                    e.WriteMessage("\nInvalid selection, {0} entity
expected",
                        RXClass.GetClass(objectClass).DxfName);
                }
            }
        }

Attempting to replace Line with FeatureLine does not work. Is there some
mechanism for getting the AECC object types included in the objectClass?
I've added all the C3D references specified in the Help and included these
in the code:
Code: [Select]
using acadApp = Autodesk.AutoCAD.ApplicationServices.Application;
using m_oAeccDoc = Autodesk.AECC.Interop.UiLand.IAeccDocument;
using m_oAeccDb = Autodesk.AECC.Interop.Land.IAeccDatabase;

Thanks!

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: C# & C3D
« Reply #1 on: December 07, 2006, 05:46:55 PM »
If I knew what a FeatureLine was .....

Jeff,
can you add a breakpoint in the editor< say at while (true)> , and run that <posted>code in debug mode using F11 to step through.
You may be able to determine the TYPE from the mouseover of the variable names.

just a WAG.

/// kwb
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: C# & C3D
« Reply #2 on: December 07, 2006, 05:50:30 PM »
I use something like this, but no idea about C3D

This, will select a TEXT and write the alignment value on the command line....

Code: [Select]
[CommandMethod("DBTEXT")]
        public void dbtext()
        {
            Document doc = acadApp.DocumentManager.MdiActiveDocument;
            Editor ed = doc.Editor;
            Database db = doc.Database;
            PromptEntityResult res = ed.GetEntity("\nSelect text: ");
            if (res.Status != PromptStatus.OK) return;
            using (Transaction tr =
db.TransactionManager.StartTransaction())
            {
                DBText text = tr.GetObject(res.ObjectId, OpenMode.ForRead,
false) as DBText;
                ed.WriteMessage("\nAlignment is " +
text.HorizontalMode.ToString());
                tr.Commit();
            }

        }

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: C# & C3D
« Reply #3 on: December 07, 2006, 05:54:09 PM »
Another WAG
would it be  AeccFeatureLine in place of Line
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: C# & C3D
« Reply #4 on: December 07, 2006, 05:59:50 PM »
Luis, What happens if you pick a Line with that , instead of Text .. ?

Have a look at the Prompt.cs file in the SDK for filtering options ..

regards
/// kwb
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.

MickD

  • King Gator
  • Posts: 3636
  • (x-in)->[process]->(y-out) ... simples!
Re: C# & C3D
« Reply #5 on: December 07, 2006, 06:01:51 PM »
You can use 'as' as a type of inline casting, if it fails it will be null (so it needs checking), if not you have your object already 'cast' ed and ready to use.
"Programming is really just the mundane aspect of expressing a solution to a problem."
- John Carmack

"Short cuts make long delays,' argued Pippin.”
- J.R.R. Tolkien

LE

  • Guest
Re: C# & C3D
« Reply #6 on: December 07, 2006, 06:04:41 PM »
Luis, What happens if you pick a Line with that , instead of Text .. ?

Have a look at the Prompt.cs file in the SDK for filtering options ..

regards
/// kwb

yes... will crash.... sorry, it was a quick one. (excuse 1000000213) -

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Re: C# & C3D
« Reply #7 on: December 07, 2006, 06:06:14 PM »
If I knew what a FeatureLine was .....

Jeff,
can you add a breakpoint in the editor< say at while (true)> , and run that <posted>code in debug mode using F11 to step through.
You may be able to determine the TYPE from the mouseover of the variable names.

just a WAG.

/// kwb
OK....A featureLine is a CustomObject defined by Civil3D...

Now if I could only figure out how to run in Debug mode using the VC# Express.......

Thinking more about this, it appears that ALL AECC objects use the AcadEntity class so I will need to use the "long" way of just using GetEntity, checking the DXFName, discard if not a match to FeatureLine, repeat if necessary.

More research is in order....off to the books I go.

Thanks Kerry & Luis for some ideas.

Hmmm, more posts flowing in as I type :-)

Mick, that's what Luis is doing with Text, right? Now I just need to know the proper name &/or reference I'm missing to cast as a FeatureLine.

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Re: C# & C3D
« Reply #8 on: December 07, 2006, 06:07:10 PM »
Here's a (vlax-dump-object) of a featureline:

Select object: ; IAecEntity: Common functions used by all AEC entities
; Property values:
;   Application (RO) = #<VLA-OBJECT IAcadApplication 00d088b4>
;   Description = ""
;   Document (RO) = #<VLA-OBJECT IAcadDocument 0127d248>
;   Handle (RO) = "81AB"
;   HasExtensionDictionary (RO) = 0
;   Hyperlinks (RO) = #<VLA-OBJECT IAcadHyperlinks 14349a74>
;   Layer = "C-TOPO-FEAT"
;   Linetype = "ByLayer"
;   LinetypeScale = 1.0
;   Lineweight = -1
;   Material = "ByLayer"
;   ObjectID (RO) = 2130631960
;   ObjectName (RO) = "AeccDbFeatureLine"
;   OwnerID (RO) = 2130574584
;   PlotStyleName = "ByLayer"
;   TrueColor = #<VLA-OBJECT IAcadAcCmColor 14349770>
;   Visible = -1

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: C# & C3D
« Reply #9 on: December 07, 2006, 06:08:56 PM »
 ObjectName (RO) = "AeccDbFeatureLine"
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: C# & C3D
« Reply #10 on: December 07, 2006, 06:10:57 PM »
Jeff, I'll try to get some info together to allow you to facilitate debugging in Express
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: C# & C3D
« Reply #11 on: December 07, 2006, 06:11:39 PM »
Luis, What happens if you pick a Line with that , instead of Text .. ?

Have a look at the Prompt.cs file in the SDK for filtering options ..

regards
/// kwb

yes... will crash.... sorry, it was a quick one. (excuse 1000000213) -

Actually it just requires to add:

Code: [Select]
               DBText text = tr.GetObject(res.ObjectId, OpenMode.ForRead, false) as DBText;
                if (text != null)
                {
                    ed.WriteMessage("\nAlignment is " + text.HorizontalMode.ToString());
                }

hth

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Re: C# & C3D
« Reply #12 on: December 07, 2006, 06:13:13 PM »
More thinking outloud here.....

Could I use a filtered selection set instead? I know I can filter for the featureline in lisp, so I'd guess it would be the same in C#.

And they said this would be easier than lisp.......... :lmao:


Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Re: C# & C3D
« Reply #13 on: December 07, 2006, 06:15:21 PM »
Kerry, this returned for a line:
;   ObjectName (RO) = "AcDbLine"

So how to get the System.Type objectClass to include the AeccDb objects? It already has the AcDb objects that can be referenced sans the AcDb........

LE

  • Guest
Re: C# & C3D
« Reply #14 on: December 07, 2006, 06:17:49 PM »
More thinking outloud here.....

Could I use a filtered selection set instead? I know I can filter for the featureline in lisp, so I'd guess it would be the same in C#.

And they said this would be easier than lisp.......... :lmao:



What is the filter looks like in lisp? - it is not easy - when you are not familiar - as far as I been using C# - I like it.