Search the Community
Showing results for tags 'autolisp'.
-
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 -
Reading Attribute value is being trimmed by empty space
Muthanna posted a topic in AutoLISP, Visual LISP & DCL
Hi everyone, I am a software developer , i program in C# C++ and Java, but lately i have been given a task to help out our engineering department to write some code + script to fix cad prints which they have issues with. our problem is we use a third party application which generates an AutoCad drawing. this third part application sets the dimscale to 1:000; But the drawing's title block scale attribute has has the correct scale value. My task was to write code in lisp and our script to automate this process; which will requires the program to read the value for the scale attribute and apply it to the drawing dimscale. after reading some tutorials and searching the web i cam across some functions that did most of my task...Thanks to this community and its forums. my main function that reads the attribute value i got from on of the threads as shown below: (defun c:AttLst (/ ss eLst bEnt aEnt aEntLst aVal blkLst) (vl-load-com) (if (setq ss (ssget "X" (list (cons 0 "INSERT") (cons 66 1) (if (getvar "CTAB") (cons 410 (getvar "CTAB")) (cons 67 (- 1 (getvar "TILEMODE"))))))) (progn (setq eLst (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss)))) (foreach e eLst (setq bEnt (cdr (assoc 2 (entget e))) aEnt (entnext e)) (while (= "ATTRIB" (cdr (assoc 0 (setq aEntLst (entget aEnt))))) (if (= (cdr (assoc 2 aEntLst)) "SCALE") (progn (setq aVal (cdr (assoc 1 aEntLst)) blkLst (cons (cons bEnt aVal) blkLst)))) (setq aEnt (entnext aEnt))))) (princ "\n<!> No Attributed Blocks Found <!>")) (alert (vl-princ-to-string blkLst)) (princ)) This function works great when the scale value has no white spaces; but when there is white spaces it only returns the right side of the scale value example 1 : SCALE 1:5 ==> Result = (( TitleBlockName. 1:5)) example 2 : SCALE 1 : 10 ==> Result = (( TitleBlockName. 1 : )) as you see in example 2 the return value is missing the right side value can you please help me with this issue to figure out why its returning the left side only?- 5 replies
-
- autolisp
- autocad2010
-
(and 2 more)
Tagged with:
-
Hey guys, I'm trying to make a lisp where the user would pick a point in the model and the lisp would create a multileader in paperspace with the coordinates pulled from the model. Here's the code I got so far: (defun c:test (/ WorkingPoint Easting Northing Point) (command "_.mspace" );;end command (setq WorkingPoint (getpoint "\nWhere is Working Point?: ")) (setq Northing (cadr WorkingPoint));;set "y" value of WorkingPoint to Northing (setq Easting (car WorkingPoint));;set "x" value of WorkingPoint to Easting (command "_.point" WorkingPoint );;end command (setq point (entlast));;set the workingpoint to point (command "_.chspace" point "" "" );;end command (setq pspaceworkingpoint (entget point)) (setq mleaderinspt (list (car pspaceworkingpoint)(cadr pspaceworkingpoint))) (princ mleadinspt) );;end defun Whenever I run this, for the "mleaderinspt" variable I get nilnil What I want to do is create the multileader insert point where the user picked the original working point but I'm having a hard time translating that to the paperspace. Please note I haven't added error checking yet as this is still in the developmental phase/proof of concept. Any and all help is appreciated. Thanks! EDIT: Think I figured it out, I'll update this thread if it works.
- 5 replies
-
- point
- multileader
-
(and 2 more)
Tagged with:
-
Hi Guys, I'm creating a layer setting pull down menu, in order to migrate my cad to revit I would like to define the linewight. So far I managed to create a command with a dashed line: (defun c:layA-SEC-LIH-005() (command "layer" "m" "A-SEC-LIH-005""C" "magenta" "" "l""DASHED2" "" "") and another one with the lineweight (defun c:layA-SEC-LIH-005() (command "layer" "m" "A-SEC-LIH-005""C" "magenta" "" "_LW" 0.10"" "") but I haven't been able to create one that combines the 2 of them.. any help? Cheers Roberto
- 14 replies
-
Recently upgraded to Civil 3D 2015 from 2013 but am having trouble using one of my most used AutoLISP commands to connect a string of points (connectpts) When I load the command I get the following error message; "; error: Automation Error. Problem in loading application" Any ideas out there? This is file; ;|Platform: AutoCAD Civil 3D Routine to draw 3dPoly between points with identical descriptions, in ascending Pt# order. by Jeff Mishler, July 25, 2007. Tested only in C3D2008. Type (vl-load-com) at command prompt first. |; (vl-load-com) (defun c:Connectpts (/ appstr coords desc grps pline point point#s points pt qbldr ss tmpgrp vrsn ) (setq vrsn (vlax-product-key)) (cond ((vl-string-search "R16.2" vrsn)(setq appstr "3.0"));;2006 ((vl-string-search "R17.0" vrsn)(setq appstr "4.0"));;2007 ((vl-string-search "R17.1" vrsn)(setq appstr "5.0"));;2008 ((vl-string-search "R17.2" vrsn)(setq appstr "6.0"));;2009 ((vl-string-search "R18.0" vrsn)(setq appstr "7.0"));;2010 ((vl-string-search "R18.1" vrsn)(setq appstr "8.0"));;2011 ((vl-string-search "R18.2" vrsn)(setq appstr "9.0"));;2012 ((vl-string-search "R19.0" vrsn)(setq appstr "10.0"));;2013 ((vl-string-search "R19.1" vrsn)(setq appstr "11.0"));;2014 ((vl-string-search "R20.0" vrsn)(setq appstr "12.0"));;2015 (t (alert "This version of C3D not supported!")) ) (if (and appstr (or *acad* (setq *acad* (vlax-get-acad-object)) ) (or *AeccApp* (setq *AeccApp* (vla-getinterfaceobject *acad* (strcat "AeccXUiLand.AeccApplication." appstr))) ) (or *AeccDoc* (setq *AeccDoc* (vlax-get *AeccApp* 'ActiveDocument)) ) (setq ss (ssget ":S:E" '((0 . "AECC_COGO_POINT")))) ) (progn (setq pt (vlax-ename->vla-object (ssname ss 0)) desc (vlax-get pt 'RawDescription) grps (vlax-get *AeccDoc* 'PointGroups) tmpgrp (vlax-invoke grps 'Add "__TEMP__") ) (setq qbldr (vlax-get tmpgrp 'querybuilder)) (vlax-put qbldr 'IncludeRawDescriptions desc) (if (> (length (setq points (vlax-get tmpgrp 'Points))) 1) (progn (setq point#s (vl-sort points ' (setq points (vlax-get *AeccDoc* 'Points)) (foreach pt# point#s (setq point (vlax-invoke points 'Find pt#)) (setq coords (append coords (list (vlax-get point 'Easting) (vlax-get point 'Northing) (vlax-get point 'Elevation) ))) ) (setq pline (vlax-invoke (vla-get-modelspace *AeccDoc*) 'Add3dPoly coords)) (vla-put-layer pline (vlax-invoke *aeccdoc* 'getvariable "Clayer")) ) ) (vlax-invoke qbldr 'clear) (vlax-invoke grps 'remove "__TEMP__") ) ) (princ) )
- 1 reply
-
- autolisp
- civil35 2015
-
(and 2 more)
Tagged with:
-
We have some text objects that having long text strings like 500 character so i need a lisp that can split the text into 45-45 characters and make them separate object of 45 character. the reason of this is we have to export the text in other software and that software don't support more than 45 character string. so now we are manually spiting them.
-
I am using autocadmap 2004 and i have closed polylines parcels in my drawing. Inside the parcel i have centroid and Parcel ID as text in separate layers. I have a object data table too. now i need to attach the object data table to all the centroids and put the parcel id as a value in the KID field of the table for all the parcels centroids respectively. Thanks Subodh
-
Can we count text or block inside the closed polyline using Autolisp.
-
Arrow and line goes missinig if cutomized copy multiple
shailujp posted a topic in AutoLISP, Visual LISP & DCL
Hi All, I'm experiencing a strange behavious of AutoCAD 2008 while using copy multiple via ACAD.lisp, the leaders and arrow goes missing (text is still visible) for the first copy but when I copy it for second time and there on within the same command, the leader and arrow shows up correctly. It requires regen to bring back the missing arrow & leader. I have triad different variable but nothing seem to work. However, the standard COPY command seem to work fine. I'm also seeing random issue while copying dimensions as well. I do not like regenerating everytime after copy considering the file is huge takes more time. At the same time, I'm addicted of using short commands via ACAD.lsp. Here is what my customized mutliple copy command looks like. (Defun C:C (/ SS1) (Setq SS1 (ssget))(Command "COPY" ss1 "" "m" pause pause)) Any suggestions?- 2 replies
-
- display
- copy and paste
-
(and 2 more)
Tagged with:
-
(vl-directory-files "C:\\Users\\wpe\\Documents" "*.dwg") Returns a list of DWGs in a folder, but is there to have it return a list of DWGs in the folder and sub-folders?
-
LISP to query MS SQL Server Database return results as list of strings
WPerciful posted a topic in AutoLISP, Visual LISP & DCL
LISP to query MS SQL Server Database return results as list of strings. (defun getMySqlData ( Name / ) (setq pm Name SQLCon "Server=OurServer;Database=engineering;Trusted_Connection=True" SQLStatement1 "USE enginering SELECT ID FROM Projects WHERE ProjectName = pm" SQLStatement2 "USE enginering SELECT * FROM LineList WHERE ProjectID = ResultsID" ) ; I'm trying to use SQLStatement1 to get the project ID. ; So that I can use it to run this SQLStatement2 ; Then return the results of the above as a list of strings. ) -
I have tried several combination and gone thru about a 100 posts but I can't figure out what I am doing wrong. I am filtering thru objects and pulling out a 3D coordinate from the database. Then I am turning that into a 3 point list (x y z). Then I want to create a list of those points and add to them to the existing list as the program filters thru the remaining objects from the selection set. (progn (setq unitpoint_orig (vl-string-right-trim ";" (substr (vlax-get entvla 'points) 12))) (if (and(or (= Z_pref "Y")(= Z_pref "y"))(/= Z_height nil)) (progn (setq unitpoint_mod (comma_pull unitpoint_orig "REAL_NUM")) (setq unitpoint (list (car unitpoint_mod) (cadr unitpoint_mod) (caddr Z_height))) ) (setq unitpoint (comma_pull unitpoint_orig "REAL_NUM")) ) (setq unitpoint_lst (append unitpoint_lst 'unitpoint)) ;(command "insert" pl_block unitpoint "1" "1" "0") ) Current Result: (105.13 3165.22 0.0 105.13 3194.65 0.0 105.13 3142.5 0.0) Desired Result: ((105.13 3165.22 0.0)(105.13 3194.65 0.0)(105.13 3142.5 0.0)) Once I get this part working, I am then planning on filtering for duplicates using Lee Mac's subroutines. Then inserting based off those points.
-
Extracting Point Information from Hangers in CADMEP+
TheyCallMeJohn posted a topic in AutoLISP, Visual LISP & DCL
Does anyone have any knowledge on how to extract the point information from a CADMEP entity without having the CADMEP information? Our clients give us there files and we have to place blocks at each hanger. Extracting the coordinates to populate the blocks would be a huge time saver. -
Hello All, I have been seeking an individual to write an AutoLISP program for some time using the normal routes, but given availability and contact it has lead me to this forum to see if anyone would be interested. There is a detailed scope available. However in brief; the task requires generation of multiple dwg for a laser marker containing text and hatches from an excel file that contains multiple batches of such data. Before I post anything further, I'd like to check if such discussions are welcome here...
-
Displaying variables and characters in an entmake dimension
plackowski posted a topic in AutoLISP, Visual LISP & DCL
Hello! I just stared working in AutoLISP a few days ago, and I've come across a problem. I need to create a dimension line where the dimension value is dependent on an input value. So if the input is y, then the text on the dimension line should equal 4.5*(y+1) inches, and it also needs to have a character width of 0.75. Currently, it just displays 4 1/2". As I understand it, this would be a real number, meaning I can't concatenate it with the inches symbol. Any help would be greatly appreciated! (defun c:retan (/ p1 p2 p3 p4 x y i j)(setvar "osmode" 0) (setq p1 (getpoint "\nfirst corner of rectangle: ")) (setq x (getint "\nEnter Horizontal Count: ")) (setq y (getint "\nEnter Vertical Count: ")) (setq p3 (list (+ (+ 1.625 (* 0.8125 (- x 1))) (car p1))(+ (+ 1.625 (* 0.8125 (- y 1))) (cadr p1)))) (setq p2 (list (car p1)(cadr p3))) (setq p4 (list (car p3)(cadr p1))) (command "pline" p1 p2 p3 p4 "c") ;c closes the rectangle's fourth side (entmakex (list (cons 0 "DIMENSION") (cons 100 "AcDbEntity") (cons 8 "E-DIMS") ;; 8 Layer (cons 100 "AcDbDimension") (cons 10 (list (- (car P1) 0.7) (cadr P2) 0)) ;; 10 Arrow Node (cons 11 (list (- (car P1) 0.9) (/ (+ (cadr P2)(cadr P1)) 2) 0)) ;; 11 Text Position (cons 70 160) (cons 1 "{\\W0.75;4 1/2\"}") ;; 1 Contents of Dimension Textbox (cons 71 5) ;; 71 Text Alignment (5=centered) (cons 42 0.8125) (cons 53 1.5708) ;; 53 Text Rotation (cons 3 "REW-1_.125txt") (cons 100 "AcDbAlignedDimension") (cons 13 P1) ;; 13 point on line (cons 14 P2) ;; 14 point on line (cons 50 1.5708) ;; 50 Angle (radians) 1.5708 (cons 100 "AcDbRotatedDimension"))) (setvar "osmode" 16383)(princ) ) -
Hi folks, I need help on fixing the arrowhead. Some drawings come with default setting for Arrowheads as OPEN. When I run an utility (which inserts a leader with custom texts as a block), it inserts arrowheads as open. My requirement is to add Solid arrowheads always. I tried to force it via below code but its not forcing. Can anyone suggest? What could be wrong? (defun Addleader (/ pt1) (setvar "DIMLDRBLK" ".") (while (setq pt1 (getpoint "\nInserting task description note, Specify Arrow End Point or hit Enter to close:")) (Command "_INSERT" "CP TEXT" pt1 "" "" "") (command "explode" "l") );end while ) ;end defun EDIT: I think it has to do something with the default DIMSTYLE. And the block I'm trying to insert it on the Standard dim style. Not sure how to handle this.
-
How do I have a command causes a function to
WPerciful posted a topic in AutoLISP, Visual LISP & DCL
I wrote a sub-routine to update drawing borders. There is a command in CADWorx called IGO which creates isometric drawings. I wanted have this command call my function which updates the borders. But my code doesn't work. (defun c:igo ( / ) (setvar "cmdecho" 0) (command "igo") (setvar "cmdecho" 1) (runisoborderupdate) (princ) ) -
BabaCAD 1.3 released as world's first LISP enabled freeware CAD
sepultura posted a topic in Useful Links
I want to inform you that BabaCAD is updated and you can download new 1.3 release at official website http://www.babacad.com or you can read great reviews at softandapps.info (spain), 4cad.info (poland), download.cnet.com etc... Most important to tell about this new release is AutoLisp compatibility (for most .lsp files). LISP is available as free extension module and you can download it from babacad website. LISP is beta and next updates will come with missing functions and fixes. LISP module comes with examples loaded at startup (chcolor.lsp, drawextent.lsp, gear.lsp). Users can edit bcad.mnu file for loading favorite lisp routines/commands and create custom toolbars (read bcad.mnu in support folder for details). defun c:mycommand (/ var1 var2) is supported so you can define custom commands. Regards, Mirza -
In a function how do you get it to not go any further? The code below doesn't exit the function. (if (or (= dir (getroot)) (= dir (strcat (getroot) "\\Titleblocks"))) (progn (princ "\nHey you’re not allowed to delete files from this folder! ") end ) ) Apparently end doesn’t do what I thought it did . . .
-
If using a Partial customization file that is still in the process of being updated regularly or you’d like that option to updated it, is the best practice to load it via the acad.lsp and your loader through the acad.lsp?
-
Do you need a separate .dcl file to load each dialog box?
-
I have 2 questions about a dialog box I wrote. 1. The drop down boxes aren’t wide enough to display all of the text. How do I fix this? 2. Currently in order to select a second line in the list box you have to hold down the shift key. How can I change it so that the selections remain selected without holding down the control key? The command that luanches the dcl (defun c:bprint ( / ) (setq retlist1 nil) ;;; lm:directorydialog ;;; Author: Lee Mac, Copyright © 2013 - www.lee-mac.com ;;; (setq thedirectory (lm:directorydialog "Select folder: " nil 0)) (if (/= thedirectory nil) (setq List1 (vl-directory-files thedirectory "*.dwg")) end ) (setq List2 (list "")) (batch thedirectory List1 List2) (if (/= retlist1 nil) (progn (if (/= (findfile "BPlotData.txt") nil) (setq filedata (readfile (findfile "BPlotData.txt") ) files (cdr filedata) batchplotfiles (list ) ) ) (foreach file files (setq batchplotfiles (append batchplotfiles (list (strcat "open \"" thedirectory "\\" file "\" (mybatchprint) ZOOM E close Y") ) ) ) ) (makefile (strcat (strcat "C:\\Users\\" (getvar "loginname") "\\Documents") "\\" "BatchPlot.scr" ) batchplotfiles ) (command "_.script" (strcat "C:\\Users\\" (getvar "loginname") "\\Documents\\BatchPlot.scr") ) ) ) ) The function the runs the dcl (defun batch ( mydir lista listb / prin ) (setq dir mydir poplist1 (list ) mylist1 lista mylist2 listb ) (setq poplist1 (getplotters) poplist2 (getplotstyles) ) (if (not (setq dcl_id (load_dialog "batch.dcl"))) (progn (alert "The DCL file could not be loaded!") (exit) ) (progn (if (not (new_dialog "batch" dcl_id)) (progn (alert "The BATCH definition could not be loaded!") (exit) ) (progn (start_list "poplist1" 3) (mapcar 'add_list poplist1) (end_list) (start_list "poplist2" 3) (mapcar 'add_list poplist2) (end_list) (start_list "mylist1" 3) (mapcar 'add_list mylist1) (end_list) (action_tile "pickdir" " (setq pickdir \"Yes\")(done_dialog 1)") (action_tile "accept" "(saveVars)(done_dialog 2)") (action_tile "cancel" "(done_dialog 3)") (setq ddiag (start_dialog)) (unload_dialog dcl_id) (if (= ddiag 1) (princ "\nSelect directory . . . ") ) (if (= ddiag 2) (princ "\nPlease wait. . . ") ) (if (= ddiag 3) (princ "\nBatch print has been cancelled! ") ) ) ) ) ) (princ) ) The DLC code batch : dialog { : boxed_column { : row { : popup_list { label ="Choose printer"; key = "poplist1"; height = 15; width = 30; multiple_select = true; fixed_width_font = true; value = "0"; } } : row { : popup_list { label ="Choose plot style table"; key = "poplist2"; height = 15; width = 30; multiple_select = true; fixed_width_font = true; value = "0"; } } : list_box { label ="Choose Item"; key = "mylist1"; height = 15; width = 25; multiple_select = true; fixed_width_font = true; value = ""; } : row { : button { key = "accept"; label = " Print "; is_default = true; } : button { key = "cancel"; label = " Cancel "; is_default = false; is_cancel = true; } } } }