Author Topic: Programming Fairies needed  (Read 10831 times)

0 Members and 1 Guest are viewing this topic.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Programming Fairies needed
« on: April 19, 2007, 07:03:51 AM »
A couple of centuries ago, when I was on the board, we used to leave biccies out at night for the drafting fairies in the hope that they'd finish our drawings ... or at least not change dimension on the tracing left on the board.

I'm sort of hoping the programming fairies see this ...

Getting the Dimension Text value requires a bit of hoop jumping in Lisp .. I think I've posted a couple of examples here. The process requires diving into nested DXF definitions.

Has anyone played with extracting the actual TextValue from dimensions in the Net API or ObjectARX.

Here's why ..

Code: [Select]
[CommandMethod("SANNO_1")]
public void SelectAnnotation()
{
    Document doc = AcadApp.DocumentManager.MdiActiveDocument;
    Database db = doc.Database;
    Editor ed = doc.Editor;
    PromptSelectionOptions selectionOptions = new PromptSelectionOptions();
    TypedValue[] filterList = { new TypedValue((int)DxfCode.Start, "MText,Text,Dimension") };
    SelectionFilter filter = new SelectionFilter(filterList);
    PromptSelectionResult selectionResult = ed.GetSelection(selectionOptions, filter);

    //Do nothing if selection is unsuccessful
    if (selectionResult.Status != PromptStatus.OK)
        return;
    using (Transaction tr = db.TransactionManager.StartTransaction())
    {
        try
        {
            ObjectId[] objIds = selectionResult.Value.GetObjectIds();
            foreach (ObjectId objId in objIds)
            {
                DBObject dbObj = (DBObject)tr.GetObject(objId, OpenMode.ForRead);
                string typeName = dbObj.GetType().Name; // temp for testing
                string textValue;
                ed.WriteMessage("\nDBObject.GetType() : "
                                + dbObj.GetType());
                switch (dbObj.GetType().Name)
                {
                    case "MText":
                        // probably should use ExplodeFragments here !!
                        // with MTextFragmentCallback
                        MText mText = (MText)dbObj;
                        textValue = mText.Text;
                        ed.WriteMessage("\nWe have Mtext:- Text Property = "
                                        + textValue);
                        break;
                    case "DBText":                               
                        DBText dText = (DBText)dbObj;
                        textValue = dText.TextString;
                        ed.WriteMessage("\nWe selected Text:- TextString Property = "
                                        + textValue);
                        break;
                     case "AlignedDimension":                             
                     case "RotatedDimension":
                     case "ArcDimension":                               
                        Dimension dimObj = (Dimension)dbObj;
                        // THIS NEEDS TO BE RESOLVED ..LEAVE FOR THE PROGRAMMING FAIRIES.
                        textValue = dimObj.DimensionText;
                        ed.WriteMessage("\nWe selected a Dimension :- DimensionText = "
                                        + textValue);
                        break;                               
                }
            }
        }
        catch (Autodesk.AutoCAD.Runtime.Exception ex)
        {
            ed.WriteMessage(ex.Message);
            tr.Abort();
        }
    }
}


.. and the obligatory piccy.


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.

Chuck Gabriel

  • Guest
Re: Programming Fairies needed
« Reply #1 on: April 19, 2007, 08:04:38 AM »
This is C++, but I think you'll get the drift:

Code: [Select]
if(acdbOpenObject(pDim, objId, AcDb::kForWrite) == Acad::eOk) {
char* pszDimText = pDim->dimensionText();
string dimText(pszDimText);
delete[] pszDimText;
pszDimText = NULL;
if(dimText.length() > 0) {
stackText(dimText);
pDim->setDimensionText(dimText.c_str());
}
else {
dimText = textFromMeasurement(pDim);
stackText(dimText);
pDim->setDimensionText(dimText.c_str());
}
pDim->close();
}

