AutoCAD Visual LISP / AutoLISP :: Math In Foreach Function
May 15, 2013In the foreach function can you use math like (foreach pt1 (add 1) so that foreach one you pick it adds one the next one will be named pt2 then pt3 and so on.
View 6 RepliesIn the foreach function can you use math like (foreach pt1 (add 1) so that foreach one you pick it adds one the next one will be named pt2 then pt3 and so on.
View 6 RepliesI need to make all the obj like one pol after I select them all not just the last one so I can get the intersection of each obj1
(DEFUN C:CHF ()
(vl-load-com)
(if (not (member "geomcal.arx" (arx)))
(arxload "geomcal")
)
(command "undo" "BE")
(setq osm (getvar "osmode"))
(setvar "osmode" 0)
[code]....
This seems absolutly silly.
(setq p1 (getpoint))
(setq p2 (getpoint))
(setq Dist (distance p1 p2))
Why does this not work?
I'm trying to build a command to replace AutoCAD's "DI" command, to give distance and delta x, y, and z values in decimal and imperial, and keep the angles in XY plane and out of XY plane.
simple example code how can i set my lisp function to radio button ?
i found simple dcl - lisp codes , there is possibility for calling simple cad commands , but this is different about call lisp with buttons
which code i have to change and how for set my lisp on radio buttons ..
here is the sample codes ...
SAMPLE1 : dialog { label = "Sample Dialog Box Routine - Part 1"; : column { : boxed_column { : button { key = "but1"; label = "Button 1";
[Code].....
I want to define en expiration date in registry, after that date the some LISP programs does not allow to run. I think that suitable commands are SetEnv and GetEnv.
define a ExpDt variable that contains Expiry Date as a string. And add some statements inside of the LISP program to call this variable and check it with today's date.
I should define once time in autocad:
(setenv "expdt" "130101"); YYMMDD date for validation period (2013.01.01)
and check this every time that a lisp program should be execeute:
(getenv "expdt") ; if today's date(with YYMMDD format) ">" expdt then lisp program doen not allow to run and should be halted.
for e.g. on 2013.02.28: "130228" > "130101" ==> so the lisp function should be halted and will not work!
(without any alert or message)
a sample list function: (how can implement on this lisp function?)
(defun c:3()
(setq w t)
(while w
(setq a (getpoint "
pick point:"))
(setq p1 (list (- (car a) 0.5)(- (cadr a) 0.5)))
(setq p2 (list (+(car a) 0.5)(+(cadr a) 0.5)))
(command "erase" "w" p1 p2 "")
(command "INSERT" "*3" a "" "" "0")
)
(if (= a nil)(setq w nil))
)
I would like a small menu to pop up near the cursor like the middle mouse button menu, but based on some other function key or quick key shortcut.
View 2 Replies View RelatedThe error below has appeared randomly when AutoCAD 2011 is started. There was not an error of this sort, but it suddenly appeared and some of the LISP routines will no longer work.
*Invalid attempt to access
a compiled function definition. You may want to define it using defun-q:
#<SUBR @000000003f5fda98 S:: STARTUP>
In asp I'd write:
arrFileName = Split(DrawingName, "_")
JobNumber = arrFileName(0)
DrawingTitle = arrFileName(1)
SheetNumber = arrFileName(2)
I'd like to do the same thing in lsp. I don't want to be limited to three fields so the split function is perfect.Is there an equivalent?
How to make a lisp command that will select all objects in the drawing?
View 3 Replies View RelatedI open the drawing without loading the function, when I modify an object with the reactors appears the following error message:
function definition: NAMEFUNCTION
You can avoid this annoying message without removing the persistent reactors?
I prepared a code to calculate number of days between two date.
I want to know how can I define negligible arguments for my lisp routins. It means if I omitted the arguments, lisp code can handle it without any errors ("; error: too few arguments")
In this case, my program defined as: (TotalDays 1st_date 2nd_date)
(TotalDays 1978 03 21 2013 06 25)
and I want to have flexibility: if I use this routine as (TotalDays 1978 03 21), the program should substitute today's date with second date.
I know if I put "nil" instead of date for 2nd_date, It will not be an error, because:
(if (and y2 m2 d2) (setq n2 (GetJDN y2 m2 d2))(setq n2 (fix (getvar "DATE"))))
but that's not my favourite!, how can I omitted 2nd_date completely? as (TotalDays 1978 03 21)
Here is my lisp
;|How to use:(TotalDays 1978 03 21 2013 06 25)|;;;;;By Abbas Aqdam(defun TotalDays ( y1 m1 d1 y2 m2 d2 / n1 n2)(setq n1 (GetJDN y1 m1 d1))(if (and y2 m2 d2) (setq n2 (GetJDN y2 m2 d2))(setq n2 (fix (getvar "DATE"))))(abs(- n1 n2)));;;;Leap years are included;;;;By Abbas Aqdam(defun GetJDN ( year month day / a y m J)(setq a (/(- 14 Month) 12))(setq y (-(+ year 4800) a))(setq m (-(+ Month (* 12 a)) 3))(setq J (-(+ day (/(+(* 153 m) 2)5) (* 365 y) (/ y 4) (/ y 400)) (/ y 100) 32045)))
I D/L a lisp file (setvars.lsp) that purports to give a list of system variables that match a short string entered in a dialog box.
Unfortunately, an error arises that says 'error : no function definition: STRNUM'
I've looked at the code and can't tell what the writer was hoping to achieve.
The specific section is as follows:
(if F1
(progn
(setq RL (read-line F1))
(while RL
(if (and (wcmatch (strcase RL) (strcase (strcat "*" DESCR1 "*")))
(wcmatch (strcase RL) (strcase (strcat "*" DESCR2 "*")))
[Code] .........
There is no other mention of STRNUM in the whole of the lisp.
There is an accompanying setvars.dat, wherein apparently, the writer compiled a data file of all the system variables in AutoCAD2008, each variable being followed by an '=' and then a description of the variable.
If necessary I can post the whole lisp and dat file, but was hoping to discover the intention from the above extract and therfore where I might work out an alternative to this line.
Looking to turn a string to a real? If so, why are there two 'arguments' following the 'function' STRNUM?
I was able to find/update a LISP program that returns the dynamic block to its original state, overriding the anonymous name and make the actual block name the effective name. I am in the process of manipulating the LISP program so I can select multiple blocks rather than one at a time.
(defun CYMEFFEC ()(vl-load-com) (setq obj (vlax-ename->vla-object (car (entsel "Select blocks: ")))) (vlax-put obj 'Name (vlax-get obj 'Effectivename)))
I would like to insert a block in a specific layout (eg. "LAYOUT13") using the function vla-insertblock
I have already searched the web and this newsgroup but have not found the solution.
I have a simple lisp function to add a scale axis to a drawing by calling a script, renamed the drawing by appending "withScale" to the file name, and then closing the file. I placed a call to the function in the acad.lsp file in the startup suite. The idea was to batch process all files by simply opening them. Upon open the startup acad.lsp file runs, which calls my lisp function, which in turn calls the scale script. It should then execute the renaming, saving, and closing commands. The problem is that it is calling the script fine and renaming the file, but it does not save the changes before closing. Here is the lisp function
(defun saveScale(); (command "-purge" "all" "" "n")(if (findfile "C:/Users/Russell/Desktop/TreeFiles/Automation/Scale&Key.scr")(command "_script" "C:/Users/Russell/Desktop/TreeFiles/Automation/Scale&Key.scr")); end if (command "_.zoom" "e") (command "_saveas" "2013" (strcat (getvar "dwgprefix") (vl-filename-base (getvar "dwgname")) "withScale.dwg")) (command "close") ) (saveScale)
Apparently you cannont run any lisp commands after calling a script, however the renaming still follows through.
I've attached the script file as well. (I couldn't attach .scr format so you may need to rename it).
I have a list function that asks for the user to pick points when it is run. It looks something like this (foo arg1 arg2) When invoked it asks the user to pick points and press enter when done It.
Instead of getting the points from the user i want to pass it a list of pre-defined points. The code cannot be changed so I must use it as is.Is this possible, if so how can it be done?
I've got a subroutine that gets the centroid of a closed polygon (lwpoly). It appears to fail if the polygon has any zero length line segments. I've added a trap that catches the error and "highlights" the offending polygon, but it stops there and does not return to the main function that called the subroutine. Is there a way to get back to the main function from the trap?
Here's the subroutine (original function by _gile (Autodesk LISP Forum 9-18-2006):
(defun return-centroid (lwpoly space / obj Region Centroid)
(setq *error* trap1)
(setq obj (vlax-ename->vla-object lwpoly))
(setq Region (vlax-invoke space 'addRegion (list obj)))
(setq Centroid (trans (vlax-get (car Region) 'Centroid) 1 0))
(vla-delete (car Region))
[code]....
I am looking for a function to print out the entire entity list of the selected entity...
so... walking down through the entity data... print out what it finds... any time it encounters an entity name... then do an entget and print that out too.
Is there a lisp that will allow me to do a continuous dimension, but will alternate the dimension position from low, high, low and high? If there is no lisp already created, how to create one?
See Continuous dimension attachment for example.
I work at a glass and glazing company and this is how we dimension mullion width and DLO. See typical window dimensioning attachment for window elevation with dimensions.
I have a list ("temp.dwg" "temp2.dwg") and would like to add the string "insert text here" into each item in the list resulting in ("insert text heretemp.dwg" "insert textheretemp2.dwg"). how would i go about doing that using LISP?
View 2 Replies View RelatedIs there a way to programatically set a visual style before a drawing actually opens?
We have some huge models and people seem to forget to change their visual styles back to 2D wireframe before saving and exiting drawings. Some models will crash on some workstations when trying to open in a rendered mode.
I found a lisp with a function that looked to set viewport visual styles. But it does not seem to be supported anymore. --> (vla-put-VisualStyle vport 1)
I'm trying to write a lisp routine that, when I invoke the mleader command, osmode is set to "nearest" & orthomode is set off. I then would like the original settings to be returned.
attached is what I have written so far:-
Lisp that switches back on Selection Preview i.e. thickens and highlights lines when you hover over them?I don't know why, but they are always unticking the boxes.
View 4 Replies View RelatedI would like to know if there is a way / setting that I can turn of to where can do simple math problems when inputing numbers say for like offsetting a line without having to use AutoLisp.
For example if I was to offset a line I would type in "5.75/2" and get 2.875. I would like to be able to do this without having to type ( / 5.75 2).
Is there a way to do this without having to type all of that.
I am using AutoCad 2014, and at work we design driveline equipment so a lot of the drawings are from a front view to a section view, and for like a round cover that is in the front view it is easy to offset the centerline in the section view by the radius and continue drawing the section view.
Is it possible to execute a certain command based on multiple selections withinin a dcl? for example: two radio colums, one with selections A and B, and a second with selections 1 and 2. is it possible to program commands based on user selections from each column? ex: if A and 1- do a command. A 2- do a different command, etc...
I tried :
(action_tile "key1" "(setq A t")
(action_tile "key2" "(setq B t")
(action_tile "key3" "(setq 1 t)(done_dialog)")
(action_tile "key4" "(setq 2 t)(done_dialog)")
(if
(and (a) (1)
)
(command ...
but was unsuccessful. no matter which combination was selected, the command under all combinations would run.
I am trying to find a lisp that would get an attribute value (tag name = NBR_5) . I'm trying to run a simple routine that would let the user place the value from the titleblock attribute as text on a drawing. I see a ton of articles regarding getting attributes but I am not well versed in programming.
View 9 Replies View RelatedI have a routine that work fine, but I receive a nil at the end of command. How to fix that?
View 7 Replies View RelatedI'm trying to find acceptable point values to feed to the vlax-3d-point function for a vla-addmtext function. With vanilla lisp I just provide the point as x y = "7/32" "2-3/8". So I assumed that I could drop a 0 in for the z like: (VLAX-3D-POINT "7/32" "2-3/8" 0).
Then I thought I was going to be tricksy and try (vlax-3D-point (getpoint)) believing that I could pick the point and get what I need to feed the function, but yet again, no deal. The command line gave me:
node
of #<variant 8197 ...>
Nothing I can use in my code. So how do I find the point in a format that vlax-3d-point will like?
What is the magic word for put a point at each end of an arc, the lisp I have only put a point at center of the arc.
(defun cAA ( / i j ss e1 e2 p1 p2 p3 points )
(if (setq i -1 ss (ssget '((0 . "ARC"))))
(progn
[Code].....
Is there a quick way of getting the value of an attribute?
I have an attributed block called "tp_attributes" and it has and attribute called "OrderNum".
I just want to be able to quickly grab that value.
I use Spell Check regularly and I always check the entire drawing. I would like to add to the Spell macro so that when I pick Spell from the toolbar it goes past the Check Spelling window and begins checking the entire drawing.
I believe I need to insert Alt S into my macro to select Start from the window to begin the check. Is there a character or series of characters that will represent Alt in a macro?