chulse Posted April 21, 2010 Posted April 21, 2010 I would love this! Be warned, I know nothing of VBA and will ask many questions on how to run it Ok, First I created a new worksheet in my excel workbook template file that combined the various datasets into the desired format and order. Then I added a button (on the main worksheet) that executes this code. It saves the new "CSV Export" worksheet as a separate .CSV file by apending the current date and time to the parent excel file name and saving it in the same location. I am by no means an expert at this, and I wouldn't be surprised if someone knows a better way to do it, but this works for us. Sub Save_WorkSheet_As_CSV() Dim Destwb As Workbook Dim TempFilePath As String Dim TempFileName As String Application.DisplayAlerts = False 'avoid safetey alert TempFilePath = ActiveWorkbook.Path & "\" TempFileName = ActiveWorkbook.Name & "-CSV_EXPORT_" & Format(Now, "yyyy-mm-dd, hh.mm.ss") 'Copy the data from the worksheet Worksheets("CSV_EXPORT").Copy 'Save the new workbook and close it With ActiveWorkbook .SaveAs TempFilePath & TempFileName & ".CSV", FileFormat:=6 .Close SaveChanges:=True End With MsgBox ("CSV file exported to:" & Chr(13) & TempFilePath & TempFileName & ".csv") Application.DisplayAlerts = True 'reset safety alerts End Sub This is the code for the actual button; Private Sub CommandButton1_Click() Dim response As Integer response = MsgBox("Do you want to export a CSV file for AutoCAD?", 36, "Export CSV Now?") If response = 7 Then Exit Sub ElseIf response = 6 Then csv_export.Save_WorkSheet_As_CSV End If End Sub Quote
Lee Mac Posted April 21, 2010 Author Posted April 21, 2010 Thanks Cary, That'll at least help those who wish to use the program to convert data into a format that may be read by the program. In the future, I hope to incorporate the ability to read from Excel, but this takes a bit more time/coding. Lee Quote
chulse Posted April 21, 2010 Posted April 21, 2010 Lee, Would it be possible to customize this to do the following? Given a csv file containing distance along a line and depth below that line (2 columns), have the user select a 2d or 3d polyline. The code would insert a block at each distance along the line (in the first column) and set it's depth at the elevation of that point on the pline less the depth in column 2. Perhaps the block would have an attribute that would display the new calculated elevation (similar to a spot elevation in a topo dwg). Seem possible? Quote
Lee Mac Posted April 21, 2010 Author Posted April 21, 2010 Possible, yes - but not really something I would want to incorporate into this program if I'm honest. I really want to keep this as generic as possible, and currently it deals consistently with 2D/3D points - I wouldn't want to add the distance/elevation just for the 2D/3D polylines... this would be better as a separate program. Quote
alanjt Posted April 22, 2010 Posted April 22, 2010 Thanks Cary, That'll at least help those who wish to use the program to convert data into a format that may be read by the program. In the future, I hope to incorporate the ability to read from Excel, but this takes a bit more time/coding. Lee Ugh, what a headache. Quote
rookie37 Posted April 28, 2010 Posted April 28, 2010 I keep getting Bad argument type I'm trying to insert a block called sun position. My spreadsheet shows the sun position every 3 weeks for the year x coordinate is column a y coordinate is column b Quote
Lee Mac Posted April 28, 2010 Author Posted April 28, 2010 Hi Rookie, I shall take a look at the code again, and see if there is anything askew. Bear in mind also that the program is set to read a Z-Coordinate if it is present, and hence it would take the values in Column C as Z-Coordinates. Quote
Lee Mac Posted April 28, 2010 Author Posted April 28, 2010 Rookie, I cannot seem to replicate your error Quote
engineeredwithlayton Posted April 28, 2010 Posted April 28, 2010 Lee Mac, I have stumbled across your program in trying to import 24 points of which I have northern and easting into my CAD drawing. I have downloaded the V2.3 but have no idea on how to run the program. I saved it locally and when I click on it I get a notepad open. I am assuming I must run this through ACAD but have no experience in doing such. Please help! Emery Quote
Lee Mac Posted April 28, 2010 Author Posted April 28, 2010 Hi Emery, Thanks for your interest in the program, take a look here: http://www.cadtutor.net/forum/showthread.php?t=1390 You only need to follow the last couple of steps Save the LISP to a known location, go to the Appload dialog, and load it from there. Quote
rookie37 Posted April 28, 2010 Posted April 28, 2010 Lee I got it working. In the dialog box, I put the drawing that I was in (test.dwg) as the output file. I tried it again and this time I used the wblock sun.dwg as the output file. Quote
engineeredwithlayton Posted April 29, 2010 Posted April 29, 2010 Hi Emery, Thanks for your interest in the program, take a look here: http://www.cadtutor.net/forum/showthread.php?t=1390 You only need to follow the last couple of steps Save the LISP to a known location, go to the Appload dialog, and load it from there. Lee...thanks for the immediate reply. I got the program uploaded and working. Now I am trying to import my points in an excel (well .csv) file. I was curious if you have an example input file format you can send me? I am getting an error prob because it is not in the correct format. Should it be x,y,z as shown on the bottom of the tool? Thus naming my columns as x-coordinate, y-coordinate, z-coordinate? What about a column for point number, descriptions, etc? Also will the output file go directly to the .dwg that I have open or do I create one as the output file? Thanks again! Emery Quote
engineeredwithlayton Posted April 29, 2010 Posted April 29, 2010 Lee...thanks for the immediate reply. I got the program uploaded and working. Now I am trying to import my points in an excel (well .csv) file. I was curious if you have an example input file format you can send me? I am getting an error prob because it is not in the correct format. Should it be x,y,z as shown on the bottom of the tool? Thus naming my columns as x-coordinate, y-coordinate, z-coordinate? What about a column for point number, descriptions, etc? Also will the output file go directly to the .dwg that I have open or do I create one as the output file? Thanks again! Emery More specific info... I am getting the following error: ** Error: bad argument type: numberp: nil ** I renamed my columns from northern to Y-coordinate and Easting to X-coordinate and my point number column to numberp and still get the above error. Quote
Lee Mac Posted April 29, 2010 Author Posted April 29, 2010 Hi Emery, The program works best without any headers, just the raw data. Its obivous from the last couple of posts that I need to revise the code slightly to deal with these few bugs, and I am surprised that I didn't spot them before... Let me know how you get on, Lee Quote
Lee Mac Posted April 30, 2010 Author Posted April 30, 2010 I've updated the code to Version 2.4, this should hopefully fix these recent issues Quote
Lee Mac Posted May 3, 2010 Author Posted May 3, 2010 Does the new version work for you now Emery? Quote
symoin Posted May 13, 2010 Posted May 13, 2010 Hello Lee MAc!! I have a lots of survey points that i have to join with a common point (center point of a circle) thats will be forming the axis of a circle. Then i have to join all those points (without the center point) with an arc contineously to form the circumference of the circle. I use the commands : Pline then option Arc then option Second Point and endpoint then second point like this to form a complete circle by arc. I have seen you lisp to join point i,e by line I need with Arc. Is there any lisp or code to ease the work. look at the attached sample drawing. Course-2.dwg Quote
PeterPan9720 Posted June 4, 2010 Posted June 4, 2010 Currently, the user can:Insert a Block at all Points from a File (txt/csv) Insert a Point at all Points from a File (txt/csv) Create a LW/3D Polyline from all Points in a File (txt/csv) Insert a Point at all vertices on all/Selected LW/3D Polylines in a drawing Insert a Block at all/selected Points in a drawing Export all/selected Points in a drawing to a File (txt/csv) Create a LW/3D Polyline from all/Selected Points in a drawing Insert a Block at all vertices of a LW/3D Polyline Export all Vertices of a LW/3D Polyline to a File (txt/csv) Create a LW/3D Polyline from all/selected LW/3D Polylines Export all insertions of a Block to a File (txt/csv). Insert a Point at all instances of a Block Create a LW/3D Polyline at all insertions of a Block > Preview: [ATTACH]16641[/ATTACH] Point Format Dialog: [ATTACH]16524[/ATTACH] Object Options Dialog: [ATTACH]16642[/ATTACH] Function Syntax: PtManager / PtM ;;;¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,;;; ;;;ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,¤º°`°º¤;;; ;; ;; ;; ;; ;; --=={ Point Manager }==-- ;; ;; ;; ;; Program will allow the user to manipulate points in the drawing or a file in ;; ;; a variety of ways, including: ;; ;; ;; ;; From File:- ;; ;; -------------- ;; ;; ;; ;; - Insert a Block at all Points from a File (txt/csv) ;; ;; - Insert a Point at all Points from a File (txt/csv) ;; ;; - Create an LW/3D Polyline from all Points in a File (txt/csv) ;; ;; ;; ;; From ACAD Points:- ;; ;; --------------------- ;; ;; ;; ;; - Insert a Block at all/selected Points in a drawing ;; ;; - Export all/selected Points in a drawing to a File (txt/csv) ;; ;; - Create an LW/3D Polyline from all/Selected Points in a drawing ;; ;; ;; ;; From LW/3D Polylines:- ;; ;; -------------------------- ;; ;; ;; ;; - Insert a Block at all vertices of an LW/3D Polyline ;; ;; - Export all Vertices of an LW/3D Polyline to a File (txt/csv) ;; ;; - Insert a Point at all Vertices of an LW/3D Polyline ;; ;; - Create an LW/3D Polyline from all/selected LW/3D Polylines ;; ;; ;; ;; From Blocks:- ;; ;; ---------------- ;; ;; ;; ;; - Export all insertions of a Block to a File (txt/csv) ;; ;; - Insert a Point at all instances of a Block ;; ;; - Create an LW/3D Polyline at all insertions of a Block ;; ;; ;; ;; ;; ;; When reading from/writing to Files, a data delimiter may be selected from ;; ;; the drop-down, with the exception of using a CSV file, in which a comma must ;; ;; be used. ;; ;; ;; ;; The user can also choose to sort the points by X/Y/Z Coordinate, in ;; ;; Ascending or Descending order. ;; ;; ;; ;; When the input is of Block type and output of File type (or vice-versa), ;; ;; Block Attributes may be written (or entered). ;; ;; ;; ;; ;; ;; --<< Click Help for more information >>-- ;; ;; ;; ;; ;; ;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=;; ;; ;; ;; FUNCTION SYNTAX: PtManager / PtM / PTM_clear (Resets Defaults) ;; ;; ;; ;; Notes:- ;; ;; ----------- ;; ;; If no Z-Coord is found, zero elevation is assumed. ;; ;; ;; ;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=;; ;; ;; ;; AUTHOR: ;; ;; ;; ;; Copyright © Lee McDonnell, December 2009. All Rights Reserved. ;; ;; ;; ;; { Contact: Lee Mac @ TheSwamp.org, CADTutor.net } ;; ;; ;; ;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=;; ;; ;; ;; VERSION: ;; ;; ;; ;; ø 1.0 ~¤~ 5th December 2009 ~¤~ º First Release ;; ;;...............................................................................;; ;; ø 1.1 ~¤~ 5th December 2009 ~¤~ º Added Dialog interface. ;; ;;...............................................................................;; ;; ø 1.2 ~¤~ 11th December 2009 ~¤~ º Updated Dialog Interface to ;; ;; allow for various input/output. ;; ;;...............................................................................;; ;; ø 1.3 ~¤~ 12th December 2009 ~¤~ º Added ability to Create LW and ;; ;; 3D Polylines. ;; ;;...............................................................................;; ;; ø 1.4 ~¤~ 14th December 2009 ~¤~ º Added ability to select data ;; ;; delimiter when reading from/ ;; ;; writing to files. ;; ;;...............................................................................;; ;; ø 1.5 ~¤~ 17th December 2009 ~¤~ º Fixed Bug when selecting 3D poly ;; ;; as output. ;; ;;...............................................................................;; ;; ø 1.6 ~¤~ 26th December 2009 ~¤~ º Added Ability to Extract Block ;; ;; information. ;; ;;...............................................................................;; ;; ø 1.7 ~¤~ 29th December 2009 ~¤~ º Added ability to sort points. ;; ;; º Added option to write/enter ;; ;; block attributes. ;; ;; º Improved Default Handling. ;; ;; º Added option to use 'other' ;; ;; delimiter. ;; ;; º Added ability to change point ;; ;; format. ;; ;;...............................................................................;; ;; ø 1.8 ~¤~ 2nd January 2010 ~¤~ º Created Help File & added Help ;; ;; (Not Released) button. ;; ;; º Fixed bug when selecting a block ;; ;; input. ;; ;;...............................................................................;; ;; ø 1.9 ~¤~ 4th January 2010 ~¤~ º Modified Delimiter functions to ;; ;; accept delimiters of length > 1. ;; ;;...............................................................................;; ;; ø 2.0 ~¤~ 5th January 2010 ~¤~ º Modified Delimiter Mode_Tile ;; ;; functions. ;; ;; º Fixed bug when selecting output ;; ;; block from drawing. ;; ;;...............................................................................;; ;; ø 2.1 ~¤~ 7th January 2010 ~¤~ º Corrected Help File Typo. ;; ;; º Updated Delimiter Check Function ;; ;;...............................................................................;; ;; ø 2.2 ~¤~ 7th January 2010 ~¤~ º Added Object Options Button and ;; ;; Dialog. ;; ;;...............................................................................;; ;; ø 2.3 ~¤~ 8th March 2010 ~¤~ º Fixed bug to include elevation. ;; ;; º Added code to disable/enable ;; ;; Object Options button. ;; ;;...............................................................................;; ;; ø 2.4 ~¤~ 19th April 2010 ~¤~ º Fixed bug when reading from ;; ;; files. ;; ;;...............................................................................;; ;; ;; ;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=;; ;; ;; ;;;¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,;;; ;;;ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,¤º°`°º¤;;; > As always, comments, suggestions and criticism are welcome Enjoy! Lee --=={ Code Updated to Version 2.4 }==-- Thank you for your code. But probably I'm not understood very well how it' works. I have a dwg open. I run ptm lsp. I would like to extract data from a block, manipulated the data with excel, and reinput data in the the same blocks in the same dwg. In order to do this below the operation: 1) Select INPUT block and output file, file created ok. 2) Manipulate the file, save in the same way (delimited). 4) Select INPUT file and output block, the block name it's the same of the previously selected. In this way I'm aspect that the modified data in the delimited file will be replaced in the same block. It's true ? Thks Quote
Lee Mac Posted June 4, 2010 Author Posted June 4, 2010 The program will insert new blocks in this way, but will not be able to manipulate existing ones. 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.