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

0 Members and 1 Guest are viewing this topic.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Selecting the right entity.
« Reply #15 on: August 02, 2006, 07:08:03 PM »
SharpDevelop 1.1 

Hey Tim;

Are you not using the latest version - SharpDevelop 2.0 - with this, you can open the SDK Lab samples.... (ignore this if not apply)
I thought to use this, I needed the .Net 2.0 framwork?  If not, then I will dl it tomorrow, and start using that.
Tim

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

Please think about donating if this post helped you.

LE

  • Guest
Re: Selecting the right entity.
« Reply #16 on: August 02, 2006, 07:10:05 PM »
Nope you don't need that.... it will allow you to open .SLN (solutions as they are in VS)

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Selecting the right entity.
« Reply #17 on: August 02, 2006, 07:13:50 PM »
Nope you don't need that.... it will allow you to open .SLN (solutions as they are in VS)
OOOoooooo.... Nice!  Thanks Luis.  I will get it tomorrow then, and see what kind of trouble I can cause.  :evil:
Tim

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

Please think about donating if this post helped you.

LE

  • Guest
Re: Selecting the right entity.
« Reply #18 on: August 02, 2006, 07:15:57 PM »
I'm in the same boat .... if I can I will start posting some code here to the table.... and maybe a more mess can do more trouble then....  :oops:

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Selecting the right entity.
« Reply #19 on: August 02, 2006, 07:19:22 PM »
I'm in the same boat .... if I can I will start posting some code here to the table.... and maybe a more mess can do more trouble then....  :oops:
Then maybe we can learn from each other.  If I can post anything useful in the .Net section.  Not for a while I suspect, but will be fun to learn.  Looking forward to your future posts Luis.  :roll:
Tim

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

Please think about donating if this post helped you.

MickD

  • King Gator
  • Posts: 3636
  • (x-in)->[process]->(y-out) ... simples!
Re: Selecting the right entity.
« Reply #20 on: August 02, 2006, 07:30:58 PM »
Shorter than you thought, huh Mick?

Mick, do you understand what Kerry was talking about earlier? 

.......

Yep, what he was talking about was a type of filter for selection, to use these filters you would use the PromptXXXXXOptions classes to set these options 'if' available. I don't see the AddAllowedClass property in the PromptNestedEntityOptions so the way you are doing it is porbably the best way to go...for now.
"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

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Selecting the right entity.
« Reply #21 on: August 02, 2006, 07:36:02 PM »
Shorter than you thought, huh Mick?

Mick, do you understand what Kerry was talking about earlier? 

.......

Yep, what he was talking about was a type of filter for selection, to use these filters you would use the PromptXXXXXOptions classes to set these options 'if' available. I don't see the AddAllowedClass property in the PromptNestedEntityOptions so the way you are doing it is porbably the best way to go...for now.
Thanks Mick, I will commit this info to the grey matter.
Tim

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

Please think about donating if this post helped you.

MickD

  • King Gator
  • Posts: 3636
  • (x-in)->[process]->(y-out) ... simples!
Re: Selecting the right entity.
« Reply #22 on: August 02, 2006, 07:39:37 PM »
That's ok, but don't take my word for it, consult the doc's. While somewhere inside my grey matter it can put it together, putting it on paper isn't always so successful ;)
« Last Edit: August 02, 2006, 07:42:06 PM by MickD »
"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: Selecting the right entity.
« Reply #23 on: August 02, 2006, 09:05:38 PM »
Tim.
This was the Method I was referring to for the PromptEntityOptions Class

... looks like they are not available for the PromptNestedEntityOptions Class
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.

TonyT

  • Guest
Re: Selecting the right entity.
« Reply #24 on: August 02, 2006, 10:18:02 PM »
Tim.
This was the Method I was referring to for the PromptEntityOptions Class

... looks like they are not available for the PromptNestedEntityOptions Class

Not really a big deal. You can easily roll your own version of
what AddAllowedClass() and SetRejectMessage() does.
In fact, I did just that before R17 came along.

The code below is from MTextFragmentSample.cs available
on caddzone.com. It does essentially the same thing the
aforementioned methods do, 'cept it also automates the
generation of the 'reject message'.

Should be fairly trivial to do a variant (SelectNestedObject?)
that also supported the automated entity type validation,
with the added benefit that it works on on R16 later.

Another possible enhancement I've pondered by never
got around to doing, is to use the errno system variable
to distinguish a 'missed' pick, and retry.

The more important message here, for Tim and other
learners, is to keep in mind that the APIs and .NET
make it relatively simple to 'roll your own' reusable
solutions for common functionality needs like this.

