AutoCAD Visual LISP / AutoLISP :: Upgrade Function To Grab Multiple Blocks?
Jan 23, 2012
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)))
View 3 Replies
ADVERTISEMENT
Mar 21, 2013
This time I'm wrestling with getting the values from multiple blocks. The blocks all have the same name but at least the attributes have names this time. Each block have exactly 4 attributes, like: att1 (a number representing chronological order), att2 (some data), att3 (the actual date as a string of when the data was added), att4 (some more data)
I need to get and store the attribute's values. I was hoping to make a selectionset of the blocks and step through using the chronological order number.
At this point I have tried several combinations of foreach and ssget "x" (list (cons 2 MYBLOCK)), but I keep getting errors that I'm sure are telling me that I'm not passing the correct information to the function for iterating through. I'm banging my head.
(DEFUN c:GFOR (/ ATTLST REVBLK CNT CNT1 BLK RBLK ATTVAL ATT REV#)
(SETQATTLST(LIST "R#" "INIT" "DATE" "DESC")REVBLK(ssget "x" (list (cons 0 "INSERT") (cons 2 "REVISION")))CNT0CNT10 )
(vlax-ldata-put "dict" "RevTotal" (BLKCNT "REVISIONS")) (FOREACH BLK REVBLK (SETQ RBLK (ssname BLK CNT1)) (setq ATTVAL (mapcar '(lambda (x) (vla-get-TextString x)) (vlax-invoke (vlax-ename->vla-object RBLK) 'GetAttributes))) (foreach ATT ATTLST (SETQ REV# (STRCAT "REVISION" (1+ CNT)))
(vlax-ldata-put "dict" REV# (member ATTVAL)) (setq CNT (1+ CNT)) ) (SETQ CNT1 (1+ CNT1)) ) (PRINC))
View 9 Replies
View Related
Mar 23, 2003
I have a lisp routine that uploads all the blocks contained within a specific folder and inserts or redefines all blocks of the same name within the current drawing.
My problem is that when I run the routine I prompts me that it can't fine the folder? I created a folder called "blocks" and is located straight onto my C:..........but it still doesn't work.
;FUNCTION TO UPDATE ALL BLOCKS WITHIN A DRAWING
;FROM A SPECIFIC DIRECTORY
(defun c:bup()
(SETVAR "cmdecho" 0)
(setq sst (ssget "X" (list (cons 0 "INSERT"))))
(setq c1 0)
[code].......
View 3 Replies
View Related
Oct 30, 2012
I am looking for a lisp routine or rename mulitple blocks by keeping the same name, but adding a suffix to it.
I have used "rename" block to add a prefix to multiple drawings, but it doesnt let you add a suffix. (As far as I can see)
View 7 Replies
View Related
Feb 27, 2013
We wanted to automatically fill a block's attributes from a selection in Excel. I have a piece of code that has the user select/pick a block to fill. What I want is for the selection to fill multiple blocks in an active drawing. Some of the blocks are the same - which means the same tags/attributes. I've included the code that allows the user to select the block and throws the Excel selection to certain attributes.change the code so that
1) I don't have to manually select blocks - it will find them.
2) One cell (from Excel) will go to multiple blocks - some are same block name.
3) An IF statement that if a certain cell isn't blank/nil
(pretend it would be (nth 21 vl) change DESC11 to XYZ and DESC12 to ABC. For Block namesake we'll call one, BLOCK1 (say it has 3 instances and gets different info in each case) BLOCK2 (say it has 2 instances, also gets different info) BLOCK 3 AND 4 both have an attribute - DESCAA1 that gets different info from Excel.
(defun C:AUTOFCM (/*error* adoc attribs blkobj enExcelapp Sel Sht Rng vl Wbk ) (defun *error* (msg)(if adoc (vla-endundomark adoc)) (if (and msg(vl-positionmsg '("console break""Function cancelled" "quit / exit abort") ))(princ msg)(princ "Error!") ) gc) (princ) ) (or adoc (setq adoc (vla-get-activedocument (vlax-get-acad-object))) ) (vla-startundomark adoc) (alert "Select a range of cells in Excel.") (setq ExcelApp (vl-catch-all-apply (function(lambda ()vlax-get-or-create-object "Excel.Application") )) ) ) (if (vl-catch-all-error-p(setq Wbk(vl-catch-all-
[code]....
View 1 Replies
View Related
Feb 4, 2013
I have to update a block in literally thousands of cad files. I have the book "AutoCAD Secrets Every User Should Know About" and the author gives examples of this by using a Batch File, Script File, and then Lisp Routine. Any easier way to do the following:
Insert "Gennnotes=" (updating the block) into any drawing that has this block in the drawing already, if not Quit.
Typically to do this I would open the drawing "insert" "gennotes=", then cancel the command and save the drawing. I have a lot of subfolders that also hold drawings so the command would have to search through each subfolder for dwgs.
Like I mentioned above, I tried to use the Batch File/Script Method but my batch file failed. It could find the folder Autocad 2012 - English. For some reason it was not seeing the spaces in between. Not sure. Here's the batch file portion of the routine:
Batch file:
For /r C:Sybex %%f in (c:sybex*.dwg) do start /wait
C:ACAD2012Autocad 2012 - Englishacad.exe "%%f" /b
C:gennotesupdate.scr
View 4 Replies
View Related
Dec 27, 2013
I have a CAD file with a couple hundred detail blocks in it, and I am trying to standardize them without haing to block edit each detail block.
What i am trying to do in each block is as follows:
- Explode all dimensions, leaders, and blocks
- Change all objects to layer "0"
- Change all lineweights to default
- Change all object on colors 7 and bylayer to byblock
- Change all text and mtext to arial font
- Delete all points
Civil 3D x64 2012
Win 7 x64 Ultimate
I7 3820 (3.6ghz quad core with HT)
32gig RAM (Corsair XMS3 4x8g)
Intel x z79 mobo (BOXDX79TO 2011 socket)
Radeon HD 7850 2gb GDDR5
View 3 Replies
View Related
Aug 1, 2013
I have this lisp that grabs all the text(the value and the location) in my drawings and I put them into a list. Here is what I have so far:
(defun c:loop ()
(setq numbers (ssget "_X" (list (cons 0 "TEXT") (cons 1 "##*")) ))
(setq newlist '())
(setq IN 0);set index
(setq SLGTH (sslength numbers))
[code].......
What i need to happen is this: When "whatever" returns "value0" i need to set "value0" to the first item in list "newlist". Then when "whatever" returns "value1" i need to set "value1" to the second item. Now I can do it the long hand way, but i am trying to simplify this step, and shorten up my overall program.
View 4 Replies
View Related
Oct 25, 2013
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.
View 9 Replies
View Related
Feb 28, 2011
(defun CELBLKS ( / e blk ss blkl)
(setq blkl "" ss (ssadd))
(while (setq e (entsel "
[Code]....
i have this lsp, it works great but how can modify it if i want select with a window.? exemple: if i have 3 differentes blocks, i want to select them with windows and the lisp select all blocks that are identical of those 3.?
View 9 Replies
View Related
Jan 24, 2012
I have a project in 3D that I would like to export to Stadd. This requires lines rather than blocks. Is is possible to convert the blocks in the attached dwg file to to lines that are centered on those blocks?
View 9 Replies
View Related
May 7, 2013
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].....
View 3 Replies
View Related
Nov 27, 2012
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))
)
View 9 Replies
View Related
May 15, 2013
In 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 Replies
View Related
Dec 29, 2011
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 Related
Aug 17, 2012
The 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>
View 1 Replies
View Related
Jan 10, 2013
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?
View 3 Replies
View Related
Jun 3, 2013
How to make a lisp command that will select all objects in the drawing?
View 3 Replies
View Related
Mar 13, 2012
I 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?
View 3 Replies
View Related
Jun 25, 2013
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)))
View 9 Replies
View Related
Jan 10, 2012
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?
View 9 Replies
View Related
Jan 28, 2012
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.
View 3 Replies
View Related
Nov 15, 2013
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).
View 9 Replies
View Related
Sep 16, 2013
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?
View 9 Replies
View Related
Mar 13, 2012
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]....
View 2 Replies
View Related
Oct 28, 2011
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.
View 8 Replies
View Related
Jan 11, 2014
I was on an older cad and am now moving to 2014.. my previous cad was heavily customized the old school way, I have decided to learn the CUI (and dynamic blocks)
My old cad has blocks on a drop down menu.. click BATH menu than WC icon, a macro sets the correct layer than inserts the WC.. took time to setup but pretty simple and straight forward (see attached for menu syntax). I also made a toolbar BATH and on that toolbar I made a WC icon.. that’s what I use the most
couple of questions
1) do I have to make a new command in CUI for each block to do the same thing?
2) I looked into the design center, but seems like its too many steps but it seems a toolbar with an icon on it, clicking the icon and a macro sets layer and insert block is still pretty quick..??
3) if a toolbar with an icon is still a fast and less step method, can I open the block and somehow make an icon of it? if so where do I put it?
View 9 Replies
View Related
Apr 12, 2012
I have this code w/ which I can open up Block Library Blocks for editing. We have R2012 installed w/out VBA.Our MIS department is impossible to deal with. We have this new fangled permission hysteria so I cannot install VBA myself.Is there any other way to open up my blocks? What I can I do instead?
(defun CpL () (prompt "...Open Library Block or Xref...")(terpri)
(setq a (entsel)) (setq b (car a )) (setq c (entget b)) (setq d (assoc 2 c))
(setq e (cdr d)) (setq ff (strcat e ".dwg")) (setq PP (findfile FF))
(setq opath (strcat "acadapplication.documents.open ""PP"""))
(command "vbastmt" opath))
View 2 Replies
View Related
Dec 24, 2013
My drawing constitutes of many blocks and other objects , and i need to find specific blocks (with same block name) in my drawing which i cannot find them one by one and i though that i can find them all with lisp routine ..
so , i wanna specify point out of my drawing area and lisp routine will draw to line from basepoint of those blocks to specify point when i select one reference block.
View 4 Replies
View Related
Feb 22, 2012
We've recently converted all our microstation drawings to autocad now that the company has decided to go with one cad program company wide.
One of the issues we are having after getting the drawings back from the this co. converting them is the cells to blocks convertion inside the drawing. when we open a drawing and see a "Fuse" block for instance and if it a has multiple inserts, it named them:
Fuse
Fuse_1
Fuse_2 etc....
is there a lisp routine or some command that would replace the "Fuse_*" blocks with "Fuse"..I've been searching the forums and know about the express tool Replace Block but need to be able to automate somehow.
I thought about trying to rename each of the "Fuse_*" but of course it won't let you rename to a block name that already exists..
View 1 Replies
View Related
Jan 14, 2013
would like to set a base point during insertion of one block.When not insert by AutoLISP, just type "b" to be able to change the base point.
But when I'm using an AutoLISP that inserts a block, it does not work, it interrupts the sequence of routine.
Lisp:
(defun c:carrobox()(setq #clayer (getvar "clayer")) (if (= unidades nil)(setq unidades "cm")).....
View 3 Replies
View Related