Author Topic: Selecting the right entity.  (Read 17889 times)

0 Members and 1 Guest are viewing this topic.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Selecting the right entity.
« Reply #30 on: August 03, 2006, 11:11:56 AM »
Thanks Tony, happy to see you here, for the code and explanation.  One question I have is; Can you set .Net (C#) code up the way you can lisp?  Mean you load toolbox type codes, from one dll, and call it from another?  If so, is it the same idea as lisp, or other programming languages?

SD2 certianly does need the .NET 2.0 Framework installed.

Thanks Tim.
Thanks for the info Tim, and thanks Luis for trying.

Thanks Luis for the code also.  Something more to study.

And thanks to everyone else, for all the information stored here.  It is a lot, and feels good to start understand it.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

TonyT

  • Guest
Re: Selecting the right entity.
« Reply #31 on: August 03, 2006, 02:36:01 PM »
Thanks Tony, happy to see you here, for the code and explanation.  One question I have is; Can you set .Net (C#) code up the way you can lisp?  Mean you load toolbox type codes, from one dll, and call it from another?  If so, is it the same idea as lisp, or other programming languages?

Thanks Tim.

Yes and no :-)

You can create reusable library code in .NET, but it must be
wrapped in a class and accessed via the class. In other words
there are no 'global' variables or functions like in LISP.

There are 'global' objects, which can have methods (both
static and instance), and you can access those methods
from another assembly. To do that, you reference the
assembly that contains your objects, and then you can
call the methods of the object from code in the referencing
assembly.

However, if you're just learning the basics of .NET and OOP,
I would consider putting this aside until you first have a
good grasp of the basic principles of OOP, as this is the
most radical difference between .NET and LISP or VBA.

In other words, until you're able to develop working code
that can do something useful, you should probably keep
all of it in a single assembly :-)

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Selecting the right entity.
« Reply #32 on: August 03, 2006, 02:58:28 PM »
Thanks Tony.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

TonyT

  • Guest
Re: Selecting the right entity.
« Reply #33 on: August 04, 2006, 04:10:08 PM »
Thank you and welcome Tony;

Well since I am starting playing with C# (and do not have installed the IDE here at home), I have a question how the nested object is selected? or it is just a code skeleton to follow? (I see there is more than one question)


Hi Luis.

I think you answered your own question.

Nested entity selection is done with the GetNestedEntity() method of the Editor.

LE

  • Guest
Re: Selecting the right entity.
« Reply #34 on: August 04, 2006, 04:50:18 PM »
Nested entity selection is done with the GetNestedEntity() method of the Editor.

Got it, thanks Tony.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Selecting the right entity.
« Reply #35 on: August 05, 2006, 05:17:10 AM »

;; Excerpt from http://www.caddzone.com/MTextFragmentSample.cs

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);
      }
   }
}

Nice construct .. I blinked when I first saw  while( true ) 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.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Selecting the right entity.
« Reply #36 on: August 05, 2006, 02:48:55 PM »

;; Excerpt from http://www.caddzone.com/MTextFragmentSample.cs

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);
      }
   }
}

Nice construct .. I blinked when I first saw  while( true ) though :-)
I still blink, but hopefully soon I will understand why.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Selecting the right entity.
« Reply #37 on: August 05, 2006, 05:01:06 PM »
Hi Tim,

The while (true)  would appear to run forever.  .. but the two return options are the escape routes.

... while is more usually seen with a more conventional conditional.
This is a nice way to handle a "keep asking untill one of several conditions are met" situation.
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.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Selecting the right entity.
« Reply #38 on: August 06, 2006, 03:07:01 PM »
Hi Tim,

The while (true)  would appear to run forever.  .. but the two return options are the escape routes.

... while is more usually seen with a more conventional conditional.
This is a nice way to handle a "keep asking untill one of several conditions are met" situation.
Thanks Kerry.  I think it threw me because it is different from lisp, but with this explaination, I think I'm closer to understand it.  I haven't looked to hard at it yet, just because I don't know enough of the lanague yet.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

TonyT

  • Guest
Re: Selecting the right entity.
« Reply #39 on: August 06, 2006, 10:57:56 PM »

;; Excerpt from http://www.caddzone.com/MTextFragmentSample.cs

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);
      }
   }
}

Nice construct .. I blinked when I first saw  while( true ) though :-)
I still blink, but hopefully soon I will understand why.

Hi Tim.  The while( true ) {...} business might cause a LISP programmer to blink since LISP (or at least the dialect we use) has no control-transfer 'statements' other than (exit), which takes you to the end of your program (that is, unless you handle it with vl-catch-xxxxx functions).

In most imperative languages, there are a number of control transfer statements (e.g., 'return'; 'break' and (gasp) 'GOTO' are found C, C# and C++), and additionally 'Exit <control_loop_statement>' in VB, like 'Exit For'.

These statements allow you to exit a loop from any point within it, without the need for a potentially complex (and IMHO, confusing) looping condition, like we often see in LISP.

Let us know when you start scratching your head over try/catch/finallly :-)

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Selecting the right entity.
« Reply #40 on: August 07, 2006, 11:17:10 AM »

;; Excerpt from http://www.caddzone.com/MTextFragmentSample.cs

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);
      }
   }
}

Nice construct .. I blinked when I first saw  while( true ) though :-)
I still blink, but hopefully soon I will understand why.

Hi Tim.  The while( true ) {...} business might cause a LISP programmer to blink since LISP (or at least the dialect we use) has no control-transfer 'statements' other than (exit), which takes you to the end of your program (that is, unless you handle it with vl-catch-xxxxx functions).

In most imperative languages, there are a number of control transfer statements (e.g., 'return'; 'break' and (gasp) 'GOTO' are found C, C# and C++), and additionally 'Exit <control_loop_statement>' in VB, like 'Exit For'.

These statements allow you to exit a loop from any point within it, without the need for a potentially complex (and IMHO, confusing) looping condition, like we often see in LISP.

Let us know when you start scratching your head over try/catch/finallly :-)

Thanks Tony.  I think I understand it a little more now.

I have also seen the 'return' statement in other's code, but haven't read up on it yet.  That one is different, but looks useful.

These answers are very good information for me to know! very helpful.  Thanks all.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

KaS

  • Guest
Re: Selecting the right entity.
« Reply #41 on: November 18, 2010, 05:39:19 PM »
... does the PromptNestedEntity class have an AddAllowedClass method ?

I'm running out the door to catch a train, so ...
If I'm reading this correctly, it does.  Hope you caught your train.  I will study this, and see if I can get it to work.  Thanks Kerry.


--- there is no AddAllowedClass method for PromptNestedEntityOptions. Is there any other way to check for a right entity selection?

Bryco

  • Water Moccasin
  • Posts: 1883
Re: Selecting the right entity.
« Reply #42 on: November 19, 2010, 07:21:27 PM »
PromptNestedEntityResult pnr=ed.GetNestedEntity("\nPick a line");
            if (pnr.Status != PromptStatus.OK) return;
            if(pnr.ObjectId.ObjectClass.DxfName!="LINE")
            {
                MessageBox.Show("Must be a line:");
                return;
            }