Code: [Select]
string textFromMeasurement(AcDbDimension* pDim) {
double dblMeasurement = 0;
pDim->measurement(dblMeasurement);
char* pszDimText = new char[26];
acdbRToS(dblMeasurement,
curDoc()->database()->dimlunit(),
curDoc()->database()->dimdec(),
pszDimText);
string retVal(pszDimText);
delete[] pszDimText;
pszDimText = NULL;
return retVal;
}

Draftek

  • Guest
Re: Programming Fairies needed
« Reply #2 on: April 19, 2007, 08:11:24 AM »
hmmm... That's odd because -
Here is something I used nested in a loop that works okay from a selection set:

Code: [Select]
Dimension oDim = (Dimension)trans.GetObject(oSS[i].ObjectId, OpenMode.ForWrite);
double dVal = oDim.Measurement;
string iValue = Math.Round(dVal, 4).ToString();
// convert to milimeters and then round to 2 decimal places
dVal = Math.Round(oCon.InchToMM(dVal), 2);
ModifyBlockAtt(oDim.DimensionText, dVal.ToString(), iValue);

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Programming Fairies needed
« Reply #3 on: April 19, 2007, 08:14:59 AM »
This is C++, but I think you'll get the drift:

Code: [Select]
...............


So you basically reconstruct it from the Measurement Property and dimVars Chuck, yes ?
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.

Chuck Gabriel

  • Guest
Re: Programming Fairies needed
« Reply #4 on: April 19, 2007, 08:17:25 AM »
This is C++, but I think you'll get the drift:

Code: [Select]
...............


So you basically reconstruct it from the Measurement Property and dimVars Chuck, yes ?

