Search the Community
Showing results for tags 'autolisp'.
-
DXF 2 doesn't match block name in properties window
WPerciful posted a topic in AutoLISP, Visual LISP & DCL
I tested the code below by selecting one type of block, but instead of returning the name it returned *U36 (cdr (assoc 2 (entget (car (entsel "\nSelect a buble: "))))) -
Hello everybody! Few programmers (including myself) decided to create a website with free (for now) AutoLisp programs and scripts for Autocad. Well, we have few questions to define where to start. Your answers would really help. - Do you use programs (scripts) in your work? - Which program (script) you would use but do not have. Best regards, ... PS Link to website asap
-
Hi all I really do not have much experience with AutoLISP but I would like to write a script that allows me to: 1. Create a new DWG 2. Draw a line from a set of existing coordinates from a .txt file 3. Save this drawing in a specified location 4. Close the drawing 5. Rinse and repeat until all of the .txt files have been drawn. Basically this will be used for hundreds of .txt files containing coordinates to draw the cross-sections of a tunnel. Is this something that can be done? As after hours of research I have only managed to be able to draw one cross-section using a batch file but haven't been able to close the drawing or save it. Thanks in advance for any help
- 13 replies
-
- autolisp
- autocad 14
-
(and 2 more)
Tagged with:
-
Hi, I am new to this forum, can anybody suggest a good autolisp tutorial for beginners??? thanks in advance
-
Lisp to draw a polyline around the extents of a set of polylines
acheok24 posted a topic in AutoLISP, Visual LISP & DCL
Hello everyone, This is my first post on here so please forgive my ignorance if this is posted somewhere else. I am trying to create a lisp that will draw a polyline around a set of polylines, essentially connecting all start points and all endpoints. I just started writing lisps last week so I'm pretty new to this stuff, but the way I'm thinking about doing this is selecting all the polylines, filter out closed polylines that could be in the set, run a while loop to create a list of start points and end points, use repeat to draw a line from start point 1 to start point 2 to start point 3 etc. and then doing the same with the endpoints, and finally join all these lines into one polyline. Let me know what you all think. Thanks in advance. -
Hello everybuddies, I am new to lisp, so please for your advise. I want to pick an existing multi-segment polyline and use it as a selection fence (ssget "_F") As far as I understand I miss a simple piece of code that lists the points of the polyline in a way that ssget can accept them as a list of points to define the fence. (setq POLY (entsel "\n Pick a Fence Line crossing your beloved entities:")) ****POLY---->(please help!)----->POINTLIST**** (setq ss (ssget "_F" POINTLIST ) ) Thanx in advance
- 13 replies
-
- points list
- fence
-
(and 2 more)
Tagged with:
-
Centre of Gravity of a group of Open or Closed Polylines
neodesigner posted a topic in AutoLISP, Visual LISP & DCL
I work as a boat designer and often require calculating total length of polyline & centre of gravity (both open & closed polylines). I have a snippet below to show the sample code I am currently using - this only works with a group of lines - it doesnt work with polylines. Currently everytime I have to calculate the CG, I have to copy the polyline over, explode it & select the lines to calculate the CG. The logic is as follows - assuming we have 3 segments on the polyline(A,B,C) : Centre of Gravity of Polyline = (Len of A multiplied by Centroid of A + Len of b multiplied by Centroid of B + Len of C multiplied by Centroid of C) divided by Total Length of polyline I am new to LISP & although have some background in other programming languages, find it is relatively difficult to write the code, the syntax being very different. I found a similar code ( TotalADD Total Addition by Andrea Andreetti & modified to come to the below code). It would be ideal if I can select a group of polylines (using select similar) and run the command to get a text table in autocad with CG & total length calculated for set of polylines on different layers. But I am not sure how this can be achieved. Would you be able to help or am I asking for too much ? any guidance will be much appreciated. (if (eq (vla-get-objectname n) "AcDbLine") (progn (setq itemlinelength (+ itemlinelength (vla-get-length n))) (setq StartPoint(vlax-safearray->list (vlax-variant-value (vla-get-startpoint n)))) (setq x1 (car Startpoint)) (setq y1 (cadr Startpoint)) (setq EndPoint(vlax-safearray->list (vlax-variant-value (vla-get-endpoint n)))) (setq x2 (car endpoint)) (setq y2 (cadr endpoint)) (setq xmid (* (+ x1 x2) 0.5)) (setq ymid (* (+ y1 y2) 0.5)) (setq xmom (* xmid (vla-get-length n))) (setq ymom (* ymid (vla-get-length n))) (setq itemxmoment (+ itemxmoment xmom)) (setq itemymoment (+ itemymoment ymom)) ) ) (setq totxcg (/ itemxmoment itemlinelength)) (setq totycg (/ itemymoment itemlinelength)) (setq tlength (rtos itemlength 2 ) (setq totxcg (rtos totxcg 2 ) (setq totycg (rtos totycg 2 ) (acet-ui-status (strcat "Length: " tlength "\n" "X CoG Pos: " totxcg "\n" "Y CoG Pos: " totycg "\n" ) -
We have many geo-referenced raster images of a drawing map. Now we are manually inserting them in drawing where required. Is there any way that if we click anywhere in the drawing the image of that place should be insert.
-
Hi All, It's been some time since I have been using AutoCAD and all the lisp controls I learnt have disappeared from memory. I basically only using CAD as a tool for cleaning files to link into Revit and so have been setting up a routine to run through all the clean and purge utilities to speed this up and remove the repetitiveness of using the same sequence of commands over and over. One utility I'd like to add into my lisp is "Flatten.lsp" I have found how to run it but is there anyway I can pre-answer the prompts? i.e. Flatten All (Return) Yes? Thanks in advance. Mark
-
How can we merge two adjacent polygons or two adjacent closed polylines using lisp or any tool in autocadmap 2004.
-
How can i write a text integer more than 32767 using lisp. when i type 123456 the message is "Requires an integer between -32768 and 32767"
-
Hey Guys, Its been a awhile since I have done any Autolisp programming and I am stuck... I am using a conditional statement to generate a number i.e. 1.625 and then I want to add that to the Z elevation of a point but it keep erroring out at this line. I have spent about an hour and half looking back thru resources and haven't been able to find the correct syntax. This is the line erroring out: (setq NEWPT1 (APPEND (LIST (CAR USRP1) (CADR USRP1)) (+ (CDDR USRP3) TRAP_Z_OFF))) ; ERRORS OUT HERE Here is the full code. (defun C:droptrap() (command "UNDO" "BEGIN") (initerr) (setvar "lunits" 2) (setvar "luprec" 4) (setvar "attreq" 0) (command "UNDO" "BEGIN") (setq OLDCMD (GETVAR "CMDECHO")) (setvar "CMDECHO" 0) (setq OLDOSMODE (GETVAR "OSMODE")) (setvar "OSMODE" 0) (setq OLDORTHOMODE (GETVAR "ORTHOMODE")) (vl-load-com) (setq thisdrawing (vla-get-activedocument (vlax-get-acad-object))) (initget "1 2 3 4") (setq TRAP_TYPE (getkword "\n Select trapeze type: ([1]:1-5/8x1-5/8, [2]:1-5/8x1-5/8 B2B, [3]1-5/8x13/16, [4]1-5/8x13/16 B2B): ")) (if (or (= TRAP_TYPE "1")(= TRAP_TYPE "3")) (progn (initget "1 2") (setq FACE_DIR (getkword "\n Trapeze opening up or down?: ([1]:UP [2]:Down): ")) ) (setq FACE_DIR "1") ) (cond ((and (= TRAP_TYPE "1")(= FACE_DIR "2")) (setq TRAP_Z_OFF 1.625)) ((and (= TRAP_TYPE "3")(= FACE_DIR "2")) (setq TRAP_Z_OFF 0.8125)) (T (setq TRAP_Z_OFF 0.0)) ) (setq blockname "TRAP-XDATA-T1_1.625") (setq USRP1 (GETPOINT "\n Select center point of rod 1: ")) (setq USRP2 (GETPOINT "\n Select center point of rod 2: ")) (setq USRP3 (getpoint "\n Select elevation of attachment point: ")) (setq NEWPT1 (APPEND (LIST (CAR USRP1) (CADR USRP1)) (+ (CDDR USRP3) TRAP_Z_OFF))) ; ERRORS OUT HERE (setq NEWPT2 (APPEND (LIST (CAR USRP2) (CADR USRP2)) (+ (CDDR USRP3) TRAP_Z_OFF))) ; ERRORS OUT HERE TOO (setq MIDPT (POLAR NEWPT1 (ANGLE NEWPT1 NEWPT2) (* (DISTANCE NEWPT1 NEWPT2) 0.5))) (setvar "ORTHOMODE" 1) (COMMAND "-INSERT" BLOCKNAME MIDPT "1" "1" NEWPT2) (command "rotate3d" (entlast) "" 2 NEWPT1 NEWPT2 90) (setvar "OSMODE" OLDOSMODE) (setvar "CMDECHO" OLDCMD) (setvar "CLAYER" LAYNAME) (COMMAND "UNDO" "END") (PRINC) ) The code is unfinished so I am trying to keep it working as I build it.
-
Hey guys, I'm working on a piece of code where I need the lisp to look up a custom property that's set and extract it. The problem I am having is that we updated our templates within the last two years so this piece of code doesn't work properly with some of the older drawings we have. I want it to assign the variable a value if it can't find it, but I don't know how to get around the automation error. Here's my attempt but I am at a loss as to what to do. (defun c:test (/ acadobject acaddocument dprops pp pp#) (setq acadObject (vlax-get-Acad-Object)) (setq acadDocument (vla-get-Activedocument acadObject)) (setq dProps (vlax-get-property acadDocument 'Summaryinfo)) (vla-getcustombyindex dprops 72 'PP 'PP#) (if (= PP# nil) (setq PP# "PLXX-X-XX-") );;end if );;end defun Here's the error I get. Error: Automation Error. Out of range FYI: The name of the custom property is Plot Plan Thanks in advance!
- 3 replies
-
- automation error
- autolisp
-
(and 1 more)
Tagged with:
-
Extracting the coordinates from a rectangle in modelspace
chiimayred posted a topic in AutoLISP, Visual LISP & DCL
Hey guys, I'm trying to get the four corners of a rectangle in modelspace set to variables and I'm having a hard time with it. I'm able to get the four corners into a list, but I'm having a hard time setting each coordinate to a variable. The issue I'm having at this point is that the second variable duplicates the coordinate values. The first variable Here's what I got so far... (defun c:test (/ ptlist x y) (setq ptlist (massoc 10 (entget(car(entsel))))) (defun c:massoc (key alist / x nlist) (foreach x alist (if (eq key (car x)) (setq nlist (cons (cdr x) nlist)) ) ) (reverse nlist) ) ;end (princ ptlist) (setq x (car ptlist)) (setq y (cadr ptlist)) (princ) (princ x) (Princ) (princ y) ) I got part of this code from here When I draw in a rectangle in modelspace and I use this code, this is what I'm getting. Command: TEST Select object: ((18.2488 -11.0958) (23.6419 -11.0958) (23.6419 -5.32136) (18.2488 -5.32136))(18.2488 -11.0958)(23.6419 -11.0958)(23.6419 -11.0958) So it builds the list and sets the first variable right, but it duplicates the second. Thanks in advance! e: I haven't added in error trapping yet, just trying to figure this out first.- 3 replies
-
- polyline
- coordinates
-
(and 2 more)
Tagged with:
-
I have a series of blocks that I am replacing via lisp routine. But the new blocks are wider than the old ones. So I wrote the routine below to trim the lines that extend into a block. It works intermittently when the block is horizontal. I haven’t added the code to trim the lines if it’s vertical yet because I can’t figure out why the code doesn’t consistently work. The code is below and the attached drawing files has the blocks I’m using as an example. (defun trimblocklines ( ent / e d ins ero bw bh pt1 pt2 ss1 cnt sslen ) (setvar "cmdecho" 0) (setq e ent d (entget e) ins (cdr (assoc 10 d)) ero (* (dxf 50 d) (/ 180 pi)) bw 0.25 bh 0.125 pt1 (list (- (nth 0 ins) (/ bw 2)) (- (nth 1 ins) (/ bh 2)) (nth 2 ins)) pt2 (list (+ (nth 0 ins) (/ bw 2)) (+ (nth 1 ins) (/ bh 2)) (nth 2 ins)) ss1 (ssget "_C" pt1 pt2 '((0 . "line"))) cnt 0 sslen (sslength ss1) ln_ents (list ) ) (command "circle" ins (list (+ (nth 0 ins) (/ bw 2)) (nth 1 ins))) (setq cent (entlast)) (while (< cnt sslen) (setq ln_ents (append ln_ents (list (ssname ss1 cnt))) cnt (1+ cnt) ) ) (command "trim" cent ss1 "" (list (- (nth 0 ins) (- (/ bw 2) 0.01)) (nth 1 ins) 0.0) "") (command "trim" cent ss1 "" (list (+ (nth 0 ins) (- (/ bw 2) 0.01)) (nth 1 ins) 0.0) "") (entdel cent) (setvar "cmdecho" 0) (princ) ) trimlines.dwg Thank you
-
I have a block with 25 and growing attributes and correspondingglobal variables. (defun attdraw (atthandle / ) ; draw out all attributes of the insert, turn them into global variablesand fill them with (setq ent (handent atthandle) ; their corresponding data. attribute name = globalvariable name. ed (entget ent) );setq (while (/="SEQEND" (dxf 0 ed)) ;whiletag value /= SEQEND (if (="ATTRIB" (dxf 0 ed)) ;make sure its an attribute (set (read(dxf 2 ed)) (dxf 1 ed)) );if (setq ent(entnext ent) ;move to the next tag ed (entgetent) ;and get entity data );setq );while );defun i update the variables in a dialog box. exiting the dialog box i update the global variables i would like to then insert the values back into theattributes using something similar. is there a way to use the attribute names as variable namesand also use the values associated with them to push them back into theattributes.
-
Creating an exterior gross poly line around the footprint of building
stapleyneil posted a topic in AutoLISP, Visual LISP & DCL
I am attempting to create a list that will place a poly line representing the footprint of a building/floor. With the ultimate aim to represent the gross exterior and gross interior if a floor. I am able with ease place the interior gross polyline but am having difficulties with the exterior as I have to use an xref of the architectural drawing and the boundary function doesn't like all the internal islands so it hangs up CAD. This is only my second attempt at creating a script. Does anyone know of a quicker way? (DEFUN C:EXGR (/) (COMMAND "LAYON") ;;;;TURNS ALL LAYERS ON;;;; (COMMAND "LAYTHW") ;;;;UNFREEZES ALL LAYERS;;; (COMMAND "LAYER" "M" "EX-GROSS" "") ;;;;CREATES A LAYER NAMED IN-GROSS AND MAKES IT CURRENT;;;;;; (COMMAND "LAYER" "OFF" "A-AREA,ARCH|A-ANNO-GRID,A-AREA-IDEN,DEFPOINTS,ARCH|A-FLOR,FURN|A-FURN,FURN|A-FURN-CHAR,FURN|A-FURN-PNLS,FURN|A-FURN-WKST,ARCH|A-EQPM,ARCH|A-MILL" "") ;;;;TURNS OFF ALL NONE ESSENTIAL LAYERS LISTED IN "";;;; (COMMAND "LAYER" "F" "A-AREA,A-AREA-IDEN,ARCH|A-ANNO-GRID,DEFPOINTS,ARCH|A-FLOR,FURN|A-FURN,FURN|A-FURN-CHAR,FURN|A-FURN-PNLS,FURN|A-FURN-WKST,ARCH|A-EQPM,ARCH|A-MILL" "") ;;;;TURNS OFF ALL NONE ESSENTIAL LAYERS LISTED IN "";;;; (SETQ A (GETPOINT "\nENTER FIRST POINT: ")) ;;;;SELECTS THE FIRST RECTANGLE POINT;;;; (SETQ B (GETPOINT "\nENTER SECOND POINT: ")) ;;;;SELECTS THE SECOND RECANGLE POINT;;; (COMMAND "RECTANG" A B "") ;;;;PLACES THE RECTANGLE;;;;; (SETQ E (GETPOINT "\nENTER THIRD POINT: ")) (SETQ f (GETPOINT "\nENTER FOUTH POINT: ")) (COMMAND "PLINE" E F "") (SETQ C (getpoint "\nPick internal point: ")) ;;;;SELECTS THE INTERNAL AREA OF THE RECTANGLE;;;; (command "_.-boundary" C "") ;;;;INITIATES THE BOUNDARY COMMAND;;;;; (COMMAND "LAYER" "OFF" "A-XREF,A-AREA|A-WALL" "") ;;;;SWITCHES OFF SPACE POLYLINES;;;; (setq D (entsel "\nSELECT THE POLY YOU WANT TO DESIGNATE AS THE INTERIOR GROSS: ")) ;;;;SELECTS THE POLYLINE YOU WISH TO DESIGNATE AS THE INTERNAL POLYLINE;;;;; (command "_.chprop" D "" "LA" "DEFPOINTS" "") ;;;CHANGES THE SELECTED POLYLINE TO LAYER DEFPOINTS;;;;;; (COMMAND "CLAYER" "0") ;;;;SETS THE CURRENT LAYER TO 0;;;;; (COMMAND "LAYDEL" "N" "EX-GROSS" "" "Y") ;;;;DELETES ALL ITEMS ON EX-GROSS LAYER;;;;;; (COMMAND "LAYON") (COMMAND "LAYTHW") ;;;;TURNS ON AND FREEZES ALL THE LAYERS;;;;;;; (PRINC) ) -
I'm not sure what happened but I can't seem to get this simple line of code to work. (command "_saveas" "2013" "D:\\Work\\Test.dwg") It just returns a nil. There is nothing wrong with the file path. If I enter the same data in at the command line it works fine.
-
AutoLisp for compiling of block attributes from csv file
nicodam84 posted a topic in AutoLISP, Visual LISP & DCL
Hi i'm looking for an Autolisp that help me to compile title block starting from a csv file. At the moment I know this Lisp http://www.lee-mac.com/updatetitleblock.html It is exactly what I need. The problem is that this program compile all the block title (present in "model" sheet) with the first line of the csv file. So all the block title will be equal. I need a routine that -for example- compile 5 block with attribute taking information from 5 different line of the csv file. This has to be done in "model" area. Does exist some progrma that colud be ok for this ?? Tnx in advance Nicola- 23 replies
-
How can we select all polylines in drawing that have length less than 2.00 or by any specific length.
-
Hi All, As a newbie to AUTOLisp, I am trying to accomplish the following with a script/function, however I still haven't found much useful information 1. While looping through the files in the directory, check if each drawing has any xrefs attached. 2. If yes, then copy all objects from all attached xrefs to the current drawing, and detach them. If no, skip the the next drawing. (If there are xref objects that cannot be copied to the drawing (such as jpgs), then leave them as they are). 3. Save the drawing with the same file name in another folder. I know this sounds like asking someone else to do the homework for me, but any kind of help is appreciated as a lot of time has been used already googling around without much progress..... Cheers
- 1 reply
-
- save as new file
- detach
-
(and 3 more)
Tagged with:
-
LISP to query MS Access Database return results as list of strings
WPerciful posted a topic in AutoLISP, Visual LISP & DCL
In Feb fixo helped me to write aSQLCon function. I used the function tooquery SQL databases. I have tried towrite one enabling me to query an access database in the same way. But I am at a total loss. (defun SQLControl ( query_statement / adocmd ADOConn adorst data field fields n sqlQuery tmp data1 data2) ;; Fixo ;; http://www.cadtutor.net/forum/showthread.php?84548-LISP-to-query-MS-SQL-Server-Database-return-results-as-list-of-strings (defun tostring (received / temp ) ; Function Syntax: (tostring received) ; received: Variable to be converted to a string (cond ((= (type received) 'STR) received) ((= (type received) 'INT) (itoa received)) ((= (type received) 'REAL) (rtos received)) ((= (type received) 'LIST) (progn (setq temp "") (foreach listitem received (setq temp (strcat temp " " (datatostring listitem) ) ) ) (setq temp (substr temp 2)) (setq received temp) ) ) ) ) (setq SqlCon "Provider=sqloledb;Data Source=SQL\\DESIGNSQL;Initial Catalog=engineering;user id=DraftingDesign;Password=12345" ADOConn(vlax-create-object "ADODB.Connection") ADORst (vlax-create-object "ADODB.Recordset") data1 (list ) data2 (list ) ) (vlax-invoke-method ADOConn 'Open SqlCon nil "" -1) (setq sqlQuery query_statement ADOcmd (vlax-create-object "ADODB.command") ) (vlax-put-property ADOcmd "ActiveConnection" ADOConn) ; optional ; (vlax-put-property cmd2 "CommandTimeout" 30) (vlax-put-property ADOcmd "CommandText" sqlQuery) (vlax-put-property ADOcmd "CommandType" 1) (setq ADORst(vl-catch-all-apply 'vlax-invoke-method (list ADOcmd 'Execute nil 2 1)));OK (setq fields (vlax-get-property ADORst 'Fields)) (vl-catch-all-apply 'vlax-invoke-method (list ADORst 'movefirst)) (while (not (equal :vlax-true (vlax-get-property ADORst 'eof))) (setq tmp nil n 0) (while (not (vl-catch-all-error-p (vl-catch-all-apply 'vlax-get-property (list fields 'item n)))) (setq field (vlax-variant-value (vlax-get-property (vlax-get-property fields 'item n) 'value))) (setq tmp (cons field tmp)) (setq n (1+ n)) ) (setq data (append data (list (reverse tmp)))) (vl-catch-all-apply 'vlax-invoke-method (list ADORst 'movenext))) ; use garbage cleaner before of the closing connection: (gc) (vlax-invoke-method ADOConn 'Close) (vlax-release-object ADORst) (vlax-release-object ADOcmd) (vlax-release-object ADOConn) ; (alert (vl-princ-to-string data)); must use (vl-string-trim " " strvalue) for string values within the data list (foreach line data (foreach item line (setq data1 (append data1 (list (cond ((= item nil)"") ((= (type item) 'SYM)(substr (vl-symbol-name item) 7)) ((/=(type item) 'STR)(tostring item)) (T item) ) ) ) ) ) (setq data2 (append data2 (list data1)) data1 (list ) ) ) data2 )-
- database programming
- database
-
(and 3 more)
Tagged with:
-
I'm interested in creating Snake using autolisp, but as far as I can tell, user input is required to get past a grread command. Is there anyway I can break the grread command if no input is received within amount of time?
-
I like to extend the last created polyline from its last endpoint using autolisp.
-
How to get first and second vertex of a Polyline
subodh_gis posted a topic in AutoLISP, Visual LISP & DCL
I like to write a text between first and second vertex of a selected Polyline. please help me to get first vertex (p1) and second vertex (p2) of a polyline. rest of things i can do myself. Thanks in advance