Jump to content

Area value from a closed polyline in to the clipboard?


tclaudiu

Recommended Posts

Hello everybody!

Is there any lisp or quick way to get the area from a closed polyline in to the clipboard memory?

I want something like this: click on a polyline and then just the press paste in another application.

 

I'm using AutoCAD Civil 3D 2010, and I disregarded the Civil functions and options from Civil (eg. parcels, styles, etc). This closed polylines are parcels (more than 400 parcels) and I have to check all their area values and paste them in to excel file. The number of the parcels are not consecutive and I didn't use excel data links, etc.

 

Thank you in advance!

Link to comment
Share on other sites

Thank you NBC for suggestion, but I need to get this area not from one step (Using Data Extraction); i have to make some adjustments in to the drawing (move text, write, rotate, etc. ) before to get the polyline area and these parcels are not correlated with the parcels from excel. These adjustment can take aprox 30 sec to 1 min. and after I finish these I have to check the parcel area in a excel "database". So it cost me some little time (aprox. 1 hour or more) to check only the areas. Until now I've used these methods:

1. click on the polyline -> hit the area field in the properties window (i have to open the Quick Calc to copy the area value :( ) -> paste the value in excel and change the dot with comma to act like a number

2. type area -> two enter -> select object -> copy from command line the area value -> paste the value in excel and change the dot with comma to act like a number

Link to comment
Share on other sites

I was looking for a lisp application or another quickly way.

Something like this:

Type the lisp command (I can use a button from AutoCAD CUI) -> select object -> and the command ends but the area value is in the clipboard and eventually convert dot (10042.34) with comma (10042,34) for excel formating cells

Thanks!

Link to comment
Share on other sites

This may be a good substitute:

 

;; Area to Excel Cell  ~  Lee McDonnell (Lee Mac)
;; Copyright © August 2009

(defun c:A2xl (/ *error* xlApp xlCells Row)
 (vl-load-com)

 (defun *error* (msg)
   (ObjRel (list xlApp xlCells))
   (if (not (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*"))
     (princ (strcat "\n** Error: " msg " **")))
   (princ))

 (setq xlApp  (vlax-get-or-create-object "Excel.Application")
       xlCells   (vlax-get-property
                   (vlax-get-property
                     (vlax-get-property
                       (vlax-invoke-method
                         (vlax-get-property xlApp 'Workbooks)
                         'Add)
                       'Sheets)
                     'Item 1)
                   'Cells)    Row 1)

 (while
   (and
     (setq ent (car (entsel "\nSelect Object: ")))
       (vlax-property-available-p
         (setq Obj
           (vlax-ename->vla-object ent)) 'Area))

   (vlax-put-property xlCells 'Item row 1
     (rtos
       (vlax-get-property Obj 'Area)))
   
   (setq Row (1+ Row)))

 (ObjRel (list xlApp xlCells))
 (gc) (gc)
 (princ))
           
(defun ObjRel (lst)
 (mapcar
   (function
     (lambda (x)
       (if (and (eq (type x) 'VLA-OBJECT)
                (not (vlax-object-released-p x)))
         (vl-catch-all-apply
           'vlax-release-object (list x))))) lst))

Link to comment
Share on other sites

Hi,

 

Attached a little DLL which defines a command: COPYAREA

Unzip CopyArea.

From AutoCAD, NETLOAD "CopyToClipBoard.dll".

Type "COPYAREA" and select a polyline, the polyline area is copy to the clipboard as a string (rounded to 2 digits).

 

The C# code:

using System;
using System.Windows.Forms;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Runtime;
using acadApp = Autodesk.AutoCAD.ApplicationServices.Application;

namespace CopyToClipboard
{
   public class PolylineArea
   {
       [CommandMethod("COPYAREA")]
       public void CopyArea()
       {
           Document doc = acadApp.DocumentManager.MdiActiveDocument;
           Editor ed = doc.Editor;
           Database db = doc.Database;
           try
           {
               PromptEntityOptions peo = new PromptEntityOptions("\nSelect a polyline: ");
               peo.SetRejectMessage("\nInvalid entity");
               peo.AllowObjectOnLockedLayer = true;
               peo.AllowNone = false;
               peo.AddAllowedClass(typeof(Polyline), true);
               PromptEntityResult per = ed.GetEntity(peo);
               if (per.Status == PromptStatus.OK)
               {
                   ObjectId objId = per.ObjectId;
                   using (Transaction tr = db.TransactionManager.StartTransaction())
                   {
                       Polyline pline = (Polyline)tr.GetObject(objId, OpenMode.ForRead);
                       Double area = pline.Area;
                       Clipboard.SetData(DataFormats.Text, Math.Round(area, 2));
                   }
               }
           }
           catch (System.Exception ex)
           {
               ed.WriteMessage("\nError: " + ex.Message);
           }
       }
   }
}

CopyArea.zip

Link to comment
Share on other sites

Nice :) Didn't know you knew C# Gile... o:)

 

I'm newbie, just begining to learn...

 

Another dll which defines two new LISP functions:

CopyToClipboard copies a string to the clipboard, returns the string if successfull, nil otherwise

TextFromClipboard returns the string stored in the clipboard

 

Using example (tclaudiu's request):

(defun c:test (/ pl)
 (and
   (setq pl (car (entsel)))
   (setq pl (vlax-ename->vla-object pl))
   (= (vla-get-ObjectName pl) "AcDbPolyline")
   (CopyToClipBoard (rtos (vla-get-Area pl) 2 2))
 )
 (princ)
)

 

C# code:

using System.Windows.Forms;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Runtime;

namespace LispExtension
{
   public class ClipBoard
   {
       // CopyToClipBoard
       // Copies a string to the clipboard
       // Returns the string if successfull, nil otherwise.
       [LispFunction("CopyToClipBoard")]
       public TypedValue CopyToClipBoard(ResultBuffer resbuf)
       {
           try
           {
               TypedValue[] args = resbuf.AsArray();
               string result = (string)args[0].Value;
               Clipboard.SetText(result);
               return new TypedValue((int)LispDataType.Text, result);
           }
           catch
           {
               return new TypedValue((int)LispDataType.Nil);
           }
       }

       // TextFromClipBoard
       // Returns the string from the clipboard or nil
       [LispFunction("TextFromClipBoard")]
       public TypedValue GetClipboard(ResultBuffer resbuf)
       {
           try
           {
               string result = Clipboard.GetData(DataFormats.Text).ToString();
               return new TypedValue((int)LispDataType.Text, result);
           }
           catch
           {
               return new TypedValue((int)LispDataType.Nil);
           }
       }
   }
}

LispExtension.zip

Link to comment
Share on other sites

Thank you gile for dll and for code. If I want to change the area precision value to 8 digits, should I have C# installed on my machine in order to recompile the dll?

I don't know very much about programming, so initial I've tried to modify the precision area value at the "Clipboard.SetData(DataFormats.Text, Math.Round(area, 2))" in notepad, like a newbie, but I've notice is no use.

Thank you in advance and if this operation (change to 8 digits) doesn't bother you, I will like to ask you if could change it.

Have a nice day!

Link to comment
Share on other sites

Hi,

 

You're welcome.

Yes, to change the DLL you have to recompile it in Visual Studio (google for "visual studio express edition" it's free)

I attach a recompiled DLL (8 digits precision)

 

But if you're more comfortable with LISP, you can load LispExtension.dll and use the new defined CopyToClipboard LISP function it requieres a string as argument.

 

If you want a DLL to be automatically loaded at startup, you can see here.

CopyArea2.zip

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...