Author Topic: C# & C3D  (Read 13805 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: 3637
  • (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.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: C# & C3D
« Reply #15 on: December 07, 2006, 06:17:58 PM »
Quote
filtered selection set

Tony's routine actually does a direct test for type in a generic manner.
You could use a filtered selection set .. see the Prompt.cs file in the SDK I mentioned to Luis for examples.

You'd need to know the 'type' either way though ..
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 #16 on: December 07, 2006, 06:19:52 PM »
OK you want responses no.... he he...

Here:
http://www.theswamp.org/index.php?topic=13836.msg166838#msg166838

I did a selection set with filters.....

 :lol:

MickD

  • King Gator
  • Posts: 3637
  • (x-in)->[process]->(y-out) ... simples!
Re: C# & C3D
« Reply #17 on: December 07, 2006, 06:21:16 PM »
....
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.

Yep, basically something like -

MyAeccType typeObj = tr.GetObject(res.ObjectId, OpenMode.ForRead, false) as MyAeccType;

if(null != typeObj)...you got it!
"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

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: C# & C3D
« Reply #18 on: December 07, 2006, 06:22:47 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........

Well that puts a spoke in that wheel ...

I'm working in the dark here Jeff, guessing games ...
Can you ask the powers that be ?

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 #19 on: December 07, 2006, 06:30:25 PM »
Jeff, can you get the different types from the object browser .. ?
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 #20 on: December 07, 2006, 06:42:17 PM »
Is this pointing in the correct direction ?

(while (setq ss (ssget ":S:E" '((0 . "AECC_FEATURE_LINE"))))

... from your lisp

this is bloody frustrating, I'm tempted to download and install C3D ... [*slap*]
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 #21 on: December 07, 2006, 06:44:56 PM »
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.

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Re: C# & C3D
« Reply #22 on: December 07, 2006, 06:47:42 PM »
I'm working in the dark here Jeff, guessing games ...
Can you ask the powers that be ?
Heh, me too! :-) 

I thought I was asking those in the know by posting to the C3D.customization newsgroup. 3-4 of the programmers actually do monitor that place. I'm just a bit impatient, I guess, since it was one of them that sternly suggested I take the .NET route.

Jeff, can you get the different types from the object browser .. ?
Yes, there are a bazillion of them.....and FeatureLine is not among them. This is one area that they neglected to expose to us outsiders which is why I wrote the lisp in the first place. But since these aren't exposed, I'm guessing they cannot be cast as this specific type?.?!?

Kerry, you said I'd need to know the type even if I used a filtered selection set. Are the C# SS filters not DXF based as all others I've used are? The lisp filter is just '(0 . "AECC_FEATURE_LINE")

Thanks again to all who are helping me to step off the edge.

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Re: C# & C3D
« Reply #23 on: December 07, 2006, 06:50:43 PM »
Is this pointing in the correct direction ?

(while (setq ss (ssget ":S:E" '((0 . "AECC_FEATURE_LINE"))))

... from your lisp

this is bloody frustrating, I'm tempted to download and install C3D ... [*slap*]
Yes, Kerry, that's what I'm thinking of doing.

NO! Do NOT install C3D unless you are a REAL glutton for punishment.......unless you are well versed in the Civil design world it will mostly be Ancient hieroglyphics to you. :|

LE

  • Guest
Re: C# & C3D
« Reply #24 on: December 07, 2006, 06:56:56 PM »
'(0 . "AECC_FEATURE_LINE")

Then if you go to the url link, I previously posted, just do:

Code: [Select]
    TypedValue[] filter = new TypedValue[1];
    Object obj = "AECC_FEATURE_LINE";
    filter[0] = new TypedValue(0, obj);
    SelectionFilter ssFilter = new SelectionFilter(filter);

and.... see if works...

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: C# & C3D
« Reply #25 on: December 07, 2006, 06:58:22 PM »
For some examples, Try a search here for SelectionFilter in the NET forums


DUH, too late !
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 #26 on: December 07, 2006, 07:01:21 PM »
I thought it needed a string,
ie  trying inline ...
filterlist[0] = new TypedValue(0, "AECC_FEATURE_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.

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Re: C# & C3D
« Reply #27 on: December 07, 2006, 07:10:41 PM »
Another dumb ????? is there any way to save/reload a DLL other than to quit Acad and restart first? It takes like 5 minutes to shutdown and reopen C3D on this PC, kinda takes the fun out of development......

Luis, Kerry - I'm testing the SS filter once I get back to my drawing.....(see previous paragraph)  :roll:

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Re: C# & C3D
« Reply #28 on: December 07, 2006, 07:15:24 PM »
Woo Hoo! I can select the FeatureLines AND cast them to a Curve object, which is what I needed in order to use the the Param/Point/Deriv methods.

And since I'm using this method I think I can safeley remove all the C3D references to lower the overhead.

OK, I'm off to the races....well, tortoise races I guess.

Thanks guys!

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: C# & C3D
« Reply #29 on: December 07, 2006, 07:24:51 PM »
Another dumb ????? is there any way to save/reload a DLL other than to quit Acad and restart first? It takes like 5 minutes to shutdown and reopen C3D on this PC, kinda takes the fun out of development......

Yep, it's an unavoidable pain.

When I'm testing I start AutoCAD directly from the editor IDE [ with F5 ] and have a lisp in my custom mnl load a VSDebug.lsp I wrote which will NETLoad the DLL .. Just need to add or comment out the current/past DLL address in the VSDebug.lsp

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

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: C# & C3D
« Reply #30 on: December 10, 2006, 04:59:59 AM »
I just subscribed to the C3D Groups to have a sticky-beak ...

Peter Funk, Civil 3D Product Manager from Autodesk, sure sems to be hands on. It would be great if the language customisation for Vanilla received that sort of attention.
I know this has probably been said before, but if, as stated, " most of [our] API
development efforts are focused on .NET" the  quality and scope of available documentation really needs to be addressed. 

Good fortune with your endevour Jeff ..

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.

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Re: C# & C3D
« Reply #31 on: December 10, 2006, 05:19:37 AM »
Thanks, Kerry. Your comment about the documentation is right on the money. The documents are almost too good as far as the individual properties/methods/objects are concerned....but there is little to no documentation on how to actually use them. The ActiveX API for LandDesktop, and even ADT, was relatively easy to get into. This C3D was described quite aptly by Laurie Comerford (from down your way) as :
Quote from: Laurie
For short term development in Civil 3D, the help available for VBA is so
much more extensive than for any of the .NET applications that only a
masochist or full time professional programmer would move to them yet.
..and that is from someone who codes much more than I.....

LE

  • Guest
Re: C# & C3D
« Reply #32 on: December 10, 2006, 11:45:53 AM »
Hey Jeff, glad that you now are moving into a new software language... have fun!

By the way, I never have seen any code by Laurie, where is it?


Thanks.

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Re: C# & C3D
« Reply #33 on: December 10, 2006, 03:05:10 PM »
Laurie only frequents the Civil3D and LandDesktop Autodesk forums. He works for CadApps Australia. All the code he has posted is in VBA only. I think part of his cynicism towards the .NET languages is due to his approaching retirement. :-)