Iftikhar Arain Posted June 11 Posted June 11 Hi, I have just started learning AutoLISP programming by watching YouTube videos so I can improve my routine work by automation with the help of AutoLISP programming. My aim is to get fully automation in exporting co-ordinates from AutoCAD drawing into excel, so step by step I would like to achieve this task. What I have learned so far to create a AutoLISP program to read co-ordinates of circles in attached drawing and to show as text at centre points of circles. I have created the program but I need help how to get co-ordinates by setting up UCS at bottom of each objects (no's 01 to 05). Coordinates.dwg AutoLISP-Coordinates.docx 1 Quote
BIGAL Posted June 12 Posted June 12 Ok first BIG comment "Dont use Word to program lisp", it will result in hidden codes that are used by Word and the lisp can fail. Always use Notepad, or better still get Notepad++ a great text editor and can detect lisp code so does some error checking for you. You can run code from Notepad++ to CAD. Ok for me start again. But I write direct to excel so will help. Need you to confirm procedure I would select "01" then circles, "02" then circles etc. So Excel will have line breaks with number. Do you want a CAD table as well ? Ok big problem but hey did something for you anyway but I am not going to fix, look at 04 & 05 have 12 circles. needs to be fixed 1st. ; https://www.cadtutor.net/forum/topic/86557-reading-co-ordinates-by-autolisp/ ; export circle cen pt to excel ; BY AlanH June 2024 (defun c:circexcel ( / myxl rows str ss circ cen) ;; Thanks to fixo ;; ;; = Set Excel cell text = ;; ;; ;; (defun xlsetcelltext ( row column text) (setq cells (vlax-get-property (vlax-get-property myxl "ActiveSheet") "Cells")) (vl-catch-all-apply 'vlax-put-property (list cells 'Item row column (vlax-make-variant (vl-princ-to-string text) vlax-vbstring))) ) (or (setq myxl (vlax-get-object "Excel.Application")) (setq myxl (vlax-get-or-create-object "excel.Application")) ) (vlax-invoke-method (vlax-get-property myXL 'WorkBooks) 'Add) (vla-put-visible myXL :vlax-true) (vlax-put-property myxl 'ScreenUpdating :vlax-true) (vlax-put-property myXL 'DisplayAlerts :vlax-true) (setq rows 1) (while (setq ent (entsel "\nPlease pick text label Enter to exit ")) (setq str (cdr (assoc 1 (entget (car ent))))) (prompt "\nselect circles") (setq ss (ssget '((0 . "CIRCLE")))) (if (= ss nil) (alert "No circles selected will skip") (progn (xlsetcelltext rows 1 str) (repeat (setq x (sslength ss)) (setq rows (1+ rows)) (setq circ (ssname ss (setq x (1- x)))) (setq cen (cdr (assoc 10 (entget circ)))) (xlsetcelltext rows 1 (car cen)) (xlsetcelltext rows 2 (cadr cen)) ) ) ) ) (princ) (c:circexcel) Quote
EnM4st3r Posted June 12 Posted June 12 or you could use Visual Studio Code with AutoLisp extension. I started with autolisp around a year ago and VSC was/is the easiest for me to work and debug with. Quote
SLW210 Posted June 12 Posted June 12 Unfortunately, Visual Studio Code needs PowerShell for some things to work, at least I occasionally get an error message stating PowerShell.exe can't be found, I put in a request to IT, but so far nothing. I still use Notepad and the VLIDE at work for this reason, though that said, I do what I can with Visual Studio Code occasionally, I also have Visual Studio 2022 at work, haven't tried it for LISP yet. Maybe I can put in a request for Notepad++ to be installed, what is needed for it to run and debug? Quote
Danielm103 Posted June 12 Posted June 12 I’ve never seen this myself, powerShell is part of windows, right? but, I think you can configure this, which makes sense because VS Code is multi-platform.. there's settings "terminal.integrated.shell.windows" and, "shellLauncher.shells.windows" you can probably just forward them to cmd.exe Quote
pkenewell Posted June 12 Posted June 12 I have worked with VScode and it works well, but still prefer the editor I am comfortable with - PSPad (https://www.pspad.com/en/). I developed the Visual LISP syntax file for it, and it also has an autocomplete feature (albeit a bit more clunky than VScode), and a tree view that shows all the functions in the Lisp file (a feature I LOVE). It also has a DCL syntax file that works well. The only disadvantage is it does not have the realtime code step through that VLIDE has, but I have rarely ever needed that feature. Quote
SLW210 Posted June 12 Posted June 12 2 hours ago, Danielm103 said: I’ve never seen this myself, powerShell is part of windows, right? but, I think you can configure this, which makes sense because VS Code is multi-platform.. there's settings "terminal.integrated.shell.windows" and, "shellLauncher.shells.windows" you can probably just forward them to cmd.exe PowerShell is blocked by IT (pretty much standard for many companies AFAIK). Though it is poor security to do so, most IT are too lazy to properly configure things, so they remove things or block them. I constantly lose my license on AutoCAD due to very poor IT security measures. Quote
SLW210 Posted June 12 Posted June 12 Back on point... Have you checked out CadTools (glamsen.se)? It may have something for this. Quote
CyberAngel Posted June 12 Posted June 12 9 hours ago, SLW210 said: ...Maybe I can put in a request for Notepad++ to be installed, what is needed for it to run and debug? As far as I know, the only advantage of Notepad++ over Notepad is that you can use language-specific highlighting, the way you do in many IDEs. It's not much of an advantage, either, since OOTB it only does basic LISP, not AutoLISP. You can get homebrew add-ons for AutoLISP, nothing official. As for running your code, it's like Notepad; you have to drop your function into AutoCAD and hold your nose. Quote
Danielm103 Posted June 13 Posted June 13 9 hours ago, SLW210 said: PowerShell is blocked by IT (pretty much standard for many companies AFAIK). Though it is poor security to do so, most IT are too lazy to properly configure things, so they remove things or block them. Interesting, since VS code is default lisp editor for AutoCAD, ZwCAD, and GStarCAD. Quote
BIGAL Posted June 13 Posted June 13 Cyberangle "As for running your code, it's like Notepad; you have to drop your function into AutoCAD and hold your nose." NO there is a ACTIVEX plugin that allows you run the code direct form Notepad++ its really helpful. You have to download it separately. Will try to find link. Maybe this one. https://sourceforge.net/projects/nppactivexplugin/ Quote
exceed Posted June 13 Posted June 13 I'm using notepad and vscode. vlide is only used for vlx compile. I don't know how to use the debug function. I catch bugs by hitting them with my palm. Quote
Iftikhar Arain Posted June 26 Author Posted June 26 Hi BIGAL, big thanks and much appreciated for your time on creating a AutoLISP program. I was on holiday so apologies for late feedback. As I did mention in my first post that I am a new learner of AutoLISP programming never done this before that's why wanted to learn step by step. The CAD drawing I did attach in my first post doesn't reflect to actual CAD drawing I work. It was just as an example and I just wanted to know how to change UCS from one object to another in AutoLISP program. I am attaching here CAD drawing for a simple Sleeper Layout with detail of Co-ordinates so you can see what I do in my routine work. As I said it's a simple layout drawing and you can imagine the possibilities of errors in exporting detail from CAD to Excel during typing & reading manually all the information for a complex Sleeper layout. That's why wanted a AutoLISP program. Dear BIGAL, I have explained in detail every thing on CAD drawing, I will be much appreciated and thankful forever if you please take a look on attached information and to create a AutoLISP program. Please do let me know if you need any further clarification on the process I use for exporting co-ordinates from CAD to Excel. I am also thankful to all other respected members who posted their comments. Sleepers Layout.dwg Sleeper Coordinates.xlsx Quote
BIGAL Posted June 26 Posted June 26 First comment I think a lisp could draw the track and sleepers for you BUT a huge task, did find 1 sleeper that appears to be short "21". Do you have that already ? Understand a little about railways they use all sorts of spirals in this situation. Will try to find time to look into it further. Quote
Iftikhar Arain Posted June 27 Author Posted June 27 Hi BIGAL, thanks for looking into above post. I would like to clarify that we don't need a AutoLISP program to draw track and Sleepers. We get CAD drawing with all the detail of track & Sleepers with housings positions (housings hold the rails) from our customer, we only transfer detail of housings co-ordinates from CAD drawing into Excel. Then we manufacture Concrete Sleepers and get the holes dilled by a CNC machine then we insert housings into holes by using a very strong glue. I have attached 3D drawing of a Sleeper and a photo which show how the rails are fitted on these sleepers(this photo of a bit more complex sleeper layout). Hope you will now understand that I only need a AutoLISP program for capturing Co-Ordinates of housings by setting up UCS on each Sleeper. Please let me know if you need any further information. C08L.dwg Quote
BIGAL Posted July 1 Posted July 1 (edited) Ok 1st task is to identify for all the "T's" where the intersection point is, as the T is 3 lines. Then should be able to do something. Thinking about it. If they were blocks much easier. Ok worked that out as it happens the lines are drawn from a single point outwards. Now need to think more about it, just read your notes and understand now why the co-ords did not seem right in Excel as they are relevant to lower left corner of sleeper dont need to use UCS etc should be able to work from this point. Looks like 1st step is use Join and make the sleeper outlines plines. Edited July 1 by BIGAL Quote
BIGAL Posted July 2 Posted July 2 (edited) Update, Ok I have used "Blockify" to convert the 3 lines to a block with insert point at intersection of 3 lines. This is a Bricscad function. So onwards and upwards. Can the clamp line work be a block ? Got the co-ords for a sleeper working but the dwg is a bit of a problem, really need the sleepers to be plines. I used the sleeper boundary to find all the clamps. About to do the excel bit but would like a cleaner dwg to work with. Else it must be edited before can proceed with code. If the dwg was on more seperate layers much easier to work with. Can that be done ? Edited July 2 by BIGAL Quote
Iftikhar Arain Posted July 2 Author Posted July 2 Hi BIGAL, Thanks for your efforts and time spending to look into my help request. I am also continuously trying if I can find any way to create AutoLISP program. I have done some work. Created one AutoLISP program to read XY co-ordinates and to show as text in CAD drawing. Also created a separate AutoLISP program to read angles of sleeper housings. I couldn't combine both programs, hope you can combine these both programs. Also the XY co-ordinates red out by program are from WCS. I have found how to move UCS from one sleeper to other by program but couldn't find to read co-ordinates from UCS. I have searched on google and it says, in AutoLISP co-ordinates are read from WCS. Hope you can find any solutions then we need to look how we can write housing Coordinates from CAD into Excel. I have attached Lisp file & drawing. Thanks LISP file 4 CADTutor.lsp Layout - Copy 2.dwg Quote
BIGAL Posted July 2 Posted July 2 I just look at each sleeper in UCS World, the secret is two things is it CW or CCW and I have set the pline points so 1st point is lower left. For right hand dual rails the corner point would be top left and offsets as -ve as per your request. I take into account sleeper may be rotated but offsets are from a corner. Working on it maybe tomorrow for code, have the get X&Y working next step is do Excel. I used Bricscad Blockify to turn the "T" into a block will see if 2025 supports that otherwise have to do the find common point of the 3 lines. 1 Quote
Iftikhar Arain Posted July 3 Author Posted July 3 Hi BIGAL, I have attached another Sleeper layout drawing for further clarification & explanation about housing Co-Ordinates. Different customer use different way to show these housings on CAD drawing. The Co-ordinates are captured at same point i.e at intersection point of T. Sleeper Layout-2.dwg 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.