Author Topic: AutoCAD DevBlog  (Read 19709 times)

0 Members and 1 Guest are viewing this topic.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: AutoCAD DevBlog
« Reply #30 on: June 13, 2012, 07:27:47 PM »

For anyone who isn't already visiting the blog regularly ..... it's becoming a good resource and well worth a regular visit.  (or subscribing to a feed :) )

Except for the horrid orange colour.
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.

BlackBox

  • King Gator
  • Posts: 3770
Re: AutoCAD DevBlog
« Reply #31 on: July 13, 2012, 10:14:00 AM »
As I learn more and more about development in .NET, I am repeatedly reminded why I love coding in LISP:

Quote from: AdnDevBlog, 2012-07-13, Getting field code from field object

Getting field code from field object

Below code shows the procedure to get the field code from text object. Code first checks whether field object is associated with text object or not using API “HasFields”. Then, uses “GetField” API of Mtext object to get the field object and shows the field code using API “GetFieldCode”.

Code - C#: [Select]
  1.  
  2.  
  3.  
  4. [CommandMethod("GetFieldcode")]
  5.  
  6. public void GetFieldcode()
  7.  
  8. {
  9.  
  10.     Document doc = Application.DocumentManager.MdiActiveDocument;
  11.  
  12.     Database db = doc.Database;
  13.  
  14.     Editor ed = doc.Editor;
  15.  
  16.  
  17.     PromptEntityOptions options =
  18.  
  19.             new PromptEntityOptions("\nSelect a Mtext object");
  20.  
  21.     options.SetRejectMessage("\nSelect Mtext object");
  22.  
  23.     options.AddAllowedClass(typeof(MText), false);
  24.  
  25.  
  26.     PromptEntityResult acSSPrompt = ed.GetEntity(options);
  27.  
  28.  
  29.     if (acSSPrompt.Status != PromptStatus.OK)
  30.  
  31.         return;
  32.  
  33.  
  34.     using (Transaction Tx = db.TransactionManager.StartTransaction())
  35.  
  36.     {
  37.  
  38.         //get the mleader
  39.  
  40.         MText mtext = Tx.GetObject(acSSPrompt.ObjectId,
  41.  
  42.                                    OpenMode.ForRead) as MText;
  43.  
  44.  
  45.         if (!mtext.HasFields)
  46.  
  47.         {
  48.  
  49.             ed.WriteMessage("\nObject does not contain fields.");
  50.  
  51.             return;
  52.  
  53.         }
  54.  
  55.  
  56.         ObjectId id = mtext.GetField("TEXT");
  57.  
  58.         Field field = Tx.GetObject(id, OpenMode.ForRead) as Field;
  59.  
  60.  
  61.         string fldCode = field.GetFieldCode(FieldCodeFlags.AddMarkers
  62.  
  63.                                          | FieldCodeFlags.FieldCode);
  64.  
  65.         ed.WriteMessage("\nField code: " + fldCode);
  66.  
  67.         Tx.Commit();
  68.  
  69.     }
  70.  
  71. }
  72.  
  73.  


... Pseudo LISP equivalent:
 
