tclaudiu Posted August 26, 2009 Posted August 26, 2009 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! Quote
NBC Posted August 26, 2009 Posted August 26, 2009 Have you looked into the function EATTEXT. It will export area data to a number of different file formats (.csv .xls etc) Quote
tclaudiu Posted August 26, 2009 Author Posted August 26, 2009 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 Quote
tclaudiu Posted August 26, 2009 Author Posted August 26, 2009 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! Quote
Lee Mac Posted August 26, 2009 Posted August 26, 2009 This isn't easily achieved without using either Arx or DosLib, see here: http://www.theswamp.org/index.php?topic=19805.0 Quote
Lee Mac Posted August 26, 2009 Posted August 26, 2009 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)) Quote
gile Posted August 26, 2009 Posted August 26, 2009 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 Quote
gile Posted August 26, 2009 Posted August 26, 2009 Nice Didn't know you knew C# Gile... 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 Quote
tclaudiu Posted August 28, 2009 Author Posted August 28, 2009 Thank you very much guys! Appreciate your attention, I.ve just solve my problem. Quote
tclaudiu Posted August 28, 2009 Author Posted August 28, 2009 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! Quote
gile Posted August 28, 2009 Posted August 28, 2009 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 Quote
Recommended Posts
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.