Yes sir!  IIRC, if there is no override text, DimensionText returns a null string and you have to derive the dimension text from the measurement value.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Programming Fairies needed
« Reply #5 on: April 19, 2007, 08:17:44 AM »
This is how I do it in Lisp
Code - Auto/Visual Lisp: [Select]
  1. ;;;------------------------------------------------------------------
  2. ;;;------------------------------------------------------------------
  3. ;;;
  4. (defun KDUB:getdimensiontext (DimEnt / anon_block nested_ent returnval)
  5.   (if (and (or (= (type DimEnt) 'ENAME) (setq DimEnt (vlax-vla-object->ename DimEnt)))
  6.            (setq dent (entget DimEnt '("*")))
  7.            (= "DIMENSION" (cdr (assoc 0 dent)))
  8.            (setq anon_block (cdr (assoc 2 dent)))
  9.            (setq nested_ent (cdr (assoc -2 (tblsearch "BLOCK" anon_block 0))))
  10.       )
  11.     (while (and (not returnval) (setq nested_ent (entnext nested_ent)))
  12.       (if (= "MTEXT" (cdr (assoc 0 (entget nested_ent))))
  13.         (setq returnval nested_ent)
  14.       )
  15.     )
  16.   )
  17.   ;; Return the Mtext Object
  18.   returnval
  19. )
« Last Edit: March 23, 2012, 06:07:37 PM by Kerry »
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: Programming Fairies needed
« Reply #6 on: April 19, 2007, 08:19:53 AM »

DrafteK, you reconstruct yours too .. yes ?
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: Programming Fairies needed
« Reply #7 on: April 19, 2007, 08:48:14 AM »
Just had a look .. looks like all the DimVAr properties are stored with the Dimension.

So shouldn't be too hard to reconstruct the DimensionText Value .. sort of ..
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: Programming Fairies needed
« Reply #8 on: April 19, 2007, 01:30:30 PM »
Haber maestro Kerry, ve si esto te puede servir:

Code: [Select]
[CommandMethod("DIMMTEXT")]
public void dimmtext()
{
    Document doc = acadApp.DocumentManager.MdiActiveDocument;
    Editor ed = doc.Editor;
    Database db = doc.Database;
    PromptEntityResult res = ed.GetEntity("\nSelect dimension: ");
    if (res.Status != PromptStatus.OK) return;
    using (Transaction tr = db.TransactionManager.StartTransaction())
    {
        Dimension dim = tr.GetObject(res.ObjectId, OpenMode.ForRead, false) as Dimension;
        if (dim != null)
        {
            ed.WriteMessage(dim.GetType().Name); //test

            String str = dim.DimensionText;
            if (str == "")
            {
                str = Math.Round(dim.Measurement, dim.Dimtdec).ToString();
            }
            else if (str.Contains("<>"))
            {
                str = Math.Round(dim.Measurement, dim.Dimtdec).ToString();
                str = "Has been overridden<> Measurement=" + str;
            }

            //if (dim.GetType().Name.Contains("LineAngularDimension2")) // no workie
            //{
            //    double d = Math.Round(dim.Measurement, dim.Dimtdec);
            //    double ang = d / Math.PI * 180.0;
            //    ed.WriteMessage(Converter.AngleToString(ang));
            //    //ed.WriteMessage("\n", Converter.AngleToString(d, AngularUnitFormat.Grads, -1));
            //}

            ed.WriteMessage("\nDimension text [{0}]", str);
        }
        tr.Commit();
    }
}

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Programming Fairies needed
« Reply #9 on: April 20, 2007, 08:50:55 AM »
I'm reviewing the way I've done the case selection.

Currently I'm using a string (the Class Type) to test against
ie:
Code: [Select]
                switch (dbObj.GetType().Name)
                {
                    case "MText":
                     //............

I have it in my mind that the Entity types are enumerated somewhere, but can't find it.

Anyone have any ideas, or a suggestion for more economical way to test other than using strings.



ps: thanks to the sprites who have responded so far.. :-)
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.

Bryco

  • Water Moccasin
  • Posts: 1883
Re: Programming Fairies needed
« Reply #10 on: April 20, 2007, 09:25:34 AM »
Kerry, is there any way to find the name of the dim block?

Glenn R

  • Guest
Re: Programming Fairies needed
« Reply #11 on: April 20, 2007, 09:31:03 AM »
if(dimObj.GetType() == typeof(Dimension))
  // Do something interesting here with a dimension

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Programming Fairies needed
« Reply #12 on: April 20, 2007, 09:32:05 AM »
I'm going to have a look over the weekend Bryco ... unless someone who knows pops is and shouts beforehand.
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: Programming Fairies needed
« Reply #13 on: April 20, 2007, 10:11:07 AM »
if(dimObj.GetType() == typeof(Dimension))
  // Do something interesting here with a dimension

Um... don't you mean:

  if( dimObj is Dimension )

Dimension is an abstract class, and the base
class of all concrete dimension classes, but
the expression:

     obj.GetType() == typeof( Dimension )

is true only if obj is an instance of a Dimension,
but false if it is an insance of a class derived
from same.

So, to tell if a given object is an instance of
any class derived from Dimension, you woud
need to use

    if( obj is Dimension )

« Last Edit: April 20, 2007, 03:51:40 PM by TonyT »

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Programming Fairies needed
« Reply #14 on: April 20, 2007, 09:43:39 PM »
DUH !!
I'm going to have a look over the weekend Bryco ... unless someone who knows pops is and shouts beforehand.
As usual, the trick is  RTFM

Quote
DBObject.GetType() : Autodesk.AutoCAD.DatabaseServices.MText
Text Property = Hello Mtext World

DBObject.GetType() : Autodesk.AutoCAD.DatabaseServices.ArcDimension
DimensionText = 1045 , Measurement = 1045.02008357775

DBObject.GetType() : Autodesk.AutoCAD.DatabaseServices.AlignedDimension
DimensionText = 566 , Measurement = 566.212198720329

DBObject.GetType() : Autodesk.AutoCAD.DatabaseServices.RotatedDimension
DimensionText = 676 , Measurement = 676.204852354089

DBObject.GetType() : Autodesk.AutoCAD.DatabaseServices.MText
Text Property = Hello Mtext World

DBObject.GetType() : Autodesk.AutoCAD.DatabaseServices.DBText
We selected Text:- TextString Property = Hello Text World

DBObject.GetType() : Autodesk.AutoCAD.DatabaseServices.RotatedDimension
DimensionText = 1338 , Measurement = 1338.13021112601

DBObject.GetType() : Autodesk.AutoCAD.DatabaseServices.RotatedDimension
DimensionText = 457 , Measurement = 456.727064654551
« Last Edit: April 20, 2007, 10:18:15 PM 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: Programming Fairies needed
« Reply #15 on: April 20, 2007, 10:09:03 PM »
I'll update later  ... but in the meantime ;

Code: [Select]
string textValue = dimObj.FormatMeasurement(dimObj.Measurement, "");
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: Programming Fairies needed
« Reply #16 on: April 20, 2007, 10:51:49 PM »
Still need some work, but ....
Code - C#: [Select]
  1. // codehimbelonga kwb@theSwamp:20070421
  2.  
  3. [CommandMethod("SUNNY_1")]
  4. public void SelectAnnotation()
  5. {
  6.     Document doc = AcadApp.DocumentManager.MdiActiveDocument;
  7.     Database db = doc.Database;
  8.     Editor ed = doc.Editor;
  9.     PromptSelectionOptions selectionOptions = new PromptSelectionOptions();
  10.     TypedValue[] filterList =   { new TypedValue((int)DxfCode.Start, "MText,Text,Dimension") };
  11.     SelectionFilter filter = new SelectionFilter(filterList);
  12.     PromptSelectionResult selectionResult = ed.GetSelection(selectionOptions, filter);
  13.  
  14.     //Do nothing if     selection is unsuccessful
  15.     if (selectionResult.Status != PromptStatus.OK)
  16.         return;
  17.     using (Transaction tr = db.TransactionManager.StartTransaction())
  18.     {
  19.         try
  20.         {
  21.             ObjectId[] objIds = selectionResult.Value.GetObjectIds();
  22.             string textValue;
  23.             foreach (ObjectId objId in objIds)
  24.             {
  25.                 Entity ent = tr.GetObject(objId, OpenMode.ForRead) as Entity ;
  26.                 if (ent == null) return;
  27.  
  28.                 ed.WriteMessage("\nDBObject.GetType() : " + ent.GetType().Name);                        
  29.                 switch (ent.GetType().Name)
  30.                 {
  31.                     case "MText":                            
  32.                         // probably should use ExplodeFragments here !!
  33.                         // with MTextFragmentCallback
  34.                         MText mText = (MText)ent;
  35.                         textValue = mText.Text;
  36.                         ed.WriteMessage("\n Text Property = "
  37.                                         + textValue);
  38.                         break;
  39.                     case "DBText":                            
  40.                         DBText dText = (DBText)ent;
  41.                         textValue = dText.TextString;
  42.                         ed.WriteMessage("\n TextString Property = "
  43.                                         + textValue);
  44.                         break;
  45.                     case "AlignedDimension":
  46.                     case "RotatedDimension":
  47.                     case "ArcDimension":
  48.                         Dimension dimObj = (Dimension)ent;                                
  49.                         if (dimObj.DimensionText.Length > 0)
  50.                             textValue = dimObj.DimensionText;
  51.                         else                                                              
  52.                             textValue = dimObj.FormatMeasurement(dimObj.Measurement, "");
  53.  
  54.                         ed.WriteMessage("\n DimensionText = "
  55.                                         + textValue
  56.                                         + " , Measurement = "
  57.                                         + dimObj.Measurement
  58.                                         );
  59.                         break;
  60.                 }
  61.             }
  62.         }
  63.         catch (Autodesk.AutoCAD.Runtime.Exception ex)
  64.         {
  65.             ed.WriteMessage(ex.Message);
  66.             tr.Abort();
  67.         }
  68.     }
  69. }

... and the piccy;
« Last Edit: March 23, 2012, 06:06:41 PM by Kerry »
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.

Bryco

  • Water Moccasin
  • Posts: 1883
Re: Programming Fairies needed
« Reply #17 on: April 20, 2007, 11:54:03 PM »
Kerry that is looking good but some pretty hard yacker to get what you need, I have to agree with the bloke who said net was for professions. If I get there  it will be only be by following in someones footsteps. Lucky there's some big feet in the swamp.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Programming Fairies needed
« Reply #18 on: April 21, 2007, 12:01:35 AM »
Bryco, I have clodhoppers, but not "big feet" :-)

Due to the nature and age of the beast there is not yet a lot of good sample stuff around .. most of it is hacked like this is.

Hopefully people here will continue/start posting their discoveries and assist in helping us ALL grow.

This particular code is perhaps more expansive than it needs to be just to show the dimension bits.

be well
and thanks for the comments.



added ps:
I'm looking forward to CharlesAlanB. to start with the C# stuff ...
with his sense of adventure and tenacity it should be fun.



« Last Edit: April 21, 2007, 12:57:08 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: Programming Fairies needed
« Reply #19 on: April 21, 2007, 12:51:37 AM »
.. this was where I was heading,  .. still pretty primitive though ..
Code - Auto/Visual Lisp: [Select]
  1. // codehimbelonga kwb@theSwamp:20070421
  2.  
  3. [CommandMethod("SUNNY_2")]
  4. public void SelectAnnotation2()
  5. {
  6.     Document doc = AcadApp.DocumentManager.MdiActiveDocument;
  7.     Database db = doc.Database;
  8.     Editor ed = doc.Editor;
  9.     PromptSelectionOptions selectionOptions = new PromptSelectionOptions();
  10.     TypedValue[] filterList =   { new TypedValue((int)DxfCode.Start, "MText,Text,Dimension") };
  11.     SelectionFilter filter = new SelectionFilter(filterList);
  12.     PromptSelectionResult selectionResult = ed.GetSelection(selectionOptions, filter);
  13.  
  14.     //Do nothing if     selection is unsuccessful
  15.     if (selectionResult.Status != PromptStatus.OK)
  16.         return;
  17.  
  18.     List<Double> numValues = new List<Double>();
  19.     string textValue;
  20.     double numValue = 0.0;
  21.     using (Transaction tr = db.TransactionManager.StartTransaction())
  22.     {
  23.         try
  24.         {
  25.             ObjectId[] objIds = selectionResult.Value.GetObjectIds();
  26.  
  27.             foreach (ObjectId objId in objIds)
  28.             {
  29.                 Entity ent = tr.GetObject(objId, OpenMode.ForRead) as Entity;
  30.                 if (ent == null) return;
  31.  
  32.                 ed.WriteMessage("\nEntity.GetType() : " + ent.GetType().Name);
  33.                 switch (ent.GetType().Name)
  34.                 {
  35.                     case "MText":
  36.                         // probably should use ExplodeFragments here !!
  37.                         // with MTextFragmentCallback
  38.                         MText mText = (MText)ent;
  39.                         textValue = mText.Text;
  40.                         ed.WriteMessage("\n Text Property = "
  41.                                         + textValue);
  42.                         if (kdubUtils.isNumeric(textValue))
  43.                             numValues.Add(Convert.ToDouble(textValue));
  44.                         break;
  45.                     case "DBText":
  46.                         DBText dText = (DBText)ent;
  47.                         textValue = dText.TextString;
  48.                         ed.WriteMessage("\n TextString Property = "
  49.                                         + textValue);
  50.                         if (kdubUtils.isNumeric(textValue))
  51.                             numValues.Add(Convert.ToDouble(textValue));
  52.                         break;
  53.                     case "AlignedDimension":
  54.                     case "RotatedDimension":
  55.                     case "ArcDimension":
  56.                         Dimension dimObj = (Dimension)ent;
  57.                         if (dimObj.DimensionText.Length > 0)
  58.                             textValue = dimObj.DimensionText;
  59.                         else
  60.                             textValue = dimObj.FormatMeasurement(dimObj.Measurement, "");
  61.  
  62.                         ed.WriteMessage("\n DimensionText = "
  63.                                         + textValue
  64.                                         + " , Measurement = "
  65.                                         + dimObj.Measurement
  66.                                         );
  67.                         if (kdubUtils.isNumeric(textValue))
  68.                             numValues.Add(Convert.ToDouble(textValue));
  69.                         break;
  70.                 }
  71.             }
  72.             foreach (double val in numValues)
  73.             {
  74.                 numValue += val;
  75.             }
  76.             ed.WriteMessage("\n Total Value = " + numValue);
  77.         }
  78.         catch (Autodesk.AutoCAD.Runtime.Exception ex)
  79.         {
  80.             ed.WriteMessage(ex.Message);
  81.             tr.Abort();
  82.         }
  83.     }
  84. }
  85.  
Quote
>>>
Entity.GetType() : MText
 Text Property = 1338
Entity.GetType() : MText
 Text Property = 457
Entity.GetType() : MText
 Text Property = 761
Entity.GetType() : RotatedDimension
 DimensionText = 1338 , Measurement = 1338.13021112601
Entity.GetType() : RotatedDimension
 DimensionText = PREFIX 624 SUFFIX , Measurement = 624.184381557403
Total Value = 5964




« Last Edit: March 23, 2012, 06:09:40 PM by Kerry »
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: Programming Fairies needed
« Reply #20 on: April 21, 2007, 01:12:46 AM »
Um... don't you mean:

  if( dimObj is Dimension )

Possibly ;) I had typeof on the brain last night and in the cold light of day, I would probably actually use, in this case, 'as' instead...potentially one less cast.

Code: [Select]
MText mt = dbObj as MText;
If (mt != null) {
  // Got some MText - do your mojo here.
}
DBText t = dbObj as DBText;
if (t != null) {
  // Got some text - do text mojo here
}

Cheers,
Glenn.

Glenn R

  • Guest
Re: Programming Fairies needed
« Reply #21 on: April 21, 2007, 01:15:47 AM »
Kerry, that's as good as anything else - nicely done.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Programming Fairies needed
« Reply #22 on: April 21, 2007, 01:23:12 AM »
Thanks Glenn .. some of the changes you may recognise.

It's been a fun couple of days < in parts >

I've decided that I will make time to hit the API every day ... "Use it or lose it "
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: Programming Fairies needed
« Reply #23 on: April 21, 2007, 01:41:43 AM »
'As' is good, since 'is' is really just (obj as type) != null;

But I would probably just use

  if( obj is Text )
     ...
  else if( obj is MText )
     ...
  else if( obj is Dimension )
     ...
 
There's two casts for each, and its the price we pay to
have code that can deal any type of object derived from
one of those classes, such as various custom objects in
AutoCAD verticals, or newly introduced objects whose
managed classes derive from those being dealt with.

Let's say for example, in the next release of AutoCAD, or
in a vertical flavor, one or more new type(s) of dimension
objects existed, and their managed type was derived from
Dimension. The code Kerry uses would simply ignore them,
becase he is using explicit comparisons against types.

I came across something similar to this when my code was
used on ADT, and found that it was hitting numerous ADT
custom objects that were derived from Curve, and the user
was amazed at how the code was able to deal with those
objects, as well as the regular AutoCAD Curve derivatives :)


Um... don't you mean:

  if( dimObj is Dimension )

Possibly ;) I had typeof on the brain last night and in the cold light of day, I would probably actually use, in this case, 'as' instead...potentially one less cast.

Code: [Select]
MText mt = dbObj as MText;
If (mt != null) {
  // Got some MText - do your mojo here.
}
DBText t = dbObj as DBText;
if (t != null) {
  // Got some text - do text mojo here
}

Cheers,
Glenn.

Glenn R

  • Guest
Re: Programming Fairies needed
« Reply #24 on: April 21, 2007, 09:00:06 AM »
Hmmmm...agreed Tony.