Code - Auto/Visual Lisp: [Select]
  1. (defun c:GetFieldCode (/ ss fieldCode)
  2.   (princ "\rSelect text entity to get field code: ")
  3.   (if (setq ss (ssget ":S:E" '((0 . "MTEXT,TEXT"))))
  4.     (prompt
  5.       (cond
  6.         ((wcmatch
  7.            (setq fieldCode
  8.                   (vla-fieldcode
  9.                     (vlax-ename->vla-object (ssname ss 0))))
  10.            "%*")
  11.          (strcat "\nField code: " fieldCode))
  12.         ("\n** No field code found ** "))))
  13.   (princ))
  14.  
"How we think determines what we do, and what we do determines what we get."

zoltan

  • Guest
Re: AutoCAD DevBlog
« Reply #32 on: July 13, 2012, 12:08:22 PM »
As I learn more and more about development in .NET, I am repeatedly reminded why I love coding in LISP:
...

I used to feel that way when realizing how much more code it takes to get anything done in .NET vs. Lisp, but then I came to learn how much more you can do in .NET and how elegant you can make things... and also that DCL is garbage for making a descent UI!

BlackBox

  • King Gator
  • Posts: 3770
Re: AutoCAD DevBlog
« Reply #33 on: July 13, 2012, 12:24:18 PM »
As I learn more and more about development in .NET, I am repeatedly reminded why I love coding in LISP:
...

I used to feel that way when realizing how much more code it takes to get anything done in .NET vs. Lisp,

Please don't mistake my meaning... I am still dedicated to all of my extra-curricular .NET development initiatives.  :kewl:

I only meant for, what I am considering to be a remedial task such as this, LISP to this day is superior with regard to the brevity of code required.

but then I came to learn how much more you can do in .NET and how elegant you can make things... and also that DCL is garbage for making a descent UI!

Obviously, the point is moot, were one to be developing a truly .NET worthy application (something which I have only contributed to in a small way (so far) ;-) ), from which this was one small Method (out of tens, hundreds, or even thousands given any Solution?).


... I simply appreciate more now, where I've come from, as I continue to move forward.
"How we think determines what we do, and what we do determines what we get."

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: AutoCAD DevBlog
« Reply #34 on: July 13, 2012, 01:24:12 PM »
I thaught the same when I began with .NET.
Now I'm a little more comfortable with .NET I like it more and more even I still do like LISP too.

If you're interest with concision and elegancy, using Linq and home made extension methods allows a more declarative/functional style (search for GetObjects<T> in this forum for instance).
Or jump to F#.
Speaking English as a French Frog

TheMaster

  • Guest
Re: AutoCAD DevBlog
« Reply #35 on: July 13, 2012, 03:31:43 PM »
.... (search for GetObjects<T> in this forum for instance)....

Hmmmm.

I just did that. Searching for GetObjects<T> produces no results.

Searching for 'GetObjects' (without the "<T>"), returns only your post containing the above quote. :s

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: AutoCAD DevBlog
« Reply #36 on: July 13, 2012, 04:47:18 PM »
.... (search for GetObjects<T> in this forum for instance)....

Hmmmm.

I just did that. Searching for GetObjects<T> produces no results.

Searching for 'GetObjects' (without the "<T>"), returns only your post containing the above quote. :s

There are two things at work here ... first the forum software apparently doesn't work with come characters or it treats them as some kind of code i.e. GetObjects<T> will not return anything. Removing the <T> will produce results ... which brings me to the second item. Searching from within any board or child-board only returns hits from those boards and its children. To search the entire swamp forum, you have to search from the main page.

Searching from the main page using GetObjects returns about 20 hits.
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

TheMaster

  • Guest
Re: AutoCAD DevBlog
« Reply #37 on: July 13, 2012, 05:26:43 PM »

Searching from within any board or child-board only returns hits from those boards and its children. To search the entire swamp forum, you have to search from the main page.

Searching from the main page using GetObjects returns about 20 hits.

Thanks.

The second attempt was made at the result page for the first attempt, so I would have expected it to have the same scope, but guess not.

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: AutoCAD DevBlog
« Reply #38 on: July 13, 2012, 08:39:39 PM »
.NET isn't necessary as verbose as shown in AutoCAD DevBlog...

Quote
There is no .NET API for it, but a COM API that can be used from .NET with AcSelect mode as acSelectionSetCrossingPolygon. The following sample function demonstrate it, and after an example of how use it. This code uses Late Binding, so you can use on your .NET code without need to reference Interop assemblies.
Code - vb.net: [Select]
  1. Public Shared Function selectCrossing(ByVal pline As Polyline, _
  2.                                 ByVal entitiesNames As String) _
  3.                                 As ObjectIdCollection
  4.   'This method was designed using COM/ActiveX API, but all types
  5.   'were replaced with Object, which means we're using Late Binding.
  6.   'Therefore no Interop references are needed
  7.  
  8.   'AcadApplication
  9.   Dim acadApp As Object = Application.AcadApplication
  10.   'AcadDocument
  11.   Dim acadDoc As Object = acadApp.ActiveDocument
  12.  
  13.   Dim ssetObj As Object
  14.   Dim pointsArray(0) As Double
  15.   Dim grpCode(0) As Integer
  16.   Dim grpValue(0) As Object
  17.   Dim mode As Integer
  18.  
  19.   'this selection only works with entities visible on the screen,
  20.   'so we need to extend to make sure everything is visible
  21.   'acadApp.ZoomExtends()
  22.   'acadApp.Update()
  23.  
  24.   ReDim pointsArray(pline.NumberOfVertices * 3 - 1)
  25.   For i As Integer = 0 To pline.NumberOfVertices - 1
  26.     Dim vertice As Point3d = pline.GetPoint3dAt(i)
  27.     pointsArray(i * 3 + 0) = vertice.X
  28.     pointsArray(i * 3 + 1) = vertice.Y
  29.     pointsArray(i * 3 + 2) = vertice.Z
  30.   Next
  31.  
  32.   'will store the entities inside the region
  33.   Dim objIdColl As New ObjectIdCollection
  34.  
  35.   ssetObj = acadDoc.SelectionSets.Add("TEMPSELSET1")
  36.   ssetObj.Clear()
  37.  
  38.   Dim gpCode As Int16()
  39.   ReDim gpCode(1)
  40.   gpCode(0) = 0
  41.   gpCode(1) = 10
  42.  
  43.   Dim dataValue As Object()
  44.   ReDim dataValue(0)
  45.   dataValue(0) = entitiesNames
  46.  
  47.   Dim groupCode As Object, dataCode As Object
  48.   groupCode = gpCode
  49.   dataCode = dataValue
  50.  
  51.   'these modes are definied under
  52.   'Autodesk.AutoCAD.Interop.Common.AcSelect
  53.   'but again we're not using explicit Interop references
  54.   mode = 7 'AcSelect.acSelectionSetCrossingPolygon
  55.   ssetObj.SelectByPolygon(mode, pointsArray, groupCode, dataCode)
  56.  
  57.   ' if one or more point entities in the selection area
  58.   If ssetObj.count >= 1 Then
  59.     For Each ent In ssetObj
  60.       objIdColl.Add(New ObjectId(New IntPtr(CLng(ent.ObjectID))))
  61.     Next ent
  62.   End If
  63.  
  64.   ssetObj.Delete() 'delete the temp selection set
  65.  
  66.   'acadApp.ZoomPrevious() 'restore the zoom
  67.  
  68.   Return objIdColl
  69. End Function

F# equivalent (using the .NET API which does exist)
Code - F#: [Select]
  1. let selectCrossing (pline: Polyline) (entityNames: string) =
  2.     let ed = Application.DocumentManager.MdiActiveDocument.Editor
  3.     let pointsArray = [| for i in 0 .. pline.NumberOfVertices - 1 -> pline.GetPoint3dAt(i) |]
  4.     use view = ed.GetCurrentView()
  5.     zoomExtents()
  6.     let psr = ed.SelectCrossingPolygon(
  7.                 new Point3dCollection(pointsArray),
  8.                 new SelectionFilter([| new TypedValue(0, entityNames) |]))
  9.     ed.SetCurrentView(view)
  10.     match psr.Status with
  11.     | PromptStatus.OK -> new ObjectIdCollection(psr.Value.GetObjectIds())
  12.     | _ -> new ObjectIdCollection()
Speaking English as a French Frog

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: AutoCAD DevBlog
« Reply #39 on: July 13, 2012, 09:16:23 PM »
Hmmm ..

I wonder why he used COM instead of .NET for the solution ??



and ...

'acadApp.ZoomExtends()
should be
'acadApp.ZoomExtents()
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.

n.yuan

  • Bull Frog
  • Posts: 348
Re: AutoCAD DevBlog
« Reply #40 on: July 15, 2012, 02:43:38 PM »
He (the author of the DevBlog) did not just "used COM instead of .NET for the solution", he actually claimed that "There is no .NET API for it".

That makes me wondering if he had ever done ACAD .NET API programming at the time when he wrote it. Well, he probably just post something he wrote long time ago. But, come on, if you post something, shouldn't you at least know what it is talk about. Such a obviously false claim from Autodesk side is laughstock.

I commented on that post and my comment did not live there for a few hours and gone. Someone removed my comment, and unfortunately, he forgot one thing: also removing the post altogether, which may give bad direction for someone who is new to Acad .NET API and trust the information posted in AutoCAD DevBlog.

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: AutoCAD DevBlog
« Reply #41 on: July 15, 2012, 04:08:06 PM »
My comment hasn't been censored.
Maybe they (Autodesk guys) didn't see it was ironical  :evil:
Speaking English as a French Frog

Jeff H

  • Needs a day job
  • Posts: 6144
Re: AutoCAD DevBlog
« Reply #42 on: July 16, 2012, 10:20:41 AM »
Someone removed my comment, and unfortunately, he forgot one thing: also removing the post altogether
Now it looks like he remembered
 
My comment hasn't been censored.
Maybe they (Autodesk guys) didn't see it was ironical  >:D
Now it has.
The link in your post is broken and not seeing post on DevLab

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: AutoCAD DevBlog
« Reply #43 on: July 17, 2012, 01:20:34 AM »
The Right Tools for the Job – AutoCAD Part 1
http://adndevblog.typepad.com/autocad/2012/07/the-right-tools-for-the-job-autocad-part-1.html

Quote from: by Fenton Webb
Recently, Stephen posted this great blog entry on Performance – perception versus reality and then asked me if I could tell you all the tricks I have learnt over the years to produce the fastest, leanest AutoCAD code on the planet !!
   

looking forward to this :)

added:

... just hope the intro isn't making use of poetic licence. :D

 
« Last Edit: July 17, 2012, 01:26:28 AM 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.