Search the Community
Showing results for tags 'autolisp'.
-
Why does ssdel remove entities from other selection sets, and how to get around it?
benhubel posted a topic in AutoLISP, Visual LISP & DCL
I am writing a routine that requires that I remove objects from a selection set while still keeping the original set around. After running into issues, I created a test routine to see how ssdel is operating. I want it to remove selB from selC, while keeping selA and selD untouched to hold the original selection. It is removing selB from all related selection sets though. Why is it doing this, and how can I fix it? (defun c:TD () ;Test Delete (setq selA(ssget)) ;get base selection A (setq selB(ssget)) ;get selection B to remove from selection C (setq selC selA) ;copies selection A and removes selection B to return the difference (setq selD selA) ;extra variable to test how ssdel works (setq i 0) ;index (repeat (sslength selB) ;repeat for each entity in selB (ssdel (ssname selB i) selC) ;intended to remove selB from selC. It is also removeing selB from selA, which I don't want. (setq i (1+ i))) ;increment ) ;Functions below are used to test which geometry is contained in which selection set (defun c:dela () ;delete geometry in selection A (If(/= nil selA)(command ".erase" selA "")(princ "\n selA is empty. Run TD to initialize"))(princ)) ;if selA contains entities, delete them. If not, display error. (defun c:delb () ;delete geometry in selection B (If(/= nil selB)(command ".erase" selB "")(princ "\n selB is empty. Run TD to initialize"))(princ)) ;if selB contains entities, delete them. If not, display error. (defun c:delc () ;delete geometry in selection C (If(/= nil selC)(command ".erase" selC "")(princ "\n selC is empty. Run TD to initialize"))(princ)) ;if selC contains entities, delete them. If not, display error. (defun c:deld () ;delete geometry in selection d (If(/= nil selD)(command ".erase" selD "")(princ "\n selD is empty. Run TD to initialize"))(princ)) ;if selD contains entities, delete them. If not, display error.- 5 replies
-
- selection sets
- autolisp
-
(and 1 more)
Tagged with:
-
Hello, guys! I need a lisp to rename the current open file. I already have a routine that takes the current file name and creates a string with the new file name (Just six numbers in the old name needs to change)... But I coudn't change the old name for the new name. I've tried to use the (Vl-File-Rename), but I think that i didn't use it right.... Here's go the code: (defun C:changename (n1 n2 n3 n4 n5 n6) (setq new_number (strcat (itoa n1) (itoa n2) (itoa n3) (itoa n4) (itoa n5) (itoa n6))) (setq old_name (strcat (getvar "DWGPREFIX") (getvar "DWGNAME"))) (setq size (strlen old_name)) (setq final (- size 18 )) ; (setq start_name (substr old_name 1 final )) (setq end_name (substr old_name (+ final 7) (- size final))) (setq new_name (strcat start_name new_number end_name)) (alert old_name) (alert new_name) (vl-file-rename old_name new_name) ); end defun The old name is: D:\Profiles\s-Andre.Almeida\Desktop\Autocad\3-157941-012-005.dwg The new name, for example, could be: D:\Profiles\s-Andre.Almeida\Desktop\Autocad\3-666666-012-005.dwg I just need to change the names with the (vl-file-rename) could someone help me?
-
Lisp to open multiple DWG's and write in each one
andr3flaviano posted a topic in AutoLISP, Visual LISP & DCL
Hello, guys! I'm creating a lisp to open multiple DWG's in a directory and alterate a number at a especific position. I have a function (called txt) to write the number at a position and I have another function (called change_all) to open every DWG in the directory and execute the function "txt". I want that the "Change_all" asks me the number and then execute the "txt" to write that number in all DWG's. The functions are already working, but i couldn't call the "txt" with the parameter number previously defined Here are the code: (defun c:txt (tval) ; (setq num0 (ssget "_C" '(347.06 18.12) '(350.90 18.12))) ; (command ".erase" num0 "" ); (setq pt1 '(346.5 15.84)) ; (if (not (tblsearch "Layer" "TEXT")) (command "-layer" "m" "TEXT" "") ) ;_ end if (entmake (list '(0 . "TEXT") '(8 . "TEXT5") (cons 10 pt1) (cons 40 4.5) (cons 1 tval) '(50 . 0.0) '(7 . "ROMANS") '(71 . 0) '(62 . 4) '(72 . 0) '(73 . 0) ) ;_ end list ) ;_ end entmake (*error* "") (princ) ) ;_ end defun (defun c: change_all (/ dwglist dwgname dwgpre file openfile uhoh len) (vl-load-com) (if (and (setq dwgpre (getvar 'dwgprefix)) (setq dwglist (vl-sort (vl-remove (strcat dwgpre (getvar 'dwgname)) (mapcar '(lambda (dwgname) (strcat dwgpre dwgname)) (vl-directory-files dwgpre "*.dwg") ) ) ' ) ) (setq uhoh "Readonly drawings will not be processed!" ) (setq len (strlen uhoh)) ) (progn (setq openfile (open (setq file (strcat dwgpre "myscript.scr")) "w")) (setq num (getstring t "\nType the numer: ")) ; (progn (foreach f dwglist (if (and (not (Is_ReadOnly f)) (/= (checkAttFile f) 1) ) (progn (write-line (strcat "_.open \"" f "\"") openfile) (write-line "(C: (txt num))" openfile) ; (write-line "_.qsave _.close" openfile) ) (setq uhoh (strcat uhoh "\n" f)) ) ) (close openfile) (command "_.script" file) (if (= (strlen uhoh) len) (princ "All drawings successfully processed...") (alert uhoh) ) ) ) ) (princ) ) ; End Defun Could someone help me, please?- 1 reply
-
- open dwg
- function calling
-
(and 3 more)
Tagged with:
-
Lisp Routine to Bring in Z Value (Lee Mac Lisps)
RigourSurvey posted a topic in AutoCAD 2D Drafting, Object Properties & Interface
Hi Everyone, We have browsed the forum looking for a Lisp Routine for creating Z values from point clouds. Lee Mac has came up with something which works well (great work Lee). Though we are looking to modify this to suit our workflow: Basically we want to pick a point and bring through the z value as text. (which the lisp below works fine) though not having the option to choose between x,y,z and only picking the z value every time would be beneficial. Having a fixed offset and text size too rather than having the option to choose Next we need the lisp to bring in some text for the selected level i.e creating text with the remark DL. Once we have one code for this lisp we can then alter this to bring in other remarks such as CL WHL CHL USB etc etc. Then we can customise each lisp with a button in CAD. One Last thing is the lisp below creates a Cross from two drawn lines. Does anyone know how to make this a separate entity like a Symbol/Block and change it so its square to the model space unlike the current cross If anyone can help with this it would be fantastic and heavily aid our workflow. The code below is as Lee Mac has posted (defun c:ptlab (/ Text _PromptWithDefault _Cross Pt pos) ;; Lee Mac ~ 30.03.10 (defun Text (pt hgt str) (entmakex (list (cons 0 "TEXT") (cons 10 pt) (cons 40 hgt) (cons 7 (getvar 'TEXTSTYLE)) (cons 1 str)))) (defun _PromptWithDefault (f arg d) (cond ((apply f arg)) (d))) (defun _Cross (p h / l) (setq l (sqrt (* 0.5 h h))) (mapcar (function (lambda (p1 p2) (entmakex (list (cons 0 "LINE") (cons 10 p1) (cons 11 p2))))) (list (polar p (/ pi 4.) l) (polar p (/ (* 3 pi) 4.) l)) (list (polar p (/ (* 5 pi) 4.) l) (polar p (/ (* 7 pi) 4.) l)))) (setq *Coord* (cond (*Coord*) ("Y")) *tHgt* (cond (*tHgt* ) ((getvar 'TEXTSIZE))) *thOff* (cond (*thOff*) (0.15)) *tvOff* (cond (*tvOff*) (0.15)) *cSze* (cond (*cSze* ) ((getvar 'TEXTSIZE)))) (setq pos '(("X" . 0) ("Y" . 0) ("Z" . 2))) (initget "X Y Z") (mapcar (function set) '(*Coord* *tHgt* *thOff* *tvOff* *cSze*) (mapcar (function _PromptWithDefault) '(getkword getdist getdist getdist getdist ) (list (list (strcat "\nSpecify Coord to Label [X/Y/Z] <" *Coord* "> : ")) (list (strcat "\nSpecify Text Height <" (rtos *tHgt*) "> : ")) (list (strcat "\nSpecify Horizontal Text Offset <" (rtos *thOff*) "> : ")) (list (strcat "\nSpecify Vertical Text Offset <" (rtos *tvOff*) "> : ")) (list (strcat "\nSpecify Cross Height <" (rtos *cSze*) "> : "))) (list *Coord* *tHgt* *thOff* *tvOff* *cSze*))) (while (setq pt (getpoint "\nPick Point to Label <Exit> : ")) (_Cross (setq pt (trans pt 1 0)) *cSze*) (Text (polar (polar pt 0. *thOff*) (/ pi 2.) *tvOff*) *tHgt* (rtos (nth (cdr (assoc *Coord* pos)) pt)))) (princ)) Thanks in Advance Mark- 1 reply
-
- point cloud
- lisp
-
(and 2 more)
Tagged with:
-
Extract Text data at a XYZ coordinate from Autocad
kArThIcK hAcKeR posted a topic in AutoLISP, Visual LISP & DCL
Hi guys, Attachment: Test Drawing.dwg I want to retrive the text's content, the text is placed at a certain XYZ co-ordinate in Autocad, (same coordinates, always for all the drawings). [Refering to the attachment]: The text below the "Surface Area" and the "Weight", are mostly the texts i'm trying to get. These texts sometimes come as a single line text or as a mtext or within blocks.. but always they appear at the same coodinates. Can somebody help me with this?- 7 replies
-
- coordinate
- autolisp
-
(and 1 more)
Tagged with:
-
Error for ObjectID of polyline using vlax-curve-*
HelplessIntern posted a topic in AutoLISP, Visual LISP & DCL
I have just started learning AutoLISP from different posts on the forums and through the reference material from Autodesk but, I am hitting an error in my lisp routine that I don't know how to fix. I am trying to right a while loop that will go through a nested list and use information in the selected list segment to find points in reference to a Polyline using the vlax-curve-* functions. Currently I am using the vlax-curve-getPointAtDist with a variable distance and using a user defined polyline from the document. My code runs up until the point I try to use the getPointAtDist line which will return the error of "unable to find ObjectID for . The way I get the polyline from the user is a (setq Var (ssget "_+.:s" '((0 . "*POLYLINE")))). I have earlier in the routine the vla-load-com to load in all of the functions of visual lisp. Can anyone help me out on what I need to do to be able to run the vlax-curve-* functions?- 10 replies
-
- objectidcollection
- autolisp code problems
-
(and 2 more)
Tagged with:
-
Flip Parameter, Dynamic Blocks & Autolisp
TheyCallMeJohn posted a topic in AutoLISP, Visual LISP & DCL
Does anyone know a clean way to toggle a specified flip parameter using auto lisp visual lisp? I use the getdynprops, getdynpropvalue, putdynpropvalue [by Jeff Mishler based on code from Steve Doman, Herman Mayfarth and Tony Tanzillo] for most of my dynamic block changing needs but I can't get it they don't seem to work for the flip parameter.- 11 replies
-
- dynamic block
- autolisp
-
(and 1 more)
Tagged with:
-
Boundary Creation Lisp- by Text selections
zefreestijl posted a topic in AutoLISP, Visual LISP & DCL
Thread: Boundary Creation Lisp- a request HI, I just learned how to create boundary smoothly from the above post. is there a way to create boundary by the coordinates of selected Texts? Thanks!- 5 replies
-
- coordinate
- boundaries
-
(and 2 more)
Tagged with:
-
Hello all you CAD Guru's out there! I am currently having trouble creating a lisp and am in desperate need of experienced guidance. I am trying to make a command such as (defun C:lo () (command "layer" "on" "*" "t" "*" "")) which turns all layers on, however i need the layers Circuit-1 through Circuit-12 to be untouched. For example if i have circuits 5 through 12 turned off, frozen, whatever state they may be in needs to not be affected by the command to turn all layers on. Basically I would like to make a command that turns all layers on with the exception of layers Circuit-1 through Circuit-12 I started to write a code based on layer groups which I though may be the way to accomplish this task. I.E. make a layer group of all layers EXCLUDING or removing Circuit 1-12 and thaw or turn on all of that layer group. I am unsuccessful in thawing the "new layer filter" using code. (I can however right click on the group and change its visibility to thawed and that works.) (defun c:TESTER (/) (COMMAND "-LAYER" "FILTER" "NEW" "GROUP" "" "*" "NEW LAYER FILTER" "") (COMMAND "-LAYER" "FILTER" "EDIT" "NEW LAYER FILTER" "DELETE" "CIRCUIT-1" "DELETE" "CIRCUIT-2" "DELETE" "CIRCUIT-3" "DELETE" "CIRCUIT-4" "DELETE" "CIRCUIT-5" "DELETE" "CIRCUIT-6" "DELETE" "CIRCUIT-7" "DELETE" "CIRCUIT-8" "DELETE" "CIRCUIT-9" "DELETE" "CIRCUIT-10" "DELETE" "CIRCUIT-11" "DELETE" "CIRCUIT-12" "") (command "-layer" "t" "new layer filter" "")) Where have I gone wrong?
-
Hello, Im using AutoCAD, AutoCAD Mechanical 2009 and Mechanical Desktop 2009 I have parts that have a material assigned to them through the 'MASSPROPS' dialog box. When assigning the material to a part, material properties associated with that part are assigned as well. Is there a way to either remove the material assignment or create a "dummy" material with material property values set to 0 and assign this new material to the part using AutoLISP? If not AutoLISP, is it possible using any other code type?
-
Routine to read Excel with unknown number of lines
undermustang posted a topic in AutoLISP, Visual LISP & DCL
Hey guys, I am writting a routine to read a excel file that contains a column with the number of the element, a column with the x's coordinate and a column with the y's coordinate. I need a way of making a loop to read whatever elements are filled by the excel's user and get this values in vectors so they can be used after. Is there anyway of doing that? Thank you very much! -
Hello, Could anyone help me let this LISP work. The lisp should go to the layer you choose (by pressing 1 or 2) when in a *DIM* command. After placing the dimension the layer should go back to the layer it was before selecting a *DIM* command. This is the code now. ; AFKORTINGEN VAN DE VARIABELEN ; ADDL Automatic dimension layer ;**************************************************************************** (defun CommandReactor:Start () (or *CommandReactor* (setq *CommandReactor* (vlr-command-reactor nil '( (:vlr-commandcancelled . CommandReactor:CommandEnded) (:vlr-commandended . CommandReactor:CommandEnded) (:vlr-commandfailed . CommandReactor:CommandEnded) (:vlr-commandwillstart . CommandReactor:CommandWillStart) ) ) ) ) (prompt "\nCommand reactor loaded. ") (princ) ) ;**************************************************************************** (defun CommandReactor:CommandEnded (rea cmd) (if (and *OldClayer* (wcmatch (strcase (car cmd)) "*DIM*") ) (progn (setvar 'clayer *OldClayer*) (setq *OldClayer* nil) ) ) ) ;**************************************************************************** (defun CommandReactor:CommandWillStart (rea cmd) (if (wcmatch (strcase (car cmd)) "*DIM*") (progn (setq *OldClayer* (getvar 'clayer)) (vla-add (vla-get-layers (vla-get-activedocument (vlax-get-acad-object))) ; Kiezen van de DIM layer (setq ADDL 0) (while (or (< ADDL 1) (> ADDL 2)) (setq ADDL (getint "\nInput the DIM layer: Dim. (1), Dim. front (2): "))) ) ; end while ;ADDL = 1, Dimension layer (if (= ADDL 1) (progn (command "_layer" "_m" "S-DIMENSIONS" "_c" "3" "" "") ); progn ); if (=ADDL 1) ;ADDL = 2, Dimension front layer (if (= ADDL 2) (progn (command "_layer" "_m" "S-DIMENSIONS front" "_c" "3" "" "") ); progn ); if (=ADDL 2) (setvar 'clayer *OldClayer*) ) ) ) ;**************************************************************************** (CommandReactor:Start) (princ) ;**************************************************************************** ;**************************************************************************** ;**************************************************************************** ;**************************************************************************** Please help! Thanks!
-
Trouble with xyz coordinate import LISP
philnesterovic posted a topic in AutoCAD 2D Drafting, Object Properties & Interface
Hi all, I am using the attached lisp to import xyz (PNEZD) coordinates into Autocad 2015 with their points numbers and descriptions. The lisp works great, the only problem is that when all the points are put in, I can't change the colour and layer of the attached descriptions and elevations. The points themselves will change colour and layer, but we can't get the writing to move to those same layers. I'm not sure if this requires working on the lisp itself, or if it is something that can be fixed in a setting in Autocad, but I'm definitely stuck! Any help would be greatly appreciated. Thanks! pointsin-v1.0.13.zip- 2 replies
-
- lisp
- coordinates
-
(and 3 more)
Tagged with:
-
I have thousands of sketches in autocad and need to calculate the weight for each sketch. The sketches are all in 2D format. The sketches are of shafts with different diameters and lengths. Each shaft has a major diameter and then a varying number of steps each with its own diameter and length. The dimensions of most of the sketches are associated to objects in the sketch; however, there are some sketches with non-associative dimensions. Is it possible to write an AutoLisp program to go through all of these sketches and pull the diameter & length of each shaft (including each diameter and length of each journal step) and then use the information to calculate volume and weight. Currently, I have an excel program that will calculate the weight if I type in all the length and diameter dimensions of the objects. The task is repetitive and time consuming. Writing a program may help expedite the task. Any advice would be helpful. Thanks
- 6 replies
-
- properties
- autolisp
-
(and 1 more)
Tagged with:
-
Hello All, This is my first post on CADTutor forum. This is a pretty extensive request, however I am looking to essentially do this exact routine: https://www.youtube.com/watch?v=FLOif87iLMw This automated process of creating the stepped boundaries to angled polylines based on the size of a panel, as well as automatically drawing panels into the drawn boundaries, etc, is everything that I need. Creating profile views, cross sections, etc. The question is, are there any AutoCAD commands that would expediate this programming or do I need to brute force this and essentially create a lisp routine from scratch? The more basic the steps, the easier I would be able to understand because I am relatively new to AutoCAD in general. In general where do I start? Thank you in advance for any help!
- 2 replies
-
- cross sections
- automation
-
(and 2 more)
Tagged with:
-
I am trying to write an autolisp program to insert a row of 20 blocks in a drawing, (one over the other), then insert attributes for each from a row in an Excel file. I am using Jeffrey Sanders' "GetCells" function. The Excel file is "RO-16.xlsx" Here's what I have done so far: (defun Addenters ( / cnt yval) (setq cnt 1) (setq yval 0) (setvar "osmode" 0) (load "getcells.lsp") (while ( ( (setq *doc* (vla-get-activedocument (vlax-get-acad-object))) (command "insert" "C:\\07509\\BD" (strcat "0," (itoa yval))"1" "1" "04" (getCellsFunction "C:\\07509\\RO-16.xlsx" "ALLOCATED" "K2") ) (setq cnt (1+ cnt)) (setq yval (+ 8 yval)) ) ) ) So the first attribute, "PLC" is read from cell K2 in the Excel file. There are 7 attributes altogether. Is there a more compact way to do this (with a list or array). I want to avoid having a long line (which is answering to the Autocad prompt for block attributes) which looks like: (getCellsFunction "C:\\07509\\RO-16.xlsx" "ALLOCATED" "L2"), (getCellsFunction "C:\\07509\\RO-16.xlsx" "ALLOCATED" "M2") and so on.
-
Generate mutiple AutoCAD drawings from data stored in an Excel file.
Berbero posted a topic in AutoLISP, Visual LISP & DCL
Dear smarties I read a few articles here and there regarding a way to generate multiple drawings from an excel file, but no one had explained step by step on how to do it. So, I am lost half way. I am very new to this kind of things, but I will try to follow, so please go slow on me. here is what I want to fix: 1. I need to automatically generate 10 drawings both in dwg and pdf copied into a folder. 2. All the variables (VAR1 to VAR3) are stored in an excel file. refer to the attached files as an example. 3. I only need to create one original drawing, which will be used to generate all the 10 drawings. Please help EXCEL-VAR.xls ORIGINAL-DWG.dwg -
I keep getting an error when I use getpoint. When I look at SPT or EPT it's nil (defun c:STUD15 (/ SPT EPT Wallth Ceilinghg) (setq SPT (getpoint "\nPick start of wall.....")) (setq EPT (getpoint "\nPick end of wall....."));at this point I get...error: bad argument type: 2D/3D point: nil (setq Wallth (distance spt ept));length of wall (setq Ceilinghgt 96.0) (setq UnflrBeamhgt (+ Ceilinghgt 0.5)); Can someone explain what I am doing wrong. Thanks
-
I’m in the process of updating nearly 400 blocks. I have to change the layer and override the color of one attribute. My test on the first block failed. It's just been a while and I can't remember what I'm missing. My attempt for changing the first one: (progn (setq e (car (entsel )) d (entget e) n_e (entnext e) n_d (entget n_e))) un_d (subst (cons 8 "SYM") (assoc 8 n_d) n_d) un_d (append un_d (list un_d (cons 62 141))) ) (entmod un_d) (entupd (cdr (assoc 330 un_d))) ) I've also tried: (command "_.attsync" "_select" n_e "" )"_Yes") note: as I step through the block entities I will be testing to insure I've got the right block with: (and (= (cdr (assoc 0 n_d)) "ATTRIB") (= (cdr (assoc 2 n_d)) "SIZE") (/= (cdr (assoc 8 n_d)) "SYM") )
-
Very usefull tool to transform 3D Faces To Solid ! ...or a 3D terrain model to a sectionable solid http://www.sharedengineering.com/index.php/13-download/autolisp/20-autolisp-to-transform-3d-faces-to-solid >>> http://www.sharedengineering.com
-
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.