So, don't look at what the AutoCAD API's do or do
not offer, and assume you're stuck with that and only
that.  If you keep in mind that much of the managed
ObjectARX API is actually implemented in managed
code (as opposed to native code), it becomes clear
that you can solve many problems and/or address
deficiencies in the API yourself, and do it in ways that
are highly reusable.

Code: [Select]

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


MickD

  • King Gator
  • Posts: 3636
  • (x-in)->[process]->(y-out) ... simples!
Re: Selecting the right entity.
« Reply #25 on: August 02, 2006, 11:17:15 PM »
Hi Tony, great tip and welcome aboard!
I've used something 'similar' in a very broad sense of the word (i.e., a hack) and used 'is' and such in a while loop to keep going until the right type was selected but your example is much more re-usable and concise. Definitely a keeper!
Thanks.
"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: Selecting the right entity.
« Reply #26 on: August 03, 2006, 12:19:12 AM »
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)

To compare with ObjectARX I have done in there something like this (very academic):

Code: [Select]
  static void SelectAttribute(void)
  {
  Acad::ErrorStatus es;
  ads_point ptres;
  ads_name entres;
  ads_matrix xformres;
  resbuf *refstkres = NULL;
  int ret = acedNEntSelP("\nSelect attribute: ", entres, ptres, FALSE, xformres, &refstkres);
  if (ret == RTCAN) return;
  if (ret == RTNORM)
  {
  AcDbObjectId objId;
  acdbGetObjectId (objId, entres);
  AcDbObjectPointer<AcDbEntity> pEnt(objId, AcDb::kForRead);
  if ((es = pEnt.openStatus ()) != Acad::eOk) {
  acutPrintf("\nError on open object %s", acadErrorStatusText(es));
  return;
  }
  AcDbAttribute *pAttribute = NULL;
  if (AcDbAttribute::cast(pEnt.object()))
  {
  acutPrintf("\nAttribute selected!.");
  pAttribute = static_cast<AcDbAttribute *>(pEnt.object());
  acutPrintf("\nTag %s", pAttribute->tag());
  acutPrintf("\nValue %s", pAttribute->textString());
  }
  }
  }

And have seen a nest selection done in C# with some code like the following:

Code: [Select]
    AcDb.Database db = AcAp.Application.DocumentManager.MdiActiveDocument.Database;
    AcEd.Editor ed = AcAp.Application.DocumentManager.MdiActiveDocument.Editor;
    AcEd.PromptEntityOptions entOpts = new AcEd.PromptEntityOptions("\nMy Selection:");
    AcEd.PromptEntityResult entRes ;
    AcDb.TransactionManager tm = db.TransactionManager;
    while (true) {
        using (AcDb.Transaction tr = tm.StartTransaction()) {
            AcDb.ObjectId objId;
            entRes = ed.GetEntity(entOpts);
            if (entRes.Status != AcEd.PromptStatus.OK) break;
            objId = entRes.ObjectId;
            AcEd.PromptNestedEntityOptions neOpts = new AcEd.PromptNestedEntityOptions("");
            neOpts.UseNonInteractivePickPoint = true;
            neOpts.NonInteractivePickPoint = entRes.PickedPoint;
            AcEd.PromptNestedEntityResult neRes = ed.GetNestedEntity(neOpts);
            if (neRes.Status == AcEd.PromptStatus.OK) objId = neRes.ObjectId;
            AcDb.Entity ent = (AcDb.Entity)tm.GetObject(objId, AcDb.OpenMode.ForRead);
            ed.WriteMessage("\n" + ent.ToString());
            tr.Commit();
        }
    }

Thanks.
« Last Edit: August 03, 2006, 11:16:53 AM by LE »

TR

  • Guest
Re: Selecting the right entity.
« Reply #27 on: August 03, 2006, 01:07:56 AM »
Nope you don't need that.... it will allow you to open .SLN (solutions as they are in VS)
SD2 certianly does need the .NET 2.0 Framework installed. From http://www.icsharpcode.net/OpenSource/SD/Download/
Quote
Notes

    * You need to have at least the .NET 2.0 runtime installed on your machine. The SDK is optional but recommended.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Selecting the right entity.
« Reply #28 on: August 03, 2006, 08:44:54 AM »
.....................  it becomes clear
that you can solve many problems and/or address
deficiencies in the API yourself, and do it in ways that
are highly reusable.

Thanks for your insight Tony.
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: Selecting the right entity.
« Reply #29 on: August 03, 2006, 09:19:19 AM »
SD2 certianly does need the .NET 2.0 Framework installed.

Thanks